Package com.yahoo.tensor
Class MappedTensor
java.lang.Object
com.yahoo.tensor.MappedTensor
- All Implemented Interfaces:
Tensor
A sparse implementation of a tensor backed by a Map of cells to values.
- Author:
- bratseth
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface com.yahoo.tensor.Tensor
Tensor.Cell
-
Field Summary
Fields inherited from interface com.yahoo.tensor.Tensor
invalidIndex
-
Method Summary
Modifier and TypeMethodDescriptionReturns the cell of this in some undefined order.cells()
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.double
get
(TensorAddress address) Returns the value of a cell, or 0.0 if this cell does not existgetAsDouble
(TensorAddress address) Returns the value at this address, or null of it does not exist.boolean
has
(TensorAddress address) Returns true if this cell existsint
hashCode()
Returns a hash computed deterministically from the content of this tensorremove
(Set<TensorAddress> addresses) Returns a new tensor where existing cells in this tensor have been removed according to the given set of addresses.long
size()
Returns the number of cells in this, allowing for very large tensors.int
Once we can store more cells than an int we should drop this.toAbbreviatedString
(boolean withType, boolean shortForms) Returns 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 the values of this in some undefined orderwithType
(TensorType other) Returns this tensor with the given type if types are compatibleMethods inherited from class java.lang.Object
clone, finalize, getClass, 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, 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, smaller, smallerOrEqual, smallest, softmax, subtract, sum, sum, sum, toAbbreviatedString, xwPlusB
-
Method Details
-
type
-
size
public long size()Description copied from interface:Tensor
Returns the number of cells in this, allowing for very large tensors. Prefer sizeAsInt in implementations that cannot handle sizes outside the int range. -
sizeAsInt
public int sizeAsInt()Once we can store more cells than an int we should drop this. -
get
Description copied from interface:Tensor
Returns the value of a cell, or 0.0 if this cell does not exist -
has
Description copied from interface:Tensor
Returns true if this cell exists -
getAsDouble
Description copied from interface:Tensor
Returns the value at this address, or null of it does not exist.- Specified by:
getAsDouble
in interfaceTensor
-
cellIterator
Description copied from interface:Tensor
Returns the cell of this in some undefined order. A cell instance is only valid until next() is called. Call detach() on the cell to obtain a long-lived instance.- Specified by:
cellIterator
in interfaceTensor
-
valueIterator
Description copied from interface:Tensor
Returns the values of this in some undefined order- Specified by:
valueIterator
in interfaceTensor
-
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 -
withType
Description copied from interface:Tensor
Returns this tensor with the given type if types are compatible -
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 mapped or mixed tensors. For mixed tensors, addresses are assumed to only contain the mapped dimensions, as the entire indexed subspace is removed. -
hashCode
public int hashCode()Description copied from interface:Tensor
Returns a hash computed deterministically from the content of this tensor -
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
- Parameters:
withType
- whether to prefix the value by the type of thisshortForms
- whether to use short forms where applicable, or always using the verbose form
-
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.
-