Documentation ¶
Index ¶
- Constants
- func BoolToFloat64(bv bool) float64
- func ColMajorStrides(sizes []int) []int
- func CopyDense(to Tensor, dm *mat.Dense)
- func EqualInts(a, b []int) bool
- func Float64ToBool(val float64) bool
- func Float64ToString(val float64) string
- func OpenCSV(tsr Tensor, filename core.Filename, delim rune) error
- func Projection2DCoords(shp *Shape, oddRow bool, row, col int) (rowCoords, colCoords []int)
- func Projection2DIndex(shp *Shape, oddRow bool, row, col int) int
- func Projection2DSet(tsr Tensor, oddRow bool, row, col int, val float64)
- func Projection2DSetString(tsr Tensor, oddRow bool, row, col int, val string)
- func Projection2DShape(shp *Shape, oddRow bool) (rows, cols, rowEx, colEx int)
- func Projection2DString(tsr Tensor, oddRow bool, row, col int) string
- func Projection2DValue(tsr Tensor, oddRow bool, row, col int) float64
- func ReadCSV(tsr Tensor, r io.Reader, delim rune) error
- func RowMajorStrides(sizes []int) []int
- func SaveCSV(tsr Tensor, filename core.Filename, delim rune) error
- func StringToFloat64(str string) float64
- func WriteCSV(tsr Tensor, w io.Writer, delim rune) error
- type Base
- func (tsr *Base[T]) Bytes() []byte
- func (tsr *Base[T]) CopyMetaData(frm Tensor)
- func (tsr *Base[T]) DataType() reflect.Kind
- func (tsr *Base[T]) DimSize(dim int) int
- func (tsr *Base[T]) Dims() (r, c int)
- func (tsr *Base[T]) Label() string
- func (tsr *Base[T]) Len() int
- func (tsr *Base[T]) MetaData(key string) (string, bool)
- func (tsr *Base[T]) MetaDataMap() map[string]string
- func (tsr *Base[T]) NumDims() int
- func (tsr *Base[T]) RowCellSize() (rows, cells int)
- func (tsr *Base[T]) Set(i []int, val T)
- func (tsr *Base[T]) Set1D(i int, val T)
- func (tsr *Base[T]) SetMetaData(key, val string)
- func (tsr *Base[T]) SetNumRows(rows int)
- func (tsr *Base[T]) SetShape(sizes []int, names ...string)
- func (tsr *Base[T]) Shape() *Shape
- func (tsr *Base[T]) Sizeof() int64
- func (tsr *Base[T]) String1D(off int) string
- func (tsr *Base[T]) StringRowCell(row, cell int) string
- func (tsr *Base[T]) StringValue(i []int) string
- func (tsr *Base[T]) Symmetric() (r int)
- func (tsr *Base[T]) SymmetricDim() int
- func (tsr *Base[T]) Value(i []int) T
- func (tsr *Base[T]) Value1D(i int) T
- type Bits
- func (tsr *Bits) At(i, j int) float64
- func (tsr *Bits) Bytes() []byte
- func (tsr *Bits) Clone() Tensor
- func (tsr *Bits) CopyCellsFrom(frm Tensor, to, start, n int)
- func (tsr *Bits) CopyFrom(frm Tensor)
- func (tsr *Bits) CopyMetaData(frm Tensor)
- func (tsr *Bits) CopyShapeFrom(frm Tensor)
- func (tsr *Bits) DataType() reflect.Kind
- func (tsr *Bits) DimSize(dim int) int
- func (tsr *Bits) Dims() (r, c int)
- func (tsr *Bits) Float(i []int) float64
- func (tsr *Bits) Float1D(off int) float64
- func (tsr *Bits) FloatRowCell(row, cell int) float64
- func (tsr *Bits) Floats(flt *[]float64)
- func (tsr *Bits) IsString() bool
- func (tsr *Bits) Label() string
- func (tsr *Bits) Len() int
- func (tsr *Bits) MetaData(key string) (string, bool)
- func (tsr *Bits) MetaDataMap() map[string]string
- func (tsr *Bits) NumDims() int
- func (tsr *Bits) Range() (min, max float64, minIndex, maxIndex int)
- func (tsr *Bits) RowCellSize() (rows, cells int)
- func (tsr *Bits) Set(i []int, val bool)
- func (tsr *Bits) Set1D(i int, val bool)
- func (tsr *Bits) SetFloat(i []int, val float64)
- func (tsr *Bits) SetFloat1D(off int, val float64)
- func (tsr *Bits) SetFloatRowCell(row, cell int, val float64)
- func (tsr *Bits) SetFloats(vals []float64)
- func (tsr *Bits) SetMetaData(key, val string)
- func (tsr *Bits) SetNumRows(rows int)
- func (tsr *Bits) SetShape(sizes []int, names ...string)
- func (tsr *Bits) SetString(i []int, val string)
- func (tsr *Bits) SetString1D(off int, val string)
- func (tsr *Bits) SetStringRowCell(row, cell int, val string)
- func (tsr *Bits) SetZeros()
- func (tsr *Bits) Shape() *Shape
- func (tsr *Bits) Sizeof() int64
- func (tsr *Bits) String() string
- func (tsr *Bits) String1D(off int) string
- func (tsr *Bits) StringRowCell(row, cell int) string
- func (tsr *Bits) StringValue(i []int) string
- func (tsr *Bits) SubSpace(offs []int) Tensor
- func (tsr *Bits) T() mat.Matrix
- func (tsr *Bits) Value(i []int) bool
- func (tsr *Bits) Value1D(i int) bool
- type Byte
- type Float32
- type Float64
- type Int
- type Int32
- type Number
- func (tsr *Number[T]) AddScalar(i []int, val float64) float64
- func (tsr *Number[T]) At(i, j int) float64
- func (tsr *Number[T]) Clone() Tensor
- func (tsr *Number[T]) CopyCellsFrom(frm Tensor, to, start, n int)
- func (tsr *Number[T]) CopyFrom(frm Tensor)
- func (tsr *Number[T]) CopyShapeFrom(frm Tensor)
- func (tsr *Number[T]) Float(i []int) float64
- func (tsr *Number[T]) Float1D(i int) float64
- func (tsr *Number[T]) FloatRowCell(row, cell int) float64
- func (tsr *Number[T]) Floats(flt *[]float64)
- func (tsr *Number[T]) IsString() bool
- func (tsr *Number[T]) MulScalar(i []int, val float64) float64
- func (tsr *Number[T]) Range() (min, max float64, minIndex, maxIndex int)
- func (tsr *Number[T]) SetFloat(i []int, val float64)
- func (tsr *Number[T]) SetFloat1D(i int, val float64)
- func (tsr *Number[T]) SetFloatRowCell(row, cell int, val float64)
- func (tsr *Number[T]) SetFloats(flt []float64)
- func (tsr *Number[T]) SetString(i []int, val string)
- func (tsr Number[T]) SetString1D(off int, val string)
- func (tsr *Number[T]) SetStringRowCell(row, cell int, val string)
- func (tsr *Number[T]) SetZeros()
- func (tsr *Number[T]) String() string
- func (tsr *Number[T]) SubSpace(offs []int) Tensor
- func (tsr *Number[T]) T() mat.Matrix
- type Shape
- func (sh *Shape) CopyShape(cp *Shape)
- func (sh *Shape) DimByName(name string) int
- func (sh *Shape) DimName(i int) string
- func (sh *Shape) DimSize(i int) int
- func (sh *Shape) DimSizeByName(name string) int
- func (sh *Shape) Index(offset int) []int
- func (sh *Shape) IndexIsValid(idx []int) bool
- func (sh *Shape) IsEqual(oth *Shape) bool
- func (sh *Shape) Len() int
- func (sh *Shape) NumDims() int
- func (sh *Shape) Offset(index []int) int
- func (sh *Shape) RowCellSize() (rows, cells int)
- func (sh *Shape) SetShape(sizes []int, names ...string)
- func (sh *Shape) String() string
- type String
- func (tsr *String) AddScalar(i []int, val float64) float64
- func (tsr *String) At(i, j int) float64
- func (tsr *String) Clone() Tensor
- func (tsr *String) CopyCellsFrom(frm Tensor, to, start, n int)
- func (tsr *String) CopyFrom(frm Tensor)
- func (tsr *String) CopyShapeFrom(frm Tensor)
- func (tsr *String) Float(i []int) float64
- func (tsr *String) Float1D(off int) float64
- func (tsr *String) FloatRowCell(row, cell int) float64
- func (tsr *String) Floats(flt *[]float64)
- func (tsr *String) IsString() bool
- func (tsr *String) MulScalar(i []int, val float64) float64
- func (tsr *String) Range() (min, max float64, minIndex, maxIndex int)
- func (tsr *String) SetFloat(i []int, val float64)
- func (tsr *String) SetFloat1D(off int, val float64)
- func (tsr *String) SetFloatRowCell(row, cell int, val float64)
- func (tsr *String) SetFloats(flt []float64)
- func (tsr *String) SetString(i []int, val string)
- func (tsr String) SetString1D(off int, val string)
- func (tsr *String) SetStringRowCell(row, cell int, val string)
- func (tsr *String) SetZeros()
- func (tsr *String) String() string
- func (tsr *String) SubSpace(offs []int) Tensor
- func (tsr *String) T() mat.Matrix
- type Tensor
Constants ¶
const ( // OddRow is for oddRow arguments to Projection2D functions, // specifies that the odd dimension goes along the row. OddRow = true // OddColumn is for oddRow arguments to Projection2D functions, // specifies that the odd dimension goes along the column. OddColumn = false )
Variables ¶
This section is empty.
Functions ¶
func BoolToFloat64 ¶
func ColMajorStrides ¶
ColMajorStrides returns strides for sizes where the first dimension is inner-most and subsequent dimensions are progressively outer
func CopyDense ¶
CopyDense copies a gonum mat.Dense matrix into given Tensor using standard Float64 interface
func Float64ToBool ¶
func Float64ToString ¶
Float64ToString converts float64 to string value using strconv, g format
func OpenCSV ¶ added in v0.1.2
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 Projection2DCoords ¶ added in v0.1.3
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).
func Projection2DIndex ¶ added in v0.1.3
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). For any odd number of dimensions, the remaining outer-most dimension can either be multipliexed across the row or column, given the oddRow arg. Even multiples of inner-most dimensions are assumed to be row, then column.
func Projection2DSet ¶ added in v0.1.3
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). For any odd number of dimensions, the remaining outer-most dimension can either be multipliexed across the row or column, given the oddRow arg. Even multiples of inner-most dimensions are assumed to be row, then column.
func Projection2DSetString ¶ added in v0.3.3
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). For any odd number of dimensions, the remaining outer-most dimension can either be multipliexed across the row or column, given the oddRow arg. Even multiples of inner-most dimensions are assumed to be row, then column.
func Projection2DShape ¶ added in v0.1.3
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 any odd number of dimensions, the remaining outer-most dimension can either be multipliexed across the row or column, given the oddRow arg. Even multiples of inner-most dimensions are assumed to be row, then column. rowEx returns the number of "extra" (higher dimensional) rows and colEx returns the number of extra cols
func Projection2DString ¶ added in v0.3.3
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). For any odd number of dimensions, the remaining outer-most dimension can either be multipliexed across the row or column, given the oddRow arg. Even multiples of inner-most dimensions are assumed to be row, then column.
func Projection2DValue ¶ added in v0.1.3
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). For any odd number of dimensions, the remaining outer-most dimension can either be multipliexed across the row or column, given the oddRow arg. Even multiples of inner-most dimensions are assumed to be row, then column.
func ReadCSV ¶ added in v0.1.2
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 outer-most and subsequent dimensions are progressively inner.
func SaveCSV ¶ added in v0.1.2
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 StringToFloat64 ¶
StringToFloat64 converts string value to float64 using strconv, returning 0 if any error
Types ¶
type Base ¶
Base is an n-dim array of float64s.
func (*Base[T]) CopyMetaData ¶
CopyMetaData copies meta data from given source tensor
func (*Base[T]) DataType ¶
DataType returns the type of the data elements in the tensor. Bool is returned for the Bits tensor type.
func (*Base[T]) Dims ¶
Dims is the gonum/mat.Matrix interface method for returning the dimensionality of the 2D Matrix. Assumes Row-major ordering and logs an error if NumDims < 2.
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]) MetaDataMap ¶
MetaDataMap returns the underlying map used for meta data
func (*Base[T]) RowCellSize ¶
RowCellSize returns the size of the outer-most 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 (*Base[T]) SetMetaData ¶
SetMetaData sets a key=value meta data (stored as a map[string]string). For TensorGrid display: top-zero=+/-, odd-row=+/-, image=+/-, min, max set fixed min / max values, background=color
func (*Base[T]) SetNumRows ¶
SetNumRows sets the number of rows (outer-most dimension) in a RowMajor organized tensor.
func (*Base[T]) Shape ¶
Shape returns a pointer to the shape that fully parametrizes the tensor shape
func (*Base[T]) StringRowCell ¶
func (*Base[T]) StringValue ¶
func (*Base[T]) Symmetric ¶
Symmetric is the gonum/mat.Matrix interface method for returning the dimensionality of a symmetric 2D Matrix.
func (*Base[T]) SymmetricDim ¶
SymmetricDim returns the number of rows/columns in the matrix.
type Bits ¶
Bits is a tensor of bits backed by a bitslice.Slice for efficient storage of binary data
func NewBits ¶
NewBits returns a new n-dimensional tensor of bit values with the given sizes per dimension (shape), and optional dimension names.
func NewBitsShape ¶
NewBitsShape returns a new n-dimensional tensor of bit values using given shape.
func (*Bits) At ¶
At is the gonum/mat.Matrix interface method for returning 2D matrix element at given row, column index. Not supported for Bits -- do not call!
func (*Bits) 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 (*Bits) 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 (*Bits) 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 (*Bits) CopyMetaData ¶
CopyMetaData copies meta data from given source tensor
func (*Bits) CopyShapeFrom ¶
CopyShapeFrom copies just the shape from given source tensor calling SetShape with the shape params from source (see for more docs).
func (*Bits) DataType ¶
DataType returns the type of the data elements in the tensor. Bool is returned for the Bits tensor type.
func (*Bits) Dims ¶
Dims is the gonum/mat.Matrix interface method for returning the dimensionality of the 2D Matrix. Not supported for Bits -- do not call!
func (*Bits) FloatRowCell ¶
func (*Bits) Label ¶
Label satisfies the core.Labeler interface for a summary description of the tensor
func (*Bits) MetaDataMap ¶
MetaDataMap returns the underlying map used for meta data
func (*Bits) RowCellSize ¶
RowCellSize returns the size of the outer-most 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 (*Bits) SetFloat1D ¶
func (*Bits) SetFloatRowCell ¶
func (*Bits) SetMetaData ¶
SetMetaData sets a key=value meta data (stored as a map[string]string). For TensorGrid display: top-zero=+/-, odd-row=+/-, image=+/-, min, max set fixed min / max values, background=color
func (*Bits) SetNumRows ¶
SetNumRows sets the number of rows (outer-most dimension) in a RowMajor organized tensor.
func (*Bits) SetString1D ¶
func (*Bits) SetStringRowCell ¶
func (*Bits) SetZeros ¶
func (tsr *Bits) SetZeros()
SetZeros is simple convenience function initialize all values to 0
func (*Bits) StringRowCell ¶
func (*Bits) StringValue ¶
type Float32 ¶
Float32 is an alias for Number[float32].
func NewFloat32 ¶ added in v0.1.2
NewFloat32 returns a new Float32 tensor with the given sizes per dimension (shape), and optional dimension names.
type Float64 ¶
Float64 is an alias for Number[float64].
func NewFloat64 ¶ added in v0.1.2
NewFloat64 returns a new Float64 tensor with the given sizes per dimension (shape), and optional dimension names.
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), and optional dimension names.
func NewNumberShape ¶
NewNumberShape returns a new n-dimensional tensor of numerical values using given shape.
func (*Number[T]) At ¶
At is the gonum/mat.Matrix interface method for returning 2D matrix element at given row, column index. Assumes Row-major ordering and logs an error if NumDims < 2.
func (*Number[T]) 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 (*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]) CopyShapeFrom ¶
CopyShapeFrom copies just the shape from given source tensor calling SetShape with the shape params from source (see for more docs).
func (*Number[T]) FloatRowCell ¶
func (*Number[T]) Floats ¶
Floats sets []float64 slice of all elements in the tensor (length is ensured to be sufficient). This can be used for all of the gonum/floats methods for basic math, gonum/stats, etc.
func (*Number[T]) 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 core api in optimized form Other math operations can be done using gonum/floats package.
func (*Number[T]) SetFloat1D ¶
func (*Number[T]) SetFloatRowCell ¶
func (Number[T]) SetString1D ¶
func (*Number[T]) SetStringRowCell ¶
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 Clone() method to separate the two.
type Shape ¶
type Shape struct { // size per dimension Sizes []int // offsets for each dimension Strides []int `display:"-"` // names of each dimension Names []string `display:"-"` }
Shape manages a tensor's shape information, including strides and dimension names and can compute the flat index into an underlying 1D data storage array based on an n-dimensional index (and vice-versa). Per C / Go / Python conventions, indexes are Row-Major, ordered from outer to inner left-to-right, so the inner-most is right-most.
func AddShapes ¶ added in v0.1.2
AddShapes returns a new shape by adding two shapes one after the other.
func NewShape ¶
NewShape returns a new shape with given sizes and optional dimension names. RowMajor ordering is used by default.
func (*Shape) CopyShape ¶
CopyShape copies the shape parameters from another Shape struct. copies the data so it is not accidentally subject to updates.
func (*Shape) DimByName ¶
DimByName returns the index of the given dimension name. returns -1 if not found.
func (*Shape) DimSizeByName ¶ added in v0.1.2
DimSizeByName returns the size of given dimension, specified by name. will crash if name not found.
func (*Shape) IndexIsValid ¶
IndexIsValid() returns true if given index is valid (within ranges for all dimensions)
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) Offset ¶
Offset returns the "flat" 1D array index into an element at the given n-dimensional index. No checking is done on the length or size of the index values relative to the shape of the tensor.
func (*Shape) RowCellSize ¶
RowCellSize returns the size of the outer-most 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.
type String ¶
String is a tensor of string values
func NewString ¶
NewString returns a new n-dimensional tensor of string values with the given sizes per dimension (shape), and optional dimension names.
func NewStringShape ¶
NewStringShape returns a new n-dimensional tensor of string values using given shape.
func (*String) At ¶
At is the gonum/mat.Matrix interface method for returning 2D matrix element at given row, column index. Assumes Row-major ordering and logs an error if NumDims < 2.
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) CopyShapeFrom ¶
CopyShapeFrom copies just the shape from given source tensor calling SetShape with the shape params from source (see for more docs).
func (*String) FloatRowCell ¶
func (*String) Floats ¶
Floats sets []float64 slice of all elements in the tensor (length is ensured to be sufficient). This can be used for all of the gonum/floats methods for basic math, gonum/stats, etc.
func (*String) 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 core api in optimized form Other math operations can be done using gonum/floats package.
func (*String) SetFloat1D ¶
func (*String) SetFloatRowCell ¶
func (String) SetString1D ¶
func (*String) SetStringRowCell ¶
func (*String) SetZeros ¶
func (tsr *String) SetZeros()
SetZeros is simple convenience function initialize all values to 0
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 Tensor ¶
type Tensor interface { fmt.Stringer mat.Matrix // Shape returns a pointer to the shape that fully parametrizes the tensor shape Shape() *Shape // Len returns the number of elements in the tensor (product of shape dimensions). Len() int // NumDims returns the total number of dimensions. NumDims() int // DimSize returns size of given dimension DimSize(dim int) int // RowCellSize returns the size of the outer-most 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. RowCellSize() (rows, cells int) // DataType returns the type of the data elements in the tensor. // Bool is returned for the Bits tensor type. DataType() reflect.Kind // Sizeof returns the number of bytes contained in the Values of this tensor. // for String types, this is just the string pointers. 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. Bytes() []byte // returns true if the data type is a String. otherwise is numeric. IsString() bool // Float returns the value of given index as a float64. Float(i []int) float64 // SetFloat sets the value of given index as a float64 SetFloat(i []int, val float64) // StringValue returns the value of given index as a string StringValue(i []int) string // SetString sets the value of given index as a string SetString(i []int, val string) // Float1D returns the value of given 1-dimensional index (0-Len()-1) as a float64 Float1D(i int) float64 // SetFloat1D sets the value of given 1-dimensional index (0-Len()-1) as a float64 SetFloat1D(i int, val float64) // FloatRowCell returns the value at given row and cell, where row is outer-most dim, // and cell is 1D index into remaining inner dims. For Table columns. FloatRowCell(row, cell int) float64 // SetFloatRowCell sets the value at given row and cell, where row is outer-most dim, // and cell is 1D index into remaining inner dims. For Table columns. SetFloatRowCell(row, cell int, val float64) // Floats sets []float64 slice of all elements in the tensor // (length is ensured to be sufficient). // This can be used for all of the gonum/floats methods // for basic math, gonum/stats, etc. Floats(flt *[]float64) // SetFloats sets tensor values from a []float64 slice (copies values). SetFloats(vals []float64) // String1D returns the value of given 1-dimensional index (0-Len()-1) as a string String1D(i int) string // SetString1D sets the value of given 1-dimensional index (0-Len()-1) as a string SetString1D(i int, val string) // StringRowCell returns the value at given row and cell, where row is outer-most dim, // and cell is 1D index into remaining inner dims. For Table columns StringRowCell(row, cell int) string // SetStringRowCell sets the value at given row and cell, where row is outer-most dim, // and cell is 1D index into remaining inner dims. For Table columns SetStringRowCell(row, cell int, val string) // 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. SubSpace(offs []int) Tensor // Range returns the min, max (and associated indexes, -1 = no values) for the tensor. // This is needed for display and is thus in the core api in optimized form // Other math operations can be done using gonum/floats package. Range() (min, max float64, minIndex, maxIndex int) // SetZeros is simple convenience function initialize all values to 0 SetZeros() // 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). Clone() Tensor // 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. CopyFrom(from Tensor) // CopyShapeFrom copies just the shape from given source tensor // calling SetShape with the shape params from source (see for more docs). CopyShapeFrom(from Tensor) // 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 Tensor, to, start, n int) // SetShape sets the sizes parameters of the tensor, and resizes backing storage appropriately. // existing names will be preserved if not presented. SetShape(sizes []int, names ...string) // SetNumRows sets the number of rows (outer-most dimension). SetNumRows(rows int) // SetMetaData sets a key=value meta data (stored as a map[string]string). // For TensorGrid display: top-zero=+/-, odd-row=+/-, image=+/-, // min, max set fixed min / max values, background=color SetMetaData(key, val string) // MetaData retrieves value of given key, bool = false if not set MetaData(key string) (string, bool) // MetaDataMap returns the underlying map used for meta data MetaDataMap() map[string]string // CopyMetaData copies meta data from given source tensor CopyMetaData(from Tensor) }
Tensor is the 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 by the Base and Number generic types specialized by different concrete types: float64, float32, int, int32, byte, string, bits (bools). For float32 and float64 values, use NaN to indicate missing values. All of the data analysis and plot packages skip NaNs.
func New ¶
func New[T string | bool | float32 | float64 | int | int32 | byte](sizes []int, names ...string) Tensor
New returns a new n-dimensional tensor of given value type with the given sizes per dimension (shape), and optional dimension names.
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. |
cmd
|
|
examples
|
|
Package agg provides aggregation functions operating on IndexView indexed views of table.Table data, along with standard AggFunc functions that can be used at any level of aggregation from tensor on up.
|
Package agg provides aggregation functions operating on IndexView indexed views of table.Table data, along with standard AggFunc functions that can be used at any level of aggregation from tensor on up. |
metric
Package metric provides various similarity / distance metrics for comparing floating-point vectors.
|
Package metric provides various similarity / distance metrics for comparing floating-point vectors. |
norm
Package norm provides normalization and norm metric computations e.g., L2 = sqrt of sum of squares of a vector.
|
Package norm provides normalization and norm metric computations e.g., L2 = sqrt of sum of squares of a vector. |
pca
Package pca performs principal component's analysis and associated covariance matrix computations, operating on table.Table or tensor.Tensor data.
|
Package pca performs principal component's analysis and associated covariance matrix computations, operating on table.Table or tensor.Tensor data. |
simat
Package simat provides similarity / distance matrix functions that create a SimMat matrix from Tensor or Table data.
|
Package simat provides similarity / distance matrix functions that create a SimMat matrix from Tensor or Table data. |
split
Package split provides GroupBy, Agg, Permute and other functions that create and populate Splits of table.Table data.
|
Package split provides GroupBy, Agg, Permute and other functions that create and populate Splits of table.Table data. |
Package tensorcore provides GUI Views of table Table and Tensor structures using the Cogent Core views framework.
|
Package tensorcore provides GUI Views of table Table and Tensor structures using the Cogent Core views framework. |
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. |