Package com.yahoo.tensor
Class IndexedTensor
java.lang.Object
com.yahoo.tensor.IndexedTensor
- All Implemented Interfaces:
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
Modifier and TypeClassDescriptionstatic class
A bound builder can create the double array directlystatic class
static interface
static class
An array of indexes into this tensor which are able to find the next index in the value order.final class
An iterator over a subspace of this tensor.Nested classes/interfaces inherited from interface com.yahoo.tensor.Tensor
Tensor.Cell
-
Method Summary
Modifier and TypeMethodDescriptionReturns an iterator over the cells of this in the standard value order.cellIterator
(PartialAddress partialAddress, DimensionSizes iterationSizes) Returns an iterator over all the cells in this tensor which matches the given partial addresscells()
Returns an immutable map of the cells of this in no particular order.boolean
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 0.0 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 floatboolean
has
(TensorAddress address) Returns true if this cell existsremove
(Set<TensorAddress> addresses) Returns a new tensor where existing cells in this tensor have been removed according to the given set of addresses.long[]
shape()
subspaceIterator
(Set<String> dimensions) Returns a subspace iterator having the sizes of the dimensions of this tensorsubspaceIterator
(Set<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 orderReturns an abbreviated string representation of this tensor suitable for human-readable messagestoString()
Returns this tensor on the tensor literal form with type included.toString
(boolean withType, boolean shortForms) Returns this tensor on the tensor literal form.type()
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 compatibleMethods 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, bit, cellCast, concat, concat, count, count, count, divide, equal, expand, fmod, hamming, hashCode, isEmpty, join, l1Normalize, l2Normalize, larger, largerOrEqual, largest, ldexp, map, matmul, max, max, max, max, median, median, median, 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 Details
-
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
Returns an iterator over the values of this returned in the standard value order- Specified by:
valueIterator
in interfaceTensor
-
subspaceIterator
public Iterator<IndexedTensor.SubspaceIterator> subspaceIterator(Set<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
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:
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:
IllegalArgumentException
- if any of the indexes are out of bound or a wrong number of indexes are given
-
get
Returns the value at this address, or 0.0 if there is no value at this address -
has
Description copied from interface:Tensor
Returns true if this cell exists -
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:
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:
IllegalArgumentException
- if index is out of bounds
-
type
-
withType
Description copied from interface:Tensor
Returns this tensor with the given type if types are compatible -
dimensionSizes
-
shape
public long[] shape() -
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
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
Description copied from interface:Tensor
Returns this tensor on the tensor literal form with type included. -
toString
Description copied from interface:Tensor
Returns this tensor on the tensor literal form. -
toAbbreviatedString
Description copied from interface:Tensor
Returns an abbreviated string representation of this tensor suitable for human-readable messages- Specified by:
toAbbreviatedString
in interfaceTensor
-
equals
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.
-