Package org.tensorics.core.tensor
Class BroadcastedTensorView<V>
- java.lang.Object
-
- org.tensorics.core.tensor.AbstractTensor<V>
-
- org.tensorics.core.tensor.BroadcastedTensorView<V>
-
- Type Parameters:
V
- the type of the values of the tensor
public final class BroadcastedTensorView<V> extends AbstractTensor<V>
Lets a tensors appear as a tensor with a bigger shape. The final ('broadcasted') shape of the tensor has more dimensions as the original tensor and is the outer product of the original shape and an additional shape passed into the view. The original set and the passed in shape have to be disjunct in dimensions, i.e. there must be no dimension which appears in both of them.The values are broadcasted such that the values will be the same for all coordinates of the new dimensions.
The resulting view will still be backed by the original tensor. Since the broadcasted shape will never be updated from the original tensor, the results might be unpredictable, if the original tensor would be mutable.
-
-
Constructor Summary
Constructors Constructor Description BroadcastedTensorView(Tensor<V> originalTensor, Shape extendingShape)
Constructs a view of the given original tensor, broadcasted to the additional shape.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(Position position)
Returnstrue
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.V
get(java.lang.Object... coordinates)
V
get(Position position)
Shape
shape()
Retrieves the shape of the tensor.java.lang.String
toString()
-
Methods inherited from class org.tensorics.core.tensor.AbstractTensor
equals, hashCode
-
-
-
-
Constructor Detail
-
BroadcastedTensorView
public BroadcastedTensorView(Tensor<V> originalTensor, Shape extendingShape)
Constructs a view of the given original tensor, broadcasted to the additional shape.- Parameters:
originalTensor
- the original tensorextendingShape
- the shape by which the original tensor shape has to be enlarged
-
-
Method Detail
-
get
public V get(Position position)
- Parameters:
position
- the position in the N-dimensional space where to find the value.- Returns:
- the value at the given position
-
get
public V get(java.lang.Object... coordinates)
- Parameters:
coordinates
- form N-dimensional space where to find the value.- Returns:
- a value at the given coordinates.
-
shape
public Shape shape()
Description copied from interface:Tensor
Retrieves the shape of the tensor. As shape we understand simply the structure of a tensor: Its dimensions and the available positions.Implementations have to take care that the returned value here is never
null
.- Returns:
- the shape of the tensor.
-
context
public Position context()
Description copied from interface:Tensor
Retrieves the context of the tensor, which is nothing else than a position. As context of the tensor we understand coordinates within a higher dimensional space than than the tensor has itself. This coordinates can e.g. transport information when e.g. a higher-dimensional tensor is split into smaller ones, so that it can potentially be reconstructed afterwards.Implementations have to guarantee that the returned value here is never
null
.- Returns:
- the context of the tensor.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
contains
public boolean contains(Position position)
Description copied from interface:Tensoric
Returnstrue
if the tensoric object contains the given position,false
otherwise.- Parameters:
position
- the position to be checked- Returns:
true
if the position is contained in the tensoric object,false
otherwise.
-
-