Data type of this sparse op output.
Data type of this sparse op output.
One-dimensional INT32 tensor with shape [rank]
.
Device on which this sparse op output will be placed.
Device on which this sparse op output will be placed.
Two-dimensional INT32 tensor with shape [N, rank]
.
Shape of this sparse tensor.
Shape of this sparse tensor.
Converts this sparse tensor to a dense tensor.
Converts this sparse tensor to a dense tensor.
The constructed op builds a tensor dense
with shape input.denseShape
, such that:
// If input.indices is scalar: dense(i) ==> (i == input.indices ? input.values : defaultValue) // If input.indices is a vector, then for each i: dense(input.indices(i)) ==> input.values(i) // If input.indices is an n by d matrix, then for each i in [0, n): dense(input.indices(i)(0), ..., input.indices(i)(d-1)) ==> input.values(i)
All other values in dense
are set to defaultValue
. If input.values
is a scalar, then all sparse indices
are set to that single value.
input.indices
should be sorted in lexicographic order and they must not contain any repeats. If
validateIndices
is true
, then these properties are checked during execution.
Scalar tensor with the same data type as input.values
, containing the value set for
indices that are not specified in input.indices
.
If true
, the indices in input.indices
are checked to make sure that they are sorted in
lexicographic order and that there are no repeats.
Result as a new tensor, with the same data type as input.values
and shape input.denseShape
.
Returns the Tensor that this TensorLike object represents.
Returns the Tensor that this TensorLike object represents.
Returns an TensorIndexedSlices that has the same value as this TensorLike.
Returns an TensorIndexedSlices that has the same value as this TensorLike.
TensorIndexedSlices that has the same value as this TensorLike.
One-dimensional tensor with shape [N]
.
Represents a sparse tensor.
TensorFlow represents a sparse tensor as three separate dense tensors:
indices
,values
, anddenseShape
. In Scala, the three tensors are collected into a SparseTensor class for ease of use. If you have separateindices
,values
, anddenseShape
tensors, wrap them in aSparseTensor
object before passing to the relevant sparse tensor manipulation.Concretely, the sparse tensor
SparseTensor(indices, values, denseShape)
comprises the following components, whereN
andrank
are the number of values and number of dimensions in the SparseTensor, respectively:indices
: Two-dimensional INT64 tensor with shape[N, rank]
, which specifies the indices of the elements in the sparse tensor that have nonzero values (elements are zero-indexed). For example,indices = 3], [2, 4
specifies that the elements with indexes[1, 3]
and[2, 4]
have nonzero values.values
: One-dimensional tensor of any type, with shape[N]
, which supplies the values for each element inindices
. For example, givenindices = 3], [2, 4
, the parametervalues = [18, 3.6]
specifies that element[1, 3]
of the sparse tensor has a value of18
, and element[2, 4]
of the tensor has a value of3.6
.denseShape
: One-dimensional INT64 tensor with shape[rank]
, which specifies the dense shape of the sparse tensor. For example,denseShape = [3, 6]
specifies a two-dimensional 3x6 tensor,denseShape = [2, 3, 4]
specifies a three-dimensional 2x3x4 tensor, anddenseShape = [9]
specifies a one-dimensional tensor with 9 elements.The corresponding dense tensor,
dense
, satisfies:dense.shape == denseShape dense(indices(i)) = values(i) // Using a somewhat loose notation with respect to indexing.
IMPORTANT NOTE: By convention,
indices
should be sorted in row-major order (or equivalently lexicographic order onindices(i)
). This is not enforced whenSparseTensor
objects are constructed, but most ops assume correct ordering. If the ordering of sparse tensorst
is wrong, a fixed version can be obtained by callingsparseReorder(st)
.For example, the sparse tensor
SparseTensor(indices = 0], [1, 2, values = [1, 2], denseShape = [3, 4])
, represents the dense tensor0, 0, 0], [0, 0, 2, 0], [0, 0, 0, 0
.Two-dimensional INT32 tensor with shape
[N, rank]
.One-dimensional tensor with shape
[N]
.One-dimensional INT32 tensor with shape
[rank]
.