cc.redberry.core.tensor
Class Tensor
- java.lang.Object
-
- cc.redberry.core.tensor.Tensor
-
- Direct Known Subclasses:
- Complex, Expression, MultiTensor, Power, ScalarFunction, SimpleTensor, TensorWrapper
public abstract class Tensor extends java.lang.Object implements java.lang.Comparable<Tensor>, java.lang.Iterable<Tensor>
Abstract class which defines common tensor properties and methods. All tensors are immutable. This class dos not implementsequals()method, and in order to compare tensors one should useTensorUtils.equals(Tensor, Tensor).- Since:
- 1.0
- See Also:
Indices,TensorUtils.equals(Tensor, Tensor)
-
-
Constructor Summary
Constructors Constructor and Description Tensor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description intcompareTo(Tensor t)Compares tensors by their hash codes.abstract Tensorget(int i)Returns element at i-th position.abstract TensorBuildergetBuilder()Creates a builder for this tensor.abstract TensorFactorygetFactory()Returns a factory for this tensor.abstract IndicesgetIndices()Returns indices of this tensor.Tensor[]getRange(int from, int to)Retrieves several sub-tensors from current tensor.inthashCode()java.util.Iterator<Tensor>iterator()Return read-only iterator over tensor elements.Tensorset(int i, Tensor tensor)Returns new tensor instance with i-th sub-tensor replaced by provided tensor.abstract intsize()Returns the number of elements in this tensor.Tensor[]toArray()java.lang.StringtoString()Returns a string representation of a tensor according to the defaultOutputFormatdefined inCC.getDefaultOutputFormat().abstract java.lang.StringtoString(OutputFormat outputFormat)Returns a string representation of a tensor according to the specifiedOutputFormat.
-
-
-
Method Detail
-
getIndices
public abstract Indices getIndices()
Returns indices of this tensor.- Returns:
- indices of this tensor
-
iterator
public java.util.Iterator<Tensor> iterator()
Return read-only iterator over tensor elements.- Specified by:
iteratorin interfacejava.lang.Iterable<Tensor>- Returns:
- read-only iterator over tensor elements
-
get
public abstract Tensor get(int i)
Returns element at i-th position.- Parameters:
i- position- Returns:
- element at i-th position
- Throws:
java.lang.IndexOutOfBoundsException- ifi < 0ori >= size()
-
size
public abstract int size()
Returns the number of elements in this tensor.- Returns:
- the number of elements in this tensor
-
set
public Tensor set(int i, Tensor tensor)
Returns new tensor instance with i-th sub-tensor replaced by provided tensor.- Parameters:
i- index of sub-tensor to be replacedtensor- tensor to replace i-th sub-tensor- Returns:
- new instance of tensor
-
getRange
public Tensor[] getRange(int from, int to)
Retrieves several sub-tensors from current tensor. This function is faster than sequential invocations ofget(int)method.- Parameters:
from- index of first sub-tensor to be retrieved (inclusive)to- next index after last sub-tensor to be retrieved (exclusive)- Returns:
- array with retrieved tensors
-
toArray
public Tensor[] toArray()
-
toString
public abstract java.lang.String toString(OutputFormat outputFormat)
Returns a string representation of a tensor according to the specifiedOutputFormat.- Parameters:
outputFormat- output format- Returns:
- a string representation of a tensor
-
toString
public final java.lang.String toString()
Returns a string representation of a tensor according to the defaultOutputFormatdefined inCC.getDefaultOutputFormat().- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of a tensor
-
compareTo
public final int compareTo(Tensor t)
Compares tensors by their hash codes.- Specified by:
compareToin interfacejava.lang.Comparable<Tensor>- Parameters:
t- tensor- Returns:
- 0 if hashes are equals, 1 if hash code of this greater the hash code of specified tensor and -1 otherwise
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getBuilder
public abstract TensorBuilder getBuilder()
Creates a builder for this tensor. SeeTensorBuilderfor more information.- Returns:
- builder for this tensor
-
getFactory
public abstract TensorFactory getFactory()
Returns a factory for this tensor. SeeTensorFactoryfor more information.- Returns:
- builder for this tensor
-
-
DataMelt 3.0 © DataMelt by jWork.ORG