Documentation ¶
Index ¶
- Constants
- func Cast[T, S PrimitiveTypes](input *Tensor[T], output *Tensor[S]) error
- type PrimitiveTypes
- type Scalar
- func (g *Scalar[T]) Clone() *Scalar[T]
- func (g *Scalar[T]) Marshal() (*tf.Tensor, error)
- func (g *Scalar[T]) MarshalJSON() ([]byte, error)
- func (g *Scalar[T]) String() string
- func (g *Scalar[T]) Unmarshal(tfTensor *tf.Tensor) error
- func (g *Scalar[T]) UnmarshalJSON(data []byte) error
- func (g *Scalar[T]) Value() T
- type Tensor
- func Abs(complexT *Tensor[complex128]) *Tensor[float64]
- func ApplyOperatorXY[T PrimitiveTypes](x, y *Tensor[T], operator func(*op.Scope, tf.Output, tf.Output) tf.Output) (*Tensor[T], error)
- func ApplyOperators[T PrimitiveTypes](input *Tensor[T], operators ...func(*op.Scope, tf.Output) tf.Output) (*Tensor[T], error)
- func Complex128(realT, imagT *Tensor[float64]) (*Tensor[complex128], error)
- func Complex64(realT, imagT *Tensor[float32]) (*Tensor[complex64], error)
- func DotApply[T PrimitiveTypes](f func(values ...T) T, tensors ...*Tensor[T]) (*Tensor[T], error)
- func Imag32(complexT *Tensor[complex64]) *Tensor[float32]
- func Imag64(complexT *Tensor[complex128]) *Tensor[float64]
- func MatrixInverse[T PrimitiveTypes](input *Tensor[T]) (*Tensor[T], error)
- func MatrixMultiply[T PrimitiveTypes](x, y *Tensor[T]) (*Tensor[T], error)
- func Mul[T PrimitiveTypes](x, y *Tensor[T]) (*Tensor[T], error)
- func NewTensor[T PrimitiveTypes](value []T, shape ...int) (*Tensor[T], error)
- func NewTensorFromAny[T PrimitiveTypes](value any) (*Tensor[T], error)
- func NewTensorFromFunc[T PrimitiveTypes](f func(int) T, shape ...int) (*Tensor[T], error)
- func Real32(complexT *Tensor[complex64]) *Tensor[float32]
- func Real64(complexT *Tensor[complex128]) *Tensor[float64]
- func Transpose[T PrimitiveTypes](input *Tensor[T], perm ...int) (*Tensor[T], error)
- func (g *Tensor[T]) ApplyFunc(f func(T) T)
- func (g *Tensor[T]) Clone() (*Tensor[T], error)
- func (g *Tensor[T]) ExpandDims(dim int) error
- func (g *Tensor[T]) GetElement(indices ...int) (T, error)
- func (g *Tensor[T]) GetMultiDimSlice() (any, error)
- func (g *Tensor[T]) Marshal() (*tf.Tensor, error)
- func (g *Tensor[T]) MarshalJSON() ([]byte, error)
- func (g *Tensor[T]) NumElements() int
- func (g *Tensor[T]) Reshape(shape ...int) error
- func (g *Tensor[T]) SetElement(value T, indices ...int) error
- func (g *Tensor[T]) Shape() []int
- func (g *Tensor[T]) String() string
- func (g *Tensor[T]) Sub(start, end, stride []int) (*Tensor[T], error)
- func (g *Tensor[T]) Unmarshal(tfTensor *tf.Tensor) error
- func (g *Tensor[T]) UnmarshalJSON(data []byte) error
- func (g *Tensor[T]) Value() []T
Constants ¶
const ( TypeScalar = "scalar" TypeTensor = "tensor" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PrimitiveTypes ¶
type PrimitiveTypes interface { bool | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | float32 | float64 | complex64 | complex128 | string }
PrimitiveTypes are type constraints for supported underlying types
type Scalar ¶
type Scalar[T PrimitiveTypes] struct { // contains filtered or unexported fields }
Scalar represents a singular value type parametrized by supported types
func NewScalar ¶
func NewScalar[T PrimitiveTypes](value T) *Scalar[T]
NewScalar generates a new scalar parametrized by a data type
func (*Scalar[T]) MarshalJSON ¶
MarshalJSON serializes scalar with additional metadata such as data types in tensorflow and go. Use scalar in json.Marshal for this method to be called indirectly.
func (*Scalar[T]) Unmarshal ¶
Unmarshal populates receiver scalar using value from input upstream tensor
func (*Scalar[T]) UnmarshalJSON ¶
UnmarshalJSON parses serialized scalar value
type Tensor ¶
type Tensor[T PrimitiveTypes] struct { // contains filtered or unexported fields }
Tensor is a generic non-scalar data structures that includes vectors, matrices and higher dimensional structures. Tensor's representation is a slice because it is easier to work with compared to multidimensional slices. Shape stores the underlying dimensionality.
func Abs ¶
func Abs(complexT *Tensor[complex128]) *Tensor[float64]
Abs returns absolute valued tensor such that each element of output is absolute value of each of the complex values of input
func ApplyOperatorXY ¶ added in v0.6.0
func ApplyOperatorXY[T PrimitiveTypes](x, y *Tensor[T], operator func(*op.Scope, tf.Output, tf.Output) tf.Output) (*Tensor[T], error)
ApplyOperatorXY applies any operator accepting two inputs tensors and outputting single tensor, hence the name XY
func ApplyOperators ¶ added in v0.6.0
func ApplyOperators[T PrimitiveTypes](input *Tensor[T], operators ...func(*op.Scope, tf.Output) tf.Output) (*Tensor[T], error)
ApplyOperators successively applies operators (last one first) For instance if the operator list is [op1, op2, op3], then it will be executed as op1(op2(op3(input)))
func Complex128 ¶
func Complex128(realT, imagT *Tensor[float64]) (*Tensor[complex128], error)
Complex128 packs input real and imaginary parts to a complex128 valued tensor
func DotApply ¶
func DotApply[T PrimitiveTypes](f func(values ...T) T, tensors ...*Tensor[T]) (*Tensor[T], error)
DotApply applies input function f over each corresponding elements of input tensors and returns a new tensor using output of that function. For instance, if input function f sums up all values of its input, then this will have a result of performing element wise sum over input tensors
func Imag32 ¶
Imag32 pulls imaginary elements from input tensor and packs them into a new tensor of float32 type
func Imag64 ¶
func Imag64(complexT *Tensor[complex128]) *Tensor[float64]
Imag64 pulls imaginary elements from input tensor and packs them into a new tensor of float64 type
func MatrixInverse ¶
func MatrixInverse[T PrimitiveTypes](input *Tensor[T]) (*Tensor[T], error)
MatrixInverse inverts the tensor assuming it is a square matrix, otherwise it will throw error
func MatrixMultiply ¶
func MatrixMultiply[T PrimitiveTypes](x, y *Tensor[T]) (*Tensor[T], error)
MatrixMultiply performs matrix multiplication
func Mul ¶
func Mul[T PrimitiveTypes](x, y *Tensor[T]) (*Tensor[T], error)
Mul performs element wise multiplication of two tensors
func NewTensor ¶
func NewTensor[T PrimitiveTypes](value []T, shape ...int) (*Tensor[T], error)
NewTensor creates a new tensor with specified dimensions. If no dimension argument is specified, it is assumed that a vector is being created and the shape assumes value equal to the length of the input slice
func NewTensorFromAny ¶
func NewTensorFromAny[T PrimitiveTypes](value any) (*Tensor[T], error)
NewTensorFromAny does not take shape inputs and infers shape of tensor from the dimensions of the value, as in value being a multidimensional slice of data. The type parametrization must be provided at the time of instantiating this function.
func NewTensorFromFunc ¶
func NewTensorFromFunc[T PrimitiveTypes](f func(int) T, shape ...int) (*Tensor[T], error)
NewTensorFromFunc generates a new tensor using an input function that is called for each element
func Real32 ¶
Real32 pulls real elements from input tensor and packs them into a new tensor of float32 type
func Real64 ¶
func Real64(complexT *Tensor[complex128]) *Tensor[float64]
Real64 pulls real elements from input tensor and packs them into a new tensor of float64 type
func Transpose ¶
func Transpose[T PrimitiveTypes](input *Tensor[T], perm ...int) (*Tensor[T], error)
Transpose transposes a tensor. perm refers to the new order of dimensions. For instance, if input tensor is 2x3 and perm for a standard transpose should be [1, 0] referring to a shape of 3x2. If perm values are not provides it defaults to such reversal of input shape.
func (*Tensor[T]) ApplyFunc ¶
func (g *Tensor[T]) ApplyFunc(f func(T) T)
ApplyFunc applies input function f over each element of tensor transforming it in place
func (*Tensor[T]) ExpandDims ¶
ExpandDims adds a new dimension
func (*Tensor[T]) GetElement ¶
GetElement retrieves an element indexed by indices. This is a slow method, for faster access it is recommended to obtain a multidimensional slice and index off of that.
func (*Tensor[T]) GetMultiDimSlice ¶
GetMultiDimSlice fetches a multidimensional slice corresponding to underlying slice. For instance a float64 tensor with shape [2, 3, 4] will result in a [][][]float64 slice as output of this method since there are three dimensions. Similarly, a bool tensor with shape [2, 3, 3, 4] will result in [][][][]bool as output. Please note that it is users responsibility to perform type assertion correctly on returned value
func (*Tensor[T]) Marshal ¶
Marshal returns an instance of upstream tensorflow tensor object. string tensor reshaping is currently not supported natively in go. it is, however, possible to reshape it via a tf session running over a graphdef that was generated using python code for reshape function
func (*Tensor[T]) MarshalJSON ¶
MarshalJSON serializes tensor with additional metadata such as tensorflow data type and go data type. Use tensor in json.Marshal for this method to be called indirectly.
func (*Tensor[T]) NumElements ¶
NumElements is the total number of elements in the tensor
func (*Tensor[T]) SetElement ¶
func (*Tensor[T]) Sub ¶
Sub fetches sub a new tensor without altering original. startIndices if nil is set to a slice of zeros indicating starting from the beginning of the tensor. Length of such slice is always equal to the receiver dimension indicating start value for each dimension. Similarly, endLengths indicate end value similar to how a sub slicing end index works. if endLengths is nil, it is set to the shape slice of the receiver tensor. strides are jumps and if nil is set to slice of ones. The lengths of each of these inputs is, therefore, either nil or equal to the length of the shape of the receiver tensor
func (*Tensor[T]) Unmarshal ¶
Unmarshal populates receiver based on input upstream tensor object. string tensor reshaping is currently not supported natively in go. it is, however, possible to reshape it via a tf session running over a graphdef that was generated using python code for reshape function
func (*Tensor[T]) UnmarshalJSON ¶
UnmarshalJSON parses serialized tensor