Package

org.platanios.tensorflow.api

tensors

Permalink

package tensors

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. tensors
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. 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

    Permalink

    Represents a sparse tensor.

    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:

    • 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 in indices. For example, given indices = 3], [2, 4, the parameter values = [18, 3.6] specifies that element [1, 3] of the sparse tensor has a value of 18, and element [2, 4] of the tensor has a value of 3.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, and denseShape = [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 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].

  2. class Tensor[+D <: types.DataType] extends TensorLike[D] with utilities.Closeable with Serializable

    Permalink

    Tensor (i.e., multi-dimensional array).

    Tensor (i.e., multi-dimensional array).

    Tensors are the main data structure underlying all operations in TensorFlow. They represent multi-dimensional arrays of various data types (e.g., FLOAT32). Operations involving tensors can be of two types:

    • Eager: Operations directly executed on the tensor arguments, returning a new tensor. For example:
    val a = Tensor(2.0, 4.5, 3.0, -1.2)
    val b = Tensor(Tensor(0.2, 0.4), Tensor(-2.3, 5.0))
    a.reshape(Shape(2, 2)) + b == Tensor(Tensor(2.2, 4.9), Tensor(0.7, 3.8))
    • Symbolic: Operations that need to be constructed as part of a computational Graph before being executing using a Session. For example:
    val a = tf.placeholder(FLOAT64, Shape(4))               // Symbolic placeholder for value of a
    val b = tf.placeholder(FLOAT64, Shape(2, 2))            // Symbolic placeholder for the value of b
    val add = tf.reshape(a, Shape(2, 2)) + b                // Symbolic representation of the computation
    val result = Session.run(
      feeds = Map(
        a -> Tensor(2.0, 4.5, 3.0, -1.2),
        b -> Tensor(Tensor(0.2, 0.4), Tensor(-2.3, 5.0))),
      fetches = add)                                        // Performs the actual computation
    result == Tensor(Tensor(2.2, 4.9), Tensor(0.7, 3.8))

    // TODO: [OPS] Update doc when we enrich op outputs similarly to tensors.

  3. trait TensorConvertible[T] extends AnyRef

    Permalink

    Type trait representing types that can be converted to tensors.

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

    Permalink

    Sparse representation of a set of tensor slices at given indices.

    Sparse representation of a set of tensor slices at given indices.

    This class if a simple wrapper for a pair (or a set of three) of Tensor objects:

    • indices: A one-dimensional integer Tensor with shape [D0].
    • values: An Tensor of any data type, with shape [D0, D1, ..., Dn].
    • denseShape: Optionally, an integer Tensor with shape [LARGE0, D1, ..., Dn].

    An TensorIndexedSlices is typically used to represent a subset of a larger Output, dense, of shape [LARGE0, D1, ..., Dn], where LARGE0 >> D0. The values in indices are the indices in the first dimension of the slices that have been extracted from the larger tensor.

    The dense Tensor, dense, represented by TensorIndexedSlices, slices, has:

    dense(slices.indices(i), ::, ::, ...) = slices.values(i, ::, ::, ...)

    The TensorIndexedSlices class is used primarily in the definition of gradients for operations that have sparse gradients, such as gather.

    Note that this is different than SparseTensor which uses multi-dimensional indices and scalar values.

    indices

    Indices along the first dimension of the corresponding dense Tensor.

    values

    Values corresponding to the provided indices.

    denseShape

    Shape of the corresponding dense Tensor.

  5. trait TensorLike[+D <: types.DataType] extends AnyRef

    Permalink

    Represents tensor-like objects.

  6. trait TensorOps[TL[DD <: types.DataType] <: TensorLike[DD]] extends AnyRef

    Permalink

    Type trait for defining functions operating on and returning tensors.

Value Members

  1. object Tensor

    Permalink
  2. object TensorConvertible

    Permalink
  3. object TensorOps

    Permalink

    Companion object that defines supported TensorOps implicit values.

  4. package ops

    Permalink

Inherited from AnyRef

Inherited from Any

Ungrouped