Tensor<T> class
A Tensor in this library is used as the fundamental unit to hold a structured collection of float values on the CPU.
These values are stored for performance enhancement inside of Float32List.
Globally a counter called idCounter ensures uniqueness of Tensors up to the integer limit of instances.
Each Tensor is both holding gradient value and its actual data value. Initialisation is to be done via its constructor.
IMPORTANT: The datatype T is not predefined as a standard value. To ensure compatibility with the framework the use of Scalar,Vector,Matrix and Tensor3D is recommended.
Tensors that end up orphaned are deleted using the Finalizer class but for maximum performance manual management
is recommended. Boolean _freed is used as an additional safety feature allowing to see if the memory allocated has already been freed.
Constructors
Properties
- creator ↔ Node?
-
Node creator stores the node that is responsible for the creation of this Tensor. This allows for backward gradient propagation as well as tracing the origin path of this Tensor.
getter/setter pair
- data ↔ Float32List
-
`Rolled out List of the Tensors value.
getter/setter pair
-
dataPtr
↔ Pointer<
Float> -
C pointer to the memory location of data.
getter/setter pair
- grad ↔ Float32List
-
`Rolled out List of the Tensors gradient value.
getter/setter pair
-
gradPtr
↔ Pointer<
Float> -
C pointer to the memory location of grad.
getter/setter pair
- gradValue → T
-
Converts grad via shape and returns the value as
T.no setter - hasData → bool
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- id ↔ String
-
Global identifier to find and query tensors. id is set to "t_
_idCounterby default. Id can be set anytime on CPU-bound Tensors.getter/setter pair - isFreed → bool
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
shape
↔ List<
int> -
Stores as which shape the Tensors value should be interpreted as. 0-3 dimensions are supported currently (2026-09).
getter/setter pair
- value → T
-
Converts data via shape and returns the value as
T.no setter
Methods
-
backward(
{double startingGrad = 1.0}) → void -
Starting point of gradient calculation. The network of Nodes and Tensors traverses in topological order over all Tensors affecting this Tensor adding a given gradient, calculated via their creator.
The value of
startingGradaffects the first gradient given into the backwards process and is set to1.0by default. -
free(
) → void -
Frees the allocated C memory and sets
_freedtotrue. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
printGraph(
) → void -
Allows the exact printing of the current compute graph for this Tensor. Topological Depth is indicated via indents.
Colors indicate tensor types. Green is indication of an input Tensor, blue an intermediate Tensor and Yellow the resulting output of the Network.
Tensor name and shape are listed as
t_tensorid [1,4,5,...]Example for a simple neuronal network: -
toString(
) → String -
A string representation of this object.
inherited
-
zeroGrad(
) → void -
Traverses the computational Graph which created this Tensor, setting every value of every gradient to
0.0. This method in machine learning is to be used in between training iterations. Forgetting this method may result in oscillating or exploding gradient values.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited