Package com.yahoo.tensor
Class TensorType
- java.lang.Object
-
- com.yahoo.tensor.TensorType
-
public class TensorType extends Object
A tensor type with its dimensions. This is immutable.A dimension can be indexed (bound or unbound) or mapped.
- Author:
- geirst, bratseth
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TensorType.Builder
static class
TensorType.Dimension
A tensor dimension.static class
TensorType.IndexedBoundDimension
static class
TensorType.IndexedUnboundDimension
static class
TensorType.MappedDimension
static class
TensorType.Value
The permissible cell value types.
-
Field Summary
Fields Modifier and Type Field Description static TensorType
empty
The empty tensor type - which is the same as a double
-
Constructor Summary
Constructors Constructor Description TensorType(TensorType.Value valueType, Collection<TensorType.Dimension> dimensions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TensorType.Value
combinedValueType(TensorType... types)
Optional<TensorType.Dimension>
dimension(String name)
Returns the dimension with this name, or empty if not presentSet<String>
dimensionNames()
Returns an immutable set of the names of the dimensions of thisList<TensorType.Dimension>
dimensions()
Returns an immutable list of the dimensions of thisOptional<TensorType>
dimensionwiseGeneralizationWith(TensorType other)
Returns the dimensionwise generalization of this and the given type, or empty if no generalization exists.boolean
equals(Object o)
static TensorType
fromSpec(String specString)
Returns a tensor type instance from a tensor type spec:tensor(dimension1, dimension2, ...)
where each dimension is eitherdimension-name[]
- an unbound indexed dimensiondimension-name[int]
- an bound indexed dimensiondimension-name{}
- a mapped dimension Example:tensor(x[10],y[20])
(a matrix)int
hashCode()
Optional<Integer>
indexOfDimension(String dimension)
Returns the 0-base index of this dimension, or empty if it is not presentboolean
isAssignableTo(TensorType generalization)
Returns whether this type can be assigned to the given type, i.e if the given type is a generalization of this type.boolean
isConvertibleTo(TensorType generalization)
Returns whether this type can be converted to the given type.boolean
isRenamableTo(TensorType other)
Returns whether this type can simply be renamed to the given type.TensorType
mappedSubtype()
The type representing the mapped subset of dimensions of this.boolean
mathematicallyEquals(TensorType other)
Returns whether the given type has the same dimension names as thisint
rank()
Returns the number of dimensions of this: dimensions().size()Optional<Long>
sizeOfDimension(String dimension)
String
toString()
TensorType.Value
valueType()
Returns the numeric type of the cell values of this
-
-
-
Field Detail
-
empty
public static final TensorType empty
The empty tensor type - which is the same as a double
-
-
Constructor Detail
-
TensorType
public TensorType(TensorType.Value valueType, Collection<TensorType.Dimension> dimensions)
-
-
Method Detail
-
combinedValueType
public static TensorType.Value combinedValueType(TensorType... types)
-
fromSpec
public static TensorType fromSpec(String specString)
Returns a tensor type instance from a tensor type spec:tensor(dimension1, dimension2, ...)
where each dimension is eitherdimension-name[]
- an unbound indexed dimensiondimension-name[int]
- an bound indexed dimensiondimension-name{}
- a mapped dimension
tensor(x[10],y[20])
(a matrix)
-
valueType
public TensorType.Value valueType()
Returns the numeric type of the cell values of this
-
mappedSubtype
public TensorType mappedSubtype()
The type representing the mapped subset of dimensions of this.
-
rank
public int rank()
Returns the number of dimensions of this: dimensions().size()
-
dimensions
public List<TensorType.Dimension> dimensions()
Returns an immutable list of the dimensions of this
-
dimensionNames
public Set<String> dimensionNames()
Returns an immutable set of the names of the dimensions of this
-
dimension
public Optional<TensorType.Dimension> dimension(String name)
Returns the dimension with this name, or empty if not present
-
indexOfDimension
public Optional<Integer> indexOfDimension(String dimension)
Returns the 0-base index of this dimension, or empty if it is not present
-
isAssignableTo
public boolean isAssignableTo(TensorType generalization)
Returns whether this type can be assigned to the given type, i.e if the given type is a generalization of this type.
-
isConvertibleTo
public boolean isConvertibleTo(TensorType generalization)
Returns whether this type can be converted to the given type. This is true if this type isAssignableTo the given type or if it is not assignable only because it has a shorter dimension length than the given type in some shared dimension(s), as it can then be converted to the given type by zero padding.
-
isRenamableTo
public boolean isRenamableTo(TensorType other)
Returns whether this type can simply be renamed to the given type. This is the same as being assignable, but disregarding dimension names.
-
mathematicallyEquals
public boolean mathematicallyEquals(TensorType other)
Returns whether the given type has the same dimension names as this
-
dimensionwiseGeneralizationWith
public Optional<TensorType> dimensionwiseGeneralizationWith(TensorType other)
Returns the dimensionwise generalization of this and the given type, or empty if no generalization exists. A dimensionwise generalization exists if the two tensors share the same dimensions, and each dimension is compatible. For example, the dimensionwise generalization of tensor(x[],y[5]) and tensor(x[5],y[]) is tensor(x[],y[])
-
-