Class MappedTensor

java.lang.Object
com.yahoo.tensor.MappedTensor
All Implemented Interfaces:
Tensor

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

    • type

      public TensorType type()
      Specified by:
      type in interface Tensor
    • 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 0.0 if this cell does not exist
      Specified by:
      get in interface Tensor
    • has

      public boolean has(TensorAddress address)
      Description copied from interface: Tensor
      Returns true if this cell exists
      Specified by:
      has in interface Tensor
    • cellIterator

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

      public Map<TensorAddress,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(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()
      Description copied from interface: Tensor
      Returns a hash computed deterministically from the content of this tensor
      Specified by:
      hashCode in interface Tensor
      Overrides:
      hashCode in class Object
    • toString

      public 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 Object
    • toString

      public String toString(boolean withType, boolean shortForms)
      Description copied from interface: Tensor
      Returns this tensor on the tensor literal form.
      Specified by:
      toString in interface Tensor
      Parameters:
      withType - whether to prefix the value by the type of this
      shortForms - whether to use short forms where applicable, or always using the verbose form
    • toAbbreviatedString

      public String toAbbreviatedString(boolean withType, boolean shortForms)
      Description copied from interface: Tensor
      Returns an abbreviated string representation of this tensor suitable for human-readable messages
      Specified by:
      toAbbreviatedString in interface Tensor
      Parameters:
      withType - whether to prefix the value by the type of this
      shortForms - whether to use short forms where applicable, or always using the verbose form
    • equals

      public boolean equals(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 Object