Documentation ¶
Index ¶
- Constants
- Variables
- func Abs(x int) int
- func Add(A, B tensor.Tensor) (tensor.Tensor, error)
- func AllInRange(arr []int, min, max int) bool
- func And(A, B tensor.Tensor) (tensor.Tensor, error)
- func AnyToIntSlice(value interface{}) ([]int, error)
- func ApplyBinaryOperation(A, B tensor.Tensor, op BinaryOp, broadcastOption BroadcastType) ([]tensor.Tensor, error)
- func Arange(size int, step float32) []float32
- func ConvertTensorDtype(t tensor.Tensor, newType int32) (tensor.Tensor, error)
- func Div(A, B tensor.Tensor) (tensor.Tensor, error)
- func EmptyNodeProto() *onnx.NodeProto
- func Equal(A, B tensor.Tensor) (tensor.Tensor, error)
- func ErrActivationNotImplemented(activation string) error
- func ErrAxisOutOfRange(min, max, actual int) error
- func ErrConversionInvalidType(dType tensor.Dtype, newType int32) error
- func ErrConversionNotSupported(dType int32) error
- func ErrDimension(reason string) error
- func ErrIncompatibleDimensions() error
- func ErrInvalidAttributeCount(expected, actual int, operator Operator) error
- func ErrInvalidInput(reason string, operator Operator) error
- func ErrInvalidInputCount(actual int, operator Operator) error
- func ErrInvalidInputType(inputNumber int, dType string, operator Operator) error
- func ErrInvalidOptionalInputCount(actual int, operator Operator) error
- func ErrInvalidTensor(reason string, operator Operator) error
- func ErrMultidirBroadcast(shapeA, shapeB tensor.Shape, err error) error
- func ErrNotAllAxesInRange(min, max int) error
- func ErrTypeAssert(expected string, actual any) error
- func ErrUnidirBroadcast(shapeA, shapeB tensor.Shape) error
- func ErrUnknownOperatorType(operatorType string) error
- func ErrUnsupportedAttribute(attributeName string, operator Operator) error
- func ErrUnsupportedInput(inputName string, operator Operator) error
- func ExtractMatrices(M tensor.Tensor, nMatrices, nDimensions, hiddenSize int) ([]tensor.Tensor, error)
- func Float32TensorFixture(shp ...int) tensor.Tensor
- func Full(size int, value float32) []float32
- func GetValueAsTensorType(value float64, dtype tensor.Dtype) (interface{}, error)
- func Gt(A, B tensor.Tensor) (tensor.Tensor, error)
- func Gte(A, B tensor.Tensor) (tensor.Tensor, error)
- func HasDuplicates(arr []int) bool
- func IfScalarToSlice(value any) any
- func Int64ToBool(v int64) bool
- func Lt(A, B tensor.Tensor) (tensor.Tensor, error)
- func Lte(A, B tensor.Tensor) (tensor.Tensor, error)
- func Mul(A, B tensor.Tensor) (tensor.Tensor, error)
- func MultidirectionalBroadcast(A, B tensor.Tensor) (tensor.Tensor, tensor.Tensor, error)
- func NElements(shp ...int) int
- func NewSlicer(start int, options ...int) tensor.Slice
- func OffsetArrayIfNegative(arr []int, offset int)
- func OffsetTensorIfNegative(t tensor.Tensor, offset int) error
- func Ones(size int) []float32
- func OnesTensor(t tensor.Tensor) tensor.Tensor
- func Or(A, B tensor.Tensor) (tensor.Tensor, error)
- func PairwiseAssign(t1, t2 tensor.Tensor) (err error)
- func RandomFloat32TensorFixture(shp ...int) tensor.Tensor
- func ReLU(X tensor.Tensor) (tensor.Tensor, error)
- func ReshapeTensorsForMultidirBroadcast(A, B tensor.Tensor) (tensor.Tensor, tensor.Tensor, error)
- func Sigmoid(X tensor.Tensor) (tensor.Tensor, error)
- func Sub(A, B tensor.Tensor) (tensor.Tensor, error)
- func Tanh(X tensor.Tensor) (tensor.Tensor, error)
- func TensorInputsFixture(nTensors int) []tensor.Tensor
- func TensorWithBackingFixture(b interface{}, shp ...int) tensor.Tensor
- func UnidirectionalBroadcast(A, B tensor.Tensor) (tensor.Tensor, tensor.Tensor, error)
- func ValidateInputs(op Operator, inputs []tensor.Tensor) ([]tensor.Tensor, error)
- func Xor(A, B tensor.Tensor) (tensor.Tensor, error)
- func ZeroTensor(shape ...int) tensor.Tensor
- func Zeros(size int) []float32
- type Activation
- type AttributeError
- type AttributeErrorKind
- type BinaryOp
- type BooleanOp
- type BroadcastError
- type BroadcastType
- type DimensionError
- type DimensionErrorKind
- type FloatType
- type InputError
- type InputErrorKind
- type InputFixture
- type InvalidTensorError
- type Number
- type Operator
- type SequenceProcessDirection
- type Slicer
- type TypeAssertError
Constants ¶
const ( ActivationAlphaAttr = "activation_alpha" ActivationBetaAttr = "activation_beta" ActivationsAttr = "activations" ClipAttr = "clip" DirectionAttr = "direction" HiddenSizeAttr = "hidden_size" )
These constants define attributes that are applicable to GRU, LSTM and RNN operators.
const InvalidInputCountErrTemplate = "%v: expected %d input tensors, got %d"
InvalidInputCountErrTemplate is used to format an error when an operator got the wrong amount of input tensors.
const InvalidInputErrTemplate = "invalid input tensor for %v: %v"
InvalidInputErrTemplate is used to format an error when an operator got an invalid input tensor as input.
const InvalidOptionalInputCountErrTemplate = "%v: expected %d-%d input tensors, got %d"
InvalidOptionalInputCountErrTemplate is used to format an error when an operator got the wrong amount of input tensors when optional inputs are present.
const UnsupportedInputErrTemplate = "unsupported input for %v: %v"
UnsupportedInputErrTemplate is used to format an error when an operator got the wrong amount of input tensors when optional inputs are present.
Variables ¶
var ( ErrCast = errors.New("cast error") ErrInvalidShape = errors.New("invalid shape error") )
var AllTypes = []tensor.Dtype{ tensor.Uint8, tensor.Uint16, tensor.Uint32, tensor.Uint64, tensor.Int8, tensor.Int16, tensor.Int32, tensor.Int64, tensor.Float32, tensor.Float64, tensor.Complex64, tensor.Complex128, tensor.String, tensor.Bool, }
AllTypes is a type constraint which allows all types.
var ErrActivationNotImplementedBase = errors.New("the given activation function is not implemented")
var ErrAxisNotInRange = errors.New("axis out of range")
var ErrConversion = errors.New("unable to convert")
var ErrUnsupportedOperator = errors.New("unsupported operator")
var ErrUnsupportedOpsetVersion = errors.New("unsupported opset version")
Functions ¶
func AllInRange ¶
AllInRange checks if all the entries in `arr` are in the inclusive range min <= x <= max.
func AnyToIntSlice ¶
AnyToIntSlice casts the data of a node to an int list. This will only be done if the data is of some sort of int type.
func ApplyBinaryOperation ¶
func ApplyBinaryOperation(A, B tensor.Tensor, op BinaryOp, broadcastOption BroadcastType) ([]tensor.Tensor, error)
ApplyBinaryOperation applies a binary operation (an operation of arity 2) to 2 tensors. It returns a list of tensors with only 1 output tensor in order for this function to be easily used in operators.
func ConvertTensorDtype ¶
ConvertTensorDtype converts an interface of a specific dtype to a new dtype.
func EmptyNodeProto ¶
EmptyNodeProto returns a node proto with no attributes.
func ErrAxisOutOfRange ¶
func ErrDimension ¶
func ErrIncompatibleDimensions ¶
func ErrIncompatibleDimensions() error
func ErrInvalidInput ¶
func ErrInvalidInputCount ¶
func ErrInvalidInputType ¶
func ErrInvalidTensor ¶
func ErrNotAllAxesInRange ¶
func ErrTypeAssert ¶
func ErrUnidirBroadcast ¶
func ErrUnknownOperatorType ¶
func ErrUnsupportedAttribute ¶
func ErrUnsupportedInput ¶
func ExtractMatrices ¶
func ExtractMatrices(M tensor.Tensor, nMatrices, nDimensions, hiddenSize int) ([]tensor.Tensor, error)
ExtractMatrices extracts a given number of matrices from tensor M. M contains concatenated matrices along a certain dimension. M is assumed to have a shape of (num_directions, nMatrices * hidden_size, ...) and we extract the by slicing over the 'nMatrices * hidden_size' dimension. This method is specific for recurrent operators RNN, GRU and LSTM.
func Float32TensorFixture ¶
Float32TensorFixture returns a float32 backed gorgonia node. It initializes all its values using tensor.Range.
func GetValueAsTensorType ¶
GetValueAsTensorType returns the given value as the given tensor type.
func HasDuplicates ¶
HasDuplicates checks if there are duplicates in the sorted array `arr`.
func IfScalarToSlice ¶
IfScalarToSlice will wrap the value in a slice if it is a scalar in a slice with that value, otherwise will return itself.
func MultidirectionalBroadcast ¶
MultidirectionalBroadcast broadcasts two tensors for a binary operator according to the ONNX standards.
func NewSlicer ¶
NewSlicer creates a new Slicer object. By default, end will be set to start + 1 and step will be set to 1. If options are given, it is assumed that the first element will be the value for the end index and the second element the value for the step of the Slicer.
func OffsetArrayIfNegative ¶
OffsetArrayIfNegative adds `offset` to negative elements in the array `arr`. `arr` is modified in place.
func OffsetTensorIfNegative ¶
OffsetTensorIfNegative adds an offset to every negative element in tensor t. Works only for tensors with Dtype int (same as offset).
func OnesTensor ¶
OnesTensor returns a new tensor with the same shape as the given tensor intialized with all ones.
func PairwiseAssign ¶
PairwiseAssign essentially does pairwise t1 = t2 in place!.
func ReshapeTensorsForMultidirBroadcast ¶
ReshapeTensorsForMultidirBroadcast reshapes the 2 tensors such that they have the same number of dimensions. This means that when the number of dimensions do not correspond, the shape of the tensor with the smaller number of dimensions gets padded with 1's such that it matches the number of dimensions of the other tensor. One of the tensors (or both) will always remain the same. Example: shapeA=(3, 4) and shapeB=(1, 3, 5, 6) yields shapeNewA=(1, 1, 3, 4).
func TensorInputsFixture ¶
TensorInputsFixture returns a list with a given number of tensors.
func TensorWithBackingFixture ¶
TensorWithBackingFixture returns a gorgonia node with a tensor using the given backing.
func UnidirectionalBroadcast ¶
UnidirectionalBroadcast tries to broadcast tensor B to tensor A according to the ONNX standards.
func ValidateInputs ¶
ValidateInputs validates if a list of nodes has enough (not too few or too many) nodes. When there are fewer input nodes then the given max, the list is padded with nils. Expects either 1 requirement ==> the expected number of inputs, or 2 requirements, the minimum and the maximum number of inputs.
func ZeroTensor ¶
ZeroTensor returns a tensor filled with zeros with the given shape.
Types ¶
type Activation ¶
Activation is an activation function.
func GetActivation ¶
func GetActivation(activation string) (Activation, error)
type AttributeError ¶
type AttributeError struct {
// contains filtered or unexported fields
}
func ErrInvalidAttribute ¶
func ErrInvalidAttribute(attributeName string, operator Operator) *AttributeError
func (*AttributeError) Error ¶
func (t *AttributeError) Error() string
type AttributeErrorKind ¶
type AttributeErrorKind string
const ( AttributeErrorCount AttributeErrorKind = "count" AttributeErrorInvalid AttributeErrorKind = "invalid" AttributeErrorUnsupported AttributeErrorKind = "unsupported" )
type BooleanOp ¶
BooleanOp describes a binary operation between two booleans that also returns a boolean.
type BroadcastError ¶
type BroadcastError struct {
// contains filtered or unexported fields
}
func (*BroadcastError) Error ¶
func (b *BroadcastError) Error() string
type BroadcastType ¶
type BroadcastType int
const ( NoBroadcasting BroadcastType = 0 UnidirectionalBroadcasting BroadcastType = 1 MultidirectionalBroadcasting BroadcastType = 2 )
type DimensionError ¶
type DimensionError struct {
// contains filtered or unexported fields
}
func (*DimensionError) Error ¶
func (d *DimensionError) Error() string
type DimensionErrorKind ¶
type DimensionErrorKind string
const (
DimensionErrorIncompatible DimensionErrorKind = "incompatible"
)
type FloatType ¶
FloatType is a type that describes a float value. Can be either float32 or float64.
type InputError ¶
type InputError struct {
// contains filtered or unexported fields
}
func (*InputError) Error ¶
func (i *InputError) Error() string
type InputErrorKind ¶
type InputErrorKind string
const ( InputErrorType InputErrorKind = "type" InputErrorCount InputErrorKind = "count" InputErrorUnsupported InputErrorKind = "unsupported" InputErrorInvalid InputErrorKind = "invalid" )
type InputFixture ¶
InputFixture is a function that generates inputs for ops. Useful in testing.
type InvalidTensorError ¶
type InvalidTensorError struct {
// contains filtered or unexported fields
}
func (*InvalidTensorError) Error ¶
func (i *InvalidTensorError) Error() string
type Number ¶
type Number interface { float32 | float64 | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 }
Number is a type which represents a number.
type Operator ¶
type Operator interface { // String should return a simple string describing the operator String() string // Init should initialize the operator based on the given node. // This node contains attributes, which outputs are expected and more. How these // attributes influence the operator is defined by the ONNX standard, and can be // found in https://github.com/onnx/onnx/blob/main/docs/Operators.md Init(*onnx.NodeProto) error // Apply should apply the operator to the list of input tensors. It should return a // list with output tensors, the result of the operator. Apply([]tensor.Tensor) ([]tensor.Tensor, error) // GetMinInputs should return the minimum number of inputs this operator expects. GetMinInputs() int // GetMaxInputs should return the maximum number of inputs this operator expects. GetMaxInputs() int // GetInputTypeConstraints should return a list. Every element represents a set of // allowed tensor dtypes for the corresponding input tensor. GetInputTypeConstraints() [][]tensor.Dtype // ValidateInputs should validate the list of input tensors. It should check for both // the right amount of inputs and the correct dtypes of the tensors. ValidateInputs([]tensor.Tensor) ([]tensor.Tensor, error) }
Operator is the base interface for all operators.
type SequenceProcessDirection ¶
type SequenceProcessDirection string
SequenceProcessDirection is the direction in which a sequential input is processed. We can process sequential inputs forward (from first to last), in reverse (from last to first) or bidirectional (which is both forward and reverse added together).
const ( Forward SequenceProcessDirection = "forward" Reverse SequenceProcessDirection = "reverse" Bidirectional SequenceProcessDirection = "bidirectional" )
type Slicer ¶
type Slicer struct {
// contains filtered or unexported fields
}
Slicer implements the tensor.Slice interface. It is able to slice the dimension of a tensor.
type TypeAssertError ¶
type TypeAssertError struct {
// contains filtered or unexported fields
}
func (*TypeAssertError) Error ¶
func (t *TypeAssertError) Error() string