V
- type of values in Tensor.public class ImmutableTensor<V> extends AbstractTensor<V> implements Mappable<V>, java.io.Serializable
Tensor
.
By constraint of creation it holds a map of Position
of certain type to values of type T, such that ALL
Positions contains the same number and type of coordinates. Number and type of coordinates can be accessed and
explored via Shape
.
There is a special type of Tensor that has ZERO dimensiality. Can be obtained via factory method.
ImmutableTensor
is immutable.
The toString() method does not print all the tensor entries.
Modifier and Type | Class and Description |
---|---|
static class |
ImmutableTensor.Builder<V>
A builder for an immutable tensor.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<Position,V> |
asMap()
By implementing this method, a tensor can provide an efficient way to convert the tensor to a map from position
to values.
|
static <T> ImmutableTensor.Builder<T> |
builder(java.lang.Class<?>... dimensions)
Returns a builder for an
ImmutableTensor . |
static <T> ImmutableTensor.Builder<T> |
builder(java.lang.Iterable<java.lang.Class<?>> dimensions)
Returns a builder for an
ImmutableTensor . |
static <T> ImmutableTensor.Builder<T> |
builderFrom(Tensor<T> tensor)
Returns a builder for an
ImmutableTensor which is initiliased with the given ImmutableTensor . |
boolean |
contains(Position position)
Returns
true if the tensoric object contains the given position, false otherwise. |
Position |
context()
Retrieves the context of the tensor, which is nothing else than a position.
|
static <T> Tensor<T> |
copyOf(Tensor<T> tensor)
Creates an immutable copy of the given tensor.
|
static <T> Tensor<T> |
fromMap(java.lang.Iterable<java.lang.Class<?>> dimensions,
java.util.Map<Position,T> map)
Creates a tensor from the given map, where the map has to contain the positions as keys and the values as values.
|
V |
get(Position position) |
Shape |
shape()
Retrieves the shape of the tensor.
|
java.lang.String |
toString()
When printing the tensor content output is automatically not larger then N ant the beginning and N at the end of
the Tensor entries.
|
equals, hashCode
public static final <T> ImmutableTensor.Builder<T> builder(java.lang.Iterable<java.lang.Class<?>> dimensions)
ImmutableTensor
. As argument it takes set of class of coordinates which
represent the dimensions of the tensor.T
- type of values in Tensor.dimensions
- a set of classes that can later be used as coordinates for the tensor entries.ImmutableTensor
public static final <T> ImmutableTensor.Builder<T> builder(java.lang.Class<?>... dimensions)
ImmutableTensor
. The dimensions (classes of coordinates) of the future tensor
have to be given as arguments here.T
- the type of values of the tensordimensions
- the dimensions of the tensor to createpublic static final <T> Tensor<T> fromMap(java.lang.Iterable<java.lang.Class<?>> dimensions, java.util.Map<Position,T> map)
dimensions
- the desired dimensions of the tensor. This has to be consistent with the position - keys in the
map.map
- the map from which to construct a tensorpublic static final <T> Tensor<T> copyOf(Tensor<T> tensor)
tensor
- the tensor whose element to copypublic static <T> ImmutableTensor.Builder<T> builderFrom(Tensor<T> tensor)
ImmutableTensor
which is initiliased with the given ImmutableTensor
.T
- type of values in Tensor.tensor
- a Tensor with which the ImmutableTensor.Builder
is initializedImmutableTensor.Builder
for an ImmutableTensor
public Position context()
Tensor
Implementations have to guarantee that the returned value here is never null
.
public java.util.Map<Position,V> asMap()
Mappable
null
TensorInternals.mapFrom(Tensor)
(internal clients) or
Tensorics.mapFrom(Tensor)
(external clients)asMap
in interface Mappable<V>
TensorInternals.mapFrom(Tensor)
,
Tensorics.mapFrom(Tensor)
public Shape shape()
Tensor
Implementations have to take care that the returned value here is never null
.
public java.lang.String toString()
toString
in class java.lang.Object