DTensor

interface DTensor : Differentiable<DTensor>

Interface for a differentiable tensor.

DTensor is an interface that is implemented as either

  • a FloatTensor, which is a wrapper around an array of floats, or

  • a ForwardTensor for forward differentiation, or

  • a ReverseTensor for reverse mode differentiation.

Functions

get
Link copied to clipboard
open operator fun get(index: Int): DTensor
open operator fun get(vararg indices: Int): DTensor
toCodeString
Link copied to clipboard
open fun toCodeString(): String
wrap
Link copied to clipboard
open override fun wrap(wrapper: Wrapper): DTensor

Wrapper around the tensor

Properties

derivativeID
Link copied to clipboard
abstract val derivativeID: DerivativeID

Each derivative is assigned a unique DerivativeID

indices
Link copied to clipboard
open val indices: Iterator<IntArray>

An iterator over the indices for the tensor

isScalar
Link copied to clipboard
open val isScalar: Boolean

True if the tensor is a scalar.

operations
Link copied to clipboard
abstract val operations: Operations

The operations available on a tensor.

primal
Link copied to clipboard
abstract val primal: DTensor

primal points to the actual tensor

rank
Link copied to clipboard
open val rank: Int

The number of dimensions in the tensor's shape. rank 0 - Scalar rank 1 - 1D array or 1D tensor rank 2 - 2D matrix or 2D tensor rank 3 - 3D tensor ... rank N - ND tensor

shape
Link copied to clipboard
open val shape: Shape

shape indicates the number of dimension of a tensor and the length of each dimension. If the shape of the tensor is 3x4x5 then the value of shape is Shape(3,4,5).

size
Link copied to clipboard
open val size: Int

The total number of elements of this tensor.

Inheritors

DScalar
Link copied to clipboard
FloatTensor
Link copied to clipboard
ForwardTensor
Link copied to clipboard
ReverseTensor
Link copied to clipboard
RandomTensorWrapper
Link copied to clipboard
TracingTensor
Link copied to clipboard

Extensions

allAxes
Link copied to clipboard
val DTensor.allAxes: IntArray
basePrimal
Link copied to clipboard
fun DTensor.basePrimal(): FloatTensor

Returns the primal value as a FloatTensor.

broadcastToShape
Link copied to clipboard
fun DTensor.broadcastToShape(shape: Shape): DTensor
concat
Link copied to clipboard
fun DTensor.concat(right: DTensor, axis: Int): DTensor

Concatenate two tensors along the provided axis.

fun DTensor.concat(right: DTensor): DTensor
div
Link copied to clipboard
operator fun DTensor.div(right: DScalar): DTensor
operator fun DTensor.div(right: Float): DTensor
operator fun DTensor.div(that: DTensor): DTensor
eq
Link copied to clipboard
infix fun DTensor.eq(other: DTensor): DTensor
infix fun DTensor.eq(other: Float): DTensor
expand
Link copied to clipboard
fun DTensor.expand(newShape: Shape): DTensor
expandToTangent
Link copied to clipboard
fun DTensor.expandToTangent(tangent: DTensor): DTensor
flatten
Link copied to clipboard
fun DTensor.flatten(): DTensor

Flattens a tensor into a vector (a tensor with rank 1).

fun DTensor.flatten(startDim: Int = 0, endDim: Int = rank - 1): DTensor

Returns a tensor with dimensions startDim, endDim (inclusive range) flattened.

flip
Link copied to clipboard
fun DTensor.flip(axes: IntArray): DTensor
@JvmName(name = "ExtensionVarargFlip")
fun DTensor.flip(vararg axes: Int): DTensor

Create a tensor of the same shape, with all elements flipped across the specified axes

gather
Link copied to clipboard
fun DTensor.gather(indices: List<Int>, axis: Int, paddingIndex: Int = -1): DTensor

Return a tensor made up of slices taken from the input tensor at the given indices along the given axis.

ge
Link copied to clipboard
infix fun DTensor.ge(other: DTensor): DTensor
infix fun DTensor.ge(other: Float): DTensor
gt
Link copied to clipboard
infix fun DTensor.gt(other: DTensor): DTensor
infix fun DTensor.gt(other: Float): DTensor
innerProduct
Link copied to clipboard
fun DTensor.innerProduct(b: Shape, right: DTensor): DTensor

Takes a tensor of shape T, a shape B, and a tensor of shape T and returns a tensor of shape T which is the inner product of the two.

into
Link copied to clipboard
infix fun <T : Layer<T>> DTensor.into(layer: Layer<T>): DTensor
le
Link copied to clipboard
infix fun DTensor.le(other: DTensor): DTensor
infix fun DTensor.le(other: Float): DTensor
leftTranspose
Link copied to clipboard
fun DTensor.leftTranspose(a: Shape, b: Shape): DTensor

Given the shape A,B,D (where A, B and D are lists of Ints, and D is possibly empty), this function converts a tensor of shape A,B,D to a tensor of shape B,A,D, shuffling the data so that the element at position i,j,k is at position j,i,k (where i, j and k are lists of integers corresponding to the shape A, B, and D).

logSoftmax
Link copied to clipboard
fun DTensor.logSoftmax(axis: Int): DTensor
lt
Link copied to clipboard
infix fun DTensor.lt(other: DTensor): DTensor
infix fun DTensor.lt(other: Float): DTensor
matdiv
Link copied to clipboard
fun DTensor.matdiv(that: DTensor): DTensor
matmul
Link copied to clipboard
fun DTensor.matmul(right: DTensor): DTensor

Matrix multiply of two tensors. See https://pytorch.org/docs/stable/generated/torch.matmul.html for the specification.

fun DTensor.matmul(right: DTensor, a: Shape, b: Shape, c: Shape, d: Shape): DTensor

Generalized matrix multiply of two tensors.

minus
Link copied to clipboard
operator fun DTensor.minus(right: DTensor): DTensor

Tensor subtraction.

operator fun DTensor.minus(right: Float): DTensor
momentumUpdated
Link copied to clipboard
fun DTensor.momentumUpdated(new: DTensor, momentum: Float): DTensor

Returns the current (this) tensor updated by the new tensor (new) scaled by momentum

ne
Link copied to clipboard
infix fun DTensor.ne(other: DTensor): DTensor
infix fun DTensor.ne(other: Float): DTensor
outerProduct
Link copied to clipboard
infix fun DTensor.outerProduct(right: DTensor): DTensor
plus
Link copied to clipboard
operator fun DTensor.plus(right: DTensor): DTensor

Tensor addition.

operator fun DTensor.plus(right: Float): DTensor
pow
Link copied to clipboard
fun DTensor.pow(x: DScalar): DTensor
fun DTensor.pow(x: Int): DTensor
fun DTensor.pow(exponent: DTensor): DTensor
fun DTensor.pow(exponent: Float): DTensor
primal
Link copied to clipboard
fun DTensor.primal(derivativeID: DerivativeID): DTensor
relu
Link copied to clipboard
@JvmName(name = "DTensorRelu")
fun DTensor.relu(): DTensor
reshape
Link copied to clipboard
fun DTensor.reshape(vararg newShape: Int): DTensor
fun DTensor.reshape(newShape: Shape): DTensor
rightTranspose
Link copied to clipboard
fun DTensor.rightTranspose(a: Shape, b: Shape): DTensor

Given the shape A,B,D (where A, B and D are lists of Ints, and D is possibly empty), this function converts a tensor of shape D,A,B to a tensor of shape D,B,A, shuffling the data so that the element at position i,j,k is at position i,k,j (where i, j and k are lists of integers corresponding to the shape D, B, and A).

scatter
Link copied to clipboard
fun DTensor.scatter(indices: List<Int>, axis: Int, newShape: Shape, paddingIndex: Int = -1): DTensor
slice
Link copied to clipboard
fun DTensor.slice(start: Int, end: Int, axis: Int = 0): DTensor

Return a slice of the input tensor, which includes only some of the indices at axis. Specifically, it includes indices from start (inclusive) until end (exclusive).

softmax
Link copied to clipboard
@JvmName(name = "DTensorSoftmaxExt")
fun DTensor.softmax(axis: Int): DTensor
split
Link copied to clipboard
fun DTensor.split(shapes: List<Shape>): List<DTensor>

Takes a tensor, and a list of the desired shapes of the components to split it into, and breaks the values up into a list of DValues. For a desired shape that is an empty List, a DScalar is produced. Otherwise a DTensor is produced with the desired shape.

squeeze
Link copied to clipboard
fun DTensor.squeeze(axis: Int): DTensor

Returns a tensor with the singleton dimension at the specified position of the shape removed.

stack
Link copied to clipboard
fun DTensor.stack(right: DTensor, axis: Int = 0): DTensor

Stack two tensors along the provided new axis.

stats
Link copied to clipboard
fun DTensor.stats(): Pair<DScalar, DScalar>

Compute the mean and variance of the data.

sum
Link copied to clipboard
fun DTensor.sum(): DScalar
@JvmName(name = "varargSum")
fun DTensor.sum(vararg axes: Int, keepDims: Boolean = false): DTensor

fun DTensor.sum(axes: IntArray = IntArray(rank) { it }, keepDims: Boolean = false): DTensor

Sum over given axes. If keepDims is true, the original rank of input is preserved. Otherwise, the dimensions provided by axis are removed from the output shape.

times
Link copied to clipboard
operator fun DTensor.times(right: Float): DTensor
operator fun DTensor.times(right: DScalar): DTensor
operator fun DTensor.times(that: DTensor): DTensor
transpose
Link copied to clipboard
fun DTensor.transpose(axes: IntArray = this.allAxes.reversedArray()): DTensor

Returns x transposed over axes. If no axes are provided, tensor is transposed over all axes (that is, the order of the axes are reversed).

unaryMinus
Link copied to clipboard
operator fun DTensor.unaryMinus(): DTensor
unsqueeze
Link copied to clipboard
fun DTensor.unsqueeze(axis: Int): DTensor

Returns a new tensor with a dimension of size one inserted at the specified position of its shape.

view
Link copied to clipboard
fun DTensor.view(indices: IntArray): DTensor
fun DTensor.view(index: Int, axis: Int): DTensor
fun DTensor.view(index: IntRange, axis: Int): DTensor
withChange
Link copied to clipboard
fun DTensor.withChange(index: Int, axis: Int, replacementValue: DTensor): DTensor
fun DTensor.withChange(indices: IntArray, replacementValue: DTensor): DTensor
fun DTensor.withChange(index: IntRange, axis: Int, replacementValue: DTensor): DTensor