Package com.yahoo.tensor
Class IndexedTensor
- java.lang.Object
-
- com.yahoo.tensor.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IndexedTensor.BoundBuilder
A bound builder can create the double array directlystatic class
IndexedTensor.Builder
static interface
IndexedTensor.DirectIndexBuilder
static class
IndexedTensor.Indexes
An array of indexes into this tensor which are able to find the next index in the value order.class
IndexedTensor.SubspaceIterator
An iterator over a subspace of this tensor.-
Nested classes/interfaces inherited from interface com.yahoo.tensor.Tensor
Tensor.Cell
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<Tensor.Cell>
cellIterator()
Returns an iterator over the cells of this in the standard value order.IndexedTensor.SubspaceIterator
cellIterator(PartialAddress partialAddress, DimensionSizes iterationSizes)
Returns an iterator over all the cells in this tensor which matches the given partial addressjava.util.Map<TensorAddress,java.lang.Double>
cells()
Returns an immutable map of the cells of this in no particular order.DimensionSizes
dimensionSizes()
boolean
equals(java.lang.Object other)
Returns whether this tensor and the given tensor is mathematically equal: That they have the same dimension *names* and the same content.abstract double
get(long valueIndex)
Returns the value at the given standard value order index as a double.double
get(long... indexes)
Returns the value at the given indexes as a doubledouble
get(TensorAddress address)
Returns the value at this address, or NaN if there is no value at this addressabstract float
getFloat(long valueIndex)
Returns the value at the given standard value order index as a float.float
getFloat(long... indexes)
Returns the value at the given indexes as a floatTensor
remove(java.util.Set<TensorAddress> addresses)
Returns a new tensor where existing cells in this tensor have been removed according to the given set of addresses.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 tensorjava.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 orderjava.lang.String
toString()
Returns this tensor on the tensor literal form with type included.TensorType
type()
java.util.Iterator<java.lang.Double>
valueIterator()
Returns an iterator over the values of this returned in the standard value orderabstract IndexedTensor
withType(TensorType type)
Returns this tensor with the given type if types are compatible-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.yahoo.tensor.Tensor
add, approxEqual, argmax, argmin, asDouble, atan2, avg, avg, avg, concat, concat, count, count, count, divide, equal, fmod, isEmpty, join, l1Normalize, l2Normalize, larger, largerOrEqual, largest, ldexp, map, matmul, max, max, max, max, merge, min, min, min, min, modify, multiply, notEqual, pow, prod, prod, prod, reduce, reduce, rename, rename, size, smaller, smallerOrEqual, smallest, softmax, subtract, sum, sum, sum, xwPlusB
-
-
-
-
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 interfaceTensor
-
cellIterator
public IndexedTensor.SubspaceIterator cellIterator(PartialAddress partialAddress, DimensionSizes iterationSizes)
Returns an iterator over all the cells in this tensor which matches the given partial address
-
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 interfaceTensor
-
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 superspacesizes
- 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
-
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
-
type
public TensorType type()
-
withType
public abstract IndexedTensor withType(TensorType type)
Description copied from interface:Tensor
Returns this tensor with the given type if types are compatible
-
dimensionSizes
public DimensionSizes dimensionSizes()
-
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
-
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.
-
toString
public java.lang.String toString()
Description copied from interface:Tensor
Returns this tensor on the tensor literal form with type included.
-
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.
-
-