Package org.diffkt

Types

Combinators
Link copied to clipboard
object Combinators
ComparisonKind
Link copied to clipboard
enum ComparisonKind : Enum<ComparisonKind>
Convolve
Link copied to clipboard
object Convolve
DerivativeID
Link copied to clipboard
abstract class DerivativeID(sequence: Int)

We identify values produced for forward or reverse differentiation with a DerivativeID. We assign each derivative a unique DerivativeID with its own unique "sequence" number. Each instance of DerivativeID represents a separate set of perturbations, the product of any two of which is zero.

Device
Link copied to clipboard
enum Device : Enum<Device>
Differentiable
Link copied to clipboard
interface Differentiable<out T : Differentiable<T>> : Wrappable<T>

Implement Differentiable to have the runtime be capable of using your data type as an input or output type of a function that can be differentiated.

DimData
Link copied to clipboard
data class DimData(inner: IntArray, outer: IntArray)

DimData represents a dimension in a SparseFloatTensor.

DScalar
Link copied to clipboard
interface DScalar : DTensor

A differentiable scalar (float). We represent a number DScalar as either

DTensor
Link copied to clipboard
interface DTensor : Differentiable<DTensor>

Interface for a differentiable tensor.

FloatScalar
Link copied to clipboard
class FloatScalar(value: Float) : FloatTensor, DScalar

A differentiable tensor of rank 0 containing a single float (a FloatTensor wrapper around a float).

FloatTensor
Link copied to clipboard
abstract class FloatTensor : DTensor
IntegralReverseScalar
Link copied to clipboard
class IntegralReverseScalar(primal: DScalar, a: ReverseScalar?, b: ReverseScalar?, f: (DScalar) -> DScalar, derivativeID: ReverseDerivativeID) : ReverseScalar
IntTensor
Link copied to clipboard
class IntTensor

An int tensor, which stores its underlying data in an int array and tracks the strides needed to access data for each dimension.

LazyList
Link copied to clipboard
class LazyList<T : Any>(size: Int, gen: (Int) -> T) : AbstractList<T>
NoDerivativeID
Link copied to clipboard
object NoDerivativeID : DerivativeID
OnDevice
Link copied to clipboard
interface OnDevice
Operations
Link copied to clipboard
interface Operations
Shape
Link copied to clipboard
class Shape
Sparse
Link copied to clipboard
interface Sparse
SparseFloatTensor
Link copied to clipboard
class SparseFloatTensor(shape: Shape, values: FloatArray, dims: List<DimData>) : FloatTensor, Sparse
SparseFloatVector
Link copied to clipboard
class SparseFloatVector(shape: Shape, values: FloatArray, inner: IntArray) : FloatTensor, Sparse
SparseRowFloatTensor
Link copied to clipboard
class SparseRowFloatTensor : FloatTensor

A sparse row float tensor, which is a FloatTensor of rank 2 which has sparse rows (e.g. has rows that are empty/zero). This data format is particularly useful for embedding table gradients.

StridedFloatTensor
Link copied to clipboard
class StridedFloatTensor : FloatTensor

A float tensor, which stores its underlying data in a float array and tracks the strides needed to access data for each dimension.

TensorInfo
Link copied to clipboard
data class TensorInfo(data: FloatArray, strides: IntArray, offset: Int)
Wrappable
Link copied to clipboard
interface Wrappable<out T : Wrappable<T>>

Implement Wrappable to have the runtime be capable of using your data type as an input or output type of a function that can be wrapped.

Wrapper
Link copied to clipboard
abstract class Wrapper

An interface that is capable of wrapping individual values. To be used by an implementation of Differentiable to wrap the individual values.

Functions

abs
Link copied to clipboard
fun abs(x: DScalar): DScalar
fun abs(x: DTensor): DTensor
atan
Link copied to clipboard
fun atan(x: DScalar): DScalar
fun atan(x: DTensor): DTensor
basePrimal
Link copied to clipboard
fun DScalar.basePrimal(): FloatScalar

Returns the primal value as a FloatScalar.

fun DTensor.basePrimal(): FloatTensor

Returns the primal value as a FloatTensor.

broadcastAll
Link copied to clipboard
fun broadcastAll(a: DTensor, b: DTensor): Pair<DTensor, DTensor>
fun broadcastAll(a: DTensor, b: DTensor, c: DTensor): Triple<DTensor, DTensor, DTensor>
broadcastToShape
Link copied to clipboard
fun DTensor.broadcastToShape(shape: Shape): DTensor
combineHash
Link copied to clipboard
fun combineHash(vararg values: Any?): Int
compareTo
Link copied to clipboard
operator fun Float.compareTo(right: DScalar): Int
operator fun Float.compareTo(right: FloatScalar): Int
operator fun DScalar.compareTo(right: Float): Int
operator fun DScalar.compareTo(right: DScalar): Int
operator fun FloatScalar.compareTo(right: Float): Int
operator fun FloatScalar.compareTo(right: FloatScalar): Int
concat
Link copied to clipboard
fun DTensor.concat(right: DTensor): DTensor
fun concat(slices: List<DTensor>, axis: Int = 0): DTensor
fun FloatTensor.concat(right: FloatTensor, axis: Int = 0): FloatTensor

fun DTensor.concat(right: DTensor, axis: Int): DTensor

Concatenate two tensors along the provided axis.

conv2d
Link copied to clipboard
fun conv2d(signal: DTensor, filter: DTensor, hStride: Int, vStride: Int, padding: Convolve.Padding2D): DTensor
fun conv2d(signal: DTensor, filter: DTensor, hStride: Int, vStride: Int, paddingStyle: Convolve.PaddingStyle = Convolve.PaddingStyle.Same): DTensor
cos
Link copied to clipboard
fun cos(x: DScalar): DScalar
fun cos(x: DTensor): DTensor
crossEntropyLoss
Link copied to clipboard
fun crossEntropyLoss(x: DTensor, labels: DTensor, fromOneHot: Boolean = false): DScalar

x is the output of the network: xi,j is its guess on whether input i is classified as a j. labels is the actual label: labelsi,j is 1 iff input i is classified as a j; 0 otherwise.

crossEntropyLossFromOneHot
Link copied to clipboard
fun crossEntropyLossFromOneHot(x: DTensor, oneHotLabels: DTensor): DScalar

x is the output of the network: xi,j is its guess on whether input i is classified as a j. labels is the actual label: labelsi,j is 1 iff input i is classified as a j; 0 otherwise.

digamma
Link copied to clipboard
fun digamma(x: DScalar): DScalar
fun digamma(x: DTensor): DTensor
div
Link copied to clipboard
operator fun Float.div(right: DScalar): DScalar
operator fun DScalar.div(right: Float): DScalar
operator fun DScalar.div(right: Int): DScalar
operator fun DScalar.div(right: DScalar): DScalar
operator fun DTensor.div(right: Float): DTensor
operator fun DTensor.div(right: DScalar): DTensor
operator fun DTensor.div(that: DTensor): DTensor
embedding
Link copied to clipboard
fun embedding(table: DTensor, indices: IntTensor, paddingIndex: Int = -1): DTensor

The backing operation for the embedding layer.

eq
Link copied to clipboard
infix fun Float.eq(other: Float): Boolean
infix fun Float.eq(other: DScalar): DScalar
infix fun Float.eq(other: DTensor): DTensor
infix fun DScalar.eq(other: Float): DScalar
infix fun DScalar.eq(other: DScalar): DScalar
infix fun DTensor.eq(other: Float): DTensor
infix fun DTensor.eq(other: DTensor): DTensor
exp
Link copied to clipboard
fun exp(x: DScalar): DScalar
fun exp(x: DTensor): 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

forwardDerivative
Link copied to clipboard
fun forwardDerivative(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun forwardDerivative(x: DTensor, f: (DTensor) -> DTensor): DTensor
fun forwardDerivative(n: Int, x: DScalar, f: (DScalar) -> DScalar): DScalar
fun forwardDerivative(n: Int, x: DTensor, f: (DTensor) -> DTensor): DTensor
fun forwardDerivative(x: DScalar, y: DScalar, f: (DScalar, DScalar) -> DScalar): Pair<DScalar, DScalar>
fun forwardDerivative(x: DTensor, y: DTensor, f: (DTensor, DTensor) -> DTensor): Pair<DTensor, DTensor>
fun <Input : Any, Output : Any, Derivative : Any> forwardDerivative(x: Input, f: (Input) -> Output, wrapInput: (Input, Wrapper) -> Input? = null, wrapOutput: (Output, Wrapper) -> Output? = null, extractDerivative: (Input, Output, extractOneDerivative: (input: DTensor, output: DTensor) -> DTensor) -> Derivative): Derivative
forwardDerivative1
Link copied to clipboard
fun forwardDerivative1(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun forwardDerivative1(x: DTensor, f: (DTensor) -> DTensor): DTensor
forwardDerivative2
Link copied to clipboard
fun forwardDerivative2(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun forwardDerivative2(x: DTensor, f: (DTensor) -> DTensor): DTensor
forwardDerivative3
Link copied to clipboard
fun forwardDerivative3(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun forwardDerivative3(x: DTensor, f: (DTensor) -> DTensor): DTensor
forwardDerivative4
Link copied to clipboard
fun forwardDerivative4(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun forwardDerivative4(x: DTensor, f: (DTensor) -> DTensor): DTensor
forwardDiff
Link copied to clipboard
fun forwardDiff(f: (DScalar) -> DScalar): (DScalar) -> DScalar
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.

fun FloatTensor.gather(indices: List<Int>, axis: Int, paddingIndex: Int = -1): FloatTensor
ge
Link copied to clipboard
infix fun Float.ge(other: Float): Boolean
infix fun Float.ge(other: DScalar): DScalar
infix fun Float.ge(other: DTensor): DTensor
infix fun DScalar.ge(other: Float): DScalar
infix fun DScalar.ge(other: DScalar): DScalar
infix fun DTensor.ge(other: Float): DTensor
infix fun DTensor.ge(other: DTensor): DTensor
gt
Link copied to clipboard
infix fun Float.gt(other: Float): Boolean
infix fun Float.gt(other: DScalar): DScalar
infix fun Float.gt(other: DTensor): DTensor
infix fun DScalar.gt(other: Float): DScalar
infix fun DScalar.gt(other: DScalar): DScalar
infix fun DTensor.gt(other: Float): DTensor
infix fun DTensor.gt(other: DTensor): DTensor
ifThenElse
Link copied to clipboard
fun ifThenElse(condition: Float, truePart: Float, falsePart: Float): Float
fun ifThenElse(condition: FloatScalar, truePart: DScalar, falsePart: DScalar): DScalar

fun ifThenElse(condition: DScalar, truePart: DScalar, falsePart: DScalar): DScalar

Test whether an input value tested is greater than zero, or less than or equal to zero. Each element of the result is, depending on the value in tested:

fun ifThenElse(condition: DTensor, truePart: DTensor, falsePart: DTensor): DTensor

Test whether an input value condition is greater than zero (true), or less than or equal to zero (false). Each element of the result is, depending on the value in condition:

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.

integral
Link copied to clipboard
fun integral(a: DScalar, b: DScalar, n: Int = 5, eps: Float = 1.0E-5f, f: (DScalar) -> DScalar): DScalar

Compute the integral of the function f from a to b using Romberg's method.

intScalarOf
Link copied to clipboard
fun intScalarOf(value: Int): IntTensor
intTensorOf
Link copied to clipboard
fun intTensorOf(vararg data: Int): IntTensor
isPrefix
Link copied to clipboard
fun List<Int>.isPrefix(list: List<Int>): Boolean
jvp
Link copied to clipboard
fun jvp(x: DTensor, v: DTensor, f: (DTensor) -> DTensor): DTensor
le
Link copied to clipboard
infix fun Float.le(other: Float): Boolean
infix fun Float.le(other: DScalar): DScalar
infix fun Float.le(other: DTensor): DTensor
infix fun DScalar.le(other: Float): DScalar
infix fun DScalar.le(other: DScalar): DScalar
infix fun DTensor.le(other: Float): DTensor
infix fun DTensor.le(other: DTensor): 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).

lgamma
Link copied to clipboard
fun lgamma(x: DScalar): DScalar
fun lgamma(x: DTensor): DTensor
ln
Link copied to clipboard
fun ln(x: DScalar): DScalar
fun ln(x: DTensor): DTensor
logSoftmax
Link copied to clipboard
fun DTensor.logSoftmax(axis: Int): DTensor
lt
Link copied to clipboard
infix fun Float.lt(other: Float): Boolean
infix fun Float.lt(other: DScalar): DScalar
infix fun Float.lt(other: DTensor): DTensor
infix fun DScalar.lt(other: Float): DScalar
infix fun DScalar.lt(other: DScalar): DScalar
infix fun DTensor.lt(other: Float): DTensor
infix fun DTensor.lt(other: DTensor): 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.

max
Link copied to clipboard
fun FloatTensor.max(axes: IntArray = allAxes, keepDims: Boolean = false): FloatTensor
meld
Link copied to clipboard
fun meld(vararg value: DTensor): DTensor
fun meld(values: List<DTensor>): DTensor

Takes a list of values (each of which can be either a DTensor or a DScalar) and combine their values into a single DTensor containing all of the values from the inputs.

min
Link copied to clipboard
fun FloatTensor.min(axes: IntArray = allAxes, keepDims: Boolean = false): FloatTensor
minus
Link copied to clipboard
operator fun Float.minus(right: DScalar): DScalar
operator fun Float.minus(right: DTensor): DTensor
operator fun DScalar.minus(right: DScalar): DScalar
operator fun DTensor.minus(right: Float): DTensor

operator fun DScalar.minus(right: Float): DScalar

Scalar (floating-point) subtraction.

operator fun DTensor.minus(right: DTensor): DTensor

Tensor subtraction.

ne
Link copied to clipboard
infix fun Float.ne(other: Float): Boolean
infix fun Float.ne(other: DScalar): DScalar
infix fun Float.ne(other: DTensor): DTensor
infix fun DScalar.ne(other: Float): DScalar
infix fun DScalar.ne(other: DScalar): DScalar
infix fun DTensor.ne(other: Float): DTensor
infix fun DTensor.ne(other: DTensor): DTensor
nllLossFromOneHot
Link copied to clipboard
fun nllLossFromOneHot(guesses: DTensor, labels: DTensor): DScalar
outerProduct
Link copied to clipboard
infix fun DTensor.outerProduct(right: DTensor): DTensor
plus
Link copied to clipboard
operator fun Float.plus(right: DScalar): DScalar

Because scalar addition is commutative, we can implement this operation in terms of the same operation with the operands swapped.

operator fun Float.plus(right: DTensor): DTensor
operator fun DTensor.plus(right: Float): DTensor

operator fun DScalar.plus(right: Float): DScalar

The addition of a floating-point number to a DScalar simply updates the primal with the scaled value.

operator fun DScalar.plus(right: DScalar): DScalar

Scalar (floating-point) addition.

operator fun DTensor.plus(right: DTensor): DTensor

Tensor addition.

polygamma
Link copied to clipboard
fun polygamma(n: Int, x: DScalar): DScalar
fun polygamma(n: Int, x: DTensor): DTensor
pow
Link copied to clipboard
fun DScalar.pow(x: Float): DScalar
fun DScalar.pow(x: Int): DScalar
fun DScalar.pow(x: DScalar): DScalar
fun DTensor.pow(exponent: Float): DTensor
fun DTensor.pow(x: Int): DTensor
fun DTensor.pow(x: DScalar): DTensor
fun DTensor.pow(exponent: DTensor): DTensor
pr
Link copied to clipboard
fun pr(lst: IntArray): String
fun pr(lst: List<Int>): String
primal
Link copied to clipboard
fun DScalar.primal(derivativeID: DerivativeID): DScalar
fun DTensor.primal(derivativeID: DerivativeID): DTensor
fun primal(x: Float, f: (DScalar) -> DScalar): Float
primalAndForwardDerivative
Link copied to clipboard
@JvmName(name = "primalAndForwardderivative_2")
fun primalAndForwardDerivative(inputs: List<DScalar>, f: (List<DScalar>) -> DScalar): Pair<DScalar, List<DScalar>>

fun primalAndForwardDerivative(inputs: List<DTensor>, f: (List<DTensor>) -> DTensor): Pair<DTensor, List<DTensor>>

The forward derivative of a multivariate function.

fun primalAndForwardDerivative(x: DScalar, f: (DScalar) -> DScalar): Pair<DScalar, DScalar>

Forward derivative of a function from DScalar to DScalar.

fun primalAndForwardDerivative(x: DTensor, f: (DTensor) -> DTensor): Pair<DTensor, DTensor>

Forward derivative of a function from DTensor to DTensor.

fun primalAndForwardDerivative(x: DScalar, y: DScalar, f: (DScalar, DScalar) -> DScalar): Pair<DScalar, Pair<DScalar, DScalar>>

The forward derivative of a multivariate scalar function.

fun primalAndForwardDerivative(x: DTensor, y: DTensor, f: (DTensor, DTensor) -> DTensor): Pair<DTensor, Pair<DTensor, DTensor>>

The forward derivative of a multivariate tensor function.

fun <Input : Any, Output : Any, Derivative : Any> primalAndForwardDerivative(x: Input, f: (Input) -> Output, wrapInput: (Input, Wrapper) -> Input? = null, wrapOutput: (Output, Wrapper) -> Output? = null, extractDerivative: (Input, Output, extractor: (input: DTensor, output: DTensor) -> DTensor) -> Derivative): Pair<Output, Derivative>

Evaluate the function, and return a pair containing its result (primal) and the derivative. This version supports user-defined types for input and output of the function.

primalAndGradient
Link copied to clipboard
fun <Input : Any> primalAndGradient(x: Input, f: (Input) -> DScalar): Pair<DScalar, Input>
fun primalAndGradient(x: DTensor, y: DTensor, f: (DTensor, DTensor) -> DScalar): Pair<DScalar, Pair<DTensor, DTensor>>
fun <Input : Any, InputTangent : Any> primalAndGradient(x: Input, f: (Input) -> DScalar, makeReverseInput: (Input, makeReverseTensor: (DTensor) -> DTensor) -> Input? = null, extractInputTangent: (Input, extractTensorTangent: (DTensor) -> DTensor) -> InputTangent): Pair<DScalar, InputTangent>

fun primalAndGradient(inputs: List<DTensor>, f: (List<DTensor>) -> DScalar): Pair<DScalar, List<DTensor>>

The Reverse gradients of a multivariate function.

fun primalAndGradient(x: DTensor, f: (DTensor) -> DScalar): Pair<DTensor, DTensor>

Reverse gradient for a function from DTensor to DTensor.

primalAndJvp
Link copied to clipboard
fun primalAndJvp(x: DTensor, v: DTensor, f: (DTensor) -> DTensor): Pair<DTensor, DTensor>
fun <Input : Any, Output : Any> primalAndJvp(x: Input, v: Input, f: (Input) -> Output, wrapInput: (Input, Wrapper) -> Input? = null, wrapOutput: (Output, Wrapper) -> Output? = null): Pair<Output, Output>
fun <Input : Any, Output : Any, OutputTangent : Any> primalAndJvp(x: Input, v: Input, f: (Input) -> Output, wrapInput: (Input, Wrapper) -> Input? = null, wrapOutput: (Output, Wrapper) -> Output? = null, extractOutputTangent: (Output, extractTensorTangent: (outputTensor: DTensor) -> DTensor) -> OutputTangent): Pair<Output, OutputTangent>
fun <Input : Any, Output : Any, InputTangent : Any, OutputTangent : Any> primalAndJvp(x: Input, v: InputTangent, f: (Input) -> Output, makeForwardInput: (Input, InputTangent, makeForwardTensor: (primal: DTensor, tangent: DTensor) -> DTensor) -> Input, wrapOutput: (Output, Wrapper) -> Output? = null, extractTangent: (Output, extractTensorTangent: (outputTensor: DTensor) -> DTensor) -> OutputTangent): Pair<Output, OutputTangent>
primalAndReverseDerivative
Link copied to clipboard
@JvmName(name = "primalAndReverseDerivative_2")
fun primalAndReverseDerivative(inputs: List<DScalar>, f: (List<DScalar>) -> DScalar): Pair<DScalar, List<DScalar>>

fun primalAndReverseDerivative(inputs: List<DTensor>, f: (List<DTensor>) -> DTensor): Pair<DTensor, List<DTensor>>

The Reverse derivative of a multivariate function.

fun primalAndReverseDerivative(x: DScalar, f: (DScalar) -> DScalar): Pair<DScalar, DScalar>

Reverse derivative of a function from DScalar to DScalar.

fun primalAndReverseDerivative(x: DTensor, f: (DTensor) -> DTensor): Pair<DTensor, DTensor>

Reverse Derivative for a function from DTensor to DTensor.

fun primalAndReverseDerivative(x: DScalar, y: DScalar, f: (DScalar, DScalar) -> DScalar): Pair<DScalar, Pair<DScalar, DScalar>>

The Reverse derivative of a multivariate scalar function.

fun primalAndReverseDerivative(x: DTensor, y: DTensor, f: (DTensor, DTensor) -> DTensor): Pair<DTensor, Pair<DTensor, DTensor>>

The Reverse derivative of a multivariate tensor function.

fun <Input : Any, Output : Any, Derivative : Any> primalAndReverseDerivative(x: Input, f: (Input) -> Output, wrapInput: (Input, Wrapper) -> Input? = null, wrapOutput: (Output, Wrapper) -> Output? = null, extractDerivative: (Input, Output, (input: DTensor, output: DTensor) -> DTensor) -> Derivative): Pair<Output, Derivative>

Evaluate the function, and return a pair containing its result (primal) and the derivative. This version supports user-defined types for input and output of the function.

primalAndReverseDerivativeImpl
Link copied to clipboard
fun primalAndReverseDerivativeImpl(inputs: List<DTensor>, scalarGradient: Boolean, f: (List<DTensor>) -> DTensor): Pair<DTensor, List<DTensor>>
primalAndReverseDerivativeTransposed
Link copied to clipboard
fun primalAndReverseDerivativeTransposed(inputs: List<DTensor>, f: (List<DTensor>) -> DTensor): Pair<DTensor, List<DTensor>>
fun primalAndReverseDerivativeTransposed(x: DTensor, f: (DTensor) -> DTensor): Pair<DTensor, DTensor>
primalAndVjp
Link copied to clipboard
fun <Input : Any, Output : Any> primalAndVjp(x: Input, v: Output, f: (Input) -> Output): Pair<Output, Input>
fun <Input : Any, Output : Any> primalAndVjp(x: Input, vf: (Output) -> Output, f: (Input) -> Output): Pair<Output, Input>
fun primalAndVjp(x: DTensor, vf: (primal: DTensor) -> DTensor, f: (x: DTensor) -> DTensor): Pair<DTensor, DTensor>
fun primalAndVjp(x: DTensor, v: DTensor, f: (x: DTensor) -> DTensor): Pair<DTensor, DTensor>
fun <Input : Any, Output : Any> primalAndVjp(x: Input, v: Output, f: (Input) -> Output, makeReverseInput: (Input, makeReverseTensor: (DTensor) -> DTensor) -> Input, extractInputTangent: (Input, extractTensorTangent: (DTensor) -> DTensor) -> Input): Pair<Output, Input>
fun <Input : Any, Output : Any, InputTangent : Any, OutputTangent : Any> primalAndVjp(x: Input, v: OutputTangent, f: (Input) -> Output, makeReverseInput: (Input, makeReverseTensor: (DTensor) -> DTensor) -> Input? = null, extractInputTangent: (Input, extractTensorTangent: (DTensor) -> DTensor) -> InputTangent, setOutputTangent: (Output, OutputTangent, setTensorTangent: (tensor: DTensor, tangent: DTensor) -> Unit) -> Unit, wrapOutput: (Output, Wrapper) -> Output? = null): Pair<Output, InputTangent>
product
Link copied to clipboard
fun List<Int>.product(): Int

Return the product of all vals in the list, or 1 if the list if empty.

relu
Link copied to clipboard
@JvmName(name = "DScalarRelu")
fun DScalar.relu(): DScalar
@JvmName(name = "DTensorRelu")
fun DTensor.relu(): DTensor
fun relu(x: DScalar): DScalar
fun relu(x: DTensor): DTensor
reluGrad
Link copied to clipboard
fun reluGrad(x: DScalar, upstream: DScalar): DScalar
fun reluGrad(x: DTensor, upstream: DTensor): DTensor
reshape
Link copied to clipboard
fun DTensor.reshape(vararg newShape: Int): DTensor
fun DTensor.reshape(newShape: Shape): DTensor
reverseDerivative
Link copied to clipboard
fun reverseDerivative(inputs: List<DScalar>, f: (List<DScalar>) -> DScalar): List<DScalar>
fun reverseDerivative(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun reverseDerivative(x: DTensor, f: (DTensor) -> DTensor): DTensor
fun reverseDerivative(n: Int, x: DScalar, f: (DScalar) -> DScalar): DScalar
fun reverseDerivative(n: Int, x: DTensor, f: (DTensor) -> DTensor): DTensor
fun reverseDerivative(x: DScalar, y: DScalar, f: (DScalar, DScalar) -> DScalar): Pair<DScalar, DScalar>
fun reverseDerivative(x: DTensor, y: DTensor, f: (DTensor, DTensor) -> DTensor): Pair<DTensor, DTensor>
fun <Input : Any, Output : Any, Derivative : Any> reverseDerivative(x: Input, f: (Input) -> Output, wrapInput: (Input, Wrapper) -> Input? = null, wrapOutput: (Output, Wrapper) -> Output? = null, extractDerivative: (Input, Output, (input: DTensor, output: DTensor) -> DTensor) -> Derivative): Derivative
reverseDerivative1
Link copied to clipboard
fun reverseDerivative1(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun reverseDerivative1(x: DTensor, f: (DTensor) -> DTensor): DTensor
reverseDerivative2
Link copied to clipboard
fun reverseDerivative2(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun reverseDerivative2(x: DTensor, f: (DTensor) -> DTensor): DTensor
reverseDerivative3
Link copied to clipboard
fun reverseDerivative3(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun reverseDerivative3(x: DTensor, f: (DTensor) -> DTensor): DTensor
reverseDerivative4
Link copied to clipboard
fun reverseDerivative4(x: DScalar, f: (DScalar) -> DScalar): DScalar
fun reverseDerivative4(x: DTensor, f: (DTensor) -> DTensor): DTensor
reverseDerivativeTransposed
Link copied to clipboard
fun reverseDerivativeTransposed(x: DScalar, y: DScalar, f: (DScalar, DScalar) -> DScalar): Pair<DScalar, DScalar>
fun reverseDerivativeTransposed(x: DTensor, y: DTensor, f: (DTensor, DTensor) -> DTensor): Pair<DTensor, DTensor>
reverseDiff
Link copied to clipboard
fun reverseDiff(f: (DScalar) -> DScalar): (DScalar) -> DScalar
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
fun FloatTensor.scatter(indices: List<Int>, axis: Int, newShape: Shape, paddingIndex: Int = -1): FloatTensor
sigmoid
Link copied to clipboard
fun sigmoid(x: DScalar): DScalar

fun sigmoid(x: DTensor): DTensor

Returns x with the sigmoid activation unit applied (1 / (1 + exp(-x))

sin
Link copied to clipboard
fun sin(x: DScalar): DScalar
fun sin(x: DTensor): 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).

fun FloatTensor.slice(start: Int, end: Int, axis: Int = 0): FloatTensor
softmax
Link copied to clipboard
@JvmName(name = "DTensorSoftmaxExt")
fun DTensor.softmax(axis: Int): DTensor

fun softmax(x: DTensor, axis: Int): DTensor

Applies softmax along the provided axis, rescaling the tensor so that every slice along the provided axis is in the range 0,1 and sums to 1.

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.

sqrt
Link copied to clipboard
fun sqrt(x: DScalar): DScalar
fun sqrt(x: DTensor): DTensor
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 stack(slices: List<DTensor>, axis: Int = 0): DTensor

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.

tan
Link copied to clipboard
fun tan(x: DScalar): DScalar
fun tan(x: DTensor): DTensor
tanh
Link copied to clipboard
fun tanh(x: DScalar): DScalar
fun tanh(x: DTensor): DTensor
tensorOf
Link copied to clipboard
fun tensorOf(vararg values: DScalar): DTensor

Create a DTensor from variable length parameters of type DScalar values.

fun tensorOf(vararg values: Float): FloatTensor

Create a FloatTensor from variable length parameters of type Float. The FloatTensor that is returned is a 1D array.

fun tensorOf(values: List<Float>): FloatTensor

Create a FloatTensor from the list of values given.

fun tensorOf(values: List<DScalar>): DTensor

Create a DTensor from the list of DScalar.

times
Link copied to clipboard
operator fun Float.times(right: DScalar): DScalar
operator fun Float.times(right: DTensor): DTensor
operator fun Int.times(right: DScalar): DScalar
operator fun DScalar.times(right: Float): DScalar
operator fun DScalar.times(right: DScalar): DScalar
operator fun DScalar.times(right: DTensor): DTensor
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 DScalar.unaryMinus(): DScalar
operator fun DTensor.unaryMinus(): DTensor
unaryPlus
Link copied to clipboard
operator fun ReverseScalar.unaryPlus(): ReverseScalar
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
vjp
Link copied to clipboard
fun <Input : Any, Output : Any> vjp(x: Input, v: Output, f: (Input) -> Output): Input
fun <Input : Any, Output : Any> vjp(x: Input, vf: (Output) -> Output, f: (Input) -> Output): Input
fun vjp(x: DTensor, vf: (primal: DTensor) -> DTensor, f: (x: DTensor) -> DTensor): DTensor
fun vjp(x: DTensor, v: DTensor, f: (x: DTensor) -> DTensor): DTensor
withChange
Link copied to clipboard
fun DTensor.withChange(indices: IntArray, replacementValue: DTensor): DTensor
fun DTensor.withChange(index: Int, axis: Int, replacementValue: DTensor): DTensor
fun DTensor.withChange(index: IntRange, axis: Int, replacementValue: DTensor): DTensor

Properties

allAxes
Link copied to clipboard
val DTensor.allAxes: IntArray
inverted
Link copied to clipboard
val ComparisonKind.inverted: ComparisonKind
product
Link copied to clipboard
val IntArray.product: Int