V
- The type parameter for the individual value items within this tensor.public interface Tensor<V> extends Nda<V>, Component<Tensor<V>>, ComponentOwner<Tensor<V>>
Tensor
is a mathematical concept and type of multidimensional
data-structure with certain transformation properties.
Technically however, it is mostly a simple container / data-structure which can house data indexed by N dimensions.
Therefore, it is often also described as a nd-array.
Elements of a tensor are also mostly numeric.Modifier and Type | Interface and Description |
---|---|
static class |
Tensor.ImageType
Use this enum as argument for the
asImage(Tensor.ImageType) method to
specify the type of image that should be returned. |
Component.IsBeing, Component.OwnerChangeRequest<O>
Modifier and Type | Method and Description |
---|---|
default Tensor<V> |
abs()
This method is a functionally identical to the following alternatives:
|
default void |
applyGradient()
If this tensor owns a gradient tensor as component, then it can be applied by this method.
|
java.awt.image.BufferedImage |
asImage(Tensor.ImageType type)
Turns this tensor into a
BufferedImage based on the provided
Tensor.ImageType formatting choice. |
<T> T |
asType(java.lang.Class<T> typeClass) |
default Tensor<V> |
backward()
Use this to back-propagate an error signal of 1.0 through the recorded computation graph.
|
default Tensor<V> |
backward(double value)
Tensors which are used or produced by the autograd system will have a
GraphNode component attached to them. |
default Tensor<V> |
backward(Tensor<V> error)
Tensors which are used or produced by the autograd system will have a
GraphNode component attached to them. |
default boolean |
belongsToGraph()
Tensors which are used or produced by the autograd system will have a
GraphNode component attached to them. |
default Tensor<V> |
cbrt()
This method is a functionally identical to the following alternatives:
|
default Tensor<V> |
concatAt(int axis,
Nda<V> other)
This method concatenates the provided nd-array together with this nd-array along a specified axis.
|
default Tensor<V> |
concatAt(int axis,
Nda<V> other,
Nda<V>... ndArrays)
This method concatenates the provided nd-arrays together with this nd-array along a specified axis.
|
default boolean |
contains(Tensor<V> other)
This method name translates to the "in" keyword in Kotlin!
The same is true for the "isCase" method in Groovy.
|
default Tensor<V> |
conv(Tensor<V> other)
This method performs convolution between this tensor and the one passed as argument.
|
default Tensor<V> |
convDot(Tensor<V> other)
This method performs a convolutional based dot product between the last dimension of this tensor
and the first dimension of the passed tensor.
|
default Tensor<V> |
cos()
This method is a functionally identical to the following alternatives:
|
Tensor<V> |
deepClone()
This is almost identical to the
deepCopy() method except that
the returned tensor will have autograd support, meaning that the cloning
will be part of the autograd computation graph, and backpropagation
will traverse the cloned tensor as well. |
Tensor<V> |
deepCopy()
This method creates and returns a new nd-array instance
which is not only a copy of the configuration of this nd-array but also a copy of
the underlying data array.
|
default Tensor<V> |
detached()
This method returns a new tensor detached from any underlying computation-graph
or simply does nothing if no graph is present.
Nodes within a computation graph are instances of the " GraphNode " class which are also
simple components of the tensors they represent in the graph. |
default Tensor<V> |
dimtrim()
This creates a new tensor with the same underlying
Data and whose shape is trimmed. |
default Tensor<V> |
div(Tensor<V> other)
This method will produce the quotient of
two tensors with the same rank (or two ranks which can be made compatible with padding ones),
where the left operand is this
Tensor
instance and the right operand is the tensor passed to the method. |
default Tensor<V> |
div(V value) |
default Tensor<V> |
dot(Tensor<V> other)
Performs a dot product between the last dimension of this tensor
and the first dimension of the provided tensor.
|
default Tensor<V> |
exp()
This method is a functionally identical to the following alternatives:
|
default java.util.Optional<NDFrame<V>> |
frame()
This is a functionally identical alternative to
getFrame() . |
default Tensor<V> |
get(int... indices)
The following method enables access to specific scalar elements within the nd-array.
|
default Tensor<V> |
get(int i)
This getter method creates and returns a slice of the original nd-array.
|
default Tensor<V> |
get(java.lang.Number i)
This getter method creates and returns a slice of the original nd-array.
|
default Tensor<V> |
get(java.lang.Object... args)
The following method enables the creation of nd-array slices which access
the same underlying data (possibly from a different view).
|
default Tensor<V> |
get(java.lang.Object key)
This method enables nd-array slicing!
It takes a key of various types and configures a slice
nd-array which shares the same underlying data as the original nd-array.
|
Tensor<V> |
getAt(int... indices)
The following method enables access to specific scalar elements within the nd-array.
|
default Tensor<V> |
getAt(int i)
This getter method creates and returns a slice of the original nd-array.
|
Tensor<V> |
getAt(java.util.List<?> key)
This method enables nd-array slicing!
It takes a key of various types and configures a slice
nd-array which shares the same underlying data as the original nd-array.
|
Tensor<V> |
getAt(java.util.Map<?,java.lang.Integer> rangToSteps)
This method is most useful when used in Groovy
where defining maps is done through square brackets,
making it possible to slice nd-arrays like so:
|
default Tensor<V> |
getAt(java.lang.Number i)
This getter method creates and returns a slice of the original nd-array.
|
default Tensor<V> |
getAt(java.lang.Object... args)
The following method enables the creation of nd-array slices which access
the same underlying data (possibly from a different view).
|
DataType<V> |
getDataType()
|
default Device<V> |
getDevice() |
default java.util.Optional<NDFrame<V>> |
getFrame() |
default java.util.Optional<Tensor<V>> |
getGradient() |
default java.util.Optional<GraphNode<V>> |
getGraphNode() |
MutateTensor<V> |
getMut()
This method exposes an API for mutating the state of this tensor.
|
java.lang.Class<?> |
getRepresentativeItemClass()
The
Class returned by this method is the representative Class of the
value items of a concrete AbstractNda but not necessarily the actual Class of
a given value item, this is especially true for numeric types, which are represented by
implementations of the NumericType interface. |
default Tensor<V> |
getT()
|
int |
getVersion()
The version number is tracking how often this tensor has been mutated.
|
default java.util.Optional<Tensor<V>> |
gradient()
This is a functionally identical alternative to the
getGradient() method. |
boolean |
gradientApplyRequested()
This flag works alongside two autograd features which can be enabled inside the library settings.
|
default java.util.Optional<GraphNode<V>> |
graphNode()
This is a functionally identical alternative to
getGraphNode() . |
default boolean |
hasGradient()
Tensors can be components of other tensors which makes the
implicitly their gradients.
|
boolean |
is(java.lang.Class<?> typeClass)
This method compares the passed class with the underlying data-type of this NDArray.
|
default boolean |
isBranch()
Tensors which are used or produced by the autograd system will have a
GraphNode component attached to them. |
boolean |
isCase(Tensor<V> other)
This method name translates to the "in" keyword in Groovy!
The same is true for the "contains" method in Kotlin.
|
boolean |
isDeleted()
This will check if the
MutateTensor.delete() method was previously called on this tensor. |
default boolean |
isEmpty()
A tensor is empty if it's
Data storage is null. |
boolean |
isIntermediate()
Intermediate tensors are internal non-user tensors which may be eligible
for deletion when further consumed by a
Function . |
default boolean |
isLeave()
Tensors which are used or produced by the autograd system will have a
GraphNode component attached to them. |
default boolean |
isOutsourced()
|
default boolean |
isPartialSlice()
If this nd-array is a partial slice of a parent nd-array then this method will yield true.
|
default boolean |
isShallowCopy()
If this nd-array is a shallow copy of a parent nd-array then this method will yield true.
|
default boolean |
isSlice()
If this nd-array is a slice of a parent nd-array then this method will yield true.
|
default boolean |
isSliceParent()
If slices have been derived from this nd-array then it is a "slice parent".
|
default boolean |
isUndefined()
A tensor is "undefined" if it has either no
NDConfiguration implementation instance
or this instance does not have a shape set for this Tensor which is needed for
a tensor to also have a rank and dimensionality... |
boolean |
isVirtual()
A Virtual tensor is a tensor whose underlying data array is of size 1, holding only a single value.
|
static <V> IterByOrIterFromOrAllTensor<V> |
like(Tensor<V> template)
Use this factory method to instantiate a new tensor with the same data type, shape
and memory location (
Device instance) as the provided template tensor. |
default Tensor<V> |
ln()
This method is a functionally identical to the following alternatives:
|
default Tensor<V> |
log10()
This method is a functionally identical to the following alternatives:
|
default Tensor<V> |
map(java.util.function.Function<V,V> mapper)
This method is a convenience method for mapping the items of this nd-array to another
nd-array of the same type based on the provided lambda function, which will be applied
to all items of this nd-array individually (element-wise).
|
default <T> Tensor<T> |
mapTo(java.lang.Class<T> typeClass,
java.util.function.Function<V,T> mapper)
This is a convenience method for mapping a nd-array to a nd-array of new type
based on a provided target item type and mapping lambda.
|
default Tensor<V> |
matMul(Tensor<V> other)
This will produce the matrix product of
two tensors with rank 2 (matrices), where the left operand is this
Tensor
instance and the right operand is the argument passed to the method. |
default Tensor<V> |
max()
Calculate the max value of all values
within this tensor and returns it
in the form of a scalar tensor.
|
default Tensor<V> |
mean()
Calculate the mean value of all values
within this tensor and returns it
in the form of a scalar tensor.
|
default Tensor<V> |
min()
Calculate the min value of all values
within this tensor and returns it
in the form of a scalar tensor.
|
default Tensor<V> |
minus(Tensor<V> other)
Performs subtraction on
two tensors with the same rank (or two ranks which can be made compatible with padding ones),
where the left operand is this
Tensor
instance and the right operand is the tensor passed to the method. |
default Tensor<V> |
minus(V other)
|
default Tensor<V> |
mod(int other) |
default Tensor<V> |
mod(Tensor<V> other)
Produces the modulus of
two tensors with the same rank (or two ranks which can be made compatible with padding ones),
where the left operand is this
Tensor
instance and the right operand is the tensor passed to the method. |
default Tensor<V> |
multiply(double value) |
default Tensor<V> |
multiply(Tensor<V> other)
This method is synonymous to the
times(Tensor) method. |
default Tensor<V> |
multiply(V other) |
default MutateTensor<V> |
mut()
This method exposes an API for mutating the state of this tensor.
|
default Tensor<V> |
neg()
This method is a functionally identical to the following alternatives:
|
default Tensor<V> |
negative() |
static Tensor<java.lang.Object> |
newInstance()
This static factory method creates and return a completely empty and undefined tensor
which is void of any contents and meaning.
|
static Tensor<java.lang.Boolean> |
of(boolean... value)
Constructs a vector of booleans based on the provided array.
|
static Tensor<java.lang.Byte> |
of(byte... value)
Constructs a vector of bytes based on the provided array.
|
static Tensor<java.lang.Byte> |
of(byte value) |
static <T> Tensor<T> |
of(java.lang.Class<T> type,
java.util.List<java.lang.Object> conf)
This factory method will turn a list of values or nested lists of values into a
Tensor
instance with the corresponding rank and shape and whose values
are of the provided type. |
static <T> Tensor<T> |
of(java.lang.Class<T> type,
Shape shape,
Filler<T> filler)
This factory method allows the creation of tensors with an additional initialization
lambda for filling the underlying data array with desired values.
|
static <V> WithShapeOrScalarOrVectorOnDevice<V> |
of(java.lang.Class<V> type)
This is the entry point to the fluent tensor builder API for building
Tensor instances in a readable and type safe fashion. |
static <V> Tensor<V> |
of(java.lang.Class<V> type,
java.util.List<java.lang.Integer> shape,
java.util.List<V> data)
Use this to construct and return a tensor of the specified type, shape and data object.
|
static <V> Tensor<V> |
of(java.lang.Class<V> type,
java.util.List<java.lang.Integer> shape,
java.lang.Object data)
Use this to construct and return a tensor of the specified type, shape and data object.
|
static <V> Tensor<V> |
of(java.lang.Class<V> valueType,
Shape shape,
Arg.Seed seed)
Use this to construct and return a seeded tensor of the specified type.
|
static <V> Tensor<V> |
of(java.lang.Class<V> type,
Shape shape,
java.util.List<V> data)
Use this to construct and return a tensor of the specified type, shape and list of items.
|
static <V extends java.lang.Number> |
of(java.lang.Class<V> type,
Shape shape,
java.lang.Number data)
Use this to construct and return a tensor of the specified type, shape and number.
|
static <V> Tensor<V> |
of(java.lang.Class<V> type,
Shape shape,
java.lang.Object data)
Use this to construct and return a tensor of the specified type, shape and data object.
|
static <T> Tensor<T> |
of(DataType<T> type,
java.util.List<java.lang.Integer> shape,
Filler<T> filler)
This factory method allows the creation of tensors with an additional initialization
lambda for filling the underlying data array with desired values.
|
static <T> Tensor<T> |
of(DataType<T> type,
Shape shape,
Filler<T> filler)
This factory method allows the creation of tensors with an additional initialization
lambda for filling the underlying data array with desired values.
|
static <V extends N,N> |
of(DataType<V> dataType,
Device<N> device,
Shape shape,
java.lang.Object data)
This factory method is among the most flexible and forgiving ways to create a
Tensor instance. |
static <V> Tensor<V> |
of(DataType<V> dataType,
java.util.List<java.lang.Integer> shape,
java.util.List<V> data)
Use this to construct and return a tensor of the specified type, shape and data object.
|
static <V> Tensor<V> |
of(DataType<V> dataType,
NDConstructor ndConstructor,
Data<V> data)
This factory method a raw tensor constructor which will not perform any type checking
or data conversion on the data provided to it.
|
static <V> Tensor<V> |
of(DataType<V> type,
Shape shape)
Use this to construct and return a tensor of the specified type and shape.
|
static <V> Tensor<V> |
of(DataType<V> dataType,
Shape shape,
java.util.List<V> data)
Use this to construct and return a tensor of the specified type, shape and a list of items.
|
static <V> Tensor<V> |
of(DataType<V> dataType,
Shape shape,
java.lang.Object data)
This factory method is among the most flexible and forgiving ways to create a
Tensor instance. |
static Tensor<java.lang.Double> |
of(double... value)
Constructs a vector of doubles based on the provided array.
|
static Tensor<java.lang.Double> |
of(double value) |
static Tensor<java.lang.Float> |
of(float... value)
Constructs a vector of floats based on the provided array.
|
static Tensor<java.lang.Float> |
of(float value) |
static Tensor<java.lang.Integer> |
of(int... value)
Constructs a vector of ints based on the provided array.
|
static Tensor<java.lang.Integer> |
of(int value) |
static <T> Tensor<T> |
of(java.lang.Iterable<T> iterable)
Constructs a vector of objects based on the provided iterable.
|
static <V> Tensor<V> |
of(java.util.List<? extends java.lang.Number> shape,
java.util.List<V> items)
Creates a new
Tensor instance based on a list of numbers representing the shape,
and a list of values representing the value of the resulting tensor. |
static Tensor<java.lang.Double> |
of(java.util.List<? extends java.lang.Number> shape,
java.lang.String seed)
|
static <T> Tensor<T> |
of(java.util.List<java.lang.Integer> shape,
T item)
This is a convenient factory method for creating
Tensor instances for
values of type T based on a list of integers
defining a shape made up of axes sizes as well as a scalar value of type T
which will fill out the data array spanned by the provided shape information. |
static Tensor<java.lang.Object> |
of(java.util.List<java.lang.Object> conf)
This factory method will turn a list of values or nested lists of values into a
Tensor
instance with the corresponding rank and shape. |
static Tensor<java.lang.Long> |
of(long... value)
Constructs a vector of longs based on the provided array.
|
static Tensor<java.lang.Long> |
of(long value) |
static <T> Tensor<T> |
of(java.lang.Object... args)
This static
Tensor factory method tries to interpret the provided
arguments to create the instance the use might wants. |
static Tensor<java.lang.Boolean> |
of(Shape shape,
boolean[] values)
Use this to construct and return a boolean tensor of the specified shape and initial values.
|
static Tensor<java.lang.Byte> |
of(Shape shape,
byte[] values)
Use this to construct and return a byte tensor of the specified shape and initial values.
|
static <V> Tensor<V> |
of(Shape shape,
Data<V> data)
Use this to construct and return a tensor of the specified shape and data object.
This method is typically used like this: |
static Tensor<java.lang.Double> |
of(Shape shape,
double value)
Use this to construct and return a homogeneously populated double tensor of the specified shape.
|
static Tensor<java.lang.Double> |
of(Shape shape,
double[] values)
Use this to construct and return a double tensor of the specified shape and initial values.
|
static Tensor<java.lang.Float> |
of(Shape shape,
float value)
Use this to construct and return a homogeneously populated float tensor of the specified shape.
|
static Tensor<java.lang.Float> |
of(Shape shape,
float[] values)
Use this to construct and return a float tensor of the specified shape and initial values.
|
static Tensor<java.lang.Integer> |
of(Shape shape,
int[] values)
Use this to construct and return an int tensor of the specified shape and initial values.
|
static <V> Tensor<V> |
of(Shape shape,
java.util.List<V> items)
Creates a new
Tensor instance based on a shape tuple of numbers representing the nd-array shape,
and a list of items representing the value of the resulting tensor. |
static Tensor<java.lang.Long> |
of(Shape shape,
long[] values)
Use this to construct and return a long tensor of the specified shape and initial values.
|
static Tensor<java.lang.Short> |
of(Shape shape,
short[] values)
Use this to construct and return a short tensor of the specified shape and initial values.
|
static <T> Tensor<T> |
of(Shape shape,
T value)
This is a convenient factory method for creating
Tensor instances for
representing items of type T . |
static Tensor<java.lang.Short> |
of(short... value)
Constructs a vector of shorts based on the provided array.
|
static Tensor<java.lang.Short> |
of(short value) |
static <V> Tensor<V> |
of(java.lang.String expression,
boolean doAD,
java.util.List<Tensor<V>> tensors)
This method takes a list of tensors and a String expression describing
operations which ought to be applied to the tensors in said list.
|
static <V> Tensor<V> |
of(java.lang.String expression,
boolean doAD,
Tensor<V>... tensors)
This method takes an array of tensors and a String expression describing
operations which ought to be applied to the tensors in said array.
|
static <V> Tensor<V> |
of(java.lang.String expression,
java.util.List<Tensor<V>> inputs)
This factory method allows for the creation and execution of
Function instances
without actually instantiating them manually,
where the result will then be returned by this factory method. |
static <T> Tensor<T> |
of(java.lang.String e1,
Tensor<T> a,
char o,
Tensor<T> b,
java.lang.String e2)
Use this to conveniently operate on 2 tensors.
|
static <T> Tensor<T> |
of(java.lang.String e1,
Tensor<T> a,
java.lang.String e2)
Use this to conveniently operate on a tensor.
|
static <T> Tensor<T> |
of(java.lang.String e1,
Tensor<T> a,
java.lang.String e2,
Tensor<T> b,
java.lang.String e3,
Tensor<T> c,
java.lang.String e4)
Use this to conveniently operate on 3 tensors.
|
static <V> Tensor<V> |
of(java.lang.String expression,
Tensor<V>... tensors)
This method takes an array of tensors and a String expression describing
operations which ought to be applied to the tensors in said array.
|
static <V> Tensor<V> |
of(java.lang.String expression,
Tensor<V> tensor)
This method takes a tensor and a String expression describing
operations which ought to be applied to said tensor.
|
static <V extends java.lang.Number> |
of(java.lang.String expression,
V... inputs)
This factory method allows for the creation and execution of
Function instances
without actually instantiating them manually,
where the result will then be returned by this factory method. |
static <T> Tensor<T> |
of(Tensor<T> a,
char o,
Tensor<T> b)
Use this to conveniently operate on 2 tensors.
|
static <T> Tensor<T> |
of(Tensor<T> a,
char o1,
Tensor<T> b,
char o2,
Tensor<T> c)
Use this to conveniently operate on 3 tensors.
|
static <V> Tensor<V> |
ofAny(java.lang.Class<V> type,
Shape shape,
java.lang.Object data)
Use this to construct and return a tensor of the specified type, shape and data object.
|
static WithShapeOrScalarOrVectorOnDevice<java.lang.Byte> |
ofBytes()
This is a simple convenience method which is simply calling the
of(Class)
method like so: of(Byte.class) . |
static WithShapeOrScalarOrVectorOnDevice<java.lang.Double> |
ofDoubles()
This is a simple convenience method which is simply calling the
of(Class)
method like so: of(Double.class) . |
static WithShapeOrScalarOrVectorOnDevice<java.lang.Float> |
ofFloats()
This is a simple convenience method which is simply calling the
of(Class)
method like so: of(Float.class) . |
static WithShapeOrScalarOrVectorOnDevice<java.lang.Integer> |
ofInts()
This is a simple convenience method which is simply calling the
of(Class)
method like so: of(Integer.class) . |
static <V> Tensor<V> |
ofRandom(java.lang.Class<V> valueTypeClass,
int... shape)
This factory method produces a randomly populated tensor of the provided
type and shape using a hard coded default seed.
|
static WithShapeOrScalarOrVectorOnDevice<java.lang.Short> |
ofShorts()
This is a simple convenience method which is simply calling the
of(Class)
method like so: of(Short.class) . |
default Tensor<V> |
permute(int... dims)
Returns a view of the original tensor input with its dimensions permuted.
Consider a 3-dimensional tensor x with shape (2×3×5), then calling x.permute(1, 0, 2) will return a 3-dimensional tensor of shape (3×2×5). |
default Tensor<V> |
plus(Tensor<V> other)
This method will produce the addition of
two tensors with the same rank (or two ranks which can be made compatible with padding ones),
where the left operand is this
Tensor
instance and the right operand is the tensor passed to the method. |
default Tensor<V> |
plus(V value)
|
default Tensor<V> |
power(Tensor<V> other)
This will produce the power of
two tensors with the same rank (or two ranks which can be made compatible with padding ones),
where the left operand is this
Tensor
instance and the right operand is the tensor passed to the method. |
default Tensor<V> |
power(V value)
Raises all items of this tensor to the power of the provided value.
|
default Tensor<V> |
relu()
This method is a functionally identical to the following alternatives:
|
default Tensor<V> |
rem(int other)
This method is synonymous to the
mod(int) method. |
default Tensor<V> |
reshape(int... shape)
Returns a nd-array with the same data and number of elements as this nd-array, but with the specified shape.
|
boolean |
rqsGradient()
This flag will indirectly trigger the activation of the autograd / auto-differentiation system of this library!
If the flag is set to 'true' and the tensor is used for computation then
it will also receive gradients when the
backward() method is being called
on any descendant tensor within the computation graph. |
default Tensor<V> |
set(OptimizerFactory optimizerFactory)
Configures an
Optimizer for this tensor based on the given OptimizerFactory
which will be used to create a new Optimizer instance specific to this tensor. |
Tensor<V> |
setGradientApplyRequested(boolean applyRequested)
This flag works alongside two autograd features which can be enabled inside the library settings.
|
Tensor<V> |
setRqsGradient(boolean rqsGradient)
Setting this flag to
true will tell the autograd system to accumulate gradients at this tensor. |
default Tensor<V> |
shallowClone() |
default Tensor<V> |
shallowCopy()
This creates a copy where the underlying data is still the same.
|
static <T> java.util.stream.Collector<T,?,Tensor<T>> |
shaped(int... shape)
Returns a
Collector that accumulates the input elements into a
new Tensor with the specified shape. |
static <T> java.util.stream.Collector<T,?,Tensor<T>> |
shaped(Shape shape)
Returns a
Collector that accumulates the input elements into a
new Tensor with the specified shape. |
default Tensor<V> |
sig()
This method is a functionally identical to the following alternatives:
|
default Tensor<V> |
sigmoid() |
default Tensor<V> |
sin()
This method is a functionally identical to the following alternatives:
|
AxisOrGetTensor<V> |
slice()
This method returns a
SliceBuilder instance exposing a simple builder API
which enables the configuration of a slice of the current nd-array via method chaining. |
default int |
sliceCount()
This method returns the number of slices which have been
created from this nd-array.
|
default Tensor<V> |
softmax() |
default Tensor<V> |
softmax(int... axes)
Calculates the softmax function along the specified axes.
|
default Tensor<V> |
softmax(int axis) |
default Tensor<V> |
softplus()
This method is a functionally identical to the following alternatives:
|
default Tensor<V> |
sqrt()
This method is a functionally identical to the following alternatives:
|
default Tensor<V> |
sum()
Calculate the sum value of all values
within this tensor and returns it
in the form of a scalar tensor.
|
default Tensor<V> |
sum(int... axes)
Calculate the sum value of all values
within this tensor along the specified axes and returns it
in the form of a tensor.
|
default Tensor<V> |
sum(int axis)
Calculate the sum value of all values
within this tensor along the specified axis and returns it
in the form of a tensor.
|
default Tensor<V> |
T()
|
default Tensor<V> |
tanh()
This method is a functionally identical to the following alternatives:
|
default Tensor<V> |
times(Tensor<V> other)
This is a functionally identical synonym to the
multiply(Tensor) method. |
default Tensor<V> |
times(V other) |
Tensor<V> |
to(Device<?> device)
|
default Tensor<V> |
to(java.lang.String deviceType) |
default java.lang.String |
toString(java.util.function.Consumer<NDPrintSettings> configurator)
This allows you to provide a lambda which configures how this nd-array should be
converted to
String instances. |
default java.lang.String |
toString(NDPrintSettings config)
Use this to turn this nd-array into a
String instance based on the provided
NDPrintSettings instance, which allows you to configure things
like the number of chars per entry, delimiters, the number of items per line, etc. |
default java.lang.String |
toString(java.lang.String conf) |
default Tensor<V> |
transpose(int dim1,
int dim2)
Returns a view of the original tensor input the targeted
axes are swapped / transposed.
|
default boolean |
update(Component.OwnerChangeRequest<Tensor<V>> changeRequest)
Important : Components of type
Tensor are simply gradients!
Currently, this method is used only to catch illegal arguments which
is for example the case when trying to attach a gradient with a different shape... |
Tensor<V> |
withLabel(java.lang.String label) |
Tensor<V> |
withLabels(java.util.List<java.util.List<java.lang.Object>> labels)
This method receives a nested
String list which
ought to contain a label for the index of this nd-array. |
Tensor<V> |
withLabels(java.util.Map<java.lang.Object,java.util.List<java.lang.Object>> labels)
This method provides the ability to
label not only the indices of the shape of this nd-array, but also
the dimension of the shape.
|
Tensor<V> |
withLabels(java.lang.String[]... labels)
This method receives a nested
String array which
ought to contain a label for the index of this nd-array. |
default Tensor<V> |
xor(double value)
This method is a functionally identical synonym to the
power(Tensor) method. |
default Tensor<V> |
xor(Tensor<V> other)
This method is a functionally identical synonym to the
power(Tensor) method. |
any, at, count, every, filter, flatMap, getDataAs, getDataAt, getItem, getItems, getItemsAs, getItemType, getLabel, getRawData, getRawItems, isFullSlice, item, item, item, items, itemType, label, maxItem, minItem, none, of, of, ofBigDecimals, ofBooleans, ofChars, ofLongs, ofNumbers, ofObjects, ofStrings, stream, toString
getNDConf, getRank, getShape, getSize, indexOfIndex, indexOfIndices, indicesMap, indicesOfIndex, offset, rank, shape, shape, size, spread, strides
static Tensor<java.lang.Object> newInstance()
Tensor
instance as a target for an inline operations which fills the instance with an actual value. MutateTensor.putAt(List, Nda)
method with an empty list as key.
This will be interpreted as an inline copy of the contents of the
second parameter into this Tensor
instance.Tensor
instance.static <T> Tensor<T> of(Tensor<T> a, char o, Tensor<T> b)
of(a,'*',b)
.T
- The value item type parameter for the involved tensors.a
- The left operand.o
- The operator, which may be '+', '-', '*'...b
- The right operand.static <T> Tensor<T> of(Tensor<T> a, char o1, Tensor<T> b, char o2, Tensor<T> c)
of(a,'*',b,'+',c)
.T
- The value item type parameter for the involved tensors.a
- The first and left most operand.o1
- The first operator, which may be '+', '-', '*'...b
- The second operand.o2
- The second operator, which may also be '+', '-', '*'...c
- The third and last operand.static <T> Tensor<T> of(java.lang.String e1, Tensor<T> a, java.lang.String e2)
of("sig(tanh(",a,"))")
.T
- The value item type parameter for the involved tensor.e1
- The first part of the string expression defining how the provided tensor should be processed.a
- The tensor which ought to be sent to whatever is defined by the provided expressions.e2
- The latter part of the expression defining how the provided tensor should be executed.static <T> Tensor<T> of(java.lang.String e1, Tensor<T> a, char o, Tensor<T> b, java.lang.String e2)
of("relu(",a,'-',b,")*2")
.T
- The value item type parameter for the involved tensor.e1
- The first part of the string expression defining how the provided tensor should be processed.a
- The first tensor which ought to be sent to whatever function is defined by the provided expressions.o
- An operator combining both a
and b
to form a result.b
- The second tensor and right operand which ought to be sent to whatever function is defined by the provided expressions.e2
- The latter part of the expression defining how the provided tensor should be executed.static <T> Tensor<T> of(java.lang.String e1, Tensor<T> a, java.lang.String e2, Tensor<T> b, java.lang.String e3, Tensor<T> c, java.lang.String e4)
of("abs((",a,"-",b,") * ",c,")")
.T
- The type parameter for the involved tensors.e1
- The first part of the expression which would typically be used to define a function name.a
- The first argument.e2
- The second part of the expression, which might be an operation.b
- The second argument.e3
- The third part of the expression...c
- The third argument.e4
- The last part of the expression which should syntactically match the other expression...static <T> Tensor<T> of(java.lang.Object... args)
Tensor
factory method tries to interpret the provided
arguments to create the instance the use might wants.args
- The arguments which ought to be interpreted.Tensor
instance of typ Object
.static <T> Tensor<T> of(java.lang.Iterable<T> iterable)
static <T> Tensor<T> of(java.util.List<java.lang.Integer> shape, T item)
Tensor
instances for
values of type T
based on a list of integers
defining a shape made up of axes sizes as well as a scalar value of type T
which will fill out the data array spanned by the provided shape information.static <T> Tensor<T> of(Shape shape, T value)
Tensor
instances for
representing items of type T
. The factory method
instantiates tensors based on a Shape
tuple of integers
defining axes sizes, and a scalar item of type T
which will fill out the data array spanned by the provided shape information.
A simple usage example would be:
Tensor.of(Shape.of( 4, 3, 6 ), 42);
of
in interface Nda<V>
shape
- An immutable tuple of integers whose values ought to define the size of the axes of the shape of the new Tensor
.value
- An object of type T
which will populate the data array of the new instance.Tensor
instance for the generic type T
.static Tensor<java.lang.Double> of(java.util.List<? extends java.lang.Number> shape, java.lang.String seed)
static <V> Tensor<V> of(java.util.List<? extends java.lang.Number> shape, java.util.List<V> items)
Tensor
instance based on a list of numbers representing the shape,
and a list of values representing the value of the resulting tensor.V
- The type parameter of the value list and returned tensor.shape
- A list of numbers whose integer values will be used to form the shape of the resulting Tensor
.items
- A list of values which will be used to populate the data array of the resulting Tensor
.Tensor
instance constructed based on the provided shape and value list.static <V> Tensor<V> of(Shape shape, java.util.List<V> items)
Tensor
instance based on a shape tuple of numbers representing the nd-array shape,
and a list of items representing the value of the resulting tensor.
Tensor.of(Shape.of( 2, 3, 4 ), myListOfItems);
V
- The type parameter of the value list and returned tensor.shape
- A shape tuple of numbers whose integer values will be used to form the shape of the resulting Tensor
.items
- A list of values which will be used to populate the data array of the resulting Tensor
.Tensor
instance constructed based on the provided shape and value list.static Tensor<java.lang.Object> of(java.util.List<java.lang.Object> conf)
Tensor
instance with the corresponding rank and shape.conf
- A list of either values or nested lists which are themselves either or.Tensor
instance whose shape and data is based on the provided list structure.static <T> Tensor<T> of(java.lang.Class<T> type, java.util.List<java.lang.Object> conf)
Tensor
instance with the corresponding rank and shape and whose values
are of the provided type.T
- The type parameter of the tensor returned by this factory method.type
- The type of the tensor produced by this factory method.conf
- A list of either values or nested lists which are themselves either or.Tensor
instance whose shape and data is based on the provided list structure.static <V> WithShapeOrScalarOrVectorOnDevice<V> of(java.lang.Class<V> type)
Tensor
instances in a readable and type safe fashion.
The returned WithShapeOrScalarOrVector
is the next step in the
fluent Tensor
builder API which will lead to the creation
of a tensor storing values defined by the provided type class.
A simple usage example would be:
Tensor.of(Double.class)
.withShape( 2, 3, 4 )
.andFill( 5, 3, 5 )
It is also possible to define a range using the API to populate the tensor with values:
Tensor.of(Double.class)
.withShape( 2, 3, 4 )
.andFillFrom( 2 ).to( 9 ).step( 2 )
If one needs a simple scalar then the following shortcut is possible:
Tensor.of(Float.class).scalar( 3f )
This principle works for vectors as well:
Tensor.of(Byte.class).vector( 2, 5, 6, 7, 8 )
For more fine-grained control over the initialization one can
pass an initialization lambda to the API:
Tensor.of(Byte.class).withShape(2, 3).andWhere( (i, indices) -> i * 5 - 30 )
ofFloats()
, ofDoubles()
, ofInts()
, ofBytes()
, ofShorts()
static WithShapeOrScalarOrVectorOnDevice<java.lang.Double> ofDoubles()
of(Class)
method like so: of(Double.class)
.
The returned WithShapeOrScalarOrVector
is the next step in the
fluent Tensor
builder API which in this case will lead to the creation
of a tensor storing doubles.
Tensor.ofDoubles()
.withShape( 2, 3, 4 )
.andFill( 5d, 3d, 5d )
static WithShapeOrScalarOrVectorOnDevice<java.lang.Float> ofFloats()
of(Class)
method like so: of(Float.class)
.
The returned WithShapeOrScalarOrVector
is the next step in the
fluent Tensor
builder API which in this case will lead to the creation
of a tensor storing floats.
Tensor.ofFloats()
.withShape( 2, 3, 4 )
.andFill( 5f, 7f, 11f )
static WithShapeOrScalarOrVectorOnDevice<java.lang.Integer> ofInts()
of(Class)
method like so: of(Integer.class)
.
The returned WithShapeOrScalarOrVector
is the next step in the
fluent Tensor
builder API which in this case will lead to the creation
of a tensor storing integers.static WithShapeOrScalarOrVectorOnDevice<java.lang.Short> ofShorts()
of(Class)
method like so: of(Short.class)
.
The returned WithShapeOrScalarOrVector
is the next step in the
fluent Tensor
builder API which in this case will lead to the creation
of a tensor storing shorts.static WithShapeOrScalarOrVectorOnDevice<java.lang.Byte> ofBytes()
of(Class)
method like so: of(Byte.class)
.
The returned WithShapeOrScalarOrVector
is the next step in the
fluent Tensor
builder API which in this case will lead to the creation
of a tensor storing bytes.static Tensor<java.lang.Double> of(double... value)
static Tensor<java.lang.Double> of(double value)
static Tensor<java.lang.Float> of(float... value)
static Tensor<java.lang.Float> of(float value)
value
- The scalar value which ought to be represented as tensor.static Tensor<java.lang.Byte> of(byte... value)
static Tensor<java.lang.Byte> of(byte value)
value
- The scalar value which ought to be represented as tensor.static Tensor<java.lang.Integer> of(int... value)
static Tensor<java.lang.Integer> of(int value)
value
- The scalar value which ought to be represented as tensor.static Tensor<java.lang.Long> of(long... value)
static Tensor<java.lang.Long> of(long value)
value
- The scalar value which ought to be represented as tensor.static Tensor<java.lang.Short> of(short... value)
static Tensor<java.lang.Short> of(short value)
value
- The scalar value which ought to be represented as tensor.static Tensor<java.lang.Boolean> of(boolean... value)
static <V> Tensor<V> of(java.lang.Class<V> valueType, Shape shape, Arg.Seed seed)
V
- The type parameter of individual tensor items.valueType
- The type class of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of any number of axis-sizes.seed
- An arbitrary String
whose hash will be used to as a seed.static Tensor<java.lang.Double> of(Shape shape, double value)
shape
- The shape of the resulting tensor consisting of any number of axis-sizes.value
- The value which ought to be used to populate the tensor homogeneously.static Tensor<java.lang.Double> of(Shape shape, double[] values)
static Tensor<java.lang.Integer> of(Shape shape, int[] values)
static Tensor<java.lang.Byte> of(Shape shape, byte[] values)
static Tensor<java.lang.Long> of(Shape shape, long[] values)
static Tensor<java.lang.Short> of(Shape shape, short[] values)
static Tensor<java.lang.Float> of(Shape shape, float[] values)
static Tensor<java.lang.Float> of(Shape shape, float value)
shape
- The shape of the resulting tensor consisting of any number of axis-sizes.value
- The value which ought to be used to populate the tensor homogeneously.static Tensor<java.lang.Boolean> of(Shape shape, boolean[] values)
static <V> Tensor<V> of(Shape shape, Data<V> data)
Tsr<Integer> tensor = Tsr.of( Shape.of(2,3), Data.of(1,2,3,4,5,6) );
The resulting tensor will have the shape [2,3]
and the values [1,2,3,4,5,6]
.V
- The type parameter of individual tensor items.shape
- The shape of the resulting tensor consisting of any number of axis-sizes.data
- The data object which contains the values to be used to populate the tensor.static <V> Tensor<V> of(DataType<V> type, Shape shape)
V
- The type parameter of individual tensor items.type
- The type of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of any number of axis-sizes.static <V> Tensor<V> of(java.lang.Class<V> type, Shape shape, java.lang.Object data)
V
- The type parameter of individual tensor items.type
- The type of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of an array of axis-sizes.data
- The data object which will be used to populate the tensor.static <V> Tensor<V> of(java.lang.Class<V> type, java.util.List<java.lang.Integer> shape, java.lang.Object data)
V
- The type parameter of individual tensor items.type
- The type of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of list of axis-sizes.data
- The data object which will be used to populate the tensor.static <V extends java.lang.Number> Tensor<V> of(java.lang.Class<V> type, Shape shape, java.lang.Number data)
V
- The type parameter of individual tensor items.type
- The type of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of a immutable tuple of axis-sizes.data
- The data object which will be used to populate the tensor.static <V> Tensor<V> ofAny(java.lang.Class<V> type, Shape shape, java.lang.Object data)
V
- The type parameter of individual tensor items.type
- The type of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of a immutable tuple of axis-sizes.data
- The data object which will be used to populate the tensor.static <V> Tensor<V> of(java.lang.Class<V> type, java.util.List<java.lang.Integer> shape, java.util.List<V> data)
V
- The type parameter of individual tensor items.type
- The type of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of a list of axis-sizes.data
- The list of items which will be used to populate the tensor.static <V> Tensor<V> of(java.lang.Class<V> type, Shape shape, java.util.List<V> data)
Tsr<Float> tensor = Tsr.of( Float.class, Shape.of(2,3), List.of(1f,2f,3f,4f,5f,6f) );
V
- The type parameter of individual tensor items.type
- The type of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of an immutable tuple of axis-sizes.data
- The list of items which will be used to populate the tensor.static <V> Tensor<V> of(DataType<V> dataType, java.util.List<java.lang.Integer> shape, java.util.List<V> data)
V
- The type parameter of individual tensor items.dataType
- The type of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of a list of axis-sizes.data
- The data object which will be used to populate the tensor.static <V> Tensor<V> of(DataType<V> dataType, Shape shape, java.util.List<V> data)
Tsr<Integer> tensor = Tsr.of( DataType.F32, Shape.of(2,3), List.of(1,2,3,4,5,6) );
V
- The type parameter of individual tensor items.dataType
- The type of the items stored by the resulting tensor.shape
- The shape of the resulting tensor consisting of an immutable tuple of axis-sizes.data
- The list of items which will be used to populate the tensor.static <V> Tensor<V> of(DataType<V> dataType, Shape shape, java.lang.Object data)
Tensor
instance.
It receives a DataType
for type safety and to ensure that the produced Tensor
instance
will contain elements of the correct type, and a Shape
tuple which stores the sizes of the axes that the
instance ought to possess, and finally it receives a data Object
which can be anything ranging from
a List
to an array or simply a single value which ought to fill out the entire Tensor
.dataType
- The data type of the data represented by Tensor
instance created by this method.shape
- An immutable tuple of axis sizes describing the dimensionality of the Tensor
created by this method.data
- The data for the Tensor
that is about to be created, which can be a list, an array or scalar.Tensor
instance of the specified type, shape and containing the provided data.static <V extends N,N> Tensor<V> of(DataType<V> dataType, Device<N> device, Shape shape, java.lang.Object data)
Tensor
instance.
It receives a DataType
for type safety and to ensure that the produced Tensor
instance
will contain elements of the correct type, and a Shape
tuple which stores the sizes of the axes that the
instance ought to possess, and finally it receives a data Object
which can be anything ranging from
a List
to an array or simply a single value which ought to fill out the entire Tensor
.dataType
- The data type of the data represented by Tensor
instance created by this method.device
- The device on which the tensor will be stored.shape
- An immutable tuple of axis sizes describing the dimensionality of the Tensor
created by this method.data
- The data for the Tensor
that is about to be created, which can be a list, an array or scalar.Tensor
instance of the specified type, shape and containing the provided data.static <V> Tensor<V> of(DataType<V> dataType, NDConstructor ndConstructor, Data<V> data)
V
- The type parameter of individual tensor items.dataType
- The data type of the data represented by Tensor
instance created by this method.ndConstructor
- The NDConstructor
that will be used to construct the Tensor
instance.data
- The data for the Tensor
that is about to be created, which is expected to be an array.Tensor
instance of the specified type, shape and containing the provided data.static <T> Tensor<T> of(DataType<T> type, java.util.List<java.lang.Integer> shape, Filler<T> filler)
T
- The type parameter for the actual data array items.type
- The data type this tensor ought to have.shape
- The shape of this new tensor ought to have.filler
- The lambda Object which ought to fill this tensor with the appropriate data.static <T> Tensor<T> of(DataType<T> type, Shape shape, Filler<T> filler)
Tsr<Double> tensor = Tsr.of( DataType.F64, Shape.of(2, 3), (i, j) -> i + j );
T
- The type parameter for the actual data array items.type
- The data type this tensor ought to have.shape
- The shape of this new tensor ought to have.filler
- The lambda Object which ought to fill this tensor with the appropriate data.static <T> Tensor<T> of(java.lang.Class<T> type, Shape shape, Filler<T> filler)
T
- The type parameter for the actual data array items.type
- The data type class the items of this tensor ought to have.shape
- The shape of this new tensor ought to have.filler
- The lambda Object which ought to fill this tensor with the appropriate data.@SafeVarargs static <V extends java.lang.Number> Tensor<V> of(java.lang.String expression, V... inputs)
Function
instances
without actually instantiating them manually,
where the result will then be returned by this factory method. String
will be parsed into a Function
AST which will be cached
using the expression as key in case it will be used in future constructor calls
like this one, or elsewhere...
The created / retrieved Function
will then be called with the supplied input list
in order to trigger an execution.
The result of which will be used for the population of the fields of this
very instance. expression
- A String which will be used for parsing a Function AST.inputs
- An array of inputs which can be tensors or numeric types.static <V> Tensor<V> of(java.lang.String expression, java.util.List<Tensor<V>> inputs)
Function
instances
without actually instantiating them manually,
where the result will then be returned by this factory method. String
will be parsed into a Function
AST which will be cached
using the expression as key in case it will be used in future constructor calls
like this one, or elsewhere...
The created / retrieved Function
will then be called with the supplied input list
in order to trigger an execution.
The result of which will be used for the population of the fields of this
very instance. expression
- A String which will be used for parsing a Function AST.inputs
- A list of inputs which can be tensors or numeric types.static <V> Tensor<V> of(java.lang.String expression, boolean doAD, java.util.List<Tensor<V>> tensors)
Function
instance expecting as many inputs
as there are array entries, namely : "I[0]", "I[1]", "I[2]", ... Function
instance emerging from the provided expression
should also allow the tracking of computations via a computation graph (GraphNode
instances).
This history tracking then enables auto-differentiation. expression
- The expression describing operations applied to the provided tensors.doAD
- A flag which when set to true commands the creation of a computation graph during operation execution.tensors
- A list of tensors used as inputs to the Function instance parsed from the provided expression.static <V> Tensor<V> of(java.lang.String expression, Tensor<V> tensor)
Function
instance expecting one input,
namely : "I[0]" tensor
- A tensor which serves as input to the Function instance parsed from the given expression.expression
- The expression describing operations applied to the provided tensor.@SafeVarargs static <V> Tensor<V> of(java.lang.String expression, Tensor<V>... tensors)
Function
instance expecting as many inputs
as there are array entries, namely : "I[0]", "I[1]", "I[2]", ... expression
- The expression describing operations applied to the provided tensors.tensors
- An array of tensors used as inputs to the Function instance parsed from the provided expression.@SafeVarargs static <V> Tensor<V> of(java.lang.String expression, boolean doAD, Tensor<V>... tensors)
Function
instance expecting as many inputs
as there are array entries, namely : "I[0]", "I[1]", "I[2]", ... Function
instance emerging from the provided expression
should also allow the tracking of computations via a computation graph (GraphNode
instances).
This history tracking then enables auto-differentiation. expression
- The expression describing operations applied to the provided tensors.doAD
- A flag which when set to true commands the creation of a computation graph during operation execution.tensors
- An array of tensors used as inputs to the Function instance parsed from the provided expression.static <V> Tensor<V> ofRandom(java.lang.Class<V> valueTypeClass, int... shape)
Double
or Float
) then the random numbers will
be gaussian ("normally") distributed values with mean 0.0
and standard
deviation 1.0
.V
- The type parameter of the values stored by the returned tensor.valueTypeClass
- The type class of the values stored by the returned tensor.shape
- The shape of the tensor produced by this factory method.static <V> IterByOrIterFromOrAllTensor<V> like(Tensor<V> template)
Device
instance) as the provided template tensor.V
- The type parameter defining the value type of the provided as well as returned tensor.template
- The template tensor whose type, shape and location should be taken to construct a new tensor.Tensor
instance with the same data type, shape and memory location as the provided template.static <T> java.util.stream.Collector<T,?,Tensor<T>> shaped(int... shape)
Collector
that accumulates the input elements into a
new Tensor
with the specified shape.
var tensor = Stream.of( 1, 2, 3, 4, 5, 6 )
.collect( Tsr.shaped( 2, 3 ) );
static <T> java.util.stream.Collector<T,?,Tensor<T>> shaped(Shape shape)
Collector
that accumulates the input elements into a
new Tensor
with the specified shape.
var tensor = Stream.of( 1, 2, 3, 4, 5, 6 )
.collect( Tsr.shaped( otherTensor.shape() ) );
T
- the type of the input elementsshape
- The shape of the tensor to be returned.Collector
which collects all the input elements into a
Tensor
, in encounter order.Tensor<V> setRqsGradient(boolean rqsGradient)
true
will tell the autograd system to accumulate gradients at this tensor.
This is achieved by allowing for the recording of a computation graph
for when this tensor is used in any autograd supporting operations.
This allows the autograd / auto-differentiation system to traverse said graph
for when the backward()
method is called
on any descendant tensor at the most recent end of the computation graph.rqsGradient
- The truth value determining if this tensor ought to receive gradients via
the built-in automatic backpropagation system.Tensor
instance in order to enable method chaining.boolean rqsGradient()
backward()
method is being called
on any descendant tensor within the computation graph.boolean isIntermediate()
Function
.
For the casual user of Neureka, this flag should always be false!Function
s consuming it.default boolean isOutsourced()
Device
implementation instance which is not the CPU
.boolean isVirtual()
Tsr.ofInts().withShape(x,y).all(n)
Use MutateTensor.setIsVirtual(boolean)
to "actualize" a "virtual" tensor, and vise versa.
boolean isDeleted()
MutateTensor.delete()
method was previously called on this tensor.
This means that the tensor data was freed on every device
and any references inside the tensor are null (to be eligable for garbage collection).MutateTensor.delete()
method has been called oin this instance.default boolean isEmpty()
Data
storage is null.
This is true for deleted tensors or tensors which have not been initialized yet.Data
.default boolean isUndefined()
NDConfiguration
implementation instance
or this instance does not have a shape set for this Tensor
which is needed for
a tensor to also have a rank and dimensionality...NDConfiguration
stored internally.default boolean isSlice()
Nda.getAt(int...)
" method.isSlice
in interface Nda<V>
Nda.getAt(int...)
,
Nda.slice()
default boolean isShallowCopy()
Nda.shallowCopy()
" method.isShallowCopy
in interface Nda<V>
Nda.shallowCopy()
default boolean isPartialSlice()
Nda.getAt(int...)
" method.
This is the inverse of Nda.isFullSlice()
.isPartialSlice
in interface Nda<V>
default int sliceCount()
Relation
component if present
which internally keeps track of slices via weak references.sliceCount
in interface Nda<V>
default boolean isSliceParent()
isSliceParent
in interface Nda<V>
default boolean belongsToGraph()
GraphNode
component attached to them.
This is because autograd requires recording a computation graph for back-prop traversal.
This autograd system however, will only be triggered by Function
implementations which
are not "detached", meaning they have their "Function.isDoingAD()
" flags set to true! GraphNode
instances to involved tensors which will prevent the formation of a computation graph.default boolean isLeave()
GraphNode
component attached to them.
This is because autograd requires recording a computation graph for back-prop traversal.
This autograd system however, will only be triggered by Function
implementations which
are not "detached", meaning they have their "Function.isDoingAD()
" flags set to true! default boolean isBranch()
GraphNode
component attached to them.
This is because autograd requires recording a computation graph for back-prop traversal.
This autograd system however, will only be triggered by Function
implementations which
are not "detached", meaning they have their "Function.isDoingAD()
" flags set to true! default boolean hasGradient()
boolean gradientApplyRequested()
Tensor<V> setGradientApplyRequested(boolean applyRequested)
applyRequested
- The truth value determining if the application of the gradient of this tensor is requested.default boolean update(Component.OwnerChangeRequest<Tensor<V>> changeRequest)
Tensor
are simply gradients!
Currently, this method is used only to catch illegal arguments which
is for example the case when trying to attach a gradient with a different shape...
(Otherwise the gradient tensor "does not mind" an owner change...)update
in interface Component<Tensor<V>>
changeRequest
- An Component.OwnerChangeRequest
implementation instance used to communicate the type of change, context information and the ability to execute the change directly.int getVersion()
java.lang.Class<?> getRepresentativeItemClass()
Class
returned by this method is the representative Class
of the
value items of a concrete AbstractNda
but not necessarily the actual Class
of
a given value item, this is especially true for numeric types, which are represented by
implementations of the NumericType
interface. Double
, this method would
return F64
which is the representative class of Double
. Nda.getItemType()
method instead of this method would return the actual value
type class, namely: Double
.AbstractNda
extension instance which might also be subclasses of the NumericType
interface
to model unsigned types or other JVM foreign numeric concepts.MutateTensor<V> getMut()
Only use this if you know what you are doing and
performance is critical!
(Like in custom backend extensions for example)
default MutateTensor<V> mut()
Only use this if you know what you are doing and
performance is critical!
(Like custom backend extensions for example)
default Tensor<V> reshape(int... shape)
default Tensor<V> permute(int... dims)
default Tensor<V> transpose(int dim1, int dim2)
default Tensor<V> to(java.lang.String deviceType)
deviceType
- A search key identifying the device onto which this tensor should be stored.default Tensor<V> set(OptimizerFactory optimizerFactory)
Optimizer
for this tensor based on the given OptimizerFactory
which will be used to create a new Optimizer
instance specific to this tensor.
The Optimizer
instance will be attached to this tensor as a component
and then called to perform the actual optimization when the applyGradient()
method is called.
Here a simple example of how to use this method:
var t = Tsr.of( 1.0, 2.0, 3.0 ).set( Optimizer.ADAM );
As you can see, the Optimizer
interface exposes various types of popular
optimization algorithm factories which can be used to quickly and conveniently create
an Optimizer
instance for a particular tensor.
optimizerFactory
- The OptimizerFactory
which will be used to create a new Optimizer
instance.default Tensor<V> backward(Tensor<V> error)
GraphNode
component attached to them.
This is because autograd requires recording a computation graph for back-prop traversal.
If this tensor is part of a computation graph then this method
will traverse an error backward in the recorded history towards tensors which require
the accumulation of gradients.error
- A tensor which is back-propagated to gradients. Must match the size og this tensor.default Tensor<V> backward(double value)
GraphNode
component attached to them.
This is because autograd requires recording a computation graph for back-prop traversal.
If this tensor is part of a computation graph then this method
will traverse an error backward in the recorded history towards tensors which require
the accumulation of gradients.value
- A scalar which is back-propagated to gradients. Must match the size og this tensor.default Tensor<V> backward()
GraphNode
components attached to them.
This is because autograd requires recording a computation graph for back-prop traversal.
If this tensor is part of a computation graph then this method
will traverse an error backward in the recorded history towards tensors which require
the accumulation of gradients. default java.util.Optional<Tensor<V>> getGradient()
default java.util.Optional<Tensor<V>> gradient()
getGradient()
method.default void applyGradient()
default Device<V> getDevice()
CPU
if it is not outsourced.default java.util.Optional<GraphNode<V>> getGraphNode()
default java.util.Optional<GraphNode<V>> graphNode()
getGraphNode()
.default java.util.Optional<NDFrame<V>> getFrame()
NDFrame
component if present.default java.util.Optional<NDFrame<V>> frame()
getFrame()
.NDFrame
component if present.default Tensor<V> detached()
GraphNode
" class which are also
simple components of the tensors they represent in the graph. GraphNode
component.Tensor<V> withLabels(java.lang.String[]... labels)
String
array which
ought to contain a label for the index of this nd-array.
The index for a single element of this nd-array would be an array
of numbers as long as the rank where every number is
in the range of the corresponding shape dimension...
Labeling an index means that for every dimension there
must be a label for elements in this range array! withLabels
in interface Nda<V>
labels
- A nested String array containing labels for indexes of the nd-array dimensions.Tensor<V> withLabels(java.util.List<java.util.List<java.lang.Object>> labels)
String
list which
ought to contain a label for the index of this nd-array.
The index for a single element of this nd-array would be an array
of numbers as long as the rank where every number is
in the range of the corresponding shape dimension...
Labeling an index means that for every dimension there
must be a label for elements in this range array! withLabels
in interface Nda<V>
labels
- A nested String list containing labels for indexes of the nd-array dimensions.Tensor<V> withLabels(java.util.Map<java.lang.Object,java.util.List<java.lang.Object>> labels)
withLabels
in interface Nda<V>
labels
- A map in which the keys are dimension labels and the values are lists of index labels for the dimension.boolean is(java.lang.Class<?> typeClass)
typeClass
- The class which ought to be compared to the underlying data-type of this NDArray.default Tensor<V> plus(Tensor<V> other)
Tensor
instance and the right operand is the tensor passed to the method.
If the shapes of both of the involved tensors is identical then
the result will be a regular element-wise addition.
Otherwise, the method will also be able to perform broadcasting, however only if
for every pair of shape dimensions the following is true:
Either the dimensions have the same size or one of them has size 1. other
- The right operand of the addition.Tensor
instance as right operand.default Tensor<V> plus(V value)
Tensor
with the provided double scalar added to all elements of this Tensor
.
The shapes of this tensor is irrelevant as the provided value will simply be broadcast to any possible shape.
value
- The right operand of the addition.default Tensor<V> minus(Tensor<V> other)
Tensor
instance and the right operand is the tensor passed to the method.
If the shapes of both of the involved tensors are identical then
the result will be a regular element-wise subtraction.
Otherwise, the method will also be able to perform broadcasting, however only if
for every pair of shape dimensions the following is true:
Either the dimensions have the same size or one of them has size 1. other
- The right operand of the subtraction.Tensor
instance as right operand.default Tensor<V> minus(V other)
Tensor
with the provided item subtracted from all elements of this Tensor
.
The shapes of this tensor is irrelevant as the provided item will simply be broadcast to all items od this tensor, irrespective of any shape.
other
- The right operand of the subtraction, which is an item of the same type as this tensor.default Tensor<V> negative()
default Tensor<V> T()
Tensor
instance which is a transposed twin of this instance.getT()
method.Data
as this tensor.default Tensor<V> getT()
Tensor
instance which is a transposed twin of this instance.T()
method.Data
as this tensor.default Tensor<V> mean()
default Tensor<V> sum()
default Tensor<V> sum(int axis)
axis
- The axis along which the sum should be calculated.default Tensor<V> sum(int... axes)
axes
- The axes along which the sum should be calculated.default Tensor<V> min()
default Tensor<V> max()
default Tensor<V> convDot(Tensor<V> other)
other
- The tensor which is the right part of the dot product operation.default Tensor<V> dot(Tensor<V> other)
matMul(Tensor)
method.other
- The tensor which is the right part of the dot product operation.default Tensor<V> matMul(Tensor<V> other)
Tensor
instance and the right operand is the argument passed to the method.other
- The right operand of the matrix multiplication.Tensor
instance as right operand.default Tensor<V> conv(Tensor<V> other)
Function
which is registered under the name "conv".other
- The tensor which is the right operand of the convolutional operation.default Tensor<V> dimtrim()
Data
and whose shape is trimmed.
A trimmed shape is simply a shape without preceding and trailing ones. boolean isCase(Tensor<V> other)
other
- The tensor which will be checked.default boolean contains(Tensor<V> other)
other
- The tensor which will be checked.default Tensor<V> multiply(Tensor<V> other)
times(Tensor)
method.
Both of which will produce the product of
two tensors with the same rank (or two ranks which can be made compatible with padding ones),
where the left operand is this Tensor
instance and the right operand is the tensor passed to the method.
If the shapes of both of the involved tensors is identical then
the result will be a regular element-wise product.
Otherwise, the method will also be able to perform broadcasting, however only if
for every pair of shape dimensions the following is true:
Either the dimensions have the same size or one of them has size 1. other
- The right operand of the multiplication.Tensor
instance as right operand.default Tensor<V> multiply(V other)
other
- The value which should be broadcast to all elements of a clone of this tensor.default Tensor<V> times(Tensor<V> other)
multiply(Tensor)
method.
Both of which will produce the product of
two tensors with the same rank (or two ranks which can be made compatible with padding ones),
where the left operand is this Tensor
instance and the right operand is the tensor passed to the method.
If the shapes of both of the involved tensors is identical then
the result will be a regular element-wise product.
Otherwise, the method will also be able to perform broadcasting, however only if
for every pair of shape dimensions the following is true:
Either the dimensions have the same size or one of them has size 1. other
- The right operand of the multiplication.Tensor
instance as right operand.default Tensor<V> times(V other)
other
- The value which should be broadcast to all elements of a clone of this tensor.default Tensor<V> multiply(double value)
value
- The value which should be broadcast to all elements of a clone of this tensor.default Tensor<V> div(Tensor<V> other)
Tensor
instance and the right operand is the tensor passed to the method.
If the shapes of both of the involved tensors are identical then
the result will be a regular element-wise division.
Otherwise, the method will also be able to perform broadcasting, however only if
for every pair of shape dimensions the following is true:
Either the dimensions have the same size or one of them has size 1. other
- The right operand of the division.Tensor
instance as right operand.default Tensor<V> mod(Tensor<V> other)
Tensor
instance and the right operand is the tensor passed to the method.
If the shapes of these 2 tensors are identical then
the result will be a regular element-wise modulo operation.
Otherwise, the method will also be able to perform broadcasting, however only if
for every pair of shape dimensions the following is true:
Either the dimensions have the same size or one of them has size 1. other
- The right operand of the modulo operation.Tensor
instance as right operand.default Tensor<V> mod(int other)
other
- The value which should be broadcast to all elements of a clone of this tensor.default Tensor<V> power(Tensor<V> other)
Tensor
instance and the right operand is the tensor passed to the method.
If the shapes of the involved tensors are identical then
the result will be a regular element-wise exponentiation.
Otherwise, the method will also be able to perform broadcasting, however only if
for every pair of shape dimensions the following is true:
Either the dimensions have the same size or one of them has size 1. other
- The right operand, also known as exponent, of the exponentiation.Tensor
instance as right operand.default Tensor<V> power(V value)
value
- The value which should be used to raise all items of this tensor to the power of.default Tensor<V> xor(Tensor<V> other)
power(Tensor)
method.default Tensor<V> xor(double value)
power(Tensor)
method.default Tensor<V> sig()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().sigmoid().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("sig(I[0])").call(myTensor);
default Tensor<V> tanh()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().tanh().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("tanh(I[0])").call(myTensor);
default Tensor<V> relu()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().relu().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("relu(I[0])").call(myTensor);
default Tensor<V> sin()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().sin().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("sin(I[0])").call(myTensor);
default Tensor<V> cos()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().cos().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("cos(I[0])").call(myTensor);
default Tensor<V> ln()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().ln().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("ln(I[0])").call(myTensor);
default Tensor<V> softplus()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().softplus().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("softplus(I[0])").call(myTensor);
default Tensor<V> exp()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().exp().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("exp(I[0])").call(myTensor);
default Tensor<V> sqrt()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().sqrt().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("sqrt(I[0])").call(myTensor);
default Tensor<V> log10()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().log10().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("log10(I[0])").call(myTensor);
default Tensor<V> cbrt()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().cbrt().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("cbrt(I[0])").call(myTensor);
default Tensor<V> abs()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().abs().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("abs(I[0])").call(myTensor);
default Tensor<V> neg()
// Pre-instantiated:
var out1 = Neureka.get().backend().getAutogradFunction().neg().call( myTensor );
// Dynamically parsed and instantiated:
var out2 = Function.of("neg(I[0])").call(myTensor);
default Tensor<V> softmax()
default Tensor<V> softmax(int axis)
default Tensor<V> softmax(int... axes)
sum(0, 2)
would in this example be a tensor of shape of (1, 3, 1) where every item is 1. axes
- The axes along which the softmax function should be applied.default Tensor<V> sigmoid()
AxisOrGetTensor<V> slice()
SliceBuilder
instance exposing a simple builder API
which enables the configuration of a slice of the current nd-array via method chaining.
myArray.slice()
.axis(0).from(0).to(1)
.axis(1).at(5) // equivalent to '.from(5).to(5)'
.axis().from(0).to(2)
.get();
slice
in interface Nda<V>
SliceBuilder
class exposing a readable builder API for creating slices.default Tensor<V> concatAt(int axis, Nda<V> other, Nda<V>... ndArrays)
concatAt
in interface Nda<V>
axis
- The axis along which the provided nd-arrays should be concatenated.
The axis must be within the range of the rank of the current nd-array.other
- The other nd-arrays which should be concatenated with this nd-array.ndArrays
- The non-null, non-empty nd-arrays which should be concatenated together with this and the other nd-array.
The nd-arrays all must have the same shape as this nd-array, except for the specified axis.
Also, it must have the same data type as the current nd-array.default Tensor<V> concatAt(int axis, Nda<V> other)
concatAt
in interface Nda<V>
axis
- The axis along which the provided nd-arrays should be concatenated.
The axis must be within the range of the rank of the current nd-array.other
- The other nd-arrays which should be concatenated with this nd-array.Tensor<V> getAt(int... indices)
default Tensor<V> getAt(java.lang.Number i)
default Tensor<V> get(int... indices)
default Tensor<V> getAt(java.lang.Object... args)
default Tensor<V> get(java.lang.Object... args)
default Tensor<V> getAt(int i)
default Tensor<V> get(int i)
default Tensor<V> get(java.lang.Number i)
default Tensor<V> get(java.lang.Object key)
Tensor<V> getAt(java.util.Map<?,java.lang.Integer> rangToSteps)
var b = a[[[0..0]:1, [0..0]:1, [0..3]:2]]
Here a single argument with the format '[i..j]:k' is equivalent
to Pythons 'i:j:k' syntax for indexing! (numpy) Tensor<V> getAt(java.util.List<?> key)
default <T> Tensor<T> mapTo(java.lang.Class<T> typeClass, java.util.function.Function<V,T> mapper)
This is a convenience method for mapping a nd-array to a nd-array of new type based on a provided target item type and mapping lambda. Here a simple example:
Nda<String> a = Nda.of(String.class).vector("1", "2", "3");
Nda<Integer> b = a.mapTo(Integer.class, s -> Integer.parseInt(s));
Note:
The provided lambda cannot be executed anywhere else but the CPU.
This is a problem if this nd-array lives somewhere other than the JVM.
So, therefore, this method will temporally transfer this nd-array from
where ever it may reside back to the JVM, execute the mapping lambda, and
then transfer the result back to the original location.
mapTo
in interface Nda<V>
T
- The type parameter of the items of the returned nd-array.typeClass
- The class of the item type to which the items of this nd-array should be mapped.mapper
- The lambda which maps the items of this nd-array to a new one.T
.default Tensor<V> map(java.util.function.Function<V,V> mapper)
This method is a convenience method for mapping the items of this nd-array to another nd-array of the same type based on the provided lambda function, which will be applied to all items of this nd-array individually (element-wise).
Here a simple example:
Nda<String> a = Nda.of(String.class).vector("1", "2", "3");
Nda<String> b = a.map( s -> s + "!" );
Note: java.awt.image.BufferedImage asImage(Tensor.ImageType type)
BufferedImage
based on the provided
Tensor.ImageType
formatting choice.type
- The type of format used to create the buffered image.BufferedImage
populated with the contents of this tensor.<T> T asType(java.lang.Class<T> typeClass)
T
- The type parameter of the type that will be returned.typeClass
- The class which is the target of the type conversion.default java.lang.String toString(java.lang.String conf)
default java.lang.String toString(NDPrintSettings config)
String
instance based on the provided
NDPrintSettings
instance, which allows you to configure things
like the number of chars per entry, delimiters, the number of items per line, etc.default java.lang.String toString(java.util.function.Consumer<NDPrintSettings> configurator)
String
instances.
The provided Consumer
will receive a NDPrintSettings
instance
which allows you to change various settings with the help of method chaining.
t.toString(it ->
it.setHasSlimNumbers(false)
.setIsScientific(true)
.setIsCellBound(true)
.setIsMultiline(true)
.setCellSize(15)
);
toString
in interface Nda<V>
configurator
- A consumer of the NDPrintSettings
ready to be configured.String
representation of this nd-array.Tensor<V> deepCopy()
default Tensor<V> shallowCopy()
shallowCopy
in interface Nda<V>
Tensor<V> deepClone()
deepCopy()
method except that
the returned tensor will have autograd support, meaning that the cloning
will be part of the autograd computation graph, and backpropagation
will traverse the cloned tensor as well.