Class IndexedTensor

  • All Implemented Interfaces:
    Tensor

    public abstract class IndexedTensor
    extends java.lang.Object
    implements Tensor
    An indexed (dense) tensor.

    Some methods on indexed tensors make use of a standard value order: Cells are ordered by increasing index where dimensions to the right are incremented before indexes to the left, where the order of dimensions are alphabetical by name. In consequence, tensor value ordering is independent of the order in which dimensions are specified, and the values of the right-most dimension are adjacent.

    Author:
    bratseth
    • Method Detail

      • cellIterator

        public java.util.Iterator<Tensor.Cell> cellIterator()
        Returns an iterator over the cells of this in the standard value order.
        Specified by:
        cellIterator in interface Tensor
      • valueIterator

        public java.util.Iterator<java.lang.Double> valueIterator()
        Returns an iterator over the values of this returned in the standard value order
        Specified by:
        valueIterator in interface Tensor
      • subspaceIterator

        public java.util.Iterator<IndexedTensor.SubspaceIterator> subspaceIterator​(java.util.Set<java.lang.String> dimensions,
                                                                                   DimensionSizes sizes)
        Returns an iterator over value iterators where the outer iterator is over each unique value of the dimensions given and the inner iterator is over each unique value of the rest of the dimensions, in the standard value order
        Parameters:
        dimensions - the names of the dimensions of the superspace
        sizes - the size of each dimension in the space we are returning values for, containing one value per dimension of this tensor (in order). Each size may be the same or smaller than the corresponding size of this tensor
      • subspaceIterator

        public java.util.Iterator<IndexedTensor.SubspaceIterator> subspaceIterator​(java.util.Set<java.lang.String> dimensions)
        Returns a subspace iterator having the sizes of the dimensions of this tensor
      • get

        public double get​(long... indexes)
        Returns the value at the given indexes as a double
        Parameters:
        indexes - the indexes into the dimensions of this. Must be one number per dimension of this
        Throws:
        java.lang.IllegalArgumentException - if any of the indexes are out of bound or a wrong number of indexes are given
      • getFloat

        public float getFloat​(long... indexes)
        Returns the value at the given indexes as a float
        Parameters:
        indexes - the indexes into the dimensions of this. Must be one number per dimension of this
        Throws:
        java.lang.IllegalArgumentException - if any of the indexes are out of bound or a wrong number of indexes are given
      • get

        public double get​(TensorAddress address)
        Returns the value at this address, or NaN if there is no value at this address
        Specified by:
        get in interface Tensor
      • get

        public abstract double get​(long valueIndex)
        Returns the value at the given standard value order index as a double.
        Parameters:
        valueIndex - the direct index into the underlying data.
        Throws:
        java.lang.IllegalArgumentException - if index is out of bounds
      • getFloat

        public abstract float getFloat​(long valueIndex)
        Returns the value at the given standard value order index as a float.
        Parameters:
        valueIndex - the direct index into the underlying data.
        Throws:
        java.lang.IllegalArgumentException - if index is out of bounds
      • withType

        public abstract IndexedTensor withType​(TensorType type)
        Description copied from interface: Tensor
        Returns this tensor with the given type if types are compatible
        Specified by:
        withType in interface Tensor
      • cells

        public java.util.Map<TensorAddress,​java.lang.Double> cells()
        Description copied from interface: Tensor
        Returns an immutable map of the cells of this in no particular order. This may be expensive for some implementations - avoid when possible
        Specified by:
        cells in interface Tensor
      • remove

        public Tensor remove​(java.util.Set<TensorAddress> addresses)
        Description copied from interface: Tensor
        Returns a new tensor where existing cells in this tensor have been removed according to the given set of addresses. Only valid for sparse or mixed tensors. For mixed tensors, addresses are assumed to only contain the sparse dimensions, as the entire dense subspace is removed.
        Specified by:
        remove in interface Tensor
        Parameters:
        addresses - list of addresses to remove
        Returns:
        a new tensor where cells have been removed
      • toString

        public java.lang.String toString()
        Description copied from interface: Tensor
        Returns this tensor on the tensor literal form with type included.
        Specified by:
        toString in interface Tensor
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Description copied from interface: Tensor
        Returns whether this tensor and the given tensor is mathematically equal: That they have the same dimension *names* and the same content.
        Specified by:
        equals in interface Tensor
        Overrides:
        equals in class java.lang.Object