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
  • Field Details

    • empty

      public static final TensorType empty
      The empty tensor type - which is the same as a double
  • Constructor Details

  • Method Details

    • 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 either
      • dimension-name[] - an unbound indexed dimension
      • dimension-name[int] - an bound indexed dimension
      • dimension-name{} - a mapped dimension
      Example: 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.
    • indexedSubtype

      public TensorType indexedSubtype()
      The type representing the indexed 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
    • sizeOfDimension

      public Optional<Long> sizeOfDimension(String dimension)
    • 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.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • 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[])
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object