Class MappedTensor

  • All Implemented Interfaces:
    Tensor

    public class MappedTensor
    extends java.lang.Object
    implements Tensor
    A sparse implementation of a tensor backed by a Map of cells to values.
    Author:
    bratseth
    • Method Detail

      • size

        public long size()
        Description copied from interface: Tensor
        Returns the number of cells in this
        Specified by:
        size in interface Tensor
      • get

        public double get​(TensorAddress address)
        Description copied from interface: Tensor
        Returns the value of a cell, or NaN if this cell does not exist/have no value
        Specified by:
        get in interface Tensor
      • cellIterator

        public java.util.Iterator<Tensor.Cell> cellIterator()
        Description copied from interface: Tensor
        Returns the cell of this in some undefined order. A cell instances is only valid until next() is called. Call detach() on the cell to obtain a long-lived instance.
        Specified by:
        cellIterator in interface Tensor
      • valueIterator

        public java.util.Iterator<java.lang.Double> valueIterator()
        Description copied from interface: Tensor
        Returns the values of this in some undefined order
        Specified by:
        valueIterator 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
      • withType

        public Tensor withType​(TensorType other)
        Description copied from interface: Tensor
        Returns this tensor with the given type if types are compatible
        Specified by:
        withType 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • 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