Class TensorType


  • public class TensorType
    extends java.lang.Object
    A tensor type with its dimensions. This is immutable.

    A dimension can be indexed (bound or unbound) or mapped.

    Author:
    geirst, bratseth
    • Field Detail

      • empty

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

      • fromSpec

        public static TensorType fromSpec​(java.lang.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.
      • rank

        public int rank()
        Returns the number of dimensions of this: dimensions().size()
      • dimensions

        public java.util.List<TensorType.Dimension> dimensions()
        Returns an immutable list of the dimensions of this
      • dimensionNames

        public java.util.Set<java.lang.String> dimensionNames()
        Returns an immutable set of the names of the dimensions of this
      • dimension

        public java.util.Optional<TensorType.Dimension> dimension​(java.lang.String name)
        Returns the dimension with this name, or empty if not present
      • indexOfDimension

        public java.util.Optional<java.lang.Integer> indexOfDimension​(java.lang.String dimension)
        Returns the 0-base index of this dimension, or empty if it is not present
      • sizeOfDimension

        public java.util.Optional<java.lang.Long> sizeOfDimension​(java.lang.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 or not this type can simply be renamed to the given type. This is the same as being assignable, but disregarding dimension names.
      • toString

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

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • mathematicallyEquals

        public boolean mathematicallyEquals​(TensorType other)
        Returns whether the given type has the same dimension names as this
      • dimensionwiseGeneralizationWith

        public java.util.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 java.lang.Object