Class SDVariable

    • Field Detail

      • varName

        protected String varName
      • shape

        protected long[] shape
    • Constructor Detail

      • SDVariable

        public SDVariable​(@NonNull
                          @NonNull String varName,
                          @NonNull
                          @NonNull VariableType varType,
                          @NonNull
                          @NonNull SameDiff sameDiff,
                          long[] shape,
                          DataType dataType)
    • Method Detail

      • name

        public String name()
        Get the name of the SDVariable
        Returns:
        Name of the variable
      • setVarName

        public void setVarName​(String varName)
      • isPlaceHolder

        public boolean isPlaceHolder()
        Returns true if this variable is a placeholder
        Returns:
      • isConstant

        public boolean isConstant()
      • getArr

        public INDArray getArr()
        A getter for the allocated ndarray with this SDVariable. This getter will lazy initialize an array if one is not found based on the associated shape and WeightInitScheme - if this is possible. If this is not possible (due to shapes being unknown, etc) null is returned
        Returns:
        the INDArray associated with this variable.
      • getArr

        public INDArray getArr​(boolean enforceExistence)
        A getter for the allocated ndarray with this SDVariable. This getter will lazy initialize an array if one is not found based on the associated shape and WeightInitScheme - if this is possible.
        If this is not possible (due to shapes being unknown, etc) either:
        (a) null is returned - if enforceExistence == false, or
        (b) an IllegalStateException is thrown, if enforceExistence == true
        Returns:
        the INDArray associated with this variable.
      • gradient

        public SDVariable gradient()
        Alias for the gradient variable - same as getGradient(). The gradient variable is the variable that represents the derivative of the loss function with respect to the output of this variable. I.e., if this variable is X and loss function is L, then gradient() returns the variable representing dL/dX.
        Note that only floating point variables can have gradients.
      • getGradient

        public SDVariable getGradient()
        The gradient variable is the variable that represents the derivative of the loss function with respect to the output of this variable. I.e., if this variable is X and loss function is L, then gradient() returns the variable representing dL/dX
        Note that only floating point variables can have gradients.
        Note also that a gradient may not yet be defined, and/or if no loss function variables have been set.
        You can set the loss function variables using SameDiff.setLossVariables(String...) and then create the gradient functions using SameDiff.createGradFunction(). Alternatively, the gradient function will be created automatically when training is performed.
      • getShape

        public long[] getShape()
        Returns the shape of this variable
        Returns:
        Shape of the variable
      • setShape

        public void setShape​(long... shape)
      • placeholderShape

        public long[] placeholderShape()
      • dup

        public SDVariable dup()
        Create a new SDVariable, the contents of which is copied from this current variable
        Returns:
        The new variable
      • assign

        public SDVariable assign​(Number value)
        Return a variable with equal shape to the input, but all elements set to the specified value
        Parameters:
        value - Value for returned variable
        Returns:
        new variable
      • neg

        public SDVariable neg()
        Negate op - returns a new variable with the values of the current variable negated
        Returns:
        Negated variable
      • neg

        public SDVariable neg​(String name)
        Negate op - returns a new variable with the values of the current variable negated
        Parameters:
        name - Name of the new variable
        Returns:
        Negated variable
      • lt

        public SDVariable lt​(String name,
                             double value)
        Less than operation: elementwise this < value
        Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise
        Parameters:
        name - Name of the output variable
        value - value argument to use in operation
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • lte

        public SDVariable lte​(String name,
                              double value)
        Less than or equals operation: elementwise this <= value
        Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise
        Parameters:
        name - Name of the output variable
        value - value argument to use in operation
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • gt

        public SDVariable gt​(String name,
                             double value)
        Greater than operation: elementwise this > value
        Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise
        Parameters:
        name - Name of the output variable
        value - value argument to use in operation
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • gte

        public SDVariable gte​(String name,
                              double value)
        Greater than or equals operation: elementwise this >= value
        Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise
        Parameters:
        name - Name of the output variable
        value - value argument to use in operation
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • eq

        public SDVariable eq​(String name,
                             double value)
        Equals operation: elementwise this == value
        Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise
        Parameters:
        name - Name of the output variable
        value - value argument to use in operation
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • neq

        public SDVariable neq​(String name,
                              double value)
        Not equals operation: elementwise this != value
        Returns an array with the same shape/size as the input, with values 1 where condition is satisfied, or value 0 otherwise
        Parameters:
        name - Name of the output variable
        value - value argument to use in operation
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • lt

        public SDVariable lt​(String name,
                             SDVariable other)
        Less than operation: elementwise this < y
        If x and y arrays have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
        Returns an array with values 1 where condition is satisfied, or value 0 otherwise.
        Parameters:
        name - Name of the output variable
        other - Variable to compare values against
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • lte

        public SDVariable lte​(String name,
                              SDVariable other)
        Less than or equal to operation: elementwise this <= y
        If x and y arrays have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
        Returns an array with values 1 where condition is satisfied, or value 0 otherwise.
        Parameters:
        name - Name of the output variable
        other - Variable to compare values against
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • gt

        public SDVariable gt​(String name,
                             SDVariable other)
        Greater than operation: elementwise this > y
        If x and y arrays have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
        Returns an array with values 1 where condition is satisfied, or value 0 otherwise.
        Parameters:
        name - Name of the output variable
        other - Variable to compare values against
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • gte

        public SDVariable gte​(String name,
                              SDVariable other)
        Greater than or equal to operation: elementwise this >= y
        If x and y arrays have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
        Returns an array with values 1 where condition is satisfied, or value 0 otherwise.
        Parameters:
        name - Name of the output variable
        other - Variable to compare values against
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • eq

        public SDVariable eq​(String name,
                             SDVariable other)
        Equal to operation: elementwise this == y
        If x and y arrays have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
        Returns an array with values 1 where condition is satisfied, or value 0 otherwise.
        Parameters:
        name - Name of the output variable
        other - Variable to compare values against
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • neq

        public SDVariable neq​(String name,
                              SDVariable other)
        Not equal to operation: elementwise this != y
        If x and y arrays have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if x and y have different shapes and are broadcastable, the output shape is broadcast.
        Returns an array with values 1 where condition is satisfied, or value 0 otherwise.
        Parameters:
        name - Name of the output variable
        other - Variable to compare values against
        Returns:
        Output SDVariable with values 0 (not satisfied) and 1 (where the condition is satisfied)
      • mmul

        public SDVariable mmul​(String name,
                               SDVariable other)
        Matrix multiplication: out = mmul(this,other)
        Parameters:
        name - Name of the output variable
        other - Other variable to perform matrix multiplication with
        Returns:
        Output variable (result of mmul)
      • mmul

        public SDVariable mmul​(String name,
                               SDVariable other,
                               @NonNull
                               @NonNull MMulTranspose mMulTranspose)
        Matrix multiplication: out = mmul(this,other)
        Parameters:
        name - Name of the output variable
        other - Other variable to perform matrix multiplication with
        mMulTranspose - Matrix transpose configuration
        Returns:
        Output variable (result of mmul)
      • dot

        public SDVariable dot​(String name,
                              SDVariable other,
                              int... dimensions)
        Matrix dot product: out = dot(this,other, dimensions)
        Parameters:
        name - Name of the output variable
        other - Other variable to perform matrix multiplication with
        Returns:
        Output variable (result of mmul)
      • add

        public SDVariable add​(String varName,
                              double scalar)
        Scalar addition: out = this + scalar
        Output variable has the same shape as the input variable
        Parameters:
        varName - Output variable name
        scalar - Scalar for operation
        Returns:
        Output variable
      • add

        public SDVariable add​(String name,
                              SDVariable x)
        Addition operation: elementwise this + x
        If this and x variables have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.
        Parameters:
        name - Name of the output variable
        x - Variable to perform operation with
        Returns:
        Output (result) SDVariable
      • sub

        public SDVariable sub​(String varName,
                              double scalar)
        Scalar subtraction: out = this - scalar
        Output variable has the same shape as the input variable
        Parameters:
        varName - Output variable name
        scalar - Scalar for operation
        Returns:
        Output variable
      • sub

        public SDVariable sub​(String name,
                              SDVariable x)
        Subtraction operation: elementwise this - x
        If this and x variables have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.
        Parameters:
        name - Name of the output variable
        x - Variable to perform operation with
        Returns:
        Output (result) SDVariable
      • div

        public SDVariable div​(String varName,
                              double scalar)
        Scalar division: out = this / scalar
        Output variable has the same shape as the input variable
        Parameters:
        varName - Output variable name
        scalar - Scalar for operation
        Returns:
        Output variable
      • div

        public SDVariable div​(String name,
                              SDVariable x)
        Division operation: elementwise this / x
        If this and x variables have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.
        Parameters:
        name - Name of the output variable
        x - Variable to perform operation with
        Returns:
        Output (result) SDVariable
      • fdiv

        public SDVariable fdiv​(String name,
                               SDVariable x)
        Floor division operation: elementwise this // x
        If this and x variables have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.
        Parameters:
        name - Name of the output variable
        x - Variable to perform operation with
        Returns:
        Output (result) SDVariable
      • mod

        public SDVariable mod​(String name,
                              SDVariable x)
        Modulo operation: elementwise this / x
        If this and x variables have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.
        Parameters:
        name - Name of the output variable
        x - Variable to perform operation with
        Returns:
        Output (result) SDVariable
      • mul

        public SDVariable mul​(String varName,
                              double scalar)
        Scalar multiplication: out = this * scalar
        Output variable has the same shape as the input variable
        Parameters:
        varName - Output variable name
        scalar - Scalar for operation
        Returns:
        Output variable
      • mul

        public SDVariable mul​(String name,
                              SDVariable x)
        Multiplication operation: elementwise this * x
        If this and x variables have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.
        Parameters:
        name - Name of the output variable
        x - Variable to perform operation with
        Returns:
        Output (result) SDVariable
      • pow

        public SDVariable pow​(String varName,
                              double scalar)
        Scalar power operation: out = this ^ scalar
        Output variable has the same shape as the input variable
        Parameters:
        varName - Output variable name
        scalar - Scalar for operation
        Returns:
        Output variable
      • rsub

        public SDVariable rsub​(String varName,
                               double scalar)
        Scalar reverse subtraction: out = scalar - this
        Output variable has the same shape as the input variable
        Parameters:
        varName - Output variable name
        scalar - Scalar for operation
        Returns:
        Output variable
      • rsub

        public SDVariable rsub​(String name,
                               SDVariable x)
        Reverse subtraction operation: elementwise x - this
        If this and x variables have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.
        Parameters:
        name - Name of the output variable
        x - Variable to perform operation with
        Returns:
        Output (result) SDVariable
      • rdiv

        public SDVariable rdiv​(String varName,
                               double scalar)
        Scalar reverse division: out = scalar / this
        Output variable has the same shape as the input variable
        Parameters:
        varName - Output variable name
        scalar - Scalar for operation
        Returns:
        Output variable
      • rdiv

        public SDVariable rdiv​(String name,
                               SDVariable x)
        Reverse division operation: elementwise x / this
        If this and x variables have equal shape, the output shape is the same as the inputs.
        Supports broadcasting: if this and x have different shapes and are broadcastable, the output shape is broadcast.
        Parameters:
        name - Name of the output variable
        x - Variable to perform operation with
        Returns:
        Output (result) SDVariable
      • squaredDifference

        public SDVariable squaredDifference​(String name,
                                            SDVariable x)
        Squared difference operation: (this - x)^2
        Parameters:
        x - Other input variable
        Returns:
        squared difference between variables
      • sum

        public SDVariable sum​(String name,
                              boolean keepDims,
                              int... dimensions)
        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]
        Parameters:
        name - Output variable name
        keepDims - If true: keep the dimensions that are reduced on (as length 1). False: remove the reduction dimensions
        dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed
        Returns:
        Output variable: reduced array of rank (input rank - num dimensions) if keepDims = false, or of rank (input rank) if keepdims = true
      • mean

        public SDVariable mean​(String name,
                               boolean keepDims,
                               int... dimensions)
        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]
        Parameters:
        name - Output variable name
        keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions
        dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed
        Returns:
        Reduced array of rank (input rank - num dimensions)
      • std

        public SDVariable std​(String name,
                              boolean biasCorrected,
                              boolean keepDims,
                              int... dimensions)
        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]
        Parameters:
        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
        dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed
        Returns:
        Output variable: reduced array of rank (input rank - num dimensions)
      • prod

        public SDVariable prod​(String name,
                               boolean keepDims,
                               int... dimensions)
        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]
        Parameters:
        name - Output variable name
        keepDims - If true: keep the dimensions that are reduced on (as length 1). False: remove the reduction dimensions
        dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed
        Returns:
        Output variable: reduced array of rank (input rank - num dimensions)
      • min

        public SDVariable min​(String name,
                              boolean keepDims,
                              int... dimensions)
        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]
        Parameters:
        name - Output variable name
        keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions
        dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed
        Returns:
        Reduced array of rank (input rank - num dimensions)
      • max

        public SDVariable max​(String name,
                              boolean keepDims,
                              int... dimensions)
        Maximum 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]
        Parameters:
        name - Output variable name
        keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions
        dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed
        Returns:
        Reduced array of rank (input rank - num dimensions)
      • norm1

        public SDVariable norm1​(String name,
                                boolean keepDims,
                                int... dimensions)
        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]
        Parameters:
        name - Output variable name
        keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions
        dimensions - dimensions to reduce over
        Returns:
        Output variable
      • norm2

        public SDVariable norm2​(String name,
                                boolean keepDims,
                                int... dimensions)
        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]
        Parameters:
        name - Output variable name
        keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions
        dimensions - dimensions to reduce over
        Returns:
        Output variable
      • normmax

        public SDVariable normmax​(String name,
                                  boolean keepDims,
                                  int... dimensions)
        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]
        Parameters:
        name - Output variable name
        keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions
        dimensions - dimensions to reduce over
        Returns:
        Output variable
      • argmax

        public SDVariable argmax​(String name,
                                 boolean keepDims,
                                 int... dimensions)
        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]
        Parameters:
        name - Name of the output variable
        keepDims - If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions
        dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed
        Returns:
        Output variable: reduced array of rank (input rank - num dimensions) if keepDims = false, or of rank (input rank) if keepdims = true
      • argmin

        public SDVariable argmin​(String name,
                                 boolean keepDims,
                                 int... dimensions)
        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]
        Parameters:
        name - Name of the output variable
        keepDims - If true: keep the dimensions that are reduced on (as length 1). False: remove the reduction dimensions
        dimensions - Dimensions to reduce over. If dimensions are not specified, full array reduction is performed
        Returns:
        Output variable: reduced array of rank (input rank - num dimensions) if keepDims = false, or of rank (input rank) if keepdims = true
      • length

        public SDVariable length()
        Return the total number of elements in this array
        Returns:
      • shape

        public SDVariable shape()
        Get the shape of the array as a dynamic SDVariable
        Returns:
        Shape SDVariable
      • rank

        public SDVariable rank()
        Get the rank of this variable as a dynamic SDVariable
        Returns:
        Rank SDVariable
      • reshape

        public SDVariable reshape​(SDVariable newShape)
        Reshape the current variable to the specified (dynamic) 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)
        Parameters:
        newShape - New shape for variable
        Returns:
        Output variable
      • reshape

        public SDVariable reshape​(String name,
                                  SDVariable newShape)
        Reshape the current variable to the specified (dynamic) 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)
        Parameters:
        newShape - New shape for variable
        Returns:
        Output variable
      • reshape

        public SDVariable reshape​(int... newShape)
        Reshape the current variable to the specified 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)
        Parameters:
        newShape - New shape for variable
        Returns:
        Output variable
      • reshape

        public SDVariable reshape​(long... newShape)
        Reshape the current variable to the specified 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)
        Parameters:
        newShape - New shape for variable
        Returns:
        Output variable
      • permute

        public SDVariable permute​(int... dimensions)
        Permute the dimensions of the current variable according to the specified permutation indices.
        Example: if the current variable has shape [a,b,c] and dimensions = [2,0,1] the output has shape [c,a,b]
        Parameters:
        dimensions - The new dimension order
        Returns:
        Output variable (permuted input)
      • setArray

        public SDVariable setArray​(INDArray array)
        Associate the specified array with this variable
        Parameters:
        array - Array to associate with this variable
        Returns:
        This variable
      • eval

        public INDArray eval()
        Evaluate the result of this variable
        Returns:
      • addControlDependency

        public void addControlDependency​(SDVariable controlDependency)
        Add a control dependency for this variable on the specified variable.
        Control dependencies can be used to enforce the execution order. For example, if a control dependency X->Y exists, then Y will only be executed after X is executed - even if Y wouldn't normally depend on the result/values of X.
        Parameters:
        controlDependency - Control dependency to add for this variable
      • getView

        public SDVariable getView​(SDIndex... indices)
        Get a variable with content equal to a specified sub-array of this variable.
        Can be used (for example) to get rows, columns, sub-matrices, etc.
        Parameters:
        indices - Indices to get
        Returns:
        Sub-array variable
      • get

        public SDVariable get​(SDIndex... indices)
        Get a variable with content equal to a specified sub-array of this variable.
        Can be used (for example) to get rows, columns, sub-matrices, etc.
        Parameters:
        indices - Indices to get
        Returns:
        Sub-array variable
      • get

        public SDVariable get​(SDVariable indices)
        Get a variable with content equal to a specified sub-array of this variable.
        Can be used (for example) to get rows, columns, sub-matrices, etc. This will loop over the indices (think of it as a list) and concatenate each slice of the input array to the final result. Expected input for indices would be a vector with indices such as 0,1,2,3,4. For each element in the index we then concatenate the result to the previous iteration. Note that this is slow and should only be used in very specific circumstances. Otherwise StridedSlice will be more performant for creating views. Many times StridedSlice avoids this slower approach by directly calculating the strides of a view.
        Parameters:
        indices - Indices to get
        Returns:
        Sub-array variable
      • put

        public SDVariable put​(SDVariable indices,
                              SDVariable toPut,
                              SDVariable putIndices)
        Get a variable with content equal to a specified sub-array of this variable.
        Can be used (for example) to get rows, columns, sub-matrices, etc. This will loop over the indices (think of it as a list) and add each slice specified by the indices from the source to the new array. The end result will be this variable but with the new updated results. Note that this is slow and should only be used in very specific circumstances. Otherwise StridedSlice will be more performant for creating views. Many times StridedSlice avoids this slower approach by directly calculating the strides of a view.
        Parameters:
        indices - Indices to get
        toPut - the source array to pull results from to put in to this array
        putIndices - the equivalent indices for the other array
        Returns:
        the updated array with the elements from the toPut array put in to this new array
      • createLoopPut

        public static SameDiff createLoopPut​(SDVariable relative,
                                             SDVariable indices)
        Create a graph that takes in the indices as a placeholder, loops over each element in the index vector and appends the slice to the end result. This graph is equivalent to something like: INDArray input = ....; INDArray indices = ...; INDArray result = input.get(NDArrayIndex.point(indices.getInt(0)); for(int i = i; i < maxIndex && customInputResult; i++) { result = Nd4j.concat(0,input.get(NDArrayIndex.point(i))); } return result

        Note this is similar to INDArray.get(INDArray)

        Parameters:
        relative - the expected target input variable. We use this to pull expected return data type for the result
        indices - the indices to get
        Returns:
        the graph for dynamically creating a result graph
      • createLoopConcat

        public static SameDiff createLoopConcat​(SDVariable relative,
                                                SDVariable indices)
        Create a graph that takes in the indices as a placeholder, loops over each element in the index vector and appends the slice to the end result. This graph is equivalent to something like: INDArray input = ....; INDArray indices = ...; INDArray result = input.get(NDArrayIndex.point(indices.getInt(0)); for(int i = i; i < maxIndex && customInputResult; i++) { result = Nd4j.concat(0,input.get(NDArrayIndex.point(i))); } return result Note this is similar to INDArray.get(INDArray)
        Parameters:
        relative - the expected target input variable. We use this to pull expected return data type for the result
        indices - the indices to get
        Returns:
        the graph for dynamically creating a result graph
      • convertToConstant

        public SDVariable convertToConstant()
        Convert this variable to a constant. This is equivalent to "freezing" a variable so that it's value won't be changed by further training.
        This can only be done for variables and placeholders, not ARRAY type variables (which are usually network activations). As a constant, this variable will no longer be modified by any subsequent training.
        Returns:
        This variable (now a constant)
      • convertToVariable

        public SDVariable convertToVariable()
        Convert this variable to a VARIABLE type SDVariable.
        This can only be done for constants and placeholders, not ARRAY type variables (which are usually network activations). As a variable, this variable will modified during any subsequent training.
        Returns:
        This variable (now a variable type SDVariable)
      • rename

        public SDVariable rename​(String newName)
        Rename this variable to a new name. Equivalent to SameDiff.renameVariable(String, String)
        Parameters:
        newName - The new name for the variable - no variable with this name must already exist
        Returns:
        The current variable (same object)
      • markAsLoss

        public void markAsLoss()
        Mark this variable as a loss function variable. This means that this variable will be minimized via backprop during training.
        This will add the variable as a loss to any others - i.e., if multiple variables are marked as losses, their values will be summed to give the total network loss.
        Note that only floating point (Float16/32/64) variables may be marked as a loss.
        Note also that only ARRAY type SDVariables can be marked as losses to be minimized. That is, we cannot mark the value of a constant, variable or placeholder to be minimized as doing so would not make sense.
        This is equivalent to SameDiff.addLossVariable(String)
      • hasGradient

        public boolean hasGradient()
        Determine if this variable has a gradient with respect to the current loss. Note that: (a) Non-floating-point variables (integer, string, etc) will never have gradients
        (b) This method will return false if no gradient function has been created yet. See SameDiff.createGradFunction() and SameDiff.setLossVariables(String...)
        (c) Floating point variables may not have any gradient if the current loss does not depend on the variable at all
        Returns:
        True if a gradient variable exists for the specified variable, for the current loss
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object