Documentation
¶
Index ¶
- Constants
- Variables
- func AddFunc(name string, fun any) error
- func AsFloat64Scalar(tsr Tensor) float64
- func AsFloat64Slice(tsr Tensor) []float64
- func AsIntScalar(tsr Tensor) int
- func AsIntSlice(tsr Tensor) []int
- func AsStringScalar(tsr Tensor) string
- func AsStringSlice(tsr Tensor) []string
- func BoolFloatsFuncOut(fun func(a, b float64) bool, a, b Tensor, out *Bool) error
- func BoolIntsFuncOut(fun func(a, b int) bool, a, b Tensor, out *Bool) error
- func BoolStringsFuncOut(fun func(a, b string) bool, a, b Tensor, out *Bool) error
- func BoolToFloat64(bv bool) float64
- func BoolToInt(bv bool) int
- func Calc(tsr Tensor) error
- func CellsSize(sizes []int) []int
- func ColumnMajorStrides(sizes ...int) []int
- func CompareAscending[T cmp.Ordered](a, b T, ascending bool) int
- func ContainsFloat(tsr, vals Tensor) bool
- func ContainsInt(tsr, vals Tensor) bool
- func ContainsString(tsr, vals Tensor, opts StringMatch) bool
- func CopyFromLargerShape(tsr, from Tensor)
- func DefaultNumThreads() int
- func Float64ToBool(val float64) bool
- func Float64ToString(val float64) string
- func FloatAssignFunc(fun func(a, b float64) float64, a, b Tensor) error
- func FloatBinaryFuncOut(flops int, fun func(a, b float64) float64, a, b Tensor, out Values) error
- func FloatFuncOut(flops int, fun func(in float64) float64, in Tensor, out Values) error
- func FloatPromoteType(tsr ...Tensor) reflect.Kind
- func FloatSetFunc(flops int, fun func(idx int) float64, a Tensor) error
- func IntToBool(val int) bool
- func MustBeSameShape(a, b Tensor) error
- func NFirstLen(tsr ...Tensor) int
- func NFirstRows(tsr ...Tensor) int
- func NMinLen(nt int, tsr ...Tensor) int
- func NegIndex(i, n int) int
- func OpenCSV(tsr Tensor, filename fsx.Filename, delim Delims) error
- func OpenFS(tsr Tensor, fsys fs.FS, filename string, delim Delims) error
- func Precision(obj any) (int, error)
- func Projection2DCoords(shp *Shape, onedRow bool, row, col int) (rowCoords, colCoords []int)
- func Projection2DIndex(shp *Shape, onedRow bool, row, col int) int
- func Projection2DSet(tsr Tensor, onedRow bool, row, col int, val float64)
- func Projection2DSetString(tsr Tensor, onedRow bool, row, col int, val string)
- func Projection2DShape(shp *Shape, onedRow bool) (rows, cols, rowEx, colEx int)
- func Projection2DString(tsr Tensor, onedRow bool, row, col int) string
- func Projection2DValue(tsr Tensor, onedRow bool, row, col int) float64
- func Range(vals Values) (min, max float64, minIndex, maxIndex int)
- func ReadCSV(tsr Tensor, r io.Reader, delim Delims) error
- func RowMajorStrides(sizes ...int) []int
- func SaveCSV(tsr Tensor, filename fsx.Filename, delim Delims) error
- func SetAllFloat64(tsr Tensor, val float64)
- func SetAllInt(tsr Tensor, val int)
- func SetAllString(tsr Tensor, val string)
- func SetCalcFunc(tsr Tensor, fun func() error)
- func SetPrecision(obj any, prec int)
- func SetShape(vals Values, sh *Shape)
- func SetShapeFrom(vals Values, from Tensor)
- func SetShapeNames(md *metadata.Data, names ...string)
- func SetShapeSizesFromTensor(vals Values, sizes Tensor)
- func ShapeNames(md *metadata.Data) []string
- func SplitAtInnerDims(tsr Tensor, nInner int) []int
- func Sprintf(format string, tsr Tensor, maxLen int) string
- func StringAssignFunc(fun func(a, b string) string, a, b Tensor) error
- func StringBinaryFuncOut(fun func(a, b string) string, a, b Tensor, out Values) error
- func StringToFloat64(str string) float64
- func ToBinary(tsr Values) []byte
- func Vectorize(nfun func(tsr ...Tensor) int, fun func(idx int, tsr ...Tensor), tsr ...Tensor)
- func VectorizeOnThreads(threads int, nfun func(tsr ...Tensor) int, fun func(idx int, tsr ...Tensor), ...)
- func VectorizeThreaded(flops int, nfun func(tsr ...Tensor) int, fun func(idx int, tsr ...Tensor), ...)
- func WrapIndex1D(sh *Shape, i ...int) int
- func WriteCSV(tsr Tensor, w io.Writer, delim Delims) error
- type Arg
- type Base
- func (tsr *Base[T]) Bytes() []byte
- func (tsr *Base[T]) DataType() reflect.Kind
- func (tsr *Base[T]) DimSize(dim int) int
- func (tsr *Base[T]) Label() string
- func (tsr *Base[T]) Len() int
- func (tsr *Base[T]) Metadata() *metadata.Data
- func (tsr *Base[T]) NumDims() int
- func (tsr *Base[T]) Set(val T, i ...int)
- func (tsr *Base[T]) Set1D(val T, i int)
- func (tsr *Base[T]) SetFromBytes(b []byte)
- func (tsr *Base[T]) SetNumRows(rows int)
- func (tsr *Base[T]) SetShapeSizes(sizes ...int)
- func (tsr *Base[T]) Shape() *Shape
- func (tsr *Base[T]) ShapeSizes() []int
- func (tsr *Base[T]) Sizeof() int64
- func (tsr *Base[T]) String1D(i int) string
- func (tsr *Base[T]) StringRow(row, cell int) string
- func (tsr *Base[T]) StringValue(i ...int) string
- func (tsr *Base[T]) Value(i ...int) T
- func (tsr *Base[T]) Value1D(i int) T
- func (tsr *Base[T]) ValuePtr(i ...int) *T
- type Bool
- func BoolFloatsFunc(fun func(a, b float64) bool, a, b Tensor) *Bool
- func BoolIntsFunc(fun func(a, b int) bool, a, b Tensor) *Bool
- func BoolStringsFunc(fun func(a, b string) bool, a, b Tensor) *Bool
- func CallOut2Bool(fun func(a, b Tensor, out *Bool) error, a, b Tensor) *Bool
- func NewBool(sizes ...int) *Bool
- func NewBoolFromValues(vals ...bool) *Bool
- func NewBoolShape(shape *Shape) *Bool
- func (tsr *Bool) AppendFrom(frm Values) Values
- func (tsr *Bool) AppendRow(val Values)
- func (tsr *Bool) AppendRowFloat(val ...float64)
- func (tsr *Bool) AppendRowInt(val ...int)
- func (tsr *Bool) AppendRowString(val ...string)
- func (tsr *Bool) AsValues() Values
- func (tsr *Bool) Bool(i ...int) bool
- func (tsr *Bool) Bool1D(off int) bool
- func (tsr *Bool) Bytes() []byte
- func (tsr *Bool) Clone() Values
- func (tsr *Bool) CopyCellsFrom(frm Values, to, start, n int)
- func (tsr *Bool) CopyFrom(frm Values)
- func (tsr *Bool) DataType() reflect.Kind
- func (tsr *Bool) DimSize(dim int) int
- func (tsr *Bool) Float(i ...int) float64
- func (tsr *Bool) Float1D(off int) float64
- func (tsr *Bool) FloatRow(row, cell int) float64
- func (tsr *Bool) Int(i ...int) int
- func (tsr *Bool) Int1D(off int) int
- func (tsr *Bool) IntRow(row, cell int) int
- func (tsr *Bool) IsString() bool
- func (tsr *Bool) Label() string
- func (tsr *Bool) Len() int
- func (tsr *Bool) Metadata() *metadata.Data
- func (tsr *Bool) NumDims() int
- func (tsr *Bool) RowTensor(row int) Values
- func (tsr *Bool) Set(val bool, i ...int)
- func (tsr *Bool) Set1D(val bool, i int)
- func (tsr *Bool) SetBool(val bool, i ...int)
- func (tsr *Bool) SetBool1D(val bool, off int)
- func (tsr *Bool) SetFloat(val float64, i ...int)
- func (tsr *Bool) SetFloat1D(val float64, off int)
- func (tsr *Bool) SetFloatRow(val float64, row, cell int)
- func (tsr *Bool) SetFromBytes(b []byte)
- func (tsr *Bool) SetInt(val int, i ...int)
- func (tsr *Bool) SetInt1D(val int, off int)
- func (tsr *Bool) SetIntRow(val int, row, cell int)
- func (tsr *Bool) SetNumRows(rows int)
- func (tsr *Bool) SetRowTensor(val Values, row int)
- func (tsr *Bool) SetShapeSizes(sizes ...int)
- func (tsr *Bool) SetString(val string, i ...int)
- func (tsr *Bool) SetString1D(val string, off int)
- func (tsr *Bool) SetStringRow(val string, row, cell int)
- func (tsr *Bool) SetTrue()
- func (tsr *Bool) SetZeros()
- func (tsr *Bool) Shape() *Shape
- func (tsr *Bool) ShapeSizes() []int
- func (tsr *Bool) Sizeof() int64
- func (tsr *Bool) String() string
- func (tsr *Bool) String1D(off int) string
- func (tsr *Bool) StringRow(row, cell int) string
- func (tsr *Bool) StringValue(i ...int) string
- func (tsr *Bool) SubSpace(offs ...int) Values
- func (tsr *Bool) Value(i ...int) bool
- func (tsr *Bool) Value1D(i int) bool
- type Byte
- type DataTypes
- type Delims
- func (i Delims) Desc() string
- func (i Delims) Int64() int64
- func (i Delims) MarshalText() ([]byte, error)
- func (dl Delims) Rune() rune
- func (i *Delims) SetInt64(in int64)
- func (i *Delims) SetString(s string) error
- func (i Delims) String() string
- func (i *Delims) UnmarshalText(text []byte) error
- func (i Delims) Values() []enums.Enum
- type FilterFunc
- type Float32
- type Float64
- func AsFloat64(tsr Tensor) *Float64
- func NewFloat64(sizes ...int) *Float64
- func NewFloat64FromValues(vals ...float64) *Float64
- func NewFloat64Full(val float64, sizes ...int) *Float64
- func NewFloat64Ones(sizes ...int) *Float64
- func NewFloat64Rand(sizes ...int) *Float64
- func NewFloat64Scalar(val float64) *Float64
- func NewFloat64SpacedLinear(start, stop Tensor, num int, endpoint bool) *Float64
- type Func
- type Indexed
- func (ix *Indexed) AsValues() Values
- func (ix *Indexed) DataType() reflect.Kind
- func (ix *Indexed) DimSize(dim int) int
- func (ix *Indexed) Float(i ...int) float64
- func (ix *Indexed) Float1D(i int) float64
- func (ix *Indexed) Int(i ...int) int
- func (ix *Indexed) Int1D(i int) int
- func (ix *Indexed) IsString() bool
- func (ix *Indexed) Label() string
- func (ix *Indexed) Len() int
- func (ix *Indexed) Metadata() *metadata.Data
- func (ix *Indexed) NumDims() int
- func (ix *Indexed) SetFloat(val float64, i ...int)
- func (ix *Indexed) SetFloat1D(val float64, i int)
- func (ix *Indexed) SetInt(val int, i ...int)
- func (ix *Indexed) SetInt1D(val int, i int)
- func (ix *Indexed) SetString(val string, i ...int)
- func (ix *Indexed) SetString1D(val string, i int)
- func (ix *Indexed) SetTensor(tsr Tensor)
- func (ix *Indexed) Shape() *Shape
- func (ix *Indexed) ShapeSizes() []int
- func (ix *Indexed) SourceIndexes(i ...int) []int
- func (ix *Indexed) SourceIndexesFrom1D(oned int) []int
- func (ix *Indexed) String() string
- func (ix *Indexed) String1D(i int) string
- func (ix *Indexed) StringValue(i ...int) string
- type Int
- type Int32
- type Masked
- func (ms *Masked) AsValues() Values
- func (ms *Masked) DataType() reflect.Kind
- func (ms *Masked) DimSize(dim int) int
- func (ms *Masked) Filter(filterer func(tsr Tensor, idx int) bool) *Masked
- func (ms *Masked) Float(i ...int) float64
- func (ms *Masked) Float1D(i int) float64
- func (ms *Masked) Int(i ...int) int
- func (ms *Masked) Int1D(i int) int
- func (ms *Masked) IsString() bool
- func (ms *Masked) Label() string
- func (ms *Masked) Len() int
- func (ms *Masked) Metadata() *metadata.Data
- func (ms *Masked) NumDims() int
- func (ms *Masked) SetFloat(val float64, i ...int)
- func (ms *Masked) SetFloat1D(val float64, i int)
- func (ms *Masked) SetInt(val int, i ...int)
- func (ms *Masked) SetInt1D(val int, i int)
- func (ms *Masked) SetString(val string, i ...int)
- func (ms *Masked) SetString1D(val string, i int)
- func (ms *Masked) SetTensor(tsr Tensor)
- func (ms *Masked) Shape() *Shape
- func (ms *Masked) ShapeSizes() []int
- func (ms *Masked) SourceIndexes(getTrue bool) *Int
- func (ms *Masked) String() string
- func (ms *Masked) String1D(i int) string
- func (ms *Masked) StringValue(i ...int) string
- func (ms *Masked) SyncShape()
- type Number
- func (tsr *Number[T]) AppendFrom(frm Values) Values
- func (tsr *Number[T]) AppendRow(val Values)
- func (tsr *Number[T]) AppendRowFloat(val ...float64)
- func (tsr *Number[T]) AppendRowInt(val ...int)
- func (tsr *Number[T]) AppendRowString(val ...string)
- func (tsr *Number[T]) AsValues() Values
- func (tsr *Number[T]) Clone() Values
- func (tsr *Number[T]) CopyCellsFrom(frm Values, to, start, n int)
- func (tsr *Number[T]) CopyFrom(frm Values)
- func (tsr *Number[T]) Float(i ...int) float64
- func (tsr *Number[T]) Float1D(i int) float64
- func (tsr *Number[T]) FloatRow(row, cell int) float64
- func (tsr *Number[T]) Int(i ...int) int
- func (tsr *Number[T]) Int1D(i int) int
- func (tsr *Number[T]) IntRow(row, cell int) int
- func (tsr *Number[T]) IsString() bool
- func (tsr *Number[T]) RowTensor(row int) Values
- func (tsr *Number[T]) SetAdd(val T, i ...int)
- func (tsr *Number[T]) SetDiv(val T, i ...int)
- func (tsr *Number[T]) SetFloat(val float64, i ...int)
- func (tsr *Number[T]) SetFloat1D(val float64, i int)
- func (tsr *Number[T]) SetFloatRow(val float64, row, cell int)
- func (tsr *Number[T]) SetInt(val int, i ...int)
- func (tsr *Number[T]) SetInt1D(val int, i int)
- func (tsr *Number[T]) SetIntRow(val int, row, cell int)
- func (tsr *Number[T]) SetMul(val T, i ...int)
- func (tsr *Number[T]) SetRowTensor(val Values, row int)
- func (tsr *Number[T]) SetString(val string, i ...int)
- func (tsr Number[T]) SetString1D(val string, i int)
- func (tsr *Number[T]) SetStringRow(val string, row, cell int)
- func (tsr *Number[T]) SetSub(val T, i ...int)
- func (tsr *Number[T]) SetZeros()
- func (tsr *Number[T]) String() string
- func (tsr *Number[T]) SubSpace(offs ...int) Values
- type Reshaped
- func (rs *Reshaped) AsValues() Values
- func (rs *Reshaped) DataType() reflect.Kind
- func (rs *Reshaped) DimSize(dim int) int
- func (rs *Reshaped) Float(i ...int) float64
- func (rs *Reshaped) Float1D(i int) float64
- func (rs *Reshaped) Int(i ...int) int
- func (rs *Reshaped) Int1D(i int) int
- func (rs *Reshaped) IsString() bool
- func (rs *Reshaped) Label() string
- func (rs *Reshaped) Len() int
- func (rs *Reshaped) Metadata() *metadata.Data
- func (rs *Reshaped) NumDims() int
- func (rs *Reshaped) SetFloat(val float64, i ...int)
- func (rs *Reshaped) SetFloat1D(val float64, i int)
- func (rs *Reshaped) SetInt(val int, i ...int)
- func (rs *Reshaped) SetInt1D(val int, i int)
- func (rs *Reshaped) SetShapeSizes(sizes ...int) error
- func (rs *Reshaped) SetString(val string, i ...int)
- func (rs *Reshaped) SetString1D(val string, i int)
- func (rs *Reshaped) Shape() *Shape
- func (rs *Reshaped) ShapeSizes() []int
- func (rs *Reshaped) String() string
- func (rs *Reshaped) String1D(i int) string
- func (rs *Reshaped) StringValue(i ...int) string
- type RowMajor
- type Rows
- func (rw *Rows) AddRows(n int)
- func (rw *Rows) AppendRow(val Values)
- func (rw *Rows) AppendRowFloat(val ...float64)
- func (rw *Rows) AppendRowInt(val ...int)
- func (rw *Rows) AppendRowString(val ...string)
- func (rw *Rows) AsValues() Values
- func (rw *Rows) CloneIndexes() *Rows
- func (rw *Rows) CopyIndexes(oix *Rows)
- func (rw *Rows) DataType() reflect.Kind
- func (rw *Rows) DeleteRows(at, n int)
- func (rw *Rows) DimSize(dim int) int
- func (rw *Rows) ExcludeMissing()
- func (rw *Rows) Filter(filterer func(tsr Values, row int) bool)
- func (rw *Rows) FilterString(str string, opts StringMatch)
- func (rw *Rows) Float(i ...int) float64
- func (rw *Rows) Float1D(i int) float64
- func (rw *Rows) FloatRow(row, cell int) float64
- func (rw *Rows) IndexesNeeded()
- func (rw *Rows) InsertRows(at, n int)
- func (rw *Rows) Int(i ...int) int
- func (rw *Rows) Int1D(i int) int
- func (rw *Rows) IntRow(row, cell int) int
- func (rw *Rows) IsString() bool
- func (rw *Rows) Label() string
- func (rw *Rows) Len() int
- func (rw *Rows) Metadata() *metadata.Data
- func (rw *Rows) NumDims() int
- func (rw *Rows) NumRows() int
- func (rw *Rows) Permuted()
- func (rw *Rows) RowCellSize() (rows, cells int)
- func (rw *Rows) RowIndex(idx int) int
- func (rw *Rows) RowTensor(row int) Values
- func (rw *Rows) Sequential()
- func (rw *Rows) SetFloat(val float64, i ...int)
- func (rw *Rows) SetFloat1D(val float64, i int)
- func (rw *Rows) SetFloatRow(val float64, row, cell int)
- func (rw *Rows) SetInt(val int, i ...int)
- func (rw *Rows) SetInt1D(val int, i int)
- func (rw *Rows) SetIntRow(val int, row, cell int)
- func (rw *Rows) SetRowTensor(val Values, row int)
- func (rw *Rows) SetString(val string, i ...int)
- func (rw *Rows) SetString1D(val string, i int)
- func (rw *Rows) SetStringRow(val string, row, cell int)
- func (rw *Rows) SetTensor(tsr Values)
- func (rw *Rows) Shape() *Shape
- func (rw *Rows) ShapeSizes() []int
- func (rw *Rows) Sort(ascending bool)
- func (rw *Rows) SortFunc(cmp func(tsr Values, i, j int) int)
- func (rw *Rows) SortIndexes()
- func (rw *Rows) SortStable(ascending bool)
- func (rw *Rows) SortStableFunc(cmp func(tsr Values, i, j int) int)
- func (rw *Rows) String() string
- func (rw *Rows) String1D(i int) string
- func (rw *Rows) StringRow(row, cell int) string
- func (rw *Rows) StringValue(i ...int) string
- func (rw *Rows) SubSpace(offs ...int) Values
- func (rw *Rows) Swap(i, j int)
- func (rw *Rows) ValidIndexes()
- type Shape
- func AddShapes(shape1, shape2 *Shape) *Shape
- func AlignForAssign(a, b Tensor) (as, bs *Shape, err error)
- func AlignShapes(a, b Tensor) (as, bs, os *Shape, err error)
- func NewShape(sizes ...int) *Shape
- func Projection2DDimShapes(shp *Shape, onedRow bool) (rowShape, colShape *Shape, rowIdxs, colIdxs []int)
- func (sh *Shape) CopyFrom(cp *Shape)
- func (sh *Shape) DimSize(i int) int
- func (sh *Shape) IndexFrom1D(oned int) []int
- func (sh *Shape) IndexIsValid(idx ...int) bool
- func (sh *Shape) IndexTo1D(index ...int) int
- func (sh *Shape) IsEqual(oth *Shape) bool
- func (sh *Shape) Len() int
- func (sh *Shape) NumDims() int
- func (sh *Shape) RowCellSize() (rows, cells int)
- func (sh *Shape) SetShapeSizes(sizes ...int)
- func (sh *Shape) SetShapeSizesFromTensor(sizes Tensor)
- func (sh *Shape) SizesAsTensor() *Int
- func (sh *Shape) String() string
- type Slice
- type Sliced
- func (sl *Sliced) AsValues() Values
- func (sl *Sliced) DataType() reflect.Kind
- func (sl *Sliced) DimSize(dim int) int
- func (sl *Sliced) Filter(dim int, filterer func(tsr Tensor, dim, idx int) bool)
- func (sl *Sliced) Float(i ...int) float64
- func (sl *Sliced) Float1D(i int) float64
- func (sl *Sliced) IndexesNeeded(d int)
- func (sl *Sliced) Int(i ...int) int
- func (sl *Sliced) Int1D(i int) int
- func (sl *Sliced) IsString() bool
- func (sl *Sliced) Label() string
- func (sl *Sliced) Len() int
- func (sl *Sliced) Metadata() *metadata.Data
- func (sl *Sliced) NumDims() int
- func (sl *Sliced) Permuted(dim int)
- func (sl *Sliced) Sequential()
- func (sl *Sliced) SetFloat(val float64, i ...int)
- func (sl *Sliced) SetFloat1D(val float64, i int)
- func (sl *Sliced) SetInt(val int, i ...int)
- func (sl *Sliced) SetInt1D(val int, i int)
- func (sl *Sliced) SetString(val string, i ...int)
- func (sl *Sliced) SetString1D(val string, i int)
- func (sl *Sliced) SetTensor(tsr Tensor)
- func (sl *Sliced) Shape() *Shape
- func (sl *Sliced) ShapeSizes() []int
- func (sl *Sliced) SortFunc(dim int, cmp func(tsr Tensor, i, j int) int)
- func (sl *Sliced) SortIndexes(dim int)
- func (sl *Sliced) SortStableFunc(dim int, cmp func(tsr Tensor, i, j int) int)
- func (sl *Sliced) SourceIndex(dim, idx int) int
- func (sl *Sliced) SourceIndexes(i ...int) []int
- func (sl *Sliced) SourceIndexesFrom1D(oned int) []int
- func (sl *Sliced) String() string
- func (sl *Sliced) String1D(i int) string
- func (sl *Sliced) StringValue(i ...int) string
- func (sl *Sliced) ValidIndexes()
- type SlicesMagic
- func (i SlicesMagic) Desc() string
- func (i SlicesMagic) Int64() int64
- func (i SlicesMagic) MarshalText() ([]byte, error)
- func (i *SlicesMagic) SetInt64(in int64)
- func (i *SlicesMagic) SetString(s string) error
- func (i SlicesMagic) String() string
- func (i *SlicesMagic) UnmarshalText(text []byte) error
- func (i SlicesMagic) Values() []enums.Enum
- type String
- func (tsr *String) AppendFrom(frm Values) Values
- func (tsr *String) AppendRow(val Values)
- func (tsr *String) AppendRowFloat(val ...float64)
- func (tsr *String) AppendRowInt(val ...int)
- func (tsr *String) AppendRowString(val ...string)
- func (tsr *String) AsValues() Values
- func (tsr *String) Bytes() []byte
- func (tsr *String) Clone() Values
- func (tsr *String) CopyCellsFrom(frm Values, to, start, n int)
- func (tsr *String) CopyFrom(frm Values)
- func (tsr *String) Float(i ...int) float64
- func (tsr *String) Float1D(i int) float64
- func (tsr *String) FloatRow(row, cell int) float64
- func (tsr *String) Int(i ...int) int
- func (tsr *String) Int1D(i int) int
- func (tsr *String) IntRow(row, cell int) int
- func (tsr *String) IsString() bool
- func (tsr *String) RowTensor(row int) Values
- func (tsr *String) SetFloat(val float64, i ...int)
- func (tsr *String) SetFloat1D(val float64, i int)
- func (tsr *String) SetFloatRow(val float64, row, cell int)
- func (tsr *String) SetFromBytes(b []byte)
- func (tsr *String) SetInt(val int, i ...int)
- func (tsr *String) SetInt1D(val int, i int)
- func (tsr *String) SetIntRow(val int, row, cell int)
- func (tsr *String) SetRowTensor(val Values, row int)
- func (tsr *String) SetString(val string, i ...int)
- func (tsr *String) SetString1D(val string, i int)
- func (tsr *String) SetStringRow(val string, row, cell int)
- func (tsr *String) SetZeros()
- func (tsr *String) String() string
- func (tsr *String) String1D(i int) string
- func (tsr *String) StringRow(row, cell int) string
- func (tsr *String) SubSpace(offs ...int) Values
- type StringMatch
- type Tensor
- func AnySlice(tsr Tensor, idx ...any) Tensor
- func As1D(tsr Tensor) Tensor
- func Cells1D(tsr Tensor, row int) Tensor
- func FloatBinaryFunc(flops int, fun func(a, b float64) float64, a, b Tensor) Tensor
- func Mask(tsr, mask Tensor) Tensor
- func Reshape(tsr Tensor, sizes ...int) Tensor
- func Reslice(tsr Tensor, sls ...any) Tensor
- func Squeeze(tsr Tensor) Tensor
- func StringBinaryFunc(fun func(a, b string) string, a, b Tensor) Tensor
- func Transpose(tsr Tensor) Tensor
- type Uint32
- type Values
- func CallOut1(fun func(a Tensor, out Values) error, a Tensor) Values
- func CallOut1Float64(fun func(a Tensor, out Values) error, a Tensor) Values
- func CallOut1Gen1[T any](fun func(g T, a Tensor, out Values) error, g T, a Tensor) Values
- func CallOut1Gen2[T any, S any](fun func(g T, h S, a Tensor, out Values) error, g T, h S, a Tensor) Values
- func CallOut2(fun func(a, b Tensor, out Values) error, a, b Tensor) Values
- func CallOut2Float64(fun func(a, b Tensor, out Values) error, a, b Tensor) Values
- func CallOut2Gen1[T any](fun func(g T, a, b Tensor, out Values) error, g T, a, b Tensor) Values
- func CallOut2Gen2[T any, S any](fun func(g T, h S, a, b Tensor, out Values) error, g T, h S, a, b Tensor) Values
- func CallOut3(fun func(a, b, c Tensor, out Values) error, a, b, c Tensor) Values
- func Clone(tsr Tensor) Values
- func Flatten(tsr Tensor) Values
- func FloatFunc(flops int, fun func(in float64) float64, in Tensor) Values
- func FromBinary(b []byte) Values
- func MustBeValues(tsr Tensor) (Values, error)
- func New[T DataTypes](sizes ...int) Values
- func NewFromValues(val ...any) Values
- func NewOfType(typ reflect.Kind, sizes ...int) Values
Constants ¶
const ( // OnedRow is for onedRow arguments to Projection2D functions, // specifies that the 1D case goes along the row. OnedRow = true // OnedColumn is for onedRow arguments to Projection2D functions, // specifies that the 1D case goes along the column. OnedColumn = false )
const ( // Ascending specifies an ascending sort direction for tensor Sort routines Ascending = true // Descending specifies a descending sort direction for tensor Sort routines Descending = false // StableSort specifies using stable, original order-preserving sort, which is slower. StableSort = true // Unstable specifies using faster but unstable sorting. UnstableSort = false )
Variables ¶
var ( // ThreadingThreshod is the threshold in number of flops (floating point ops), // computed as tensor N * flops per element, to engage actual parallel processing. // Heuristically, numbers below this threshold do not result in // an overall speedup, due to overhead costs. See tmath/ops_test.go for benchmark. ThreadingThreshold = 300 // NumThreads is the number of threads to use for parallel threading. // The default of 0 causes the [runtime.GOMAXPROCS] to be used. NumThreads = 0 )
var Funcs map[string]*Func
Funcs is the global tensor named function registry. All functions must have a signature like this: func([opt any,] a, b, out tensor.Tensor) error i.e., taking some specific number of Tensor arguments (up to 5), with the number of output vs. input arguments registered. Functions can also take an 'any' first argument to handle other non-tensor inputs (e.g., function pointer, dirfs directory, etc). This is used to make tensor functions available to the Goal language.
var MaxPrintLineWidth = 80
MaxPrintLineWidth is the maximum line width in characters to generate for tensor Sprintf function.
var MaxSprintLength = 1000
MaxSprintLength is the default maximum length of a String() representation of a tensor, as generated by the Sprint function. Defaults to 1000.
Functions ¶
func AddFunc ¶
AddFunc adds given named function to the global tensor named function registry, which is used by Goal to call functions by name. See NewFunc for more informa.tion.
func AsFloat64Scalar ¶
AsFloat64Scalar returns the first value of tensor as a float64 scalar. Returns 0 if no values.
func AsFloat64Slice ¶
AsFloat64Slice returns all the tensor values as a slice of float64's. This allocates a new slice for the return values, and is not a good option for performance-critical code.
func AsIntScalar ¶
AsIntScalar returns the first value of tensor as an int scalar. Returns 0 if no values.
func AsIntSlice ¶
AsIntSlice returns all the tensor values as a slice of ints. This allocates a new slice for the return values, and is not a good option for performance-critical code.
func AsStringScalar ¶
AsStringScalar returns the first value of tensor as a string scalar. Returns "" if no values.
func AsStringSlice ¶
AsStringSlice returns all the tensor values as a slice of strings. This allocates a new slice for the return values, and is not a good option for performance-critical code.
func BoolFloatsFuncOut ¶
BoolFloatsFuncOut sets boolean output value based on a function involving float64 values from the two tensors.
func BoolIntsFuncOut ¶
BoolIntsFuncOut sets boolean output value based on a function involving int values from the two tensors.
func BoolStringsFuncOut ¶
BoolStringsFuncOut sets boolean output value based on a function involving string values from the two tensors.
func BoolToFloat64 ¶
BoolToFloat64 converts bool to float64 value.
func Calc ¶
Calc calls function set by SetCalcFunc to compute an updated value for given tensor. Returns an error if func not set, or any error from func itself. Function is stored as CalcFunc in Metadata.
func CellsSize ¶
CellsSizes returns the sizes of inner cells dimensions given overall tensor sizes. It returns []int{1} for the 1D case. Used for ensuring cell-wise outputs are the right size.
func ColumnMajorStrides ¶
ColumnMajorStrides returns strides for sizes where the first dimension is inner-most and subsequent dimensions are progressively outer
func CompareAscending ¶
CompareAscending is a sort compare function that reverses direction based on the ascending bool.
func ContainsFloat ¶
ContainsFloat returns true if source tensor contains any of given vals, using Float value method for comparison.
func ContainsInt ¶
ContainsInt returns true if source tensor contains any of given vals, using Int value method for comparison.
func ContainsString ¶
func ContainsString(tsr, vals Tensor, opts StringMatch) bool
ContainsString returns true if source tensor contains any of given vals, using String value method for comparison, and given options for how to compare the strings.
func CopyFromLargerShape ¶ added in v0.1.3
func CopyFromLargerShape(tsr, from Tensor)
CopyFromLargerShape copies values from another tensor of a larger shape, using indexes in this shape. The other tensor must have at least the same or greater shape values on each dimension as the target. Uses float numbers to copy if not a string.
func DefaultNumThreads ¶
func DefaultNumThreads() int
DefaultNumThreads returns the default number of threads to use: NumThreads if non-zero, otherwise runtime.GOMAXPROCS.
func Float64ToBool ¶
Float64ToBool converts float64 value to bool.
func Float64ToString ¶
Float64ToString converts float64 to string value using strconv, g format
func FloatAssignFunc ¶
FloatAssignFunc sets a to a binary function of a and b float64 values.
func FloatBinaryFuncOut ¶
FloatBinaryFuncOut sets output to a binary function of a, b float64 values.
func FloatFuncOut ¶
FloatFuncOut sets output to a function of tensor float64 values.
func FloatPromoteType ¶
FloatPromoteType returns the DataType for Tensor(s) that promotes the Float type if any of the elements are of that type. Otherwise it returns the type of the first tensor.
func FloatSetFunc ¶
FloatSetFunc sets tensor float64 values from a function, which gets the index. Must be parallel threadsafe. The flops (floating point operations) estimate is used to control parallel threading using goroutines, and should reflect number of flops in the function. See VectorizeThreaded for more information.
func MustBeSameShape ¶
MustBeSameShape returns an error if the two tensors do not have the same shape.
func NFirstLen ¶
NFirstLen is an N function for Vectorize that returns the number of elements in the tensor, taking into account the Indexes view.
func NFirstRows ¶
NFirstRows is an N function for Vectorize that returns the number of outer-dimension rows (or Indexes) of the first tensor.
func NMinLen ¶
NMinLen is an N function for Vectorize that returns the min number of elements across given number of tensors in the list. Use a closure to call this with the nt.
func OpenCSV ¶
OpenCSV reads a tensor from a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg), using the Go standard encoding/csv reader conforming to the official CSV standard. Reads all values and assigns as many as fit.
func Precision ¶
Precision gets the "precision" metadata value that determines the precision to use in writing floating point numbers to files. returns an error if not set.
func Projection2DCoords ¶
Projection2DCoords returns the corresponding full-dimensional coordinates that go into the given row, col coords for a 2D projection of the given tensor, collapsing higher dimensions down to 2D (and 1D up to 2D). See Projection2DShape for full info.
func Projection2DIndex ¶
Projection2DIndex returns the flat 1D index for given row, col coords for a 2D projection of the given tensor shape, collapsing higher dimensions down to 2D (and 1D up to 2D). See Projection2DShape for full info.
func Projection2DSet ¶
Projection2DSet sets a float64 value at given row, col coords for a 2D projection of the given tensor, collapsing higher dimensions down to 2D (and 1D up to 2D). See Projection2DShape for full info.
func Projection2DSetString ¶
Projection2DSetString sets a string value at given row, col coords for a 2D projection of the given tensor, collapsing higher dimensions down to 2D (and 1D up to 2D). See Projection2DShape for full info.
func Projection2DShape ¶
Projection2DShape returns the size of a 2D projection of the given tensor Shape, collapsing higher dimensions down to 2D (and 1D up to 2D). For the 1D case, onedRow determines if the values are row-wise or not. Even multiples of inner-most dimensions are placed along the row, odd in the column. If there are an odd number of dimensions, the first dimension is row-wise, and the remaining inner dimensions use the above logic from there, as if it was even. rowEx returns the number of "extra" (outer-dimensional) rows and colEx returns the number of extra cols, to add extra spacing between these dimensions.
func Projection2DString ¶
Projection2DString returns the string value at given row, col coords for a 2D projection of the given tensor, collapsing higher dimensions down to 2D (and 1D up to 2D). See Projection2DShape for full info.
func Projection2DValue ¶
Projection2DValue returns the float64 value at given row, col coords for a 2D projection of the given tensor, collapsing higher dimensions down to 2D (and 1D up to 2D). See Projection2DShape for full info.
func Range ¶
Range returns the min, max (and associated indexes, -1 = no values) for the tensor. This is needed for display and is thus in the tensor api on Values.
func ReadCSV ¶
ReadCSV reads a tensor from a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg), using the Go standard encoding/csv reader conforming to the official CSV standard. Reads all values and assigns as many as fit.
func RowMajorStrides ¶
RowMajorStrides returns strides for sizes where the first dimension is outermost and subsequent dimensions are progressively inner.
func SaveCSV ¶
SaveCSV writes a tensor to a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg). Outer-most dims are rows in the file, and inner-most is column -- Reading just grabs all values and doesn't care about shape.
func SetAllFloat64 ¶
SetAllFloat64 sets all values of given tensor to given value.
func SetAllString ¶
SetAllString sets all values of given tensor to given value.
func SetCalcFunc ¶
SetCalcFunc sets a function to calculate updated value for given tensor, storing the function pointer in the Metadata "CalcFunc" key for the tensor. Can be called by Calc function.
func SetPrecision ¶
SetPrecision sets the "precision" metadata value that determines the precision to use in writing floating point numbers to files.
func SetShapeFrom ¶
SetShapeFrom sets shape of given tensor from a source tensor.
func SetShapeNames ¶
SetShapeNames sets the tensor shape dimension names into given metadata.
func SetShapeSizesFromTensor ¶
SetShapeSizesFromTensor sets the dimension sizes as 1D int values from given tensor. The backing storage is resized appropriately, retaining all existing data that fits.
func ShapeNames ¶
ShapeNames gets the tensor shape dimension names from given metadata.
func SplitAtInnerDims ¶
SplitAtInnerDims returns the sizes of the given tensor's shape with the given number of inner-most dimensions retained as is, and those above collapsed to a single dimension. If the total number of dimensions is < nInner the result is nil.
func Sprintf ¶
Sprintf returns a string representation of the given tensor, with a maximum length of as given: output is terminated when it exceeds that length. If maxLen = 0, MaxSprintLength is used. The format is the per-element format string. If empty it uses general %g for number or %s for string.
func StringAssignFunc ¶
StringAssignFunc sets a to a binary function of a and b string values.
func StringBinaryFuncOut ¶
StringBinaryFuncOut sets output to a binary function of a, b string values.
func StringToFloat64 ¶
StringToFloat64 converts string value to float64 using strconv, returning 0 if any error
func ToBinary ¶ added in v0.1.2
ToBinary returns a binary encoding of the tensor that includes its type, shape and all data. FromBinary makes a tensor from this binary data.
func Vectorize ¶
Vectorize applies given function 'fun' to tensor elements indexed by given index, with the 'nfun' providing the number of indexes to vectorize over, and initializing any output vectors. Thus the nfun is often specific to a particular class of functions. Both functions are called with the same set of Tensors passed as the final argument(s). The role of each tensor is function-dependent: there could be multiple inputs and outputs, and the output could be effectively scalar, as in a sum operation. The interpretation of the index is function dependent as well, but often is used to iterate over the outermost row dimension of the tensor. This version runs purely sequentially on on this go routine. See VectorizeThreaded and VectorizeGPU for other versions.
func VectorizeOnThreads ¶
func VectorizeOnThreads(threads int, nfun func(tsr ...Tensor) int, fun func(idx int, tsr ...Tensor), tsr ...Tensor)
VectorizeOnThreads runs given Vectorize function on given number of threads. Use VectorizeThreaded to only use parallel threads when it is likely to be beneficial, in terms of the ThreadingThreshold. If threads is 0, then the DefaultNumThreads will be used: GOMAXPROCS subject to NumThreads constraint if non-zero.
func VectorizeThreaded ¶
func VectorizeThreaded(flops int, nfun func(tsr ...Tensor) int, fun func(idx int, tsr ...Tensor), tsr ...Tensor)
VectorizeThreaded is a version of Vectorize that will automatically distribute the computation in parallel across multiple "threads" (goroutines) if the number of elements to be computed times the given flops (floating point operations) for the function exceeds the ThreadingThreshold. Heuristically, numbers below this threshold do not result in an overall speedup, due to overhead costs. Each elemental math operation in the function adds a flop. See estimates in [tmath] for basic math functions.
func WrapIndex1D ¶
WrapIndex1D returns the 1d flat index for given n-dimensional index based on given shape, where any singleton dimension sizes cause the resulting index value to remain at 0, effectively causing that dimension to wrap around, while the other tensor is presumably using the full range of the values along this dimension. See AlignShapes for more info.
Types ¶
type Arg ¶
type Arg struct {
// Type has full reflection type info.
Type reflect.Type
// IsTensor is true if it satisfies the Tensor interface.
IsTensor bool
// IsInt is true if Kind = Int, for shape, slice etc params.
IsInt bool
// IsVariadic is true if this is the last arg and has ...; type will be an array.
IsVariadic bool
}
Arg has key information that Goal needs about each arg, for converting expressions into the appropriate type.
type Base ¶
type Base[T any] struct { // Values is a flat 1D slice of the underlying data. Values []T // Meta data is used extensively for Name, Plot styles, etc. // Use standard Go camel-case key names, standards in [metadata]. Meta metadata.Data // contains filtered or unexported fields }
Base is the base Tensor implementation for given type.
func (*Base[T]) DataType ¶
DataType returns the type of the data elements in the tensor. Bool is returned for the Bool tensor type.
func (*Base[T]) Label ¶
Label satisfies the core.Labeler interface for a summary description of the tensor.
func (*Base[T]) Len ¶
Len returns the number of elements in the tensor (product of shape dimensions).
func (*Base[T]) Metadata ¶
Metadata returns the metadata for this tensor, which can be used to encode plotting options, etc.
func (*Base[T]) SetFromBytes ¶ added in v0.1.2
func (*Base[T]) SetNumRows ¶
SetNumRows sets the number of rows (outermost dimension) in a RowMajor organized tensor. It is safe to set this to 0. For incrementally growing tensors (e.g., a log) it is best to first set the anticipated full size, which allocates the full amount of memory, and then set to 0 and grow incrementally.
func (*Base[T]) SetShapeSizes ¶
SetShapeSizes sets the dimension sizes of the tensor, and resizes backing storage appropriately, retaining all existing data that fits.
func (*Base[T]) ShapeSizes ¶
ShapeSizes returns the sizes of each dimension as a slice of ints. The returned slice is a copy and can be modified without side effects.
func (*Base[T]) StringValue ¶
type Bool ¶
type Bool struct {
// Values is a flat 1D slice of the underlying data, using [bitslice].
Values bitslice.Slice
// Meta data is used extensively for Name, Plot styles, etc.
// Use standard Go camel-case key names, standards in [metadata].
Meta metadata.Data
// contains filtered or unexported fields
}
Bool is a tensor of bits backed by a bitslice.Slice for efficient storage of binary, boolean data. Bool does not support [RowMajor.SubSpace] access and related methods due to the nature of the underlying data representation.
func BoolFloatsFunc ¶
BoolFloatsFunc sets boolean output value based on a function involving float64 values from the two tensors.
func BoolIntsFunc ¶
BoolIntsFunc sets boolean output value based on a function involving int values from the two tensors.
func BoolStringsFunc ¶
BoolStringsFunc sets boolean output value based on a function involving string values from the two tensors.
func NewBool ¶
NewBool returns a new n-dimensional tensor of bit values with the given sizes per dimension (shape).
func NewBoolFromValues ¶ added in v0.1.1
NewBoolFromValues returns a new 1-dimensional tensor of given value type initialized directly from the given slice values, which are not copied. The resulting Tensor thus "wraps" the given values.
func NewBoolShape ¶
NewBoolShape returns a new n-dimensional tensor of bit values using given shape.
func (*Bool) AppendFrom ¶
AppendFrom appends values from other tensor into this tensor, which must have the same cell size as this tensor. It uses and optimized implementation if the other tensor is of the same type, and otherwise it goes through appropriate standard type.
func (*Bool) AppendRowFloat ¶
AppendRowFloat not possible with Bool.
func (*Bool) AppendRowInt ¶
AppendRowInt not possible with Bool.
func (*Bool) AppendRowString ¶
AppendRowString not possible with Bool.
func (*Bool) Clone ¶
Clone clones this tensor, creating a duplicate copy of itself with its own separate memory representation of all the values, and returns that as a Tensor (which can be converted into the known type as needed).
func (*Bool) CopyCellsFrom ¶
CopyCellsFrom copies given range of values from other tensor into this tensor, using flat 1D indexes: to = starting index in this Tensor to start copying into, start = starting index on from Tensor to start copying from, and n = number of values to copy. Uses an optimized implementation if the other tensor is of the same type, and otherwise it goes through appropriate standard type.
func (*Bool) CopyFrom ¶
CopyFrom copies all avail values from other tensor into this tensor, with an optimized implementation if the other tensor is of the same type, and otherwise it goes through appropriate standard type.
func (*Bool) DataType ¶
DataType returns the type of the data elements in the tensor. Bool is returned for the Bool tensor type.
func (*Bool) Label ¶
Label satisfies the core.Labeler interface for a summary description of the tensor
func (*Bool) Metadata ¶
Metadata returns the metadata for this tensor, which can be used to encode plotting options, etc.
func (*Bool) SetFloat1D ¶
func (*Bool) SetFloatRow ¶
func (*Bool) SetFromBytes ¶ added in v0.1.2
func (*Bool) SetNumRows ¶
SetNumRows sets the number of rows (outermost dimension) in a RowMajor organized tensor. It is safe to set this to 0. For incrementally growing tensors (e.g., a log) it is best to first set the anticipated full size, which allocates the full amount of memory, and then set to 0 and grow incrementally.
func (*Bool) SetRowTensor ¶
SetRowTensor not possible with Bool.
func (*Bool) SetShapeSizes ¶
func (*Bool) SetString1D ¶
func (*Bool) SetStringRow ¶
func (*Bool) SetTrue ¶
func (tsr *Bool) SetTrue()
SetTrue is simple convenience function initialize all values to 0
func (*Bool) SetZeros ¶
func (tsr *Bool) SetZeros()
SetZeros is a convenience function initialize all values to 0 (false).
func (*Bool) ShapeSizes ¶
ShapeSizes returns the sizes of each dimension as a slice of ints. The returned slice is a copy and can be modified without side effects.
func (*Bool) StringValue ¶
type DataTypes ¶
type DataTypes interface {
string | bool | float32 | float64 | int | int64 | uint64 | int32 | uint32 | byte
}
DataTypes are the primary tensor data types with specific support. Any numerical type can also be used. bool is represented using an efficient bit slice.
type Delims ¶
type Delims int32 //enums:enum
Delim are standard CSV delimiter options (Tab, Comma, Space)
const ( // Tab is the tab rune delimiter, for TSV tab separated values Tab Delims = iota // Comma is the comma rune delimiter, for CSV comma separated values Comma // Space is the space rune delimiter, for SSV space separated value Space // Detect is used during reading a file -- reads the first line and detects tabs or commas Detect )
const DelimsN Delims = 4
DelimsN is the highest valid value for type Delims, plus one.
func DelimsValues ¶
func DelimsValues() []Delims
DelimsValues returns all possible values for the type Delims.
func (Delims) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Delims) SetString ¶
SetString sets the Delims value from its string representation, and returns an error if the string is invalid.
func (*Delims) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type FilterFunc ¶
FilterFunc is a function used for filtering that returns true if Tensor row should be included in the current filtered view of the tensor, and false if it should be removed.
type Float32 ¶
Float32 is an alias for Number[float32].
func AsFloat32 ¶
AsFloat32 returns the tensor as a Float32 tensor. If already is a Float32, it is returned as such. Otherwise, a new Float32 tensor is created and values are copied.
func NewFloat32 ¶
NewFloat32 returns a new Float32 tensor with the given sizes per dimension (shape).
func NewFloat32FromValues ¶
NewFloat32FromValues returns a new 1-dimensional tensor of given value type initialized directly from the given slice values, which are not copied. The resulting Tensor thus "wraps" the given values.
func NewFloat32Scalar ¶
NewFloat32Scalar is a convenience method for a Tensor representation of a single float32 scalar value.
type Float64 ¶
Float64 is an alias for Number[float64].
func AsFloat64 ¶
AsFloat64 returns the tensor as a Float64 tensor. If already is a Float64, it is returned as such. Otherwise, a new Float64 tensor is created and values are copied. Use this function for interfacing with gonum or other apis that only operate on float64 types.
func NewFloat64 ¶
NewFloat64 returns a new Float64 tensor with the given sizes per dimension (shape).
func NewFloat64FromValues ¶
NewFloat64FromValues returns a new 1-dimensional tensor of given value type initialized directly from the given slice values, which are not copied. The resulting Tensor thus "wraps" the given values.
func NewFloat64Full ¶
NewFloat64Full returns a new tensor full of given scalar value, of given shape sizes.
func NewFloat64Ones ¶
NewFloat64Ones returns a new tensor full of 1s, of given shape sizes.
func NewFloat64Rand ¶
NewFloat64Rand returns a new tensor full of random numbers from global random source, of given shape sizes.
func NewFloat64Scalar ¶
NewFloat64Scalar is a convenience method for a Tensor representation of a single float64 scalar value.
func NewFloat64SpacedLinear ¶
NewFloat64SpacedLinear returns a new Float64 tensor with num linearly spaced numbers between start and stop values, as tensors, which must be the same length and determine the cell shape of the output. If num is 0, then a default of 50 is used. If endpoint = true, then the stop value is _inclusive_, i.e., it will be the final value, otherwise it is exclusive. This corresponds to the NumPy linspace function.
type Func ¶
type Func struct {
// Name is the original CamelCase Go name for function
Name string
// Fun is the function, which must _only_ take some number of Tensor
// args, with an optional any first arg.
Fun any
// Args has parsed information about the function args, for Goal.
Args []*Arg
}
Func represents a registered tensor function, which has In number of input Tensor arguments, and Out number of output arguments (typically 1). There can also be an 'any' first argument to support other kinds of parameters. This is used to make tensor functions available to the Goal language.
func FuncByName ¶
FuncByName finds function of given name in the registry, returning an error if the function name has not been registered.
func NewFunc ¶
NewFunc creates a new Func desciption of the given function, which must have a signature like this: func([opt any,] a, b, out tensor.Tensor) error i.e., taking some specific number of Tensor arguments (up to 5). Functions can also take an 'any' first argument to handle other non-tensor inputs (e.g., function pointer, dirfs directory, etc). The name should be a standard 'package.FuncName' qualified, exported CamelCase name, with 'out' indicating the number of output arguments, and an optional arg indicating an 'any' first argument. The remaining arguments in the function (automatically determined) are classified as input arguments.
type Indexed ¶
type Indexed struct {
// Tensor source that we are an indexed view onto.
Tensor Tensor
// Indexes is the list of indexes into the source tensor,
// with the innermost dimension providing the index values
// (size = number of dimensions in the source tensor), and
// the remaining outer dimensions determine the shape
// of this [Indexed] tensor view.
Indexes *Int
}
Indexed provides an arbitrarily indexed view onto another "source" Tensor with each index value providing a full n-dimensional index into the source. The shape of this view is determined by the shape of the [Indexed.Indexes] tensor up to the final innermost dimension, which holds the index values. Thus the innermost dimension size of the indexes is equal to the number of dimensions in the source tensor. Given the essential role of the indexes in this view, it is not usable without the indexes. This view is not memory-contiguous and does not support the RowMajor interface or efficient access to inner-dimensional subspaces. To produce a new concrete Values that has raw data actually organized according to the indexed order (i.e., the copy function of numpy), call Indexed.AsValues.
func AsIndexed ¶
AsIndexed returns the tensor as a Indexed view, if it is one. Otherwise, it returns nil; there is no usable "null" Indexed view.
func NewIndexed ¶
NewIndexed returns a new Indexed view of given tensor, with tensor of indexes into the source tensor.
func (*Indexed) AsValues ¶
AsValues returns a copy of this tensor as raw Values. This "renders" the Indexed view into a fully contiguous and optimized memory representation of that view, which will be faster to access for further processing, and enables all the additional functionality provided by the Values interface.
func (*Indexed) Float ¶
Float returns the value of given index as a float64. The indexes are indirected through the [Indexed.Indexes].
func (*Indexed) Float1D ¶
Float1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Indexed) Int ¶
Int returns the value of given index as an int. The indexes are indirected through the [Indexed.Indexes].
func (*Indexed) Int1D ¶
Int1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Indexed) SetFloat ¶
SetFloat sets the value of given index as a float64 The indexes are indirected through the [Indexed.Indexes].
func (*Indexed) SetFloat1D ¶
SetFloat1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Indexed) SetInt ¶
SetInt sets the value of given index as an int The indexes are indirected through the [Indexed.Indexes].
func (*Indexed) SetInt1D ¶
SetInt1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Indexed) SetString ¶
SetString sets the value of given index as a string The indexes are indirected through the [Indexed.Indexes].
func (*Indexed) SetString1D ¶
SetString1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Indexed) SetTensor ¶
SetTensor sets as indexes into given tensor with sequential initial indexes.
func (*Indexed) ShapeSizes ¶
func (*Indexed) SourceIndexes ¶
SourceIndexes returns the actual indexes into underlying source tensor based on given list of indexes into the [Indexed.Indexes] tensor, _excluding_ the final innermost dimension.
func (*Indexed) SourceIndexesFrom1D ¶
SourceIndexesFrom1D returns the full indexes into source tensor based on the given 1d index, which is based on the outer dimensions, excluding the final innermost dimension.
func (*Indexed) String1D ¶
String1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Indexed) StringValue ¶
StringValue returns the value of given index as a string. The indexes are indirected through the [Indexed.Indexes].
type Int ¶
Int is an alias for Number[int].
func AsInt ¶
AsInt returns the tensor as a Int tensor. If already is a Int, it is returned as such. Otherwise, a new Int tensor is created and values are copied.
func NewIntFromValues ¶
NewIntFromValues returns a new 1-dimensional tensor of given value type initialized directly from the given slice values, which are not copied. The resulting Tensor thus "wraps" the given values.
func NewIntFull ¶
NewIntFull returns a new tensor full of given scalar value, of given shape sizes.
func NewIntRange ¶
NewIntRange returns a new Int Tensor with given Slice range parameters, with the same semantics as NumPy arange based on the number of arguments passed:
- 1 = stop
- 2 = start, stop
- 3 = start, stop, step
func NewIntScalar ¶
NewIntScalar is a convenience method for a Tensor representation of a single int scalar value.
type Masked ¶
type Masked struct {
// Tensor source that we are a masked view onto.
Tensor Tensor
// Bool tensor with same shape as source tensor, providing mask.
Mask *Bool
}
Masked is a filtering wrapper around another "source" Tensor, that provides a bit-masked view onto the Tensor defined by a Bool Values tensor with a matching shape. If the bool mask has a 'false' then the corresponding value cannot be Set, and Float access returns NaN indicating missing data (other type access returns the zero value). A new Masked view defaults to a full transparent view of the source tensor. To produce a new Values tensor with only the 'true' cases, (i.e., the copy function of numpy), call Masked.AsValues.
func AsMasked ¶
AsMasked returns the tensor as a Masked view. If it already is one, then it is returned, otherwise it is wrapped with an initially fully transparent mask.
func NewMasked ¶
NewMasked returns a new Masked view of given tensor, with given Bool mask values. If no mask is provided, a default full transparent (all bool values = true) mask is used.
func (*Masked) AsValues ¶
AsValues returns a copy of this tensor as raw Values. This "renders" the Masked view into a fully contiguous and optimized memory representation of that view. Because the masking pattern is unpredictable, only a 1D shape is possible.
func (*Masked) Filter ¶
Filter sets the mask values using given Filter function. The filter function gets the 1D index into the source tensor.
func (*Masked) SetFloat1D ¶
func (*Masked) SetInt1D ¶
SetInt1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Masked) SetString1D ¶
func (*Masked) SetTensor ¶
SetTensor sets the given source tensor. If the shape does not match the current Mask, then a new transparent mask is established.
func (*Masked) ShapeSizes ¶
func (*Masked) SourceIndexes ¶
SourceIndexes returns a flat Int tensor of the mask values that match the given getTrue argument state. These can be used as indexes in the Indexed view, for example. The resulting tensor is 2D with inner dimension = number of source tensor dimensions, to hold the indexes, and outer dimension = number of indexes.
func (*Masked) StringValue ¶
type Number ¶
Number is a tensor of numerical values
func NewNumber ¶
NewNumber returns a new n-dimensional tensor of numerical values with the given sizes per dimension (shape).
func NewNumberFromValues ¶
NewNumberFromValues returns a new 1-dimensional tensor of given value type initialized directly from the given slice values, which are not copied. The resulting Tensor thus "wraps" the given values.
func NewNumberShape ¶
NewNumberShape returns a new n-dimensional tensor of numerical values using given shape.
func (*Number[T]) AppendFrom ¶
AppendFrom appends values from other tensor into this tensor, which must have the same cell size as this tensor. It uses and optimized implementation if the other tensor is of the same type, and otherwise it goes through appropriate standard type.
func (*Number[T]) AppendRowFloat ¶
AppendRowFloat adds a row and sets float value(s), up to number of cells.
func (*Number[T]) AppendRowInt ¶
AppendRowInt adds a row and sets int value(s), up to number of cells.
func (*Number[T]) AppendRowString ¶
AppendRowString adds a row and sets string value(s), up to number of cells.
func (*Number[T]) Clone ¶
Clone clones this tensor, creating a duplicate copy of itself with its own separate memory representation of all the values.
func (*Number[T]) CopyCellsFrom ¶
CopyCellsFrom copies given range of values from other tensor into this tensor, using flat 1D indexes: to = starting index in this Tensor to start copying into, start = starting index on from Tensor to start copying from, and n = number of values to copy. Uses an optimized implementation if the other tensor is of the same type, and otherwise it goes through appropriate standard type.
func (*Number[T]) CopyFrom ¶
CopyFrom copies all avail values from other tensor into this tensor, with an optimized implementation if the other tensor is of the same type, and otherwise it goes through appropriate standard type.
func (*Number[T]) RowTensor ¶
RowTensor is a convenience version of [RowMajor.SubSpace] to return the SubSpace for the outermost row dimension. Rows defines a version of this that indirects through the row indexes.
func (*Number[T]) SetFloat1D ¶
func (*Number[T]) SetFloatRow ¶
func (*Number[T]) SetRowTensor ¶
SetRowTensor sets the values of the SubSpace at given row to given values.
func (Number[T]) SetString1D ¶
func (*Number[T]) SetStringRow ¶
func (*Number[T]) SetZeros ¶
func (tsr *Number[T]) SetZeros()
SetZeros is simple convenience function initialize all values to 0
func (*Number[T]) SubSpace ¶
SubSpace returns a new tensor with innermost subspace at given offset(s) in outermost dimension(s) (len(offs) < NumDims). The new tensor points to the values of the this tensor (i.e., modifications will affect both), as its Values slice is a view onto the original (which is why only inner-most contiguous supsaces are supported). Use AsValues() method to separate the two.
type Reshaped ¶
type Reshaped struct {
// Tensor source that we are a masked view onto.
Tensor Tensor
// Reshape is the effective shape we use for access.
// This must have the same Len() as the source Tensor.
Reshape Shape
}
Reshaped is a reshaping wrapper around another "source" Tensor, that provides a length-preserving reshaped view onto the source Tensor. Reshaping by adding new size=1 dimensions (via NewAxis value) is often important for properly aligning two tensors in a computationally compatible manner; see the AlignShapes function. Reshaped.AsValues on this view returns a new Values with the view shape, calling Clone on the source tensor to get the values.
func AsReshaped ¶
AsReshaped returns the tensor as a Reshaped view. If it already is one, then it is returned, otherwise it is wrapped with an initial shape equal to the source tensor.
func NewReshaped ¶
NewReshaped returns a new Reshaped view of given tensor, with given shape sizes. If no such sizes are provided, the source shape is used. A single -1 value can be used to automatically specify the remaining tensor length, as long as the other sizes are an even multiple of the total length. A single -1 returns a 1D view of the entire tensor.
func NewRowCellsView ¶
NewRowCellsView returns a 2D Reshaped view onto the given tensor, with a single outer "row" dimension and a single inner "cells" dimension, with the given 'split' dimension specifying where the cells start. All dimensions prior to split are collapsed to form the new outer row dimension, and the remainder are collapsed to form the 1D cells dimension. This is useful for stats, metrics and other packages that operate on data in this shape.
func (*Reshaped) AsValues ¶
AsValues returns a copy of this tensor as raw Values, with the same shape as our view. This calls Clone on the source tensor to get the Values and then sets our shape sizes to it.
func (*Reshaped) SetFloat1D ¶
func (*Reshaped) SetShapeSizes ¶
SetShapeSizes sets our shape sizes to the given values, which must result in the same length as the source tensor. An error is returned if not. If a different subset of content is desired, use another view such as Sliced. Note that any number of size = 1 dimensions can be added without affecting the length, and the NewAxis value can be used to semantically indicate when such a new dimension is being inserted. This is often useful for aligning two tensors to achieve a desired computation; see AlignShapes function. A single -1 can be used to specify a dimension size that takes the remaining length, as long as the other sizes are an even multiple of the length. A single -1 indicates to use the full length.
func (*Reshaped) SetString1D ¶
func (*Reshaped) ShapeSizes ¶
func (*Reshaped) StringValue ¶
type RowMajor ¶
type RowMajor interface {
Tensor
// SubSpace returns a new tensor with innermost subspace at given
// offset(s) in outermost dimension(s) (len(offs) < [NumDims]).
// The new tensor points to the values of the this tensor (i.e., modifications
// will affect both), as its Values slice is a view onto the original (which
// is why only inner-most contiguous supsaces are supported).
// Use AsValues() method to separate the two. See [Slice] function to
// extract arbitrary subspaces along ranges of each dimension.
SubSpace(offs ...int) Values
// RowTensor is a convenience version of [RowMajor.SubSpace] to return the
// SubSpace for the outermost row dimension. [Rows] defines a version
// of this that indirects through the row indexes.
RowTensor(row int) Values
// SetRowTensor sets the values of the [RowMajor.SubSpace] at given row to given values.
SetRowTensor(val Values, row int)
// AppendRow adds a row and sets values to given values.
AppendRow(val Values)
// FloatRow returns the value at given row and cell, where row is the outermost
// dimension, and cell is a 1D index into remaining inner dimensions (0 for scalar).
FloatRow(row, cell int) float64
// SetFloatRow sets the value at given row and cell, where row is the outermost
// dimension, and cell is a 1D index into remaining inner dimensions.
SetFloatRow(val float64, row, cell int)
// AppendRowFloat adds a row and sets float value(s), up to number of cells.
AppendRowFloat(val ...float64)
// IntRow returns the value at given row and cell, where row is the outermost
// dimension, and cell is a 1D index into remaining inner dimensions.
IntRow(row, cell int) int
// SetIntRow sets the value at given row and cell, where row is the outermost
// dimension, and cell is a 1D index into remaining inner dimensions.
SetIntRow(val int, row, cell int)
// AppendRowInt adds a row and sets int value(s), up to number of cells.
AppendRowInt(val ...int)
// StringRow returns the value at given row and cell, where row is the outermost
// dimension, and cell is a 1D index into remaining inner dimensions.
// [Rows] tensors index along the row, and use this interface extensively.
// This is useful for lists of patterns, and the [table.Table] container.
StringRow(row, cell int) string
// SetStringRow sets the value at given row and cell, where row is the outermost
// dimension, and cell is a 1D index into remaining inner dimensions.
// [Rows] tensors index along the row, and use this interface extensively.
// This is useful for lists of patterns, and the [table.Table] container.
SetStringRow(val string, row, cell int)
// AppendRowString adds a row and sets string value(s), up to number of cells.
AppendRowString(val ...string)
}
RowMajor is subtype of Tensor that maintains a row major memory organization that thereby supports efficient access via the outermost 'row' dimension, with all remaining inner dimensions comprising the 'cells' of data per row (1 scalar value in the case of a 1D tensor). It is implemented by raw Values tensors, and the Rows indexed view of raw Values tensors. Other views however do not retain the underlying outer to inner row major memory structure and thus do not implement this interface.
type Rows ¶
type Rows struct {
// Tensor source that we are an indexed view onto.
// Note that this must be a concrete [Values] tensor, to enable efficient
// [RowMajor] access and subspace functions.
Tensor Values
// Indexes are the indexes into Tensor rows, with nil = sequential.
// Only set if order is different from default sequential order.
// Use the [Rows.RowIndex] method for nil-aware logic.
Indexes []int
}
Rows is a row-indexed wrapper view around a Values Tensor that allows arbitrary row-wise ordering and filtering according to the [Rows.Indexes]. Sorting and filtering a tensor along this outermost row dimension only requires updating the indexes while leaving the underlying Tensor alone. Unlike the more general Sliced view, Rows maintains memory contiguity for the inner dimensions ("cells") within each row, and supports the RowMajor interface, with the [Set]FloatRow[Cell] methods providing efficient access. Use Rows.AsValues to obtain a concrete Values representation with the current row sorting.
func AsRows ¶
AsRows returns the tensor as a Rows view. If it already is one, then it is returned, otherwise a new Rows is created to wrap around the given tensor, which is enforced to be a Values tensor either because it already is one, or by calling [Tensor.AsValues] on it.
func NewRows ¶
NewRows returns a new Rows view of given tensor, with optional list of indexes (none / nil = sequential).
func (*Rows) AddRows ¶
AddRows adds n rows to end of underlying Tensor, and to the indexes in this view
func (*Rows) AppendRowFloat ¶
AppendRowFloat adds a row and sets float value(s), up to number of cells.
func (*Rows) AppendRowInt ¶
AppendRowInt adds a row and sets int value(s), up to number of cells.
func (*Rows) AppendRowString ¶
AppendRowString adds a row and sets string value(s), up to number of cells.
func (*Rows) AsValues ¶
AsValues returns this tensor as raw Values. If the row [Rows.Indexes] are nil, then the wrapped Values tensor is returned. Otherwise, it "renders" the Rows view into a fully contiguous and optimized memory representation of that view, which will be faster to access for further processing, and enables all the additional functionality provided by the Values interface.
func (*Rows) CloneIndexes ¶
CloneIndexes returns a copy of the current Rows view with new indexes, with a pointer to the same underlying Tensor as the source.
func (*Rows) CopyIndexes ¶
CopyIndexes copies indexes from other Rows view.
func (*Rows) DeleteRows ¶
DeleteRows deletes n rows of indexes starting at given index in the list of indexes
func (*Rows) DimSize ¶
DimSize returns size of given dimension, returning NumRows() for first dimension.
func (*Rows) ExcludeMissing ¶
func (rw *Rows) ExcludeMissing()
ExcludeMissing deletes indexes where the values are missing, as indicated by NaN. Uses first cell of higher dimensional data.
func (*Rows) Filter ¶
Filter filters the indexes using given Filter function. The Filter function operates directly on row numbers into the Tensor as these row numbers have already been projected through the indexes.
func (*Rows) FilterString ¶
func (rw *Rows) FilterString(str string, opts StringMatch)
FilterString filters the indexes using string values compared to given string. Includes rows with matching values unless the Exclude option is set. If Contains option is set, it only checks if row contains string; if IgnoreCase, ignores case, otherwise filtering is case sensitive. Uses first cell of higher dimensional data.
func (*Rows) Float ¶
Float returns the value of given index as a float64. The first index value is indirected through the indexes.
func (*Rows) Float1D ¶
Float1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Rows) FloatRow ¶
FloatRow returns the value at given row and cell, where row is outermost dim, and cell is 1D index into remaining inner dims. Row is indirected through the [Rows.Indexes]. This is the preferred interface for all Rows operations.
func (*Rows) IndexesNeeded ¶
func (rw *Rows) IndexesNeeded()
IndexesNeeded is called prior to an operation that needs actual indexes, e.g., Sort, Filter. If Indexes == nil, they are set to all rows, otherwise current indexes are left as is. Use Sequential, then IndexesNeeded to ensure all rows are represented.
func (*Rows) InsertRows ¶
InsertRows adds n rows to end of underlying Tensor, and to the indexes starting at given index in this view
func (*Rows) Int ¶
Int returns the value of given index as an int. The first index value is indirected through the indexes.
func (*Rows) Int1D ¶
Int1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Rows) IntRow ¶
IntRow returns the value at given row and cell, where row is outermost dim, and cell is 1D index into remaining inner dims. Row is indirected through the [Rows.Indexes]. This is the preferred interface for all Rows operations.
func (*Rows) Len ¶
Len returns the total number of elements in the tensor, taking into account the Indexes via Rows, as NumRows() * cell size.
func (*Rows) NumRows ¶
NumRows returns the effective number of rows in this Rows view, which is the length of the index list or number of outer rows dimension of tensor if no indexes (full sequential view).
func (*Rows) Permuted ¶
func (rw *Rows) Permuted()
Permuted sets indexes to a permuted order. If indexes already exist then existing list of indexes is permuted, otherwise a new set of permuted indexes are generated
func (*Rows) RowCellSize ¶
RowCellSize returns the size of the outermost Row shape dimension (via Rows.NumRows method), and the size of all the remaining inner dimensions (the "cell" size).
func (*Rows) RowIndex ¶
RowIndex returns the actual index into underlying tensor row based on given index value. If Indexes == nil, index is passed through.
func (*Rows) RowTensor ¶
RowTensor is a convenience version of Rows.SubSpace to return the SubSpace for the outermost row dimension, indirected through the indexes.
func (*Rows) Sequential ¶
func (rw *Rows) Sequential()
Sequential sets Indexes to nil, resulting in sequential row-wise access into tensor.
func (*Rows) SetFloat ¶
SetFloat sets the value of given index as a float64 The first index value is indirected through the [Rows.Indexes].
func (*Rows) SetFloat1D ¶
SetFloat1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Rows) SetFloatRow ¶
SetFloatRow sets the value at given row and cell, where row is outermost dim, and cell is 1D index into remaining inner dims. Row is indirected through the [Rows.Indexes]. This is the preferred interface for all Rows operations.
func (*Rows) SetInt ¶
SetInt sets the value of given index as an int The first index value is indirected through the [Rows.Indexes].
func (*Rows) SetInt1D ¶
SetInt1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Rows) SetIntRow ¶
SetIntRow sets the value at given row and cell, where row is outermost dim, and cell is 1D index into remaining inner dims. Row is indirected through the [Rows.Indexes]. This is the preferred interface for all Rows operations.
func (*Rows) SetRowTensor ¶
SetRowTensor sets the values of the SubSpace at given row to given values, with row indirected through the indexes.
func (*Rows) SetString ¶
SetString sets the value of given index as a string The first index value is indirected through the [Rows.Indexes].
func (*Rows) SetString1D ¶
SetString1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Rows) SetStringRow ¶
SetStringRow sets the value at given row and cell, where row is outermost dim, and cell is 1D index into remaining inner dims. Row is indirected through the [Rows.Indexes]. This is the preferred interface for all Rows operations.
func (*Rows) SetTensor ¶
SetTensor sets as indexes into given Values tensor with sequential initial indexes.
func (*Rows) Shape ¶
Shape() returns a Shape representation of the tensor shape (dimension sizes). If we have Indexes, this is the effective shape using the current number of indexes as the outermost row dimension size.
func (*Rows) ShapeSizes ¶
If we have Indexes, this is the effective shape sizes using the current number of indexes as the outermost row dimension size.
func (*Rows) Sort ¶
Sort does default alpha or numeric sort of row-wise data. Uses first cell of higher dimensional data.
func (*Rows) SortFunc ¶
SortFunc sorts the row-wise indexes using given compare function. The compare function operates directly on row numbers into the Tensor as these row numbers have already been projected through the indexes. cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
func (*Rows) SortIndexes ¶
func (rw *Rows) SortIndexes()
SortIndexes sorts the indexes into our Tensor directly in numerical order, producing the native ordering, while preserving any filtering that might have occurred.
func (*Rows) SortStable ¶
SortStable does stable default alpha or numeric sort. Uses first cell of higher dimensional data.
func (*Rows) SortStableFunc ¶
SortStableFunc stably sorts the row-wise indexes using given compare function. The compare function operates directly on row numbers into the Tensor as these row numbers have already been projected through the indexes. cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b. It is *essential* that it always returns 0 when the two are equal for the stable function to actually work.
func (*Rows) String1D ¶
String1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Rows) StringRow ¶
StringRow returns the value at given row and cell, where row is outermost dim, and cell is 1D index into remaining inner dims. Row is indirected through the [Rows.Indexes]. This is the preferred interface for all Rows operations.
func (*Rows) StringValue ¶
StringValue returns the value of given index as a string. The first index value is indirected through the indexes.
func (*Rows) SubSpace ¶
SubSpace returns a new tensor with innermost subspace at given offset(s) in outermost dimension(s) (len(offs) < NumDims). The new tensor points to the values of the this tensor (i.e., modifications will affect both), as its Values slice is a view onto the original (which is why only inner-most contiguous supsaces are supported). Use Clone() method to separate the two. Rows version does indexed indirection of the outermost row dimension of the offsets.
func (*Rows) ValidIndexes ¶
func (rw *Rows) ValidIndexes()
ValidIndexes deletes all invalid indexes from the list. Call this if rows (could) have been deleted from tensor.
type Shape ¶
type Shape struct {
// size per dimension.
Sizes []int
// offsets for each dimension.
Strides []int `display:"-"`
}
Shape manages a tensor's shape information, including sizes and strides, and can compute the flat index into an underlying 1D data storage array based on an n-dimensional index (and vice-versa). Per Go / C / Python conventions, indexes are Row-Major, ordered from outer to inner left-to-right, so the inner-most is right-most.
func AlignForAssign ¶
AlignForAssign ensures that the shapes of two tensors, a and b have the proper alignment for assigning b into a. Alignment proceeds from the innermost dimension out, with 1s provided beyond the number of dimensions for a or b. An error is returned if the rules of alignment are violated: each dimension size must be either the same, or b is equal to 1. This corresponds to the "broadcasting" logic of NumPy.
func AlignShapes ¶
AlignShapes aligns the shapes of two tensors, a and b for a binary computation producing an output, returning the effective aligned shapes for a, b, and the output, all with the same number of dimensions. Alignment proceeds from the innermost dimension out, with 1s provided beyond the number of dimensions for a or b. The output has the max of the dimension sizes for each dimension. An error is returned if the rules of alignment are violated: each dimension size must be either the same, or one of them is equal to 1. This corresponds to the "broadcasting" logic of NumPy.
func NewShape ¶
NewShape returns a new shape with given sizes. RowMajor ordering is used by default.
func Projection2DDimShapes ¶
func Projection2DDimShapes(shp *Shape, onedRow bool) (rowShape, colShape *Shape, rowIdxs, colIdxs []int)
Projection2DDimShapes returns the shapes and dimension indexes for a 2D projection of given tensor Shape, collapsing higher dimensions down to 2D (and 1D up to 2D). For the 1D case, onedRow determines if the values are row-wise or not. Even multiples of inner-most dimensions are placed along the row, odd in the column. If there are an odd number of dimensions, the first dimension is row-wise, and the remaining inner dimensions use the above logic from there, as if it was even. This is the main organizing function for all Projection2D calls.
func (*Shape) CopyFrom ¶
CopyFrom copies the shape parameters from another Shape struct. copies the data so it is not accidentally subject to updates.
func (*Shape) IndexFrom1D ¶
IndexFrom1D returns the n-dimensional index from a "flat" 1D array index.
func (*Shape) IndexIsValid ¶
IndexIsValid() returns true if given index is valid (within ranges for all dimensions)
func (*Shape) IndexTo1D ¶
IndexTo1D returns the flat 1D index from given n-dimensional indicies. No checking is done on the length or size of the index values relative to the shape of the tensor.
func (*Shape) IsEqual ¶
IsEqual returns true if this shape is same as other (does not compare names)
func (*Shape) Len ¶
Len returns the total length of elements in the tensor (i.e., the product of the shape sizes).
func (*Shape) RowCellSize ¶
RowCellSize returns the size of the outermost Row shape dimension, and the size of all the remaining inner dimensions (the "cell" size). Used for Tensors that are columns in a data table.
func (*Shape) SetShapeSizes ¶
SetShapeSizes sets the shape sizes from list of ints. RowMajor ordering is used by default.
func (*Shape) SetShapeSizesFromTensor ¶
SetShapeSizesFromTensor sets the shape sizes from given tensor. RowMajor ordering is used by default.
func (*Shape) SizesAsTensor ¶
SizesAsTensor returns shape sizes as an Int Tensor.
type Slice ¶
type Slice struct {
// Start is the starting value. If 0 and Step < 0, = size-1;
// If negative, = size+Start.
Start int
// Stop value. If 0 and Step >= 0, = size;
// If 0 and Step < 0, = -1, to include whole range.
// If negative = size+Stop.
Stop int
// Step increment. If 0, = 1; if negative then Start must be > Stop
// to produce anything.
Step int
}
Slice represents a slice of index values, for extracting slices of data, along a dimension of a given size, which is provided separately as an argument. Uses standard 'for' loop logic with a Start and _exclusive_ Stop value, and a Step increment: for i := Start; i < Stop; i += Step. The values stored in this struct are the _inputs_ for computing the actual slice values based on the actual size parameter for the dimension. Negative numbers count back from the end (i.e., size + val), and the zero value results in a list of all values in the dimension, with Step = 1 if 0. The behavior is identical to the NumPy slice.
func (Slice) IntSlice ¶
IntSlice returns []int slice with slice index values, up to given actual size.
func (Slice) ToIntSlice ¶
ToIntSlice writes values to given []int slice, with given size parameter for the dimension being sliced. If slice is wrong size to hold values, not all are written: allocate ints using Len(size) to fit.
type Sliced ¶
type Sliced struct {
// Tensor source that we are an indexed view onto.
Tensor Tensor
// Indexes are the indexes for each dimension, with dimensions as the outer
// slice (enforced to be the same length as the NumDims of the source Tensor),
// and a list of dimension index values (within range of DimSize(d)).
// A nil list of indexes for a dimension automatically provides a full,
// sequential view of that dimension.
Indexes [][]int
}
Sliced provides a re-sliced view onto another "source" Tensor, defined by a set of [Sliced.Indexes] for each dimension (must have at least 1 index per dimension to avoid a null view). Thus, each dimension can be transformed in arbitrary ways relative to the original tensor (filtered subsets, reversals, sorting, etc). This view is not memory-contiguous and does not support the RowMajor interface or efficient access to inner-dimensional subspaces. A new Sliced view defaults to a full transparent view of the source tensor. There is additional cost for every access operation associated with the indexed indirection, and access is always via the full n-dimensional indexes. See also Rows for a version that only indexes the outermost row dimension, which is much more efficient for this common use-case, and does support RowMajor. To produce a new concrete Values that has raw data actually organized according to the indexed order (i.e., the copy function of numpy), call Sliced.AsValues.
func AsSliced ¶
AsSliced returns the tensor as a Sliced view. If it already is one, then it is returned, otherwise it is wrapped in a new Sliced, with default full sequential ("transparent") view.
func NewSliced ¶
NewSliced returns a new Sliced view of given tensor, with optional list of indexes for each dimension (none / nil = sequential). Any dimensions without indexes default to nil = full sequential view.
func (*Sliced) AsValues ¶
AsValues returns a copy of this tensor as raw Values. This "renders" the Sliced view into a fully contiguous and optimized memory representation of that view, which will be faster to access for further processing, and enables all the additional functionality provided by the Values interface.
func (*Sliced) Filter ¶
Filter filters the indexes using the given Filter function for setting the indexes for given dimension, and index into the source data.
func (*Sliced) Float ¶
Float returns the value of given index as a float64. The indexes are indirected through the [Sliced.Indexes].
func (*Sliced) Float1D ¶
Float1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Sliced) IndexesNeeded ¶
IndexesNeeded is called prior to an operation that needs actual indexes, on given dimension. If Indexes == nil, they are set to all items, otherwise current indexes are left as is. Use Sequential, then IndexesNeeded to ensure all dimension indexes are represented.
func (*Sliced) Int ¶
Int returns the value of given index as an int. The indexes are indirected through the [Sliced.Indexes].
func (*Sliced) Int1D ¶
Int1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Sliced) Permuted ¶
Permuted sets indexes in given dimension to a permuted order. If indexes already exist then existing list of indexes is permuted, otherwise a new set of permuted indexes are generated
func (*Sliced) Sequential ¶
func (sl *Sliced) Sequential()
Sequential sets all Indexes to nil, resulting in full sequential access into tensor.
func (*Sliced) SetFloat ¶
SetFloat sets the value of given index as a float64 The indexes are indirected through the [Sliced.Indexes].
func (*Sliced) SetFloat1D ¶
SetFloat1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Sliced) SetInt ¶
SetInt sets the value of given index as an int The indexes are indirected through the [Sliced.Indexes].
func (*Sliced) SetInt1D ¶
SetInt1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Sliced) SetString ¶
SetString sets the value of given index as a string The indexes are indirected through the [Sliced.Indexes].
func (*Sliced) SetString1D ¶
SetString1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Sliced) SetTensor ¶
SetTensor sets tensor as source for this view, and initializes a full transparent view onto source (calls Sliced.Sequential).
func (*Sliced) ShapeSizes ¶
For each dimension, we return the effective shape sizes using the current number of indexes per dimension.
func (*Sliced) SortFunc ¶
SortFunc sorts the indexes along given dimension using given compare function. The compare function operates directly on indexes into the source Tensor that Sliced is a view of, as these row numbers have already been projected through the indexes. That is why the tensor is passed through to the compare function, to ensure the proper tensor values are being used. cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
func (*Sliced) SortIndexes ¶
SortIndexes sorts the indexes along given dimension directly in numerical order, producing the native ordering, while preserving any filtering that might have occurred.
func (*Sliced) SortStableFunc ¶
SortStableFunc stably sorts along given dimension using given compare function. The compare function operates directly on indexes into the source Tensor that Sliced is a view of, as these row numbers have already been projected through the indexes. That is why the tensor is passed through to the compare function, to ensure the proper tensor values are being used. cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b. It is *essential* that it always returns 0 when the two are equal for the stable function to actually work.
func (*Sliced) SourceIndex ¶
SourceIndex returns the actual index into source tensor dimension based on given index value.
func (*Sliced) SourceIndexes ¶
SourceIndexes returns the actual n-dimensional indexes into source tensor based on given list of indexes based on the Sliced view shape.
func (*Sliced) SourceIndexesFrom1D ¶
SourceIndexesFrom1D returns the n-dimensional indexes into source tensor based on the given 1D index based on the Sliced view shape.
func (*Sliced) String1D ¶
String1D is somewhat expensive if indexes are set, because it needs to convert the flat index back into a full n-dimensional index and then use that api.
func (*Sliced) StringValue ¶
StringValue returns the value of given index as a string. The indexes are indirected through the [Sliced.Indexes].
func (*Sliced) ValidIndexes ¶
func (sl *Sliced) ValidIndexes()
ValidIndexes ensures that [Sliced.Indexes] are valid, removing any out-of-range values and setting the view to nil (full sequential) for any dimension with no indexes (which is an invalid condition). Call this when any structural changes are made to underlying Tensor.
type SlicesMagic ¶
type SlicesMagic int //enums:enum
SlicesMagic are special elements in slice expressions, including NewAxis, FullAxis, and Ellipsis in NewSliced expressions.
const ( // FullAxis indicates that the full existing axis length should be used. // This is equivalent to Slice{}, but is more semantic. In NumPy it is // equivalent to a single : colon. FullAxis SlicesMagic = iota // NewAxis creates a new singleton (length=1) axis, used to to reshape // without changing the size. Can also be used in [Reshaped]. NewAxis // Ellipsis (...) is used in [NewSliced] expressions to produce // a flexibly-sized stretch of FullAxis dimensions, which automatically // aligns the remaining slice elements based on the source dimensionality. Ellipsis )
const SlicesMagicN SlicesMagic = 3
SlicesMagicN is the highest valid value for type SlicesMagic, plus one.
func SlicesMagicValues ¶
func SlicesMagicValues() []SlicesMagic
SlicesMagicValues returns all possible values for the type SlicesMagic.
func (SlicesMagic) Desc ¶
func (i SlicesMagic) Desc() string
Desc returns the description of the SlicesMagic value.
func (SlicesMagic) Int64 ¶
func (i SlicesMagic) Int64() int64
Int64 returns the SlicesMagic value as an int64.
func (SlicesMagic) MarshalText ¶
func (i SlicesMagic) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*SlicesMagic) SetInt64 ¶
func (i *SlicesMagic) SetInt64(in int64)
SetInt64 sets the SlicesMagic value from an int64.
func (*SlicesMagic) SetString ¶
func (i *SlicesMagic) SetString(s string) error
SetString sets the SlicesMagic value from its string representation, and returns an error if the string is invalid.
func (SlicesMagic) String ¶
func (i SlicesMagic) String() string
String returns the string representation of this SlicesMagic value.
func (*SlicesMagic) UnmarshalText ¶
func (i *SlicesMagic) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (SlicesMagic) Values ¶
func (i SlicesMagic) Values() []enums.Enum
Values returns all possible values for the type SlicesMagic.
type String ¶
String is a tensor of string values
func AsString ¶
AsString returns the tensor as a String tensor. If already is a String, it is returned as such. Otherwise, a new String tensor is created and values are copied.
func NewString ¶
NewString returns a new n-dimensional tensor of string values with the given sizes per dimension (shape).
func NewStringFromValues ¶
NewStringFromValues returns a new 1-dimensional tensor of given value type initialized directly from the given slice values, which are not copied. The resulting Tensor thus "wraps" the given values.
func NewStringFull ¶
NewStringFull returns a new tensor full of given scalar value, of given shape sizes.
func NewStringScalar ¶
NewStringScalar is a convenience method for a Tensor representation of a single string scalar value.
func NewStringShape ¶
NewStringShape returns a new n-dimensional tensor of string values using given shape.
func (*String) AppendFrom ¶
AppendFrom appends values from other tensor into this tensor, which must have the same cell size as this tensor. It uses and optimized implementation if the other tensor is of the same type, and otherwise it goes through appropriate standard type.
func (*String) AppendRowFloat ¶
AppendRowFloat adds a row and sets float value(s), up to number of cells.
func (*String) AppendRowInt ¶
AppendRowInt adds a row and sets int value(s), up to number of cells.
func (*String) AppendRowString ¶
AppendRowString adds a row and sets string value(s), up to number of cells.
func (*String) Bytes ¶ added in v0.1.2
Bytes encodes the actual string values starting with the length of each string as an encoded int value. SetFromBytes decodes this format to reconstruct the contents.
func (*String) Clone ¶
Clone clones this tensor, creating a duplicate copy of itself with its own separate memory representation of all the values, and returns that as a Tensor (which can be converted into the known type as needed).
func (*String) CopyCellsFrom ¶
CopyCellsFrom copies given range of values from other tensor into this tensor, using flat 1D indexes: to = starting index in this Tensor to start copying into, start = starting index on from Tensor to start copying from, and n = number of values to copy. Uses an optimized implementation if the other tensor is of the same type, and otherwise it goes through appropriate standard type.
func (*String) CopyFrom ¶
CopyFrom copies all avail values from other tensor into this tensor, with an optimized implementation if the other tensor is of the same type, and otherwise it goes through appropriate standard type.
func (*String) RowTensor ¶
RowTensor is a convenience version of [RowMajor.SubSpace] to return the SubSpace for the outermost row dimension. Rows defines a version of this that indirects through the row indexes.
func (*String) SetFloat1D ¶
func (*String) SetFloatRow ¶
func (*String) SetFromBytes ¶ added in v0.1.2
SetFromBytes sets string values from strings encoded using String.Bytes function.
func (*String) SetRowTensor ¶
SetRowTensor sets the values of the SubSpace at given row to given values.
func (*String) SetString1D ¶
func (*String) SetStringRow ¶
func (*String) SetZeros ¶
func (tsr *String) SetZeros()
SetZeros is a simple convenience function initialize all values to the zero value of the type (empty strings for string type).
func (*String) SubSpace ¶
SubSpace returns a new tensor with innermost subspace at given offset(s) in outermost dimension(s) (len(offs) < NumDims). The new tensor points to the values of the this tensor (i.e., modifications will affect both), as its Values slice is a view onto the original (which is why only inner-most contiguous supsaces are supported). Use Clone() method to separate the two.
type StringMatch ¶
type StringMatch struct {
// Contains means the string only needs to contain the target string,
// with the default (false) requiring a complete match to entire string.
Contains bool
// IgnoreCase means that differences in case are ignored in comparing strings,
// with the default (false) using case.
IgnoreCase bool
// Exclude means to exclude matches,
// with the default (false) being to include.
Exclude bool
}
StringMatch are options for how to compare strings.
func (*StringMatch) Match ¶
func (sm *StringMatch) Match(trg, str string) bool
Match compares two strings according to the options. The trg is the target string that you are comparing, such that it must contain the given str string, not the other way around.
type Tensor ¶
type Tensor interface {
fmt.Stringer
// Label satisfies the core.Labeler interface for a summary
// description of the tensor, including metadata Name if set.
Label() string
// Metadata returns the metadata for this tensor, which can be used
// to encode name, docs, shape dimension names, plotting options, etc.
Metadata() *metadata.Data
// Shape() returns a [Shape] representation of the tensor shape
// (dimension sizes). For tensors that present a view onto another
// tensor, this typically must be constructed.
// In general, it is better to use the specific [Tensor.ShapeSizes],
// [Tensor.ShapeSizes], [Tensor.DimSize] etc as neeed.
Shape() *Shape
// ShapeSizes returns the sizes of each dimension as a slice of ints.
// The returned slice is a copy and can be modified without side effects.
ShapeSizes() []int
// Len returns the total number of elements in the tensor,
// i.e., the product of all shape dimensions.
// Len must always be such that the 1D() accessors return
// values using indexes from 0..Len()-1.
Len() int
// NumDims returns the total number of dimensions.
NumDims() int
// DimSize returns size of given dimension.
DimSize(dim int) int
// DataType returns the type of the data elements in the tensor.
// Bool is returned for the Bool tensor type.
DataType() reflect.Kind
// IsString returns true if the data type is a String; otherwise it is numeric.
IsString() bool
// AsValues returns this tensor as raw [Values]. If it already is,
// it is returned directly. If it is a View tensor, the view is
// "rendered" into a fully contiguous and optimized [Values] representation
// of that view, which will be faster to access for further processing,
// and enables all the additional functionality provided by the [Values] interface.
AsValues() Values
// Float returns the value of given n-dimensional index (matching Shape) as a float64.
Float(i ...int) float64
// SetFloat sets the value of given n-dimensional index (matching Shape) as a float64.
SetFloat(val float64, i ...int)
// Float1D returns the value of given 1-dimensional index (0-Len()-1) as a float64.
// If index is negative, it indexes from the end of the list (-1 = last).
// This can be somewhat expensive in wrapper views ([Rows], [Sliced]), which
// convert the flat index back into a full n-dimensional index and use that api.
// [Tensor.FloatRow] is preferred.
Float1D(i int) float64
// SetFloat1D sets the value of given 1-dimensional index (0-Len()-1) as a float64.
// If index is negative, it indexes from the end of the list (-1 = last).
// This can be somewhat expensive in the commonly-used [Rows] view;
// [Tensor.SetFloatRow] is preferred.
SetFloat1D(val float64, i int)
// StringValue returns the value of given n-dimensional index (matching Shape) as a string.
// 'String' conflicts with [fmt.Stringer], so we have to use StringValue here.
StringValue(i ...int) string
// SetString sets the value of given n-dimensional index (matching Shape) as a string.
SetString(val string, i ...int)
// String1D returns the value of given 1-dimensional index (0-Len()-1) as a string.
// If index is negative, it indexes from the end of the list (-1 = last).
String1D(i int) string
// SetString1D sets the value of given 1-dimensional index (0-Len()-1) as a string.
// If index is negative, it indexes from the end of the list (-1 = last).
SetString1D(val string, i int)
// Int returns the value of given n-dimensional index (matching Shape) as a int.
Int(i ...int) int
// SetInt sets the value of given n-dimensional index (matching Shape) as a int.
SetInt(val int, i ...int)
// Int1D returns the value of given 1-dimensional index (0-Len()-1) as a int.
// If index is negative, it indexes from the end of the list (-1 = last).
Int1D(i int) int
// SetInt1D sets the value of given 1-dimensional index (0-Len()-1) as a int.
// If index is negative, it indexes from the end of the list (-1 = last).
SetInt1D(val int, i int)
}
Tensor is the most general interface for n-dimensional tensors. Per C / Go / Python conventions, indexes are Row-Major, ordered from outer to inner left-to-right, so the inner-most is right-most. It is implemented for raw Values with direct integer indexing by the Number, String, and Bool types, covering the different concrete types specified by DataTypes (see Values for additional interface methods for raw value types). For float32 and float64 values, use NaN to indicate missing values, as all of the data analysis and plot packages skip NaNs. View Tensor types provide different ways of viewing a source tensor, including Sliced for arbitrary slices of dimension indexes, Masked for boolean masked access of individual elements, and Indexed for arbitrary indexes of values, organized into the shape of the indexes, not the original source data. Reshaped provides length preserving reshaping (mostly for computational alignment purposes), and Rows provides an optimized row-indexed view for [table.Table] data.
func AnySlice ¶ added in v0.1.2
AnySlice returns a new Tensor view using the given index variables to be used for Sliced, Masked, or Indexed depending on what is present.
- If a Bool tensor is provided then NewMasked is called.
- If a single tensor is provided with Len > max(1, tsr.NumDims()), NewIndexed is called.
- Otherwise, Reslice is called with the args.
func As1D ¶
As1D returns a 1D tensor, which is either the input tensor if it is already 1D, or a new Reshaped 1D view of it. This can be useful e.g., for stats and metric functions that operate on a 1D list of values. See also Flatten.
func Cells1D ¶
Cells1D returns a flat 1D view of the innermost cells for given row index. For a RowMajor tensor, it uses the [RowTensor] subspace directly, otherwise it uses Sliced to extract the cells. In either case, As1D is used to ensure the result is a 1D tensor.
func FloatBinaryFunc ¶
FloatBinaryFunc sets output to a binary function of a, b float64 values. The flops (floating point operations) estimate is used to control parallel threading using goroutines, and should reflect number of flops in the function. See VectorizeThreaded for more information.
func Mask ¶
Mask is the general purpose masking function, which checks if the mask arg is a Bool and uses if so. Otherwise, it logs an error.
func Reshape ¶
Reshape returns a view of the given tensor with given shape sizes. A single -1 value can be used to automatically specify the remaining tensor length, as long as the other sizes are an even multiple of the total length. A single -1 returns a 1D view of the entire tensor.
func Reslice ¶
Reslice returns a new Sliced (and potentially Reshaped) view of given tensor, with given slice expressions for each dimension, which can be:
- an integer, indicating a specific index value along that dimension. Can use negative numbers to index from the end. This axis will also be removed using a Reshaped.
- a Slice object expressing a range of indexes.
- FullAxis includes the full original axis (equivalent to `Slice{}`).
- Ellipsis creates a flexibly-sized stretch of FullAxis dimensions, which automatically aligns the remaining slice elements based on the source dimensionality.
- NewAxis creates a new singleton (length=1) axis, used to to reshape without changing the size. This triggers a Reshaped.
- any remaining dimensions without indexes default to nil = full sequential view.
func Squeeze ¶
Squeeze a Reshaped view of given tensor with all singleton (size = 1) dimensions removed (if none, just returns the tensor).
func StringBinaryFunc ¶
StringBinaryFunc sets output to a binary function of a, b string values.
type Values ¶
type Values interface {
RowMajor
// SetShapeSizes sets the dimension sizes of the tensor, and resizes
// backing storage appropriately, retaining all existing data that fits.
SetShapeSizes(sizes ...int)
// SetNumRows sets the number of rows (outermost dimension).
// It is safe to set this to 0. For incrementally growing tensors (e.g., a log)
// it is best to first set the anticipated full size, which allocates the
// full amount of memory, and then set to 0 and grow incrementally.
SetNumRows(rows int)
// Sizeof returns the number of bytes contained in the Values of this tensor.
// For String types, this is just the string pointers, not the string content.
Sizeof() int64
// Bytes returns the underlying byte representation of the tensor values.
// This is the actual underlying data, so make a copy if it can be
// unintentionally modified or retained more than for immediate use.
// For the [String] type, this is a len int + bytes encoding of each string.
Bytes() []byte
// SetFromBytes sets the values from given bytes. See [Values.Bytes] for
// the [String] encoding.
SetFromBytes(b []byte)
// SetZeros is a convenience function initialize all values to the
// zero value of the type (empty strings for string type).
// New tensors always start out with zeros.
SetZeros()
// Clone clones this tensor, creating a duplicate copy of itself with its
// own separate memory representation of all the values.
Clone() Values
// CopyFrom copies all values from other tensor into this tensor, with an
// optimized implementation if the other tensor is of the same type, and
// otherwise it goes through the appropriate standard type (Float, Int, String).
CopyFrom(from Values)
// CopyCellsFrom copies given range of values from other tensor into this tensor,
// using flat 1D indexes: to = starting index in this Tensor to start copying into,
// start = starting index on from Tensor to start copying from, and n = number of
// values to copy. Uses an optimized implementation if the other tensor is
// of the same type, and otherwise it goes through appropriate standard type.
CopyCellsFrom(from Values, to, start, n int)
// AppendFrom appends all values from other tensor into this tensor, with an
// optimized implementation if the other tensor is of the same type, and
// otherwise it goes through the appropriate standard type (Float, Int, String).
AppendFrom(from Values) Values
}
Values is an extended Tensor interface for raw value tensors. This supports direct setting of the shape of the underlying values, sub-space access to inner-dimensional subspaces of values, etc.
func CallOut1Float64 ¶
CallOut1Float64 adds Float64 output Values tensor for function.
func CallOut1Gen1 ¶
func CallOut1Gen2 ¶
func CallOut2Float64 ¶
func CallOut2Gen1 ¶
func CallOut2Gen2 ¶
func Clone ¶
Clone returns a copy of the given tensor. If it is raw Values then a [Values.Clone] is returned. Otherwise if it is a view, then [Tensor.AsValues] is returned. This is equivalent to the NumPy copy function.
func Flatten ¶
Flatten returns a copy of the given tensor as a 1D flat list of values, by calling Clone(As1D(tsr)). It is equivalent to the NumPy flatten function.
func FloatFunc ¶
FloatFunc sets output to a function of tensor float64 values. The flops (floating point operations) estimate is used to control parallel threading using goroutines, and should reflect number of flops in the function. See VectorizeThreaded for more information.
func FromBinary ¶ added in v0.1.2
FromBinary returns a Values tensor reconstructed from the binary encoding generated by ToBinary.
func MustBeValues ¶
MustBeValues returns the given tensor as a Values subtype, or nil and an error if it is not one. Typically outputs of compute operations must be values, and are reshaped to hold the results as needed.
func New ¶
New returns a new n-dimensional tensor of given value type with the given sizes per dimension (shape).
func NewFromValues ¶ added in v0.1.1
NewFromValues returns a new Values tensor from given list of values which must be the same type, for the supported tensor types including string, bool, and standard float, int types.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bitslice implements a simple slice-of-bits using a []byte slice for storage, which is used for efficient storage of boolean data, such as projection connectivity patterns.
|
Package bitslice implements a simple slice-of-bits using a []byte slice for storage, which is used for efficient storage of boolean data, such as projection connectivity patterns. |
|
Package tensormpi has methods to support use of MPI with tensor and table data structures.
|
Package tensormpi has methods to support use of MPI with tensor and table data structures. |
|
Package tmath provides basic math operations and functions that operate on tensor.Tensor.
|
Package tmath provides basic math operations and functions that operate on tensor.Tensor. |