Base Operations

These ops are generally available directly on SameDiff instances. Due to an oversight before the release, this ops aren't also available on Nd4j. To use the INDArray variants of these operations, you will have to instantiate a NDBase instance.

all

INDArray all(INDArray x, int[] dimensions)

SDVariable all(SDVariable x, int[] dimensions)
SDVariable all(String name, SDVariable x, int[] dimensions)

Boolean and array reduction operation, optionally along specified dimensions

  • x (NDARRAY) - Input variable

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

any

INDArray any(INDArray x, int[] dimensions)

SDVariable any(SDVariable x, int[] dimensions)
SDVariable any(String name, SDVariable x, int[] dimensions)

Boolean or array reduction operation, optionally along specified dimensions

  • x (NDARRAY) - Input variable

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

argmax

Argmax array reduction operation, optionally along specified dimensions.

Output values are the index of the maximum value of each slice along the specified dimension.

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • in (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

argmin

Argmin array reduction operation, optionally along specified dimensions.

Output values are the index of the minimum value of each slice along the specified dimension.

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

  • in (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

batchMmul

Matrix multiply a batch of matrices. matricesA and matricesB have to be arrays of same

length and each pair taken from these sets has to have dimensions (M, N) and (N, K),

respectively. If transposeA is true, matrices from matricesA will have shape (N, M) instead.

Likewise, if transposeB is true, matrices from matricesB will have shape (K, N).

The result of this operation will be a batch of multiplied matrices. The

result has the same length as both input batches and each output matrix is of shape (M, K).

  • inputsA (NUMERIC) - First array of input matrices, all of shape (M, N) or (N, M)

  • inputsB (NUMERIC) - Second array of input matrices, all of shape (N, K) or (K, N)

  • transposeA - Whether to transpose A arrays or not - default = false

  • transposeB - Whether to transpose B arrays or not - default = false

castTo

Cast the array to a new datatype - for example, Integer -> Float

  • arg (NDARRAY) - Input variable to cast

  • datatype - Datatype to cast to

concat

Concatenate a set of inputs along the specified dimension.

Note that inputs must have identical rank and identical dimensions, other than the dimension to stack on.

For example, if 2 inputs have shape [a, x, c] and [a, y, c] and dimension = 1, then the output has shape [a, x+y, c]

  • inputs (NUMERIC) - Input variables

  • dimension - Dimension to concatenate on

cumprod

Cumulative product operation.

For input: [ a, b, c], output is:

exclusive=false, reverse=false: [a, a_b, a_b*c]

exclusive=true, reverse=false, [0, a, a*b]

exclusive=false, reverse=true: [a_b_c, b*c, c]

exclusive=true, reverse=true: [b*c, c, 0]

  • in (NUMERIC) - Input variable

  • exclusive - If true: exclude the first value - default = false

  • reverse - If true: reverse the direction of the accumulation - default = false

  • axis - Scalar axis argument for dimension to perform cumululative sum operations along (Size: AtLeast(min=1))

cumsum

Cumulative sum operation.

For input: [ a, b, c], output is:

exclusive=false, reverse=false: [a, a+b, a+b+c]

exclusive=true, reverse=false, [0, a, a+b]

exclusive=false, reverse=true: [a+b+c, b+c, c]

exclusive=true, reverse=true: [b+c, c, 0]

  • in (NUMERIC) - Input variable

  • exclusive - If true: exclude the first value - default = false

  • reverse - If true: reverse the direction of the accumulation - default = false

  • axis - Scalar axis argument for dimension to perform cumululative sum operations along (Size: AtLeast(min=1))

dot

Pairwise dot product reduction along dimension

output = sum(i=0 ... size(dim)-1) x[i] * y[i]

  • x (NUMERIC) - first input

  • y (NUMERIC) - second input

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

dynamicPartition

Dynamically partition the input variable values into the specified number of paritions, using the indices.

Example:

  • x (NUMERIC) - Input variable

  • partitions (INT) - 1D input with values 0 to numPartitions-1

  • numPartitions - Number of partitions, >= 1

dynamicStitch

Dynamically merge the specified input arrays into a single array, using the specified indices

  • indices (INT) - Indices to use when merging. Must be >= 1, same length as input variables

  • x (NUMERIC) - Input variables.

eq

Equals operation: elementwise x == y

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input array

  • y - Double value argument to use in operation

eq

Equal to operation: elementwise x == y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input 1

  • y (NUMERIC) - Input 2

expandDims

Reshape the input by adding a 1 at the specified location.

For example, if input has shape [a, b], then output shape is:

axis = 0: [1, a, b]

axis = 1: [a, 1, b]

axis = 2: [a, b, 1]

  • x (NDARRAY) - Input variable

  • axis - Axis to expand

fill

Generate an output variable with the specified (dynamic) shape with all elements set to the specified value

  • shape (INT) - Shape: must be a 1D array/variable

  • dataType - Datatype of the output array

  • value - Value to set all elements to

gather

Gather slices from the input variable where the indices are specified as fixed int[] values.

Output shape is same as input shape, except for axis dimension, which has size equal to indices.length.

  • df (NUMERIC) - Input variable

  • indices - Indices to get (Size: AtLeast(min=1))

  • axis - Axis that the indices refer to

gather

Gather slices from the input variable where the indices are specified as dynamic array values.

Output shape is same as input shape, except for axis dimension, which has size equal to indices.length.

  • df (NUMERIC) - Input variable

  • indices (INT) - Indices to get slices for. Rank 0 or 1 input

  • axis - Axis that the indices refer to

gatherNd

Gather slices from df with shape specified by indices.

  • df (NUMERIC) -

  • indices (NUMERIC) -

gt

Greater than operation: elementwise x > y

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input array

  • y - Double value argument to use in operation

gt

Greater than operation: elementwise x > y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input 1

  • y (NUMERIC) - Input 2

gte

Greater than or equals operation: elementwise x >= y

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input array

  • y - Double value argument to use in operation

gte

Greater than or equal to operation: elementwise x >= y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input 1

  • y (NUMERIC) - Input 2

identity

Elementwise identity operation: out = x

  • input (NUMERIC) - Input variable

invertPermutation

Compute the inverse permutation indices for a permutation operation

Example: if input is [2, 0, 1] then output is [1, 2, 0]

The idea is that x.permute(input).permute(invertPermutation(input)) == x

  • input (INT) - 1D indices for permutation

isNumericTensor

Is the director a numeric tensor? In the current version of ND4J/SameDiff, this always returns true/1

  • x (NUMERIC) - Input variable

linspace

Create a new 1d array with values evenly spaced between values 'start' and 'stop'

For example, linspace(start=3.0, stop=4.0, number=3) will generate [3.0, 3.5, 4.0]

  • dataType - Data type of the output array

  • start - Start value

  • stop - Stop value

  • number - Number of values to generate

linspace

Create a new 1d array with values evenly spaced between values 'start' and 'stop'

For example, linspace(start=3.0, stop=4.0, number=3) will generate [3.0, 3.5, 4.0]

  • start (NUMERIC) - Start value

  • stop (NUMERIC) - Stop value

  • number (LONG) - Number of values to generate

  • dataType - Data type of the output array

lt

Less than operation: elementwise x < y

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input array

  • y - Double value argument to use in operation

lt

Less than operation: elementwise x < y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input 1

  • y (NUMERIC) - Input 2

lte

Less than or equals operation: elementwise x <= y

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input array

  • y - Double value argument to use in operation

lte

Less than or equal to operation: elementwise x <= y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input 1

  • y (NUMERIC) - Input 2

matchCondition

Returns a boolean mask of equal shape to the input, where the condition is satisfied - value 1 where satisfied, 0 otherwise

  • in (NUMERIC) - Input

  • condition - Condition

matchConditionCount

Returns a count of the number of elements that satisfy the condition

  • in (NUMERIC) - Input

  • condition - Condition

matchConditionCount

Returns a count of the number of elements that satisfy the condition (for each slice along the specified dimensions)

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • in (NUMERIC) - Input variable

  • condition - Condition

  • keepDim - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

max

Max array reduction operation, optionally along specified dimensions

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

max

Element-wise maximum operation: out[i] = max(first[i], second[i])

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

  • first (NUMERIC) - First input array

  • second (NUMERIC) - Second input array

mean

Mean (average) array reduction operation, optionally along specified dimensions

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

merge

The merge operation is a control operation that forwards the either of the inputs to the output, when

the first of them becomes available. If both are available, the output is undefined (either input could

be forwarded to the output)

  • x (NUMERIC) - Input variable

  • y (NUMERIC) - Input variable

min

Minimum array reduction operation, optionally along specified dimensions. out = min(in)

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

min

Element-wise minimum operation: out[i] = min(first[i], second[i])

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

  • first (NUMERIC) - First input array

  • second (NUMERIC) - Second input array

mmul

Matrix multiplication: out = mmul(x,y)

Supports specifying transpose argument to perform operation such as mmul(a^T, b), etc.

  • x (NUMERIC) - First input variable

  • y (NUMERIC) - Second input variable

  • transposeX - Transpose x (first argument) - default = false

  • transposeY - Transpose y (second argument) - default = false

  • transposeZ - Transpose result array - default = false

neq

Not equals operation: elementwise x != y

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input array

  • y - Double value argument to use in operation

neq

Not equal to operation: elementwise x != y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

Return boolean array with values true where satisfied, or false otherwise.

  • x (NUMERIC) - Input 1

  • y (NUMERIC) - Input 2

norm1

Norm1 (L1 norm) reduction operation: The output contains the L1 norm for each tensor/subset along the specified dimensions:

out = sum_i abs(x[i])

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - dimensions to reduce over (Size: AtLeast(min=0))

norm2

Norm2 (L2 norm) reduction operation: The output contains the L2 norm for each tensor/subset along the specified dimensions:

out = sqrt(sum_i x[i]^2)

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - dimensions dimensions to reduce over (Size: AtLeast(min=0))

normmax

Max norm (infinity norm) reduction operation: The output contains the max norm for each tensor/subset along the

specified dimensions:

out = max(abs(x[i]))

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - dimensions to reduce over (Size: AtLeast(min=0))

oneHot

Convert the array to a one-hot array with walues and for each entry

If input has shape [ a, ..., n] then output has shape [ a, ..., n, depth],

with {out[i, ..., j, in[i,...,j]] with other values being set to

  • indices (NUMERIC) - Indices - value 0 to depth-1

  • depth - Number of classes

  • axis -

  • on -

  • off -

  • dataType - Output data type - default = DataType.FLOAT

oneHot

Convert the array to a one-hot array with walues 0 and 1 for each entry

If input has shape [ a, ..., n] then output has shape [ a, ..., n, depth],

with out[i, ..., j, in[i,...,j]] = 1 with other values being set to 0

see oneHot(SDVariable, int, int, double, double)

  • indices (NUMERIC) - Indices - value 0 to depth-1

  • depth - Number of classes

onesLike

Return a variable of all 1s, with the same shape as the input variable. Note that this is dynamic:

if the input shape changes in later execution, the returned variable's shape will also be updated

  • input (NUMERIC) - Input INDArray

onesLike

As per onesLike(String, SDVariable) but the output datatype may be specified

  • input (NUMERIC) -

  • dataType -

permute

Array permutation operation: permute the dimensions according to the specified permutation indices.

Example: if input has shape [a,b,c] and dimensions = [2,0,1] the output has shape [c,a,b]

  • x (NUMERIC) - Input variable

  • dimensions (INT) - Permute dimensions

permute

Array permutation operation: permute the dimensions according to the specified permutation indices.

Example: if input has shape [a,b,c] and dimensions = [2,0,1] the output has shape [c,a,b]

  • x (NUMERIC) - Input variable

  • dimensions - (Size: AtLeast(min=0))

prod

Product array reduction operation, optionally along specified dimensions

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

range

Create a new variable with a 1d array, where the values start at from and increment by step

up to (but not including) limit.

For example, range(1.0, 3.0, 0.5) will return [1.0, 1.5, 2.0, 2.5]

  • from - Initial/smallest value

  • to - Largest value (exclusive)

  • step - Step size

  • dataType -

range

Create a new variable with a 1d array, where the values start at from and increment by step

up to (but not including) limit.

For example, range(1.0, 3.0, 0.5) will return [1.0, 1.5, 2.0, 2.5]

  • from (NUMERIC) - Initial/smallest value

  • to (NUMERIC) - Largest value (exclusive)

  • step (NUMERIC) - Step size

  • dataType -

rank

Returns the rank (number of dimensions, i.e., length(shape)) of the specified INDArray as a 0D scalar variable

  • in (NUMERIC) - Input variable

replaceWhere

Element-wise replace where condition:

out[i] = from[i] if condition(update[i]) is satisfied, or

out[i] = update[i] if condition(update[i]) is NOT satisfied

  • update (NUMERIC) - Source array

  • from (NUMERIC) - Replacement values array (used conditionally). Must be same shape as 'update' array

  • condition - Condition to check on update array elements

replaceWhere

Element-wise replace where condition:

out[i] = value if condition(update[i]) is satisfied, or

out[i] = update[i] if condition(update[i]) is NOT satisfied

  • update (NUMERIC) - Source array

  • value - Value to set at the output, if the condition is satisfied

  • condition - Condition to check on update array elements

reshape

Reshape the input variable to the specified (fixed) shape. The output variable will have the same values as the

input, but with the specified shape.

Note that prod(shape) must match length(input) == prod(input.shape)

  • x (NUMERIC) - Input variable

  • shape (NUMERIC) - New shape for variable

reshape

Reshape the input variable to the specified (fixed) shape. The output variable will have the same values as the

input, but with the specified shape.

Note that prod(shape) must match length(input) == prod(input.shape)

  • x (NUMERIC) - Input variable

  • shape - New shape for variable (Size: AtLeast(min=0))

reverse

Reverse the values of an array for the specified dimensions

If input is:

[ 1, 2, 3]

[ 4, 5, 6]

then

reverse(in, 0):

[3, 2, 1]

[6, 5, 4]

reverse(in, 1):

[4, 5, 6]

[1, 2 3]

  • x (NUMERIC) - Input variable

  • dimensions - Input variable (Size: AtLeast(min=0))

reverseSequence

Reverse sequence op: for each slice along dimension seqDimension, the first seqLength values are reversed

  • x (NUMERIC) - Input variable

  • seq_lengths (INT) - Length of the sequences

  • seqDim - Sequence dimension - default = -1

  • batchDim - Batch dimension - default = 0

scalarFloorMod

Element-wise scalar floor modulus operation: out = floorMod(in, value).

i.e., returns the remainder after division by 'value'

  • in (NUMERIC) - Input variable

  • value - Scalar value to compare

scalarMax

Element-wise scalar maximum operation: out = max(in, value)

  • in (NUMERIC) - Input variable

  • value - Scalar value to compare

scalarMin

Element-wise scalar minimum operation: out = min(in, value)

  • in (NUMERIC) - Input variable

  • value - Scalar value to compare

scalarSet

Return a variable with equal shape to the input, but all elements set to value 'set'

  • in (NUMERIC) - Input variable

  • set - Value to set

scatterAdd

Scatter addition operation.

If indices is rank 0 (a scalar), then out[index, ...] = out[index, ...] + op(updates[...])

If indices is rank 1 (a vector), then for each position i, out[indices[i], ...] = out[indices[i], ...] + op(updates[i, ...])

If indices is rank 2+, then for each position (i,...,k), out[indices[i], ..., indices[k], ...] = out[indices[i], ..., indices[k], ...] + op(updates[i, ..., k, ...])

Note that if multiple indices refer to the same location, the contributions from each is handled correctly.

  • ref (NUMERIC) - Initial/source variable

  • indices (NUMERIC) - Indices array

  • updates (NUMERIC) - Updates to add to the initial/source array

scatterDiv

Scatter division operation.

If indices is rank 0 (a scalar), then out[index, ...] = out[index, ...] + op(updates[...])

If indices is rank 1 (a vector), then for each position i, out[indices[i], ...] = out[indices[i], ...] + op(updates[i, ...])

If indices is rank 2+, then for each position (i,...,k), out[indices[i], ..., indices[k], ...] = out[indices[i], ..., indices[k], ...] + op(updates[i, ..., k, ...])

Note that if multiple indices refer to the same location, the contributions from each is handled correctly.

  • ref (NUMERIC) - Initial/source variable

  • indices (NUMERIC) - Indices array

  • updates (NUMERIC) - Updates to add to the initial/source array

scatterMax

Scatter max operation.

If indices is rank 0 (a scalar), then out[index, ...] = out[index, ...] + op(updates[...])

If indices is rank 1 (a vector), then for each position i, out[indices[i], ...] = out[indices[i], ...] + op(updates[i, ...])

If indices is rank 2+, then for each position (i,...,k), out[indices[i], ..., indices[k], ...] = out[indices[i], ..., indices[k], ...] + op(updates[i, ..., k, ...])

Note that if multiple indices refer to the same location, the contributions from each is handled correctly.

  • ref (NUMERIC) - Initial/source variable

  • indices (NUMERIC) - Indices array

  • updates (NUMERIC) - Updates to add to the initial/source array

scatterMin

Scatter min operation.

If indices is rank 0 (a scalar), then out[index, ...] = out[index, ...] + op(updates[...])

If indices is rank 1 (a vector), then for each position i, out[indices[i], ...] = out[indices[i], ...] + op(updates[i, ...])

If indices is rank 2+, then for each position (i,...,k), out[indices[i], ..., indices[k], ...] = out[indices[i], ..., indices[k], ...] + op(updates[i, ..., k, ...])

Note that if multiple indices refer to the same location, the contributions from each is handled correctly.

  • ref (NUMERIC) - Initial/source variable

  • indices (NUMERIC) - Indices array

  • updates (NUMERIC) - Updates to add to the initial/source array

scatterMul

Scatter multiplication operation.

If indices is rank 0 (a scalar), then out[index, ...] = out[index, ...] + op(updates[...])

If indices is rank 1 (a vector), then for each position i, out[indices[i], ...] = out[indices[i], ...] + op(updates[i, ...])

If indices is rank 2+, then for each position (i,...,k), out[indices[i], ..., indices[k], ...] = out[indices[i], ..., indices[k], ...] + op(updates[i, ..., k, ...])

Note that if multiple indices refer to the same location, the contributions from each is handled correctly.

  • ref (NUMERIC) - Initial/source variable

  • indices (NUMERIC) - Indices array

  • updates (NUMERIC) - Updates to add to the initial/source array

scatterSub

Scatter subtraction operation.

If indices is rank 0 (a scalar), then out[index, ...] = out[index, ...] + op(updates[...])

If indices is rank 1 (a vector), then for each position i, out[indices[i], ...] = out[indices[i], ...] + op(updates[i, ...])

If indices is rank 2+, then for each position (i,...,k), out[indices[i], ..., indices[k], ...] = out[indices[i], ..., indices[k], ...] + op(updates[i, ..., k, ...])

Note that if multiple indices refer to the same location, the contributions from each is handled correctly.

  • ref (NUMERIC) - Initial/source variable

  • indices (NUMERIC) - Indices array

  • updates (NUMERIC) - Updates to add to the initial/source array

scatterUpdate

Scatter update operation.

If indices is rank 0 (a scalar), then out[index, ...] = out[index, ...] + op(updates[...])

If indices is rank 1 (a vector), then for each position i, out[indices[i], ...] = out[indices[i], ...] + op(updates[i, ...])

If indices is rank 2+, then for each position (i,...,k), out[indices[i], ..., indices[k], ...] = out[indices[i], ..., indices[k], ...] + op(updates[i, ..., k, ...])

Note that if multiple indices refer to the same location, the contributions from each is handled correctly.

  • ref (NUMERIC) - Initial/source variable

  • indices (NUMERIC) - Indices array

  • updates (NUMERIC) - Updates to add to the initial/source array

segmentMax

Segment max operation.

If data = [3, 6, 1, 4, 9, 2, 8]

segmentIds = [0, 0, 1, 1, 1, 2, 2]

then output = [6, 9, 8] = [op(3,6), op(1,4,9), op(2,8)]

Note that the segment IDs must be sorted from smallest to largest segment.

See {unsortedSegment (String, SDVariable, SDVariable, int) ops

for the same op without this sorted requirement

  • data (NDARRAY) - Data to perform segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

segmentMean

Segment mean operation.

If data = [3, 6, 1, 4, 9, 2, 8]

segmentIds = [0, 0, 1, 1, 1, 2, 2]

then output = [6, 9, 8] = [op(3,6), op(1,4,9), op(2,8)]

Note that the segment IDs must be sorted from smallest to largest segment.

See {unsortedSegment (String, SDVariable, SDVariable, int) ops

for the same op without this sorted requirement

  • data (NDARRAY) - Data to perform segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

segmentMin

Segment min operation.

If data = [3, 6, 1, 4, 9, 2, 8]

segmentIds = [0, 0, 1, 1, 1, 2, 2]

then output = [6, 9, 8] = [op(3,6), op(1,4,9), op(2,8)]

Note that the segment IDs must be sorted from smallest to largest segment.

See {unsortedSegment (String, SDVariable, SDVariable, int) ops

for the same op without this sorted requirement

  • data (NDARRAY) - Data to perform segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

segmentProd

Segment product operation.

If data = [3, 6, 1, 4, 9, 2, 8]

segmentIds = [0, 0, 1, 1, 1, 2, 2]

then output = [6, 9, 8] = [op(3,6), op(1,4,9), op(2,8)]

Note that the segment IDs must be sorted from smallest to largest segment.

See {unsortedSegment (String, SDVariable, SDVariable, int) ops

for the same op without this sorted requirement

  • data (NDARRAY) - Data to perform segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

segmentSum

Segment sum operation.

If data = [3, 6, 1, 4, 9, 2, 8]

segmentIds = [0, 0, 1, 1, 1, 2, 2]

then output = [6, 9, 8] = [op(3,6), op(1,4,9), op(2,8)]

Note that the segment IDs must be sorted from smallest to largest segment.

See {unsortedSegment (String, SDVariable, SDVariable, int) ops

for the same op without this sorted requirement

  • data (NDARRAY) - Data to perform segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

sequenceMask

Generate a sequence mask (with values 0 or 1) based on the specified lengths

Specifically, out[i, ..., k, j] = (j < lengths[i, ..., k] ? 1.0 : 0.0)

  • lengths (NUMERIC) - Lengths of the sequences

  • maxLen - Maximum sequence length

  • dataType -

sequenceMask

Generate a sequence mask (with values 0 or 1) based on the specified lengths

Specifically, out[i, ..., k, j] = (j < lengths[i, ..., k] ? 1.0 : 0.0)

  • lengths (NUMERIC) - Lengths of the sequences

  • maxLen (INT) - Maximum sequence length

  • dataType -

sequenceMask

see sequenceMask(String, SDVariable, SDVariable, DataType)

  • lengths (NUMERIC) -

  • dataType -

shape

Returns the shape of the specified INDArray as a 1D INDArray

  • input (NUMERIC) - Input variable

size

Returns the size (number of elements, i.e., prod(shape)) of the specified INDArray as a 0D scalar variable

  • in (NUMERIC) - Input variable

sizeAt

Returns a rank 0 (scalar) variable for the size of the specified dimension.

For example, if X has shape [10,20,30] then sizeAt(X,1)=20. Similarly, sizeAt(X,-1)=30

  • in (NUMERIC) - Input variable

  • dimension - Dimension to get size of

slice

Get a subset of the specified input, by specifying the first element and the size of the array.

For example, if input is:

[a, b, c]

[d, e, f]

then slice(input, begin=[0,1], size=[2,1] will return:

[b]

[e]

Note that for each dimension i, begin[i] + size[i] <= input.size(i)

  • input (NUMERIC) - input Variable to get subset of

  • begin - Beginning index. Must be same length as rank of input array (Size: AtLeast(min=1))

  • size - Size of the output array. Must be same length as rank of input array (Size: AtLeast(min=1))

slice

Get a subset of the specified input, by specifying the first element and the size of the array.

For example, if input is:

[a, b, c]

[d, e, f]

then slice(input, begin=[0,1], size=[2,1] will return:

[b]

[e]

Note that for each dimension i, begin[i] + size[i] <= input.size(i)

  • input (NUMERIC) - input Variable to get subset of

  • begin (INT) - Beginning index. Must be same length as rank of input array

  • size (INT) - Size of the output array. Must be same length as rank of input array

squaredNorm

Squared L2 norm: see norm2(String, SDVariable, boolean, int...)

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) -

  • keepDims - - default = false

  • dimensions - (Size: AtLeast(min=0))

squeeze

Remove a single dimension of size 1.

For example, if input has shape [a,b,1,c] then squeeze(input, 2) returns an array of shape [a,b,c]

  • x (NUMERIC) - Input variable

  • axis - Size 1 dimension to remove

stack

Stack a set of N INDArray of rank X into one rank X+1 variable.

If inputs have shape [a,b,c] then output has shape:

axis = 0: [N,a,b,c]

axis = 1: [a,N,b,c]

axis = 2: [a,b,N,c]

axis = 3: [a,b,c,N]

see unstack(String[], SDVariable, int, int)

  • values (NDARRAY) - Input variables to stack. Must have the same shape for all inputs

  • axis - Axis to stack on

standardDeviation

Stardard deviation array reduction operation, optionally along specified dimensions

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • biasCorrected - If true: divide by (N-1) (i.e., sample stdev). If false: divide by N (population stdev)

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

stridedSlice

Get a subset of the specified input, by specifying the first element, last element, and the strides.

For example, if input is:

[a, b, c]

[d, e, f]

[g, h, i]

then stridedSlice(input, begin=[0,1], end=[2,2], strides=[2,1], all masks = 0) will return:

[b, c]

[h, i]

  • in (NUMERIC) - Variable to get subset of

  • begin - Beginning index (Size: AtLeast(min=1))

  • end - End index (Size: AtLeast(min=1))

  • strides - Stride ("step size") for each dimension. For example, stride of 2 means take every second element. (Size: AtLeast(min=1))

  • beginMask - Bit mask: If the ith bit is set to 1, then the value in the begin long[] is ignored, and a value of 0 is used instead for the beginning index for that dimension - default = 0

  • endMask - Bit mask: If the ith bit is set to 1, then the value in the end long[] is ignored, and a value of size(i)-1 is used instead for the end index for that dimension - default = 0

  • ellipsisMask - Bit mask: only one non-zero value is allowed here. If a non-zero value is set, then other dimensions are inserted as required at the specified position - default = 0

  • newAxisMask - Bit mask: if the ith bit is set to 1, then the begin/end/stride values are ignored, and a size 1 dimension is inserted at this point - default = 0

  • shrinkAxisMask - Bit mask: if the ith bit is set to 1, then the begin/end/stride values are ignored, and a size 1 dimension is removed at this point. Note that begin/end/stride values must result in a size 1 output for these dimensions - default = 0

sum

Sum array reduction operation, optionally along specified dimensions.

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • keepDims - If true: keep the dimensions that are reduced on (as length 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

switchOp

Switch operation

Predictate - if false, values are output to left (first) branch/output; if true, to right (second) branch/output

  • x (NDARRAY) - Input variable

  • predicate (BOOL) - Predictate - if false, values are output to left (first) branch/output; if true, to right (second) branch/output

tensorMmul

//TODO: Ops must be documented.

  • x (NUMERIC) - Input variable x

  • y (NUMERIC) - Input variable y

  • dimensionsX - dimensions for first input array (x) (Size: AtLeast(min=1))

  • dimensionsY - dimensions for second input array (y) (Size: AtLeast(min=1))

  • transposeX - Transpose x (first argument) - default = false

  • transposeY - Transpose y (second argument) - default = false

  • transposeZ - Transpose result array - default = false

tile

Repeat (tile) the input tensor the specified number of times.

For example, if input is

[1, 2]

[3, 4]

and repeat is [2, 3]

then output is

[1, 2, 1, 2, 1, 2]

[3, 4, 3, 4, 3, 4]

[1, 2, 1, 2, 1, 2]

[3, 4, 3, 4, 3, 4]

  • x (NDARRAY) - Input variable

  • repeat (INT) - Number of times to repeat in each axis. Must have length equal to the rank of the input array

tile

see tile(String, SDVariable, int...)

  • x (NDARRAY) -

  • repeat - (Size: AtLeast(min=1))

transpose

Matrix transpose operation: If input has shape [a,b] output has shape [b,a]

  • x (NDARRAY) - Input variable

unsortedSegmentMax

Unsorted segment max operation. As per segmentMax(String, SDVariable, SDVariable) but without

the requirement for the indices to be sorted.

If data = [1, 3, 2, 6, 4, 9, 8]

segmentIds = [1, 0, 2, 0, 1, 1, 2]

then output = [6, 9, 8] = [max(3,6), max(1,4,9), max(2,8)]

  • data (NUMERIC) - Data (variable) to perform unsorted segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

  • numSegments - Number of segments

unsortedSegmentMean

Unsorted segment mean operation. As per segmentMean(String, SDVariable, SDVariable) but without

the requirement for the indices to be sorted.

If data = [1, 3, 2, 6, 4, 9, 8]

segmentIds = [1, 0, 2, 0, 1, 1, 2]

then output = [4.5, 4.666, 5] = [mean(3,6), mean(1,4,9), mean(2,8)]

  • data (NUMERIC) - Data (variable) to perform unsorted segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

  • numSegments - Number of segments

unsortedSegmentMin

Unsorted segment min operation. As per segmentMin(String, SDVariable, SDVariable) but without

the requirement for the indices to be sorted.

If data = [1, 3, 2, 6, 4, 9, 8]

segmentIds = [1, 0, 2, 0, 1, 1, 2]

then output = [3, 1, 2] = [min(3,6), min(1,4,9), min(2,8)]

  • data (NUMERIC) - Data (variable) to perform unsorted segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

  • numSegments - Number of segments

unsortedSegmentProd

Unsorted segment product operation. As per segmentProd(String, SDVariable, SDVariable) but without

the requirement for the indices to be sorted.

If data = [1, 3, 2, 6, 4, 9, 8]

segmentIds = [1, 0, 2, 0, 1, 1, 2]

then output = [4.5, 4.666, 5] = [mean(3,6), mean(1,4,9), mean(2,8)]

  • data (NUMERIC) - Data (variable) to perform unsorted segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

  • numSegments - Number of segments

unsortedSegmentSqrtN

Unsorted segment sqrtN operation. Simply returns the sqrt of the count of the number of values in each segment

If data = [1, 3, 2, 6, 4, 9, 8]

segmentIds = [1, 0, 2, 0, 1, 1, 2]

then output = [1.414, 1.732, 1.414] = [sqrt(2), sqrtN(3), sqrtN(2)]

  • data (NUMERIC) - Data (variable) to perform unsorted segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

  • numSegments - Number of segments

unsortedSegmentSum

Unsorted segment sum operation. As per segmentSum(String, SDVariable, SDVariable) but without

the requirement for the indices to be sorted.

If data = [1, 3, 2, 6, 4, 9, 8]

segmentIds = [1, 0, 2, 0, 1, 1, 2]

then output = [9, 14, 10] = [sum(3,6), sum(1,4,9), sum(2,8)]

  • data (NUMERIC) - Data (variable) to perform unsorted segment max on

  • segmentIds (NUMERIC) - Variable for the segment IDs

  • numSegments - Number of segments

unstack

Unstack a variable of rank X into N rank X-1 variables by taking slices along the specified axis.

If input has shape [a,b,c] then output has shape:

axis = 0: [b,c]

axis = 1: [a,c]

axis = 2: [a,b]

  • value (NDARRAY) - Input variable to unstack

  • axis - Axis to unstack on

  • num - Number of output variables

variance

Variance array reduction operation, optionally along specified dimensions

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

  • x (NUMERIC) - Input variable

  • biasCorrected - If true: divide by (N-1) (i.e., sample variable). If false: divide by N (population variance)

  • keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false

  • dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

zerosLike

Return a variable of all 0s, with the same shape as the input variable. Note that this is dynamic:

if the input shape changes in later execution, the returned variable's shape will also be updated

  • input (NUMERIC) - Input

Was this helpful?