base

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2021 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const NotId = int32(-1)

NotId represents an ID doesn't exist.

Variables

This section is empty.

Functions

func BatchParallel added in v0.2.0

func BatchParallel(nJobs, nWorkers, batchSize int, worker func(workerId, beginJobId, endJobId int) error) error

BatchParallel run parallel jobs in batches to reduce the cost of context switch.

func CheckPanic added in v0.2.0

func CheckPanic()

CheckPanic catches panic.

func DateNow added in v0.2.5

func DateNow() time.Time

func Escape added in v0.2.0

func Escape(text string) string

Escape text for csv.

func GetRandomName added in v0.2.0

func GetRandomName(retry int) string

GetRandomName generates a random name from the list of adjectives and surnames in this package formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3`

func Hex added in v0.2.0

func Hex(v int64) string

Hex returns the hex form of a 64-bit integer.

func Logger added in v0.2.0

func Logger() *zap.Logger

Logger get current logger

func Max

func Max(a int32, b ...int32) int32

Max finds the maximum in a vector of integers. Panic if the slice is empty.

func Min

func Min(a int, b ...int) int

Min finds the minimum in a vector of integers. Panic if the slice is empty.

func NewMatrix32 added in v0.2.0

func NewMatrix32(row, col int) [][]float32

NewMatrix32 creates a 2D matrix of 32-bit floats.

func NewMatrixInt

func NewMatrixInt(row, col int) [][]int

NewMatrixInt creates a 2D matrix of integers.

func Now added in v0.2.0

func Now() string

Now returns the current time in the format of `2006-01-02T15:04:05Z07:00`.

func Parallel

func Parallel(nJobs, nWorkers int, worker func(workerId, jobId int) error) error

Parallel schedules and runs tasks in parallel. nTask is the number of tasks. nJob is the number of executors. worker is the executed function which passed a range of task Names (begin, end).

func RangeInt added in v0.2.0

func RangeInt(n int) []int

RangeInt generate a slice [0, ..., n-1].

func ReadLines added in v0.2.0

func ReadLines(sc *bufio.Scanner, sep string, handler func(int, []string) bool) error

ReadLines parse fields of each line for csv file.

func RepeatFloat32s added in v0.2.5

func RepeatFloat32s(n int, value float32) []float32

RepeatFloat32s repeats value n times.

func SetDevelopmentLogger added in v0.2.0

func SetDevelopmentLogger()

SetDevelopmentLogger set current logger in development mode.

func SetProductionLogger added in v0.2.0

func SetProductionLogger()

SetProductionLogger set current logger in production mode.

func ValidateId added in v0.2.0

func ValidateId(text string) error

ValidateId validates user/item id. Id cannot be empty and contain [/,].

func ValidateLabel added in v0.2.0

func ValidateLabel(text string) error

ValidateLabel validates label. Label cannot be empty and contain [/,|].

Types

type DirectIndex added in v0.2.0

type DirectIndex struct {
	Limit int32
}

DirectIndex means that the name and its index is the same. For example, the index of "1" is 1, vice versa.

func NewDirectIndex added in v0.2.0

func NewDirectIndex() *DirectIndex

NewDirectIndex create a direct mapping index.

func (*DirectIndex) Add added in v0.2.0

func (idx *DirectIndex) Add(s string)

Add a name to current index.

func (*DirectIndex) GetNames added in v0.2.0

func (idx *DirectIndex) GetNames() []string

GetNames returns all names in current index.

func (*DirectIndex) Len added in v0.2.0

func (idx *DirectIndex) Len() int32

Len returns the number of names in current index.

func (*DirectIndex) ToName added in v0.2.0

func (idx *DirectIndex) ToName(index int32) string

ToName converts a index to corresponding name.

func (*DirectIndex) ToNumber added in v0.2.0

func (idx *DirectIndex) ToNumber(name string) int32

ToNumber converts a name to corresponding index.

type Floats added in v0.2.6

type Floats struct {
	Data [][]float32
}

func (*Floats) Append added in v0.2.6

func (i *Floats) Append(val float32)

func (*Floats) Get added in v0.2.6

func (i *Floats) Get(index int) float32

func (*Floats) Len added in v0.2.6

func (i *Floats) Len() int

type Index added in v0.2.0

type Index interface {
	Len() int32
	Add(name string)
	ToNumber(name string) int32
	ToName(index int32) string
	GetNames() []string
}

Index keeps the mapping between names (string) and indices (integer).

type Integers added in v0.2.6

type Integers struct {
	Data [][]int32
}

func (*Integers) Append added in v0.2.6

func (i *Integers) Append(val int32)

func (*Integers) Get added in v0.2.6

func (i *Integers) Get(index int) int32

func (*Integers) Len added in v0.2.6

func (i *Integers) Len() int

type MapIndex added in v0.2.0

type MapIndex struct {
	Numbers map[string]int32 // sparse ID -> dense index
	Names   []string         // dense index -> sparse ID
}

MapIndex manages the map between sparse Names and dense indices. A sparse ID is a user ID or item ID. The dense index is the internal user index or item index optimized for faster parameter access and less memory usage.

func NewMapIndex added in v0.2.0

func NewMapIndex() *MapIndex

NewMapIndex creates a MapIndex.

func (*MapIndex) Add added in v0.2.0

func (idx *MapIndex) Add(name string)

Add adds a new ID to the indexer.

func (*MapIndex) GetNames added in v0.2.0

func (idx *MapIndex) GetNames() []string

GetNames returns all names in current index.

func (*MapIndex) Len added in v0.2.0

func (idx *MapIndex) Len() int32

Len returns the number of indexed Names.

func (*MapIndex) ToName added in v0.2.0

func (idx *MapIndex) ToName(index int32) string

ToName converts a dense index to a sparse ID.

func (*MapIndex) ToNumber added in v0.2.0

func (idx *MapIndex) ToNumber(name string) int32

ToNumber converts a sparse ID to a dense index.

type RandomGenerator

type RandomGenerator struct {
	*rand.Rand
}

RandomGenerator is the random generator for gorse.

func NewRandomGenerator

func NewRandomGenerator(seed int64) RandomGenerator

NewRandomGenerator creates a RandomGenerator.

func (RandomGenerator) NewNormalVector

func (rng RandomGenerator) NewNormalVector(size int, mean, stdDev float32) []float32

NewNormalVector makes a vec filled with normal random floats.

func (RandomGenerator) NormalMatrix added in v0.2.0

func (rng RandomGenerator) NormalMatrix(row, col int, mean, stdDev float32) [][]float32

NormalMatrix makes a matrix filled with normal random floats.

func (RandomGenerator) NormalMatrix64 added in v0.2.0

func (rng RandomGenerator) NormalMatrix64(row, col int, mean, stdDev float64) [][]float64

NormalMatrix64 makes a matrix filled with normal random floats.

func (RandomGenerator) NormalVector64 added in v0.2.0

func (rng RandomGenerator) NormalVector64(size int, mean, stdDev float64) []float64

NormalVector64 makes a vec filled with normal random floats.

func (RandomGenerator) Sample added in v0.2.0

func (rng RandomGenerator) Sample(low, high, n int, exclude ...*iset.Set) []int

Sample n values between low and high, but not in exclude.

func (RandomGenerator) SampleInt32 added in v0.2.6

func (rng RandomGenerator) SampleInt32(low, high int32, n int, exclude ...*i32set.Set) []int32

SampleInt32 n 32bit values between low and high, but not in exclude.

func (RandomGenerator) UniformMatrix added in v0.2.0

func (rng RandomGenerator) UniformMatrix(row, col int, low, high float32) [][]float32

UniformMatrix makes a matrix filled with uniform random floats.

func (RandomGenerator) UniformVector added in v0.2.0

func (rng RandomGenerator) UniformVector(size int, low, high float32) []float32

UniformVector makes a vec filled with uniform random floats,

type TopKFilter added in v0.2.0

type TopKFilter struct {
	// contains filtered or unexported fields
}

TopKFilter filters out top k items with maximum weights.

func NewTopKFilter added in v0.2.0

func NewTopKFilter(k int) *TopKFilter

NewTopKFilter creates a top k filter.

func (*TopKFilter) Len added in v0.2.0

func (filter *TopKFilter) Len() int

func (*TopKFilter) Less added in v0.2.0

func (filter *TopKFilter) Less(i, j int) bool

func (*TopKFilter) PopAll added in v0.2.0

func (filter *TopKFilter) PopAll() ([]int32, []float32)

PopAll pops all items in the filter with decreasing order.

func (*TopKFilter) Push added in v0.2.0

func (filter *TopKFilter) Push(item int32, weight float32)

Push pushes the element x onto the heap. The complexity is O(log n) where n = h.Count().

func (*TopKFilter) Swap added in v0.2.0

func (filter *TopKFilter) Swap(i, j int)

type TopKStringFilter added in v0.2.0

type TopKStringFilter struct {
	// contains filtered or unexported fields
}

TopKStringFilter filters out top k strings with maximum weights.

func NewTopKStringFilter added in v0.2.0

func NewTopKStringFilter(k int) *TopKStringFilter

NewTopKStringFilter creates a top k string filter.

func (*TopKStringFilter) Len added in v0.2.0

func (filter *TopKStringFilter) Len() int

func (*TopKStringFilter) Less added in v0.2.0

func (filter *TopKStringFilter) Less(i, j int) bool

func (*TopKStringFilter) PopAll added in v0.2.0

func (filter *TopKStringFilter) PopAll() ([]string, []float32)

PopAll pops all strings in the filter with decreasing order.

func (*TopKStringFilter) Push added in v0.2.0

func (filter *TopKStringFilter) Push(item string, weight float32)

Push pushes the element x onto the heap. The complexity is O(log n) where n = h.Count().

func (*TopKStringFilter) Swap added in v0.2.0

func (filter *TopKStringFilter) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL