Class

org.platanios.tensorflow.api.tensors

SparseTensor

Related Doc: package tensors

Permalink

final case class SparseTensor[+D <: types.DataType](indices: Tensor[types.INT64], values: Tensor[D], denseShape: Tensor[types.INT64]) extends TensorLike[D] with Product with Serializable

Represents a sparse tensor.

TensorFlow represents a sparse tensor as three separate dense tensors: indices, values, and denseShape. In Scala, the three tensors are collected into a SparseTensor class for ease of use. If you have separate indices, values, and denseShape tensors, wrap them in a SparseTensor object before passing to the relevant sparse tensor manipulation.

Concretely, the sparse tensor SparseTensor(indices, values, denseShape) comprises the following components, where N and rank are the number of values and number of dimensions in the SparseTensor, respectively:

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 on indices(i)). This is not enforced when SparseTensor objects are constructed, but most ops assume correct ordering. If the ordering of sparse tensor st is wrong, a fixed version can be obtained by calling sparseReorder(st).

For example, the sparse tensor SparseTensor(indices = 0], [1, 2, values = [1, 2], denseShape = [3, 4]), represents the dense tensor 0, 0, 0], [0, 0, 2, 0], [0, 0, 0, 0.

indices

Two-dimensional INT32 tensor with shape [N, rank].

values

One-dimensional tensor with shape [N].

denseShape

One-dimensional INT32 tensor with shape [rank].

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. SparseTensor
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. TensorLike
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SparseTensor(indices: Tensor[types.INT64], values: Tensor[D], denseShape: Tensor[types.INT64])

    Permalink

    indices

    Two-dimensional INT32 tensor with shape [N, rank].

    values

    One-dimensional tensor with shape [N].

    denseShape

    One-dimensional INT32 tensor with shape [rank].

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. val dataType: D

    Permalink

    Data type of this sparse op output.

    Data type of this sparse op output.

    Definition Classes
    SparseTensorTensorLike
  7. val denseShape: Tensor[types.INT64]

    Permalink

    One-dimensional INT32 tensor with shape [rank].

  8. val device: String

    Permalink

    Device on which this sparse op output will be placed.

    Device on which this sparse op output will be placed.

    Definition Classes
    SparseTensorTensorLike
  9. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. val indices: Tensor[types.INT64]

    Permalink

    Two-dimensional INT32 tensor with shape [N, rank].

  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. val shape: core.Shape

    Permalink

    Shape of this sparse tensor.

    Shape of this sparse tensor.

    Definition Classes
    SparseTensorTensorLike
  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  19. def toString(): String

    Permalink
    Definition Classes
    SparseTensor → AnyRef → Any
  20. def toTensor[DD >: D <: types.DataType](defaultValue: Tensor[DD] = Tensor.zeros(dataType, Shape()), validateIndices: Boolean = true): Tensor[DD]

    Permalink

    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.

    defaultValue

    Scalar tensor with the same data type as input.values, containing the value set for indices that are not specified in input.indices.

    validateIndices

    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.

    returns

    Result as a new tensor, with the same data type as input.values and shape input.denseShape.

  21. def toTensor: Tensor[D]

    Permalink

    Returns the Tensor that this TensorLike object represents.

    Returns the Tensor that this TensorLike object represents.

    Definition Classes
    SparseTensorTensorLike
  22. def toTensorIndexedSlices: TensorIndexedSlices[D]

    Permalink

    Returns an TensorIndexedSlices that has the same value as this TensorLike.

    Returns an TensorIndexedSlices that has the same value as this TensorLike.

    returns

    TensorIndexedSlices that has the same value as this TensorLike.

    Definition Classes
    SparseTensorTensorLike
    Annotations
    @throws( ... )
  23. val values: Tensor[D]

    Permalink

    One-dimensional tensor with shape [N].

  24. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from TensorLike[D]

Inherited from AnyRef

Inherited from Any

Ungrouped