signature:
public class SameDiff { /** * Associate the array with the given variable .
 * @ param arr the array to get the variable for
 * @ param variable the variable to associate */
public void associateArrayWithVariable ( INDArray arr , SDVariable variable ) { } }

implementation: if ( variable == null ) { throw new ND4JIllegalArgumentException ( "Variable must not be null!" ) ; } if ( arr == null ) { throw new ND4JIllegalArgumentException ( "Array must not be null" ) ; } reverseArrayLookup . put ( arr , variable ) ; variableNameToArr . put ( variable . getVarName ( ) , arr ) ; if ( ! shapeAlreadyExistsForVarName ( variable . getVarName ( ) ) ) putShapeForVarName ( variable . getVarName ( ) , arr . shape ( ) ) ; else { updateShapeForVarName ( variable . getVarName ( ) , arr . shape ( ) ) ; }


signature:
public class SameDiff { /** * Get the property for a given function
 * @ param functionInstance the function to get the
 * property for
 * @ param propertyName the name of the property to get
 * @ param < T > the inferred return type
 * @ return the property for the given function */
public < T > T getPropertyForFunction ( DifferentialFunction functionInstance , String propertyName ) { } }

implementation: if ( ! propertiesForFunction . containsKey ( functionInstance . getOwnName ( ) ) ) { return null ; } else { val map = propertiesForFunction . get ( functionInstance . getOwnName ( ) ) ; return ( T ) map . get ( propertyName ) ; }


signature:
public class SameDiff { /** * Add a property for the given function
 * @ param functionFor the function add a property for
 * @ param propertyName the property name
 * @ param property the property value */
public void addPropertyForFunction ( DifferentialFunction functionFor , String propertyName , INDArray property ) { } }

implementation: addPropertyForFunction ( functionFor , propertyName , ( Object ) property ) ;


signature:
public class SameDiff { /** * Adds outgoing arguments to the graph .
 * Also checks for input arguments
 * and updates the graph adding an appropriate edge
 * when the full graph is declared .
 * @ param varNames
 * @ param function */
public void addOutgoingFor ( String [ ] varNames , DifferentialFunction function ) { } }

implementation: if ( function . getOwnName ( ) == null ) throw new ND4JIllegalStateException ( "Instance id can not be null. Function not initialized properly" ) ; if ( outgoingArgsReverse . containsKey ( function . getOwnName ( ) ) ) { throw new ND4JIllegalStateException ( "Outgoing arguments already declared for " + function ) ; } if ( varNames == null ) throw new ND4JIllegalStateException ( "Var names can not be null!" ) ; for ( int i = 0 ; i < varNames . length ; i ++ ) { if ( varNames [ i ] == null ) throw new ND4JIllegalStateException ( "Variable name elements can not be null!" ) ; } outgoingArgsReverse . put ( function . getOwnName ( ) , varNames ) ; outgoingArgs . put ( varNames , function ) ; for ( val resultName : varNames ) { List < DifferentialFunction > funcs = functionOutputFor . get ( resultName ) ; if ( funcs == null ) { funcs = new ArrayList < > ( ) ; functionOutputFor . put ( resultName , funcs ) ; } funcs . add ( function ) ; }


signature:
public class SameDiff { /** * Adds incoming args to the graph
 * @ param variables
 * @ param function */
public void addArgsFor ( String [ ] variables , DifferentialFunction function ) { } }

implementation:
if ( function . getOwnName ( ) == null ) throw new ND4JIllegalStateException ( "Instance id can not be null. Function not initialized properly" ) ; // double check if function contains placeholder args
for ( val varName : variables ) { if ( isPlaceHolder ( varName ) ) { placeHolderFunctions . add ( function . getOwnName ( ) ) ; } } incomingArgs . put ( variables , function ) ; incomingArgsReverse . put ( function . getOwnName ( ) , variables ) ; for ( val variableName : variables ) { List < DifferentialFunction > funcs = functionsArgsFor . get ( variableName ) ; if ( funcs == null ) { funcs = new ArrayList < > ( ) ; functionsArgsFor . put ( variableName , funcs ) ; } funcs . add ( function ) ; }


signature:
public class SameDiff { /** * Returns true if this function already
 * has defined arguments
 * @ param function the function to check
 * @ return true if the function has args false otherwise */
public boolean hasArgs ( DifferentialFunction function ) { } }

implementation: val vertexIdArgs = incomingArgsReverse . get ( function . getOwnName ( ) ) ; if ( vertexIdArgs != null ) { val args = incomingArgs . get ( vertexIdArgs ) ; if ( args != null ) return true ; } return false ;


signature:
public class SameDiff { /** * Evaluate the given inputs
 * based on the current graph
 * @ param inputs the inputs to evaluate
 * @ return */
public INDArray [ ] eval ( Map < String , INDArray > inputs ) { } }

implementation: SameDiff execPipeline = dup ( ) ; List < DifferentialFunction > opExecAction = execPipeline . exec ( ) . getRight ( ) ; if ( opExecAction . isEmpty ( ) ) throw new IllegalStateException ( "No ops found to execute." ) ; INDArray [ ] ret = new INDArray [ opExecAction . size ( ) ] ; for ( int i = 0 ; i < ret . length ; i ++ ) { val varName = opExecAction . get ( i ) . outputVariables ( ) [ 0 ] . getVarName ( ) ; ret [ i ] = execPipeline . getArrForVarName ( varName ) ; } return ret ;


signature:
public class SameDiff { /** * Variable initialization
 * with 1.0
 * @ param name the opName of the variable
 * @ param shape the shape of the array to be created
 * @ return the created variable */
public SDVariable one ( String name , int [ ] shape ) { } }

implementation: return var ( name , ArrayUtil . toLongArray ( shape ) , new ConstantInitScheme ( 'f' , 1.0 ) ) ;


signature:
public class SameDiff { /** * Return a variable of all 1s , with the same shape as the input
 * @ param input
 * @ return */
public SDVariable onesLike ( String name , SDVariable input ) { } }

implementation: return f ( ) . onesLike ( name , input ) ;


signature:
public class SameDiff { /** * Return a variable of all 0s , with the same shape as the input
 * @ param input
 * @ return */
public SDVariable zerosLike ( String name , SDVariable input ) { } }

implementation: return f ( ) . zerosLike ( name , input ) ;


signature:
public class SameDiff { /** * Variable initialization
 * with a specified { @ link WeightInitScheme }
 * @ param name the opName of the variable
 * @ param shape the shape of the array to be created
 * @ param weightInitScheme the weight init scheme
 * @ return the created variable */
public SDVariable var ( String name , long [ ] shape , WeightInitScheme weightInitScheme ) { } }

implementation: if ( variableMap . containsKey ( name ) && variableMap . get ( name ) . getArr ( ) != null ) return variableMap . get ( name ) ; if ( name == null || name . length ( ) < 1 ) throw new IllegalArgumentException ( "Name for variable must be defined" ) ; if ( workspace == null ) initWorkspace ( ) ; SDVariable ret = SDVariable . builder ( ) . sameDiff ( this ) . shape ( shape ) . weightInitScheme ( weightInitScheme ) . varName ( name ) . build ( ) ; addVariable ( ret ) ; variableMap . put ( name , ret ) ; return ret ;


signature:
public class SameDiff { /** * Assign a vertex id
 * to a gradient
 * @ param variableName the vertex id
 * to assign
 * @ param variable the variable */
public void setGradientForVariableName ( String variableName , SDVariable variable ) { } }

implementation: if ( variable == null ) { throw new ND4JIllegalStateException ( "Unable to set null gradient for variable name " + variableName ) ; } gradients . put ( variableName , variable ) ;


signature:
public class SameDiff { /** * Average pooling 2d operation .
 * @ param inputs the inputs to average pooling 2d
 * @ param pooling2DConfig the configuration
 * @ return */
public SDVariable avgPooling2d ( SDVariable [ ] inputs , Pooling2DConfig pooling2DConfig ) { } }

implementation: return avgPooling2d ( null , inputs , pooling2DConfig ) ;


signature:
public class SameDiff { /** * Average pooling 2d operation .
 * @ param name name of the operation in SameDiff
 * @ param inputs the inputs to average pooling 2d
 * @ param pooling2DConfig the configuration
 * @ return */
public SDVariable avgPooling2d ( String name , SDVariable [ ] inputs , Pooling2DConfig pooling2DConfig ) { } }

implementation: SDVariable ret = f ( ) . avgPooling2d ( inputs , pooling2DConfig ) ; return updateVariableNameAndReference ( ret , name ) ;


signature:
public class SameDiff { /** * Max pooling 2d operation .
 * @ param inputs the inputs to max pooling 2d
 * @ param pooling2DConfig the configuration
 * @ return */
public SDVariable maxPooling2d ( SDVariable [ ] inputs , Pooling2DConfig pooling2DConfig ) { } }

implementation: return maxPooling2d ( null , inputs , pooling2DConfig ) ;


signature:
public class SameDiff { /** * Average pooling 3d operation .
 * @ param inputs the inputs to average pooling 3d
 * @ param pooling3DConfig the configuration
 * @ return */
public SDVariable avgPooling3d ( SDVariable [ ] inputs , Pooling3DConfig pooling3DConfig ) { } }

implementation: return avgPooling3d ( null , inputs , pooling3DConfig ) ;


signature:
public class SameDiff { /** * Max pooling 3d operation .
 * @ param inputs the inputs to max pooling 3d
 * @ param pooling3DConfig the configuration
 * @ return */
public SDVariable maxPooling3d ( SDVariable [ ] inputs , Pooling3DConfig pooling3DConfig ) { } }

implementation: return maxPooling3d ( null , inputs , pooling3DConfig ) ;


signature:
public class SameDiff { /** * Max pooling 3d operation .
 * @ param name name of the operation in SameDiff
 * @ param inputs the inputs to max pooling 3d
 * @ param pooling3DConfig the configuration
 * @ return */
public SDVariable maxPooling3d ( String name , SDVariable [ ] inputs , Pooling3DConfig pooling3DConfig ) { } }

implementation: SDVariable ret = f ( ) . maxPooling3d ( inputs , pooling3DConfig ) ; return updateVariableNameAndReference ( ret , name ) ;


signature:
public class SameDiff { /** * Conv1d operation .
 * @ param inputs the inputs to conv1d
 * @ param conv1DConfig the configuration
 * @ return */
public SDVariable conv1d ( SDVariable [ ] inputs , Conv1DConfig conv1DConfig ) { } }

implementation: return conv1d ( null , inputs , conv1DConfig ) ;


signature:
public class SameDiff { /** * Conv1d operation .
 * @ param name name of the operation in SameDiff
 * @ param inputs the inputs to conv1d
 * @ param conv1DConfig the configuration
 * @ return */
public SDVariable conv1d ( String name , SDVariable [ ] inputs , Conv1DConfig conv1DConfig ) { } }

implementation: SDVariable ret = f ( ) . conv1d ( inputs , conv1DConfig ) ; return updateVariableNameAndReference ( ret , name ) ;


signature:
public class SameDiff { /** * Local response normalization operation .
 * @ param inputs the inputs to lrn
 * @ param lrnConfig the configuration
 * @ return */
public SDVariable localResponseNormalization ( SDVariable inputs , LocalResponseNormalizationConfig lrnConfig ) { } }

implementation: return localResponseNormalization ( null , inputs , lrnConfig ) ;


signature:
public class SameDiff { /** * Local response normalization operation .
 * @ param name name of the operation in SameDiff
 * @ param inputs the inputs to lrn
 * @ param lrnConfig the configuration
 * @ return */
public SDVariable localResponseNormalization ( String name , SDVariable inputs , LocalResponseNormalizationConfig lrnConfig ) { } }

implementation: SDVariable ret = f ( ) . localResponseNormalization ( inputs , lrnConfig ) ; return updateVariableNameAndReference ( ret , name ) ;


signature:
public class SameDiff { /** * Conv2d operation .
 * @ param inputs the inputs to conv2d
 * @ param conv2DConfig the configuration
 * @ return */
public SDVariable conv2d ( SDVariable [ ] inputs , Conv2DConfig conv2DConfig ) { } }

implementation: return conv2d ( null , inputs , conv2DConfig ) ;


signature:
public class SameDiff { /** * Depth - wise Conv2d operation .
 * @ param inputs the inputs to conv2d
 * @ param depthConv2DConfig the configuration
 * @ return */
public SDVariable depthWiseConv2d ( SDVariable [ ] inputs , Conv2DConfig depthConv2DConfig ) { } }

implementation: return depthWiseConv2d ( null , inputs , depthConv2DConfig ) ;


signature:
public class SameDiff { /** * Depth - wise Conv2d operation .
 * @ param name name of the operation in SameDiff
 * @ param inputs the inputs to sconv2d
 * @ param depthConv2DConfig the configuration
 * @ return */
public SDVariable depthWiseConv2d ( String name , SDVariable [ ] inputs , Conv2DConfig depthConv2DConfig ) { } }

implementation: SDVariable ret = f ( ) . depthWiseConv2d ( inputs , depthConv2DConfig ) ; return updateVariableNameAndReference ( ret , name ) ;


signature:
public class SameDiff { /** * Separable Conv2d operation .
 * @ param inputs the inputs to conv2d
 * @ param conv2DConfig the configuration
 * @ return */
public SDVariable sconv2d ( SDVariable [ ] inputs , Conv2DConfig conv2DConfig ) { } }

implementation: return sconv2d ( null , inputs , conv2DConfig ) ;


signature:
public class SameDiff { /** * Separable Conv2d operation .
 * @ param name name of the operation in SameDiff
 * @ param inputs the inputs to sconv2d
 * @ param conv2DConfig the configuration
 * @ return */
public SDVariable sconv2d ( String name , SDVariable [ ] inputs , Conv2DConfig conv2DConfig ) { } }

implementation: SDVariable ret = f ( ) . sconv2d ( inputs , conv2DConfig ) ; return updateVariableNameAndReference ( ret , name ) ;


signature:
public class SameDiff { /** * Deconv2d operation .
 * @ param inputs the inputs to sconv2d
 * @ param deconv2DConfig the configuration
 * @ return */
public SDVariable deconv2d ( SDVariable [ ] inputs , DeConv2DConfig deconv2DConfig ) { } }

implementation: return deconv2d ( null , inputs , deconv2DConfig ) ;


signature:
public class SameDiff { /** * Deconv2d operation .
 * @ param name name of the operation in SameDiff
 * @ param inputs the inputs to sconv2d
 * @ param deconv2DConfig the configuration
 * @ return */
public SDVariable deconv2d ( String name , SDVariable [ ] inputs , DeConv2DConfig deconv2DConfig ) { } }

implementation: SDVariable ret = f ( ) . deconv2d ( inputs , deconv2DConfig ) ; return updateVariableNameAndReference ( ret , name ) ;


signature:
public class SameDiff { /** * Conv3d operation .
 * @ param inputs the inputs to conv3d
 * @ param conv3DConfig the configuration
 * @ return */
public SDVariable conv3d ( SDVariable [ ] inputs , Conv3DConfig conv3DConfig ) { } }

implementation: return conv3d ( null , inputs , conv3DConfig ) ;


signature:
public class SameDiff { /** * Conv3d operation .
 * @ param name name of the operation in SameDiff
 * @ param inputs the inputs to conv3d
 * @ param conv3DConfig the configuration
 * @ return */
public SDVariable conv3d ( String name , SDVariable [ ] inputs , Conv3DConfig conv3DConfig ) { } }

implementation: SDVariable ret = f ( ) . conv3d ( inputs , conv3DConfig ) ; return updateVariableNameAndReference ( ret , name ) ;


signature:
public class SameDiff { /** * Batch norm operation . */
public SDVariable batchNorm ( SDVariable input , SDVariable mean , SDVariable variance , SDVariable gamma , SDVariable beta , boolean applyGamma , boolean applyBeta , double epsilon ) { } }

implementation: return batchNorm ( null , input , mean , variance , gamma , beta , applyGamma , applyBeta , epsilon ) ;


signature:
public class SameDiff { /** * Batch norm operation . */
public SDVariable batchNorm ( String name , SDVariable input , SDVariable mean , SDVariable variance , SDVariable gamma , SDVariable beta , boolean applyGamma , boolean applyBeta , double epsilon ) { } }

implementation: SDVariable res = f ( ) . batchNorm ( input , mean , variance , gamma , beta , applyGamma , applyBeta , epsilon ) ; return updateVariableNameAndReference ( res , name ) ;


signature:
public class SameDiff { /** * LSTM unit
 * @ param baseName the base name for outputs
 * @ param configuration the configuration to use
 * @ return */
public SDVariable lstm ( String baseName , LSTMCellConfiguration configuration ) { } }

implementation: return new LSTMCell ( this , configuration ) . outputVariables ( baseName ) [ 0 ] ;


signature:
public class SameDiff { /** * The gru cell
 * @ param baseName the base name for the gru cell
 * @ param configuration teh configuration to use
 * @ return */
public SDVariable gru ( String baseName , GRUCellConfiguration configuration ) { } }

implementation: return new GRUCell ( this , configuration ) . outputVariables ( baseName ) [ 0 ] ;


signature:
public class SameDiff { /** * Generate the variables based on the given input op
 * and return the output variable names .
 * @ param function the function to generate the output
 * variable names for
 * @ return the set of names generated for each output of the function . */
public SDVariable [ ] generateOutputVariableForOp ( DifferentialFunction function , String baseName ) { } }

implementation:
// xyz ops only have 1 output
// if there is already a base name defined , use that
if ( baseName == null || baseName . isEmpty ( ) && getBaseNameForFunction ( function ) != null ) baseName = getBaseNameForFunction ( function ) ; if ( baseName == null ) baseName = function . opName ( ) ; val outputShape = function . calculateOutputShape ( ) ; if ( outputShape == null || outputShape . isEmpty ( ) ) { if ( function instanceof CustomOp ) { CustomOp customOp = ( CustomOp ) function ; val descriptor = customOp . getDescriptor ( ) ; // can ' t guess number of outputs , variable
if ( descriptor == null || descriptor . getNumOutputs ( ) <= 0 ) { throw new ND4JIllegalStateException ( "No output variables found!" ) ; } else { char ordering = 'c' ; if ( function . args ( ) [ 0 ] . getArr ( ) != null ) { ordering = function . args ( ) [ 0 ] . getArr ( ) . ordering ( ) ; } SDVariable [ ] ret = new SDVariable [ descriptor . getNumOutputs ( ) ] ; // dynamic shapes
for ( int i = 0 ; i < ret . length ; i ++ ) { SDVariable checkGet = getVariable ( baseName ) ; if ( checkGet == null ) { checkGet = var ( generateNewVarName ( baseName , i ) , null , new ZeroInitScheme ( ordering ) ) ; } else if ( i > 0 && ! importedVarName . contains ( baseName ) ) { // need to find a new name
String newName = generateNewVarName ( baseName , i ) ; checkGet = getVariable ( newName ) ; } if ( checkGet == null ) { String newName = generateNewVarName ( baseName , i ) ; checkGet = var ( newName , null , new ZeroInitScheme ( ordering ) ) ; } ret [ i ] = checkGet ; } return ret ; } } // this is for unresolved shapes , we know xyz is always 1 output
else if ( function instanceof BaseOp && outputShape . isEmpty ( ) ) { SDVariable [ ] ret = new SDVariable [ 1 ] ; SDVariable checkGet = getVariable ( baseName ) ; char ordering = 'c' ; if ( function . args ( ) [ 0 ] . getArr ( ) != null ) { ordering = function . args ( ) [ 0 ] . getArr ( ) . ordering ( ) ; } if ( checkGet == null ) { checkGet = var ( baseName , null , new ZeroInitScheme ( ordering ) ) ; } else if ( ! importedVarName . contains ( baseName ) ) { // need to find a new name
String newName = generateNewVarName ( baseName , 0 ) ; checkGet = var ( newName , null , new ZeroInitScheme ( ordering ) ) ; } if ( checkGet == null ) { checkGet = var ( baseName , null , new ZeroInitScheme ( ordering ) ) ; } ret [ 0 ] = checkGet ; return ret ; } } char ordering = 'c' ; if ( function . args ( ) [ 0 ] . getArr ( ) != null ) { ordering = function . args ( ) [ 0 ] . getArr ( ) . ordering ( ) ; } SDVariable [ ] ret = new SDVariable [ outputShape . size ( ) ] ; // ownName / baseName will be used to get variables names
val ownName = function . getOwnName ( ) ; val rootName = baseName ; for ( int i = 0 ; i < ret . length ; i ++ ) { val shape = outputShape . get ( i ) ; // it should be : rootName : index . i . e . : split : 1 , split : 2 , split : 3 , split : 4 etc
baseName = rootName + ( i > 0 ? ":" + i : "" ) ; SDVariable checkGet = getVariable ( baseName ) ; if ( checkGet == null ) { // obviously - there ' s no such var , just add it
checkGet = var ( baseName , shape , new ZeroInitScheme ( ordering ) ) ; } else if ( shape != null && ! shapeAlreadyExistsForVarName ( checkGet . getVarName ( ) ) ) { // var exists , let ' s update its shape
putShapeForVarName ( checkGet . getVarName ( ) , shape ) ; } else if ( shape != null && shapeAlreadyExistsForVarName ( checkGet . getVarName ( ) ) ) { // no - op .
// TODO : maybe we should check shapes equality here ?
// it ' s either var that already exist , or something bad happening
} else if ( ! importedVarName . contains ( baseName ) ) { // FIXME : dead end . it ' s impossible to get here with null as shape
// need to find a new name
int count = 1 ; String name = baseName + "_" + count + ( i > 0 ? ":" + i : "" ) ; while ( getVariable ( name ) != null ) { count ++ ; name = baseName + "_" + count + ( i > 0 ? ":" + i : "" ) ; } if ( getVariable ( name ) != null ) { throw new ND4JIllegalStateException ( "Converged on already generated variable!" ) ; } checkGet = var ( name , shape , new ZeroInitScheme ( ordering ) ) ; } if ( checkGet == null ) { checkGet = var ( baseName + ( i > 0 ? ":" + i : "" ) , shape , new ZeroInitScheme ( ordering ) ) ; } ret [ i ] = checkGet ; } return ret ;


signature:
public class SameDiff { /** * @ return */
public INDArray execAndEndResult ( List < DifferentialFunction > ops ) { } }

implementation: List < DifferentialFunction > exec = exec ( ops ) ; Op op = ( Op ) exec . get ( exec . size ( ) - 1 ) ; return op . z ( ) ;


signature:
public class SameDiff { /** * Executes the list of operations .
 * This exec method is for
 * only invoking operations
 * rather than creating them
 * @ param ops the list of already created ops
 * @ return the passes in list */
public List < DifferentialFunction > exec ( List < DifferentialFunction > ops ) { } }

implementation: for ( int i = 0 ; i < ops . size ( ) ; i ++ ) { Op op = ( Op ) ops . get ( i ) ; Nd4j . getExecutioner ( ) . exec ( op ) ; } return ops ;


signature:
public class SameDiff { /** * Creates a while statement
 * @ param sameDiffConditional
 * @ param loopBody
 * @ return */
public While whileStatement ( SameDiffConditional sameDiffConditional , SameDiffFunctionDefinition conditionBody , SameDiff . SameDiffFunctionDefinition loopBody , SDVariable [ ] inputVars ) { } }

implementation: return While . builder ( ) . inputVars ( inputVars ) . condition ( conditionBody ) . predicate ( sameDiffConditional ) . trueBody ( loopBody ) . parent ( this ) . blockName ( "while-" + UUID . randomUUID ( ) . toString ( ) ) . build ( ) ;


signature:
public class SameDiff { /** * Exec a given function
 * @ param functionName the opName of the function
 * to invoke
 * @ return */
public Pair < Map < SDVariable , DifferentialFunction > , List < DifferentialFunction > > exec ( String functionName ) { } }

implementation: if ( debugMode ) { return sameDiffFunctionInstances . get ( functionName ) . enableDebugMode ( ) . exec ( ) ; } else return sameDiffFunctionInstances . get ( functionName ) . exec ( ) ;


signature:
public class SameDiff { /** * Exec the given function
 * given the ops
 * @ param functionName the opName of the function to
 * exec
 * @ param cachedOps the cached operations
 * @ return */
public List < DifferentialFunction > exec ( String functionName , List < DifferentialFunction > cachedOps ) { } }

implementation: return sameDiffFunctionInstances . get ( functionName ) . exec ( cachedOps ) ;


signature:
public class SameDiff { /** * Builds a backwards graph
 * and executes the operations
 * on that graph .
 * @ return */
public Pair < Map < SDVariable , DifferentialFunction > , List < DifferentialFunction > > execBackwards ( ) { } }

implementation:
final SameDiff outer = this ; if ( getFunction ( "grad" ) == null ) defineFunction ( "grad" , new SameDiffFunctionDefinition ( ) { @ Override public SDVariable [ ] define ( SameDiff sameDiff , Map < String , INDArray > inputs , SDVariable [ ] variableInputs ) { // propagate graph to this samediff instance
// which will also contain the backward
if ( SameDiff . this . debugMode ) { sameDiff . enableDebugMode ( ) ; } outer . invokeGraphOn ( sameDiff ) ; List < DifferentialFunction > allFunctions = new ArrayList < > ( sameDiff . functionInstancesById . values ( ) ) ; if ( allFunctions . isEmpty ( ) ) { throw new ND4JIllegalStateException ( "No ops found!" ) ; } for ( val func : allFunctions ) { if ( func instanceof SDVariable ) { continue ; } val args = func . args ( ) ; for ( val arg : args ) arg . setSameDiff ( sameDiff ) ; val outputs = func . outputVariables ( ) ; for ( val output : outputs ) output . setSameDiff ( sameDiff ) ; func . setSameDiff ( sameDiff ) ; } val initialOuts = allFunctions . get ( allFunctions . size ( ) - 1 ) . outputVariables ( ) ; val firstBackward = initialOuts [ 0 ] ; // start with scalar backprop
SDVariable initialGrad = sameDiff . var ( "one-var" , Nd4j . scalar ( 1.0 ) ) ; sameDiff . forwardVarForGrad . put ( firstBackward . getVarName ( ) , initialGrad ) ; sameDiff . gradients . put ( firstBackward . getVarName ( ) , initialGrad ) ; SDVariable gradientBackwardsMarker = sameDiff . gradientBackwardsMarker ( firstBackward ) ; // reinitialize list with all declared variables
allFunctions = new ArrayList < DifferentialFunction > ( sameDiff . functionInstancesById . values ( ) ) ; Collections . reverse ( allFunctions ) ; for ( DifferentialFunction action : allFunctions ) { if ( action instanceof GradientBackwardsMarker ) { log . warn ( "Action op state is null for " + action . opName ( ) ) ; continue ; } DifferentialFunction currFunction = action ; Preconditions . checkState ( currFunction . getSameDiff ( ) == sameDiff , "Wrong samediff instance found!" ) ; // Preconditions . checkNotNull ( " Gradient for " + currFunction . opName ( ) + " was null ! " + sameDiff . getVariableForVertexId ( currFunction . getVertexId ( ) ) . getGradient ( ) ) ;
val args = currFunction . outputVariables ( ) ; for ( val arg : args ) { if ( arg . getSameDiff ( ) != sameDiff ) { arg . setSameDiff ( sameDiff ) ; } } List < SDVariable > grads = new ArrayList < > ( ) ; for ( val varToGrad : args ) { val grad = varToGrad . gradient ( ) ; if ( grad == null ) throw new ND4JIllegalStateException ( "No gradient found for " + varToGrad . getVarName ( ) ) ; grads . add ( grad ) ; } List < SDVariable > currFnGrads = currFunction . diff ( grads ) ; } if ( sameDiff . isDebugMode ( ) ) { // ensure all gradients are present for all variables
for ( SDVariable sdVariable : variables ( ) ) { sdVariable . gradient ( ) ; } } return new SDVariable [ ] { sameDiff . var ( "grad" , new int [ ] { 1 , 1 } ) } ; } } ) ; Pair < Map < SDVariable , DifferentialFunction > , List < DifferentialFunction > > forward = exec ( "grad" ) ; SameDiff grad = getFunction ( "grad" ) ; if ( grad . isDebugMode ( ) ) { // ensure all gradients are present for all variables
for ( SDVariable sdVariable : grad . variables ( ) ) { sdVariable . gradient ( ) ; } } return forward ;


signature:
public class SameDiff { /** * Exec a backwards operation
 * and return the end result
 * @ return */
public INDArray execBackwardAndEndResult ( ) { } }

implementation: List < DifferentialFunction > backwards = execBackwards ( ) . getRight ( ) ; DifferentialFunction df = backwards . get ( backwards . size ( ) - 1 ) ; if ( df instanceof Op ) { return ( ( Op ) df ) . z ( ) ; } else if ( df instanceof DynamicCustomOp ) { return ( ( DynamicCustomOp ) df ) . getOutputArgument ( 0 ) ; } else { return null ; }


signature:
public class SameDiff { /** * Add this vertex id as a place holder
 * @ param varName the vertex id to add */
public void addAsPlaceHolder ( String varName ) { } }

implementation: placeHolderVarNames . add ( varName ) ; if ( getVariable ( varName ) != null && getVariable ( varName ) . getShape ( ) != null ) { placeHolderOriginalShapes . put ( varName , getVariable ( varName ) . getShape ( ) ) ; }


signature:
public class SameDiff { /** * Resolve all ndarrays by updating the variables
 * for each array specified in the given map .
 * An { @ link IllegalStateException } will be thrown
 * if not all arrays are
 * specified for resolution .
 * @ param arrays the arrays to resolve . */
public void resolveVariablesWith ( Map < String , INDArray > arrays ) { } }

implementation:
for ( val arrayEntry : arrays . entrySet ( ) ) { val varForName = getVariable ( arrayEntry . getKey ( ) ) ; if ( varForName == null ) { throw new ND4JIllegalStateException ( "No variable name found for " + arrayEntry . getKey ( ) ) ; } if ( placeHolderOriginalShapes . containsKey ( arrayEntry . getKey ( ) ) ) { val originalShape = placeHolderOriginalShapes . get ( arrayEntry . getKey ( ) ) ; if ( originalShape . length == arrayEntry . getValue ( ) . rank ( ) ) { for ( int i = 0 ; i < originalShape . length ; i ++ ) { if ( originalShape [ i ] != arrayEntry . getValue ( ) . shape ( ) [ i ] && originalShape [ i ] >= 1 ) { throw new ND4JIllegalStateException ( "Incompatible shape passed for variable. " + Arrays . toString ( arrayEntry . getValue ( ) . shape ( ) ) ) ; } } } } } for ( val entry : arrays . entrySet ( ) ) { if ( ! placeHolderVarNames . contains ( entry . getKey ( ) ) ) { throw new ND4JIllegalStateException ( "Illegal variable " + entry . getKey ( ) + " passed in. Variable found not to be a place holder variable" ) ; } val specifiedShape = getOriginalShapeForPlaceHolder ( entry . getKey ( ) ) ; // whole shape was specified : validate whether the input array shape is equal
if ( ! Shape . isPlaceholderShape ( specifiedShape ) ) { if ( ! Shape . shapeEquals ( specifiedShape , entry . getValue ( ) . shape ( ) ) ) { throw new ND4JIllegalStateException ( "Place holder shape specified was " + Arrays . toString ( specifiedShape ) + " but array shape was " + Arrays . toString ( entry . getValue ( ) . shape ( ) ) ) ; } } updateShapeForVarName ( entry . getKey ( ) , entry . getValue ( ) . shape ( ) ) ; associateArrayWithVariable ( entry . getValue ( ) , getVariable ( entry . getKey ( ) ) ) ; updateArrayForVarName ( entry . getKey ( ) , entry . getValue ( ) ) ; } for ( val funcName : propertiesToResolve . keySet ( ) ) { val func = functionInstancesById . get ( funcName ) ; if ( ! functionInstancesById . containsKey ( funcName ) ) { throw new ND4JIllegalStateException ( "Unable to resolve function name " + funcName ) ; } if ( func instanceof CustomOp ) { CustomOp customOp = ( CustomOp ) func ; customOp . populateInputsAndOutputsFromSameDiff ( ) ; } } // declare resolved
resolvedVariables = true ;


signature:
public class SameDiff { /** * Returns true if all place holder variables
 * are resolved .
 * A place holder variable is resolved when
 * { @ link # getVariable ( String ) }
 * getArr ( ) does not return null and
 * the shape is properly resolved .
 * @ return true if all place holder variables are resolved . */
public boolean allPlaceHolderVariablesResolved ( ) { } }

implementation: for ( val vertexId : placeHolderVarNames ) { val var = getVariable ( vertexId ) ; if ( var . getArr ( ) == null ) { return false ; } } return true ;


signature:
public class SameDiff { /** * Add one or or more place holder variables
 * for the given vertex id .
 * Note that if a vertex id in placeHolderVariables
 * isn ' t present in this samediff instance anyways ,
 * an { @ link ND4JIllegalStateException } is thrown
 * @ param varName the vertex id to add place holders for
 * @ param placeHolderVariables the place holder variables */
public void putPlaceHolderForVariable ( String varName , String ... placeHolderVariables ) { } }

implementation: for ( val placeHolderVariable : placeHolderVariables ) { if ( ! variableMap . containsKey ( placeHolderVariable ) ) { throw new ND4JIllegalStateException ( "No variable found for " + placeHolderVariable ) ; } } List < String [ ] > placeHolders = placeHolderMap . get ( varName ) ; if ( placeHolders == null ) { placeHolders = new ArrayList < > ( ) ; placeHolderMap . put ( varName , placeHolders ) ; } placeHolders . add ( placeHolderVariables ) ;


signature:
public class SameDiff { /** * Creates and executes a list of operations
 * based on the given variables passed in .
 * { @ link # resolveVariablesWith ( Map ) }
 * is called
 * @ return */
public Pair < Map < SDVariable , DifferentialFunction > , List < DifferentialFunction > > execWithPlaceHolder ( Map < String , INDArray > inputs ) { } }

implementation: resolveVariablesWith ( inputs ) ; return exec ( ) ;


signature:
public class SameDiff { /** * Get the { @ link SDVariable }
 * associated with each function
 * based on the { @ link DifferentialFunction # outputVariables ( ) } ( ) }
 * @ param functions the functions to get the variables for
 * @ return the list of variables associated with the given { @ link DifferentialFunction } */
public List < SDVariable > getVariablesAssociatedWithFunctions ( List < DifferentialFunction > functions ) { } }

implementation: List < SDVariable > ret = new ArrayList < > ( functions . size ( ) ) ; for ( DifferentialFunction function : functions ) { ret . addAll ( Arrays . asList ( function . outputVariables ( ) ) ) ; } return ret ;


signature:
public class SameDiff { /** * Updates the variable name
 * property on the passed in variable ,
 * the reference in samediff ,
 * and returns the variable .
 * Note that if null for the new variable is passed in ,
 * it will just return the original input variable .
 * @ param varToUpdate the variable to update
 * @ param newVarName the new variable name
 * @ return the passed in variable */
public SDVariable updateVariableNameAndReference ( SDVariable varToUpdate , String newVarName ) { } }

implementation:
if ( varToUpdate == null ) { throw new NullPointerException ( "Null input: No variable found for updating!" ) ; } if ( newVarName == null && variableMap . containsKey ( varToUpdate . getVarName ( ) ) ) { // Edge case : suppose we do m1 = sd . mean ( in ) , m2 = sd . mean ( m1 ) - > both initially have the name
// " mean " and consequently a new variable name needs to be generated
newVarName = generateNewVarName ( varToUpdate . getVarName ( ) , 0 ) ; } if ( newVarName == null || varToUpdate . getVarName ( ) . equals ( newVarName ) ) { return varToUpdate ; } val oldVarName = varToUpdate . getVarName ( ) ; varToUpdate . setVarName ( newVarName ) ; updateVariableName ( oldVarName , newVarName ) ; return varToUpdate ;


signature:
public class SameDiff { /** * Print the given function for debugging ( will not print functions )
 * @ param differentialFunction the function to print */
public void printFunction ( DifferentialFunction differentialFunction ) { } }

implementation: if ( ! logExecution ) return ; if ( differentialFunction instanceof SDVariable ) return ; StringBuilder argShapes = new StringBuilder ( ) ; for ( val arg : differentialFunction . args ( ) ) { argShapes . append ( " Variable " + arg . getVarName ( ) + " Shape for " + Arrays . toString ( arg . getShape ( ) ) ) ; } for ( val func : differentialFunction . outputVariables ( ) ) { argShapes . append ( "  Output variable " + func . getVarName ( ) + " is " + Arrays . toString ( func . getShape ( ) ) ) ; } StringBuilder realShapes = new StringBuilder ( ) ; for ( val arg : differentialFunction . args ( ) ) { realShapes . append ( " Input shape for " + arg . getVarName ( ) + " is  " + Arrays . toString ( getShapeForVarName ( arg . getVarName ( ) ) ) ) ; } for ( val arg : differentialFunction . outputVariables ( ) ) { realShapes . append ( " Output shape for " + arg . getVarName ( ) + " is  " + Arrays . toString ( getShapeForVarName ( arg . getVarName ( ) ) ) ) ; } // log . info ( realShapes . toString ( ) ) ;


signature:
public class SameDiff { /** * Update the { @ link INDArray }
 * ndarray for the given variable name
 * @ param variableName the variable to update
 * @ param arr the array to update with */
public void updateVariable ( String variableName , INDArray arr ) { } }

implementation: if ( ! variableNameToArr . containsKey ( variableName ) ) putArrayForVarName ( variableName , arr ) ; else updateArrayForVarName ( variableName , arr ) ;


signature:
public class SameDiff { /** * This method exports given SameDiff instance into FlatBuffers
 * @ param configuration - ExecutorConfiguration to be embedded into serialized graph
 * @ return */
public ByteBuffer asFlatBuffers ( @ NonNull ExecutorConfiguration configuration ) { } }

implementation:
Nd4j . getExecutioner ( ) . commit ( ) ; FlatBufferBuilder bufferBuilder = new FlatBufferBuilder ( 1024 ) ; val idCounter = new AtomicInteger ( 0 ) ; val flatVariables = new ArrayList < Integer > ( ) ; val flatOffsets = new ArrayList < Integer > ( ) ; val flatNodes = new ArrayList < Integer > ( ) ; // first of all we build VariableSpace dump
List < SDVariable > variableList = new ArrayList < > ( variables ( ) ) ; val reverseMap = new LinkedHashMap < String , Integer > ( ) ; val forwardMap = new LinkedHashMap < String , Integer > ( ) ; val framesMap = new LinkedHashMap < String , Integer > ( ) ; int idx = 0 ; for ( val variable : variables ( ) ) { log . debug ( "Exporting variable: [{}]" , variable . getVarName ( ) ) ; if ( variable . getArr ( ) == null || variable . getShape ( ) == null ) { // putArrayForVarName ( variable . getVarName ( ) , Nd4j . scalar ( 1.0 ) ) ;
// addAsPlaceHolder ( variable . getVarName ( ) ) ;
continue ; } val pair = parseVariable ( variable . getVarName ( ) ) ; reverseMap . put ( pair . getFirst ( ) , idCounter . incrementAndGet ( ) ) ; log . debug ( "Adding [{}] as [{}]" , pair . getFirst ( ) , idCounter . get ( ) ) ; val arr = variable . getArr ( ) ; int name = bufferBuilder . createString ( variable . getVarName ( ) ) ; int array = arr . toFlatArray ( bufferBuilder ) ; int id = IntPair . createIntPair ( bufferBuilder , idCounter . get ( ) , 0 ) ; int flatVariable = FlatVariable . createFlatVariable ( bufferBuilder , id , name , 0 , array , - 1 ) ; flatVariables . add ( flatVariable ) ; } // add functions
for ( val func : functionInstancesById . values ( ) ) { flatNodes . add ( asFlatNode ( func , bufferBuilder , variableList , reverseMap , forwardMap , framesMap , idCounter ) ) ; } // we ' re dumping scopes now
for ( val scope : sameDiffFunctionInstances . entrySet ( ) ) { flatNodes . add ( asFlatNode ( scope . getKey ( ) , scope . getValue ( ) , bufferBuilder ) ) ; val currVarList = new ArrayList < SDVariable > ( scope . getValue ( ) . variables ( ) ) ; // converting all ops from node
for ( val node : scope . getValue ( ) . variables ( ) ) { INDArray arr = node . getArr ( ) ; if ( arr == null ) { // val otherArr = Nd4j . scalar ( 1.0 ) ;
// scope . getValue ( ) . putArrayForVarName ( node . getVarName ( ) , otherArr ) ;
// log . warn ( " Adding placeholder for export for var name { } " , node . getVarName ( ) ) ;
// arr = otherArr ;
continue ; } int name = bufferBuilder . createString ( node . getVarName ( ) ) ; int array = arr . toFlatArray ( bufferBuilder ) ; int id = IntPair . createIntPair ( bufferBuilder , ++ idx , 0 ) ; val pair = parseVariable ( node . getVarName ( ) ) ; reverseMap . put ( pair . getFirst ( ) , idx ) ; log . debug ( "Adding [{}] as [{}]" , pair . getFirst ( ) , idx ) ; int flatVariable = FlatVariable . createFlatVariable ( bufferBuilder , id , name , 0 , array , - 1 ) ; flatVariables . add ( flatVariable ) ; } // add functions
for ( val func : scope . getValue ( ) . functionInstancesById . values ( ) ) { flatNodes . add ( asFlatNode ( func , bufferBuilder , currVarList , reverseMap , forwardMap , framesMap , idCounter ) ) ; } } int outputsOffset = FlatGraph . createVariablesVector ( bufferBuilder , Ints . toArray ( flatOffsets ) ) ; int variablesOffset = FlatGraph . createVariablesVector ( bufferBuilder , Ints . toArray ( flatVariables ) ) ; int nodesOffset = FlatGraph . createNodesVector ( bufferBuilder , Ints . toArray ( flatNodes ) ) ; int fg = FlatGraph . createFlatGraph ( bufferBuilder , 119 , variablesOffset , nodesOffset , outputsOffset , configuration . getFlatConfiguration ( bufferBuilder ) ) ; bufferBuilder . finish ( fg ) ; return bufferBuilder . dataBuffer ( ) ;


signature:
public class SameDiff { /** * This method returns " flattened " graph .
 * @ return */
public String asFlatPrint ( ) { } }

implementation: val sb = new StringBuilder ( ) ; val fb = asFlatBuffers ( ) ; val graph = FlatGraph . getRootAsFlatGraph ( fb ) ; sb . append ( "\nExternal variables:\n\n" ) ; for ( int e = 0 ; e < graph . variablesLength ( ) ; e ++ ) { val var = graph . variables ( e ) ; val ndarray = Nd4j . createFromFlatArray ( var . ndarray ( ) ) ; sb . append ( var . id ( ) . first ( ) ) . append ( ":<" ) . append ( var . name ( ) ) . append ( "> " ) . append ( Arrays . toString ( ndarray . shapeInfoDataBuffer ( ) . asInt ( ) ) ) . append ( "; Values: " ) . append ( Arrays . toString ( ndarray . data ( ) . asFloat ( ) ) ) . append ( ";\n" ) ; } val map = Nd4j . getExecutioner ( ) . getCustomOperations ( ) ; sb . append ( "\nOps sequence:\n\n" ) ; for ( int e = 0 ; e < graph . nodesLength ( ) ; e ++ ) { val node = graph . nodes ( e ) ; log . info ( "{}:<{}>" , node . id ( ) , node . name ( ) ) ; sb . append ( node . id ( ) ) . append ( ":<" ) . append ( node . name ( ) ) . append ( "> " ) . append ( SameDiff . getTypeFromByte ( node . opType ( ) ) ) ; if ( SameDiff . getTypeFromByte ( node . opType ( ) ) != Op . Type . CUSTOM ) sb . append ( ": " ) . append ( node . opNum ( ) ) ; else { val keys = map . keySet ( ) ; String opName = null ; for ( val k : keys ) { val d = map . get ( k ) ; if ( d . getHash ( ) == node . opNum ( ) ) opName = k ; } if ( opName == null ) opName = "unknown" ; sb . append ( ": " ) . append ( opName ) ; } sb . append ( "; Inputs: {" ) ; for ( int i = 0 ; i < node . inputPairedLength ( ) ; i ++ ) { val pair = node . inputPaired ( i ) ; sb . append ( "[" ) . append ( pair . first ( ) ) . append ( ":" ) . append ( pair . second ( ) ) . append ( "]" ) ; if ( i < node . inputPairedLength ( ) - 1 ) sb . append ( ", " ) ; } sb . append ( "};" ) ; sb . append ( " OpNum: {" ) . append ( node . opNum ( ) ) . append ( "};" ) ; sb . append ( "\n" ) ; } return sb . toString ( ) ;


signature:
public class SameDiff { /** * This method converts enums for DataType
 * @ param val
 * @ return */
public static DataBuffer . Type getDataTypeFromByte ( byte val ) { } }

implementation: if ( val == DataType . FLOAT ) return DataBuffer . Type . FLOAT ; else if ( val == DataType . DOUBLE ) return DataBuffer . Type . DOUBLE ; else if ( val == DataType . HALF ) return DataBuffer . Type . HALF ; throw new UnsupportedOperationException ( "Unsupported DataType: [" + val + "]" ) ;


signature:
public class SameDiff { /** * This method converts enums for DataType
 * @ param type
 * @ return */
public static byte getDataTypeAsByte ( DataBuffer . Type type ) { } }

implementation: switch ( type ) { case FLOAT : return DataType . FLOAT ; case DOUBLE : return DataType . DOUBLE ; case HALF : return DataType . HALF ; case INT : return DataType . INT32 ; case LONG : return DataType . INT64 ; default : throw new ND4JIllegalStateException ( "Unknown or unsupported DataType used: [" + type + "]" ) ; }


signature:
public class SameDiff { /** * This method return operation ID for given op name / type pair .
 * @ param name
 * @ param type
 * @ return */
public static long getOpNum ( String name , Op . Type type ) { } }

implementation: if ( type == Op . Type . LOOP ) { return 0 ; } else if ( type == Op . Type . RETURN ) { return 40 ; } else if ( type == Op . Type . IF ) { return 30 ; } else if ( type == Op . Type . CONDITIONAL ) { return 10 ; } else if ( type == Op . Type . MERGE ) { return 60L ; } else if ( type == Op . Type . LOOP_COND ) { return 70L ; } else if ( type == Op . Type . NEXT_ITERATION ) { return 80L ; } else if ( type == Op . Type . EXIT ) { return 90L ; } else if ( type == Op . Type . ENTER ) { return 100L ; } else if ( type == Op . Type . CUSTOM ) { val name2 = Nd4j . getExecutioner ( ) . getCustomOperations ( ) . get ( name . toLowerCase ( ) ) ; if ( name2 == null ) return 0 ; return Nd4j . getExecutioner ( ) . getCustomOperations ( ) . get ( name . toLowerCase ( ) ) . getHash ( ) ; } else return ( long ) Nd4j . getOpFactory ( ) . getOpNumByName ( name ) ;


signature:
public class SameDiff { /** * This method converts enums for DataType
 * @ param type
 * @ return */
public static Op . Type getTypeFromByte ( byte type ) { } }

implementation: switch ( type ) { case OpType . SCALAR : return Op . Type . SCALAR ; case OpType . BROADCAST : return Op . Type . BROADCAST ; case OpType . TRANSFORM : return Op . Type . TRANSFORM ; case OpType . ACCUMULATION : return Op . Type . REDUCE ; case OpType . ACCUMULATION3 : return Op . Type . REDUCE3 ; case OpType . INDEX_ACCUMULATION : return Op . Type . INDEXREDUCE ; case OpType . RANDOM : return Op . Type . RANDOM ; case OpType . LOGIC : return Op . Type . META ; case OpType . CUSTOM : return Op . Type . CUSTOM ; case OpType . SHAPE : return Op . Type . SHAPE ; case OpType . PAIRWISE : return Op . Type . PAIRWISE ; case OpType . SUMMARYSTATS : return Op . Type . SUMMARYSTATS ; default : throw new UnsupportedOperationException ( "Unknown op type passed in: " + type ) ; }


signature:
public class SameDiff { /** * This method converts enums for DataType
 * @ param type
 * @ return */
public static byte getFlatOpType ( Op . Type type ) { } }

implementation: switch ( type ) { case SCALAR : return OpType . SCALAR ; case BROADCAST : return OpType . BROADCAST ; case TRANSFORM : case SPECIAL : return OpType . TRANSFORM ; case REDUCE : return OpType . ACCUMULATION ; case REDUCE3 : return OpType . ACCUMULATION3 ; case INDEXREDUCE : return OpType . INDEX_ACCUMULATION ; case RANDOM : return OpType . RANDOM ; case MERGE : case CONDITIONAL : case LOOP : case RETURN : case ENTER : case EXIT : case NEXT_ITERATION : case LOOP_COND : case IF : return OpType . LOGIC ; case CUSTOM : return OpType . CUSTOM ; case SHAPE : return OpType . SHAPE ; case PAIRWISE : return OpType . PAIRWISE ; case SUMMARYSTATS : return OpType . SUMMARYSTATS ; default : throw new UnsupportedOperationException ( "Unknown op type passed in: " + type ) ; }


signature:
public class CudaMemoryManager { /** * This method returns Pointer to allocated memory chunk
 * PLEASE NOTE : Cache options depend on specific implementations
 * @ param bytes
 * @ param kind
 * @ param initialize */
@ Override public Pointer allocate ( long bytes , MemoryKind kind , boolean initialize ) { } }

implementation:
AtomicAllocator allocator = AtomicAllocator . getInstance ( ) ; // log . info ( " Allocating { } bytes in { } memory . . . " , bytes , kind ) ;
if ( kind == MemoryKind . HOST ) { Pointer ptr = NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) . mallocHost ( bytes , 0 ) ; if ( ptr == null ) throw new RuntimeException ( "Failed to allocate " + bytes + " bytes from HOST memory" ) ; if ( initialize ) Pointer . memset ( ptr , 0 , bytes ) ; return ptr ; // allocator . getMemoryHandler ( ) . alloc ( AllocationStatus . HOST , null , null , initialize ) . getHostPointer ( ) ;
} else if ( kind == MemoryKind . DEVICE ) { Pointer ptr = NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) . mallocDevice ( bytes , null , 0 ) ; // log . info ( " Allocating { } bytes for device _ { } " , bytes , Nd4j . getAffinityManager ( ) . getDeviceForCurrentThread ( ) ) ;
if ( ptr == null ) throw new RuntimeException ( "Failed to allocate " + bytes + " bytes from DEVICE [" + Nd4j . getAffinityManager ( ) . getDeviceForCurrentThread ( ) + "] memory" ) ; if ( initialize ) { CudaContext context = ( CudaContext ) AtomicAllocator . getInstance ( ) . getDeviceContext ( ) . getContext ( ) ; int i = NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) . memsetAsync ( ptr , 0 , bytes , 0 , context . getSpecialStream ( ) ) ; if ( i == 0 ) throw new ND4JIllegalStateException ( "memset failed on device_" + Nd4j . getAffinityManager ( ) . getDeviceForCurrentThread ( ) ) ; context . getSpecialStream ( ) . synchronize ( ) ; } return ptr ; // allocator . getMemoryHandler ( ) . alloc ( AllocationStatus . HOST , null , null , initialize ) . getDevicePointer ( ) ;
} else throw new RuntimeException ( "Unknown MemoryKind requested: " + kind ) ;


signature:
public class BlasBufferUtil { /** * Set the data for the underlying array .
 * If the underlying buffer ' s array is equivalent to this array
 * it returns ( avoiding an unneccessary copy )
 * If the underlying storage mechanism isn ' t heap ( no arrays )
 * it just copied the data over ( strided access with offsets where neccessary )
 * This is meant to be used with blas operations where the underlying blas implementation
 * takes an array but the data buffer being used might not be an array .
 * This is also for situations where there is strided access and it ' s not
 * optimal to want to use the whole data buffer but just the subset of the
 * buffer needed for calculations .
 * @ param data the data to set
 * @ param toSet the array to set the data to */
public static void setData ( float [ ] data , INDArray toSet ) { } }

implementation:
if ( toSet . data ( ) . dataType ( ) != DataBuffer . Type . FLOAT ) { throw new IllegalArgumentException ( "Unable to set double data for opType " + toSet . data ( ) . dataType ( ) ) ; } if ( toSet . data ( ) . allocationMode ( ) == DataBuffer . AllocationMode . HEAP ) { Object array = toSet . data ( ) . array ( ) ; // data is assumed to have already been updated
if ( array == data ) return ; else { // copy the data over directly to the underlying array
float [ ] d = ( float [ ] ) array ; if ( toSet . offset ( ) == 0 && toSet . length ( ) == data . length ) System . arraycopy ( data , 0 , d , 0 , d . length ) ; else { int count = 0 ; // need to do strided access with offset
for ( int i = 0 ; i < data . length ; i ++ ) { // FIXME : LONG
int dIndex = ( int ) toSet . offset ( ) + ( i * toSet . majorStride ( ) ) ; d [ dIndex ] = data [ count ++ ] ; } } } } else { // assumes the underlying data is in the right order
DataBuffer underlyingData = toSet . data ( ) ; if ( data . length == toSet . length ( ) && toSet . offset ( ) == 0 ) { for ( int i = 0 ; i < toSet . length ( ) ; i ++ ) { underlyingData . put ( i , data [ i ] ) ; } } else { int count = 0 ; // need to do strided access with offset
for ( int i = 0 ; i < data . length ; i ++ ) { // FIXME : LONG
int dIndex = ( int ) toSet . offset ( ) + ( i * toSet . majorStride ( ) ) ; underlyingData . put ( dIndex , data [ count ++ ] ) ; } } }


signature:
public class DataTypeUtil { /** * Returns the length for the given data opType
 * @ param type
 * @ return */
public static int lengthForDtype ( DataBuffer . Type type ) { } }

implementation: switch ( type ) { case DOUBLE : return 8 ; case FLOAT : return 4 ; case INT : return 4 ; case HALF : return 2 ; case LONG : return 8 ; case COMPRESSED : default : throw new IllegalArgumentException ( "Illegal opType for length" ) ; }


signature:
public class DataTypeUtil { /** * Get the allocation mode from the context
 * @ return */
public static DataBuffer . Type getDtypeFromContext ( String dType ) { } }

implementation: switch ( dType ) { case "double" : return DataBuffer . Type . DOUBLE ; case "float" : return DataBuffer . Type . FLOAT ; case "int" : return DataBuffer . Type . INT ; case "half" : return DataBuffer . Type . HALF ; default : return DataBuffer . Type . FLOAT ; }


signature:
public class DataTypeUtil { /** * Gets the name of the alocation mode
 * @ param allocationMode
 * @ return */
public static String getDTypeForName ( DataBuffer . Type allocationMode ) { } }

implementation: switch ( allocationMode ) { case DOUBLE : return "double" ; case FLOAT : return "float" ; case INT : return "int" ; case HALF : return "half" ; default : return "float" ; }


signature:
public class DataTypeUtil { /** * get the allocation mode from the context
 * @ return */
public static DataBuffer . Type getDtypeFromContext ( ) { } }

implementation: try { lock . readLock ( ) . lock ( ) ; if ( dtype == null ) { lock . readLock ( ) . unlock ( ) ; lock . writeLock ( ) . lock ( ) ; if ( dtype == null ) dtype = getDtypeFromContext ( Nd4jContext . getInstance ( ) . getConf ( ) . getProperty ( "dtype" ) ) ; lock . writeLock ( ) . unlock ( ) ; lock . readLock ( ) . lock ( ) ; } return dtype ; } finally { lock . readLock ( ) . unlock ( ) ; }


signature:
public class DataTypeUtil { /** * Set the allocation mode for the nd4j context
 * The value must be one of : heap , java cpp , or direct
 * or an @ link { IllegalArgumentException } is thrown
 * @ param allocationModeForContext */
public static void setDTypeForContext ( DataBuffer . Type allocationModeForContext ) { } }

implementation: try { lock . writeLock ( ) . lock ( ) ; dtype = allocationModeForContext ; setDTypeForContext ( getDTypeForName ( allocationModeForContext ) ) ; } finally { lock . writeLock ( ) . unlock ( ) ; }


signature:
public class DefaultOpFactory { /** * This method returns op id number for given opName
 * @ param opName
 * @ return */
@ Override public int getOpNumByName ( String opName ) { } }

implementation: try { DifferentialFunction op = DifferentialFunctionClassHolder . getInstance ( ) . getInstance ( opName ) ; return op . opNum ( ) ; } catch ( Exception e ) { throw new RuntimeException ( "OpName failed: [" + opName + "]" , e ) ; }


signature:
public class BasicWorkspaceManager { /** * @ Override
 * public MemoryWorkspace getWorkspaceForCurrentThread ( @ NonNull WorkspaceConfiguration configuration , @ NonNull String id ) {
 * ensureThreadExistense ( ) ;
 * MemoryWorkspace workspace = backingMap . get ( ) . get ( id ) ;
 * if ( workspace = = null ) {
 * workspace = new Nd4jWorkspace ( configuration , id ) ;
 * backingMap . get ( ) . put ( id , workspace ) ;
 * return workspace ; */
protected void pickReference ( MemoryWorkspace workspace ) { } }

implementation: Nd4jWorkspace . GarbageWorkspaceReference reference = new Nd4jWorkspace . GarbageWorkspaceReference ( workspace , queue ) ; referenceMap . put ( reference . getKey ( ) , reference ) ;


signature:
public class BasicWorkspaceManager { /** * This method destroys all workspaces allocated in current thread */
@ Override public void destroyAllWorkspacesForCurrentThread ( ) { } }

implementation: ensureThreadExistense ( ) ; List < MemoryWorkspace > workspaces = new ArrayList < > ( ) ; workspaces . addAll ( backingMap . get ( ) . values ( ) ) ; for ( MemoryWorkspace workspace : workspaces ) { destroyWorkspace ( workspace ) ; } System . gc ( ) ;


signature:
public class BasicWorkspaceManager { /** * This method prints out basic statistics for workspaces allocated in current thread */
public synchronized void printAllocationStatisticsForCurrentThread ( ) { } }

implementation: ensureThreadExistense ( ) ; Map < String , MemoryWorkspace > map = backingMap . get ( ) ; log . info ( "Workspace statistics: ---------------------------------" ) ; log . info ( "Number of workspaces in current thread: {}" , map . size ( ) ) ; log . info ( "Workspace name: Allocated / external (spilled) / external (pinned)" ) ; for ( String key : map . keySet ( ) ) { long current = ( ( Nd4jWorkspace ) map . get ( key ) ) . getCurrentSize ( ) ; long spilled = ( ( Nd4jWorkspace ) map . get ( key ) ) . getSpilledSize ( ) ; long pinned = ( ( Nd4jWorkspace ) map . get ( key ) ) . getPinnedSize ( ) ; log . info ( String . format ( "%-26s %8s / %8s / %8s (%11d / %11d / %11d)" , ( key + ":" ) , StringUtils . TraditionalBinaryPrefix . long2String ( current , "" , 2 ) , StringUtils . TraditionalBinaryPrefix . long2String ( spilled , "" , 2 ) , StringUtils . TraditionalBinaryPrefix . long2String ( pinned , "" , 2 ) , current , spilled , pinned ) ) ; }


signature:
public class BaseLevel2 { /** * gemv computes a matrix - vector product using a general matrix and performs one of the following matrix - vector operations :
 * y : = alpha * a * x + beta * y for trans = ' N ' or ' n ' ;
 * y : = alpha * a ' * x + beta * y for trans = ' T ' or ' t ' ;
 * y : = alpha * conjg ( a ' ) * x + beta * y for trans = ' C ' or ' c ' .
 * Here a is an m - by - n band matrix , x and y are vectors , alpha and beta are scalars .
 * @ param order
 * @ param transA
 * @ param alpha
 * @ param A
 * @ param X
 * @ param beta
 * @ param Y */
@ Override public void gemv ( char order , char transA , double alpha , INDArray A , INDArray X , double beta , INDArray Y ) { } }

implementation: if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( false , A , X , Y ) ; if ( A . isSparse ( ) && ! X . isSparse ( ) ) { Nd4j . getSparseBlasWrapper ( ) . level2 ( ) . gemv ( order , transA , alpha , A , X , beta , Y ) ; return ; } GemvParameters parameters = new GemvParameters ( A , X , Y ) ; if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . DOUBLE , parameters . getA ( ) , parameters . getX ( ) , parameters . getY ( ) ) ; dgemv ( order , parameters . getAOrdering ( ) , parameters . getM ( ) , parameters . getN ( ) , alpha , parameters . getA ( ) , parameters . getLda ( ) , parameters . getX ( ) , parameters . getIncx ( ) , beta , parameters . getY ( ) , parameters . getIncy ( ) ) ; } else { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . FLOAT , parameters . getA ( ) , parameters . getX ( ) , parameters . getY ( ) ) ; sgemv ( order , parameters . getAOrdering ( ) , parameters . getM ( ) , parameters . getN ( ) , ( float ) alpha , parameters . getA ( ) , parameters . getLda ( ) , parameters . getX ( ) , parameters . getIncx ( ) , ( float ) beta , parameters . getY ( ) , parameters . getIncy ( ) ) ; } OpExecutionerUtil . checkForAny ( Y ) ;


signature:
public class BaseLevel2 { /** * gemv computes a matrix - vector product using a general matrix and performs one of the following matrix - vector operations :
 * y : = alpha * a * x + beta * y for trans = ' N ' or ' n ' ;
 * y : = alpha * a ' * x + beta * y for trans = ' T ' or ' t ' ;
 * y : = alpha * conjg ( a ' ) * x + beta * y for trans = ' C ' or ' c ' .
 * Here a is an m - by - n band matrix , x and y are vectors , alpha and beta are scalars .
 * @ param order
 * @ param transA
 * @ param alpha
 * @ param A
 * @ param X
 * @ param beta
 * @ param Y */
@ Override public void gemv ( char order , char transA , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray X , IComplexNumber beta , IComplexNDArray Y ) { } }

implementation: if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( false , A , X , Y ) ; GemvParameters parameters = new GemvParameters ( A , X , Y ) ; if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zgemv ( order , transA , parameters . getM ( ) , parameters . getN ( ) , alpha . asDouble ( ) , A , parameters . getLda ( ) , X , parameters . getIncx ( ) , beta . asDouble ( ) , Y , parameters . getIncy ( ) ) ; else cgemv ( order , transA , parameters . getM ( ) , parameters . getN ( ) , alpha . asFloat ( ) , A , parameters . getLda ( ) , X , parameters . getIncx ( ) , beta . asFloat ( ) , Y , parameters . getIncy ( ) ) ;


signature:
public class BaseLevel2 { /** * gbmv computes a matrix - vector product using a general band matrix and performs one of the following matrix - vector operations :
 * y : = alpha * a * x + beta * y for trans = ' N ' or ' n ' ;
 * y : = alpha * a ' * x + beta * y for trans = ' T ' or ' t ' ;
 * y : = alpha * conjg ( a ' ) * x + beta * y for trans = ' C ' or ' c ' .
 * Here a is an m - by - n band matrix with ku superdiagonals and kl subdiagonals , x and y are vectors , alpha and beta are scalars .
 * @ param order
 * @ param TransA
 * @ param KL
 * @ param KU
 * @ param alpha
 * @ param A
 * @ param X
 * @ param beta
 * @ param Y */
@ Override public void gbmv ( char order , char TransA , int KL , int KU , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray X , IComplexNumber beta , IComplexNDArray Y ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { zgbmv ( order , TransA , ( int ) A . rows ( ) , ( int ) A . columns ( ) , KL , KU , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) / 2 , beta . asDouble ( ) , Y , Y . majorStride ( ) / 2 ) ; } else { cgbmv ( order , TransA , ( int ) A . rows ( ) , ( int ) A . columns ( ) , KL , KU , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) / 2 , beta . asFloat ( ) , Y , Y . majorStride ( ) / 2 ) ; }


signature:
public class BaseLevel2 { /** * performs a rank - 1 update of a general m - by - n matrix a , without conjugation :
 * a : = alpha * x * y ' + a .
 * @ param order
 * @ param alpha
 * @ param X
 * @ param Y
 * @ param A */
@ Override public void geru ( char order , IComplexNumber alpha , IComplexNDArray X , IComplexNDArray Y , IComplexNDArray A ) { } }

implementation:
// FIXME : int cast
if ( X . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zgeru ( order , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asDouble ( ) , X , X . majorStride ( ) / 2 , Y , Y . majorStride ( ) / 2 , A , ( int ) A . size ( 0 ) ) ; else cgeru ( order , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asFloat ( ) , X , X . majorStride ( ) / 2 , Y , Y . majorStride ( ) / 2 , A , ( int ) A . size ( 0 ) ) ;


signature:
public class BaseLevel2 { /** * performs a rank - 1 update of a general m - by - n matrix a , without conjugation :
 * a : = alpha * x * y ' + a .
 * @ param order
 * @ param Uplo
 * @ param alpha
 * @ param A
 * @ param X
 * @ param beta
 * @ param Y */
@ Override public void hbmv ( char order , char Uplo , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray X , IComplexNumber beta , IComplexNDArray Y ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zhbmv ( order , Uplo , ( int ) X . length ( ) , ( int ) A . columns ( ) , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) / 2 , beta . asDouble ( ) , Y , Y . majorStride ( ) / 2 ) ; else chbmv ( order , Uplo , ( int ) X . length ( ) , ( int ) A . columns ( ) , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) / 2 , beta . asFloat ( ) , Y , Y . majorStride ( ) / 2 ) ;


signature:
public class BaseLevel2 { /** * hemv computes a matrix - vector product using a Hermitian matrix :
 * y : = alpha * a * x + beta * y .
 * Here a is an n - by - n Hermitian band matrix with k superdiagonals , x and y are n - element vectors , alpha and beta are scalars .
 * @ param order
 * @ param Uplo
 * @ param alpha
 * @ param A
 * @ param X
 * @ param beta
 * @ param Y */
@ Override public void hemv ( char order , char Uplo , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray X , IComplexNumber beta , IComplexNDArray Y ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zhemv ( order , Uplo , ( int ) A . rows ( ) , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) / 2 , beta . asDouble ( ) , Y , Y . majorStride ( ) / 2 ) ; else chemv ( order , Uplo , ( int ) A . rows ( ) , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) / 2 , beta . asFloat ( ) , Y , Y . majorStride ( ) / 2 ) ;


signature:
public class BaseLevel2 { /** * ? her2 performs a rank - 2 update of an n - by - n Hermitian matrix a :
 * a : = alpha * x * conjg ( y ' ) + conjg ( alpha ) * y * conjg ( x ' ) + a .
 * @ param order
 * @ param Uplo
 * @ param alpha
 * @ param X
 * @ param Y
 * @ param A */
@ Override public void her2 ( char order , char Uplo , IComplexNumber alpha , IComplexNDArray X , IComplexNDArray Y , IComplexNDArray A ) { } }

implementation:
// FIXME : int cast
if ( X . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zher2 ( order , Uplo , ( int ) A . rows ( ) , alpha . asDouble ( ) , X , X . majorStride ( ) / 2 , Y , Y . majorStride ( ) / 2 , A , ( int ) A . size ( 0 ) ) ; else cher2 ( order , Uplo , ( int ) A . rows ( ) , alpha . asFloat ( ) , X , X . majorStride ( ) / 2 , Y , Y . majorStride ( ) / 2 , A , ( int ) A . size ( 0 ) ) ;


signature:
public class BaseLevel2 { /** * ? hpmv computes a matrix - vector product using a Hermitian packed matrix :
 * y : = alpha * a * x + beta * y .
 * Here a is an n - by - n packed Hermitian matrix , x and y are n - element vectors , alpha and beta are scalars .
 * @ param order
 * @ param Uplo
 * @ param N
 * @ param alpha
 * @ param Ap
 * @ param X
 * @ param beta
 * @ param Y */
@ Override public void hpmv ( char order , char Uplo , int N , IComplexNumber alpha , IComplexNDArray Ap , IComplexNDArray X , IComplexNumber beta , IComplexNDArray Y ) { } }

implementation:
// FIXME : int cast
if ( Ap . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zhpmv ( order , Uplo , ( int ) Ap . rows ( ) , alpha . asDouble ( ) , Ap , X , X . majorStride ( ) / 2 , beta . asDouble ( ) , Y , Y . majorStride ( ) / 2 ) ; else chpmv ( order , Uplo , ( int ) Ap . rows ( ) , alpha . asFloat ( ) , Ap , X , X . majorStride ( ) / 2 , beta . asFloat ( ) , Y , Y . majorStride ( ) / 2 ) ;


signature:
public class BaseLevel2 { /** * hpr2 performs a rank - 2 update of an n - by - n packed Hermitian matrix a :
 * a : = alpha * x * conjg ( y ' ) + conjg ( alpha ) * y * conjg ( x ' ) + a .
 * @ param order
 * @ param Uplo
 * @ param alpha
 * @ param X
 * @ param Y
 * @ param Ap */
@ Override public void hpr2 ( char order , char Uplo , IComplexNumber alpha , IComplexNDArray X , IComplexNDArray Y , IComplexNDArray Ap ) { } }

implementation:
// FIXME : int cast
if ( X . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zhpr2 ( order , Uplo , ( int ) Ap . rows ( ) , alpha . asDouble ( ) , X , X . majorStride ( ) / 2 , Y , Y . majorStride ( ) / 2 , Ap ) ; else chpr2 ( order , Uplo , ( int ) Ap . rows ( ) , alpha . asFloat ( ) , X , X . majorStride ( ) / 2 , Y , Y . majorStride ( ) / 2 , Ap ) ;


signature:
public class BaseLevel2 { /** * sbmv computes a matrix - vector product using a symmetric band matrix :
 * y : = alpha * a * x + beta * y .
 * Here a is an n - by - n symmetric band matrix with k superdiagonals , x and y are n - element vectors , alpha and beta are scalars .
 * @ param order
 * @ param Uplo
 * @ param alpha
 * @ param A
 * @ param X
 * @ param beta
 * @ param Y */
@ Override public void sbmv ( char order , char Uplo , double alpha , INDArray A , INDArray X , double beta , INDArray Y ) { } }

implementation:
if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( false , A , X , Y ) ; // FIXME : int cast
if ( X . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . DOUBLE , A , X , Y ) ; dsbmv ( order , Uplo , ( int ) X . length ( ) , ( int ) A . columns ( ) , alpha , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) , beta , Y , ( int ) Y . majorStride ( ) ) ; } else { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . FLOAT , A , X , Y ) ; ssbmv ( order , Uplo , ( int ) X . length ( ) , ( int ) A . columns ( ) , ( float ) alpha , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) , ( float ) beta , Y , Y . majorStride ( ) ) ; } OpExecutionerUtil . checkForAny ( Y ) ;


signature:
public class BaseLevel2 { /** * syr2 performs a rank - 2 update of an n - by - n symmetric matrix a :
 * a : = alpha * x * y ' + alpha * y * x ' + a .
 * @ param order
 * @ param Uplo
 * @ param TransA
 * @ param Diag
 * @ param A
 * @ param X */
@ Override public void tbmv ( char order , char Uplo , char TransA , char Diag , INDArray A , INDArray X ) { } }

implementation:
if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( false , A , X ) ; // FIXME : int cast
if ( X . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . DOUBLE , A , X ) ; dtbmv ( order , Uplo , TransA , Diag , ( int ) X . length ( ) , ( int ) A . columns ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) ) ; } else { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . FLOAT , A , X ) ; stbmv ( order , Uplo , TransA , Diag , ( int ) X . length ( ) , ( int ) A . columns ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) ) ; }


signature:
public class BaseLevel2 { /** * trmv computes a matrix - vector product using a triangular matrix .
 * @ param order
 * @ param Uplo
 * @ param TransA
 * @ param Diag
 * @ param A
 * @ param X */
@ Override public void trmv ( char order , char Uplo , char TransA , char Diag , INDArray A , INDArray X ) { } }

implementation:
if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( false , A , X ) ; // FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . DOUBLE , A , X ) ; dtrmv ( order , Uplo , TransA , Diag , ( int ) X . length ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) ) ; } else { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . FLOAT , A , X ) ; strmv ( order , Uplo , TransA , Diag , ( int ) X . length ( ) , A , ( int ) A . size ( 0 ) , X , X . majorStride ( ) ) ; } OpExecutionerUtil . checkForAny ( X ) ;


signature:
public class Nd4jKafkaConsumer { /** * Receive an ndarray
 * @ return */
public INDArray receive ( ) { } }

implementation: if ( consumerTemplate == null ) consumerTemplate = camelContext . createConsumerTemplate ( ) ; return consumerTemplate . receiveBody ( "direct:receive" , INDArray . class ) ;


signature:
public class BaseUnderSamplingPreProcessor { /** * Given a list of labels return the bernoulli prob that the masks
 * will be sampled at to meet the target minority label distribution
 * Masks at time steps where label is the minority class will always be one
 * i . e a bernoulli with p = 1
 * Masks at time steps where label is the majority class will be sampled from
 * a bernoulli dist with p
 * = ( minorityCount / majorityCount ) * ( ( 1 - targetDist ) / targetDist ) */
private INDArray calculateBernoulli ( INDArray minorityLabels , INDArray labelMask , double targetMinorityDist ) { } }

implementation:
INDArray minorityClass = minorityLabels . dup ( ) . muli ( labelMask ) ; INDArray majorityClass = Transforms . not ( minorityLabels ) . muli ( labelMask ) ; // all minorityLabel class , keep masks as is
// presence of minoriy class and donotmask minority windows set to true return label as is
if ( majorityClass . sumNumber ( ) . intValue ( ) == 0 || ( minorityClass . sumNumber ( ) . intValue ( ) > 0 && donotMaskMinorityWindows ) ) return labelMask ; // all majority class and set to not mask all majority windows sample majority class by 1 - targetMinorityDist
if ( minorityClass . sumNumber ( ) . intValue ( ) == 0 && ! maskAllMajorityWindows ) return labelMask . muli ( 1 - targetMinorityDist ) ; // Probabilities to be used for bernoulli sampling
INDArray minoritymajorityRatio = minorityClass . sum ( 1 ) . div ( majorityClass . sum ( 1 ) ) ; INDArray majorityBernoulliP = minoritymajorityRatio . muli ( 1 - targetMinorityDist ) . divi ( targetMinorityDist ) ; BooleanIndexing . replaceWhere ( majorityBernoulliP , 1.0 , Conditions . greaterThan ( 1.0 ) ) ; // if minority ratio is already met round down to 1.0
return majorityClass . muliColumnVector ( majorityBernoulliP ) . addi ( minorityClass ) ;


signature:
public class SameDiffOpExecutioner { /** * Execute an accumulation along one or more dimensions
 * @ param accumulation the accumulation
 * @ param biasCorrected
 * @ param dimension the dimension @ return the accmulation op */
@ Override public INDArray exec ( Variance accumulation , boolean biasCorrected , int ... dimension ) { } }

implementation: return processOp ( accumulation ) . z ( ) ;


signature:
public class SameDiffOpExecutioner { /** * This method executes specific RandomOp against specified RNG
 * @ param op
 * @ param rng */
@ Override public INDArray exec ( RandomOp op , Random rng ) { } }

implementation: return processOp ( op ) . z ( ) ;


signature:
public class SameDiffOpExecutioner { /** * This method encodes array as thresholds , updating input array at the same time
 * @ param input
 * @ param threshold
 * @ return encoded array is returned */
@ Override public INDArray thresholdEncode ( INDArray input , double threshold ) { } }

implementation: return backendExecutioner . thresholdEncode ( input , threshold ) ;


signature:
public class SameDiffOpExecutioner { /** * This method encodes array as thresholds , updating input array at the same time
 * @ param input
 * @ param threshold
 * @ param boundary @ return encoded array is returned */
@ Override public INDArray thresholdEncode ( INDArray input , double threshold , Integer boundary ) { } }

implementation: return backendExecutioner . thresholdEncode ( input , threshold , boundary ) ;


signature:
public class SameDiffOpExecutioner { /** * This method decodes thresholds array , and puts it into target array
 * @ param encoded
 * @ param target
 * @ return target is returned */
@ Override public INDArray thresholdDecode ( INDArray encoded , INDArray target ) { } }

implementation: return backendExecutioner . thresholdDecode ( encoded , target ) ;


signature:
public class StandardizeStrategy { /** * Normalize a data array
 * @ param array the data to normalize
 * @ param stats statistics of the data population */
@ Override public void preProcess ( INDArray array , INDArray maskArray , DistributionStats stats ) { } }

implementation:
if ( array . rank ( ) <= 2 ) { array . subiRowVector ( stats . getMean ( ) ) ; array . diviRowVector ( filteredStd ( stats ) ) ; } // if array Rank is 3 ( time series ) samplesxfeaturesxtimesteps
// if array Rank is 4 ( images ) samplesxchannelsxrowsxcols
// both cases operations should be carried out in dimension 1
else { Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastSubOp ( array , stats . getMean ( ) , array , 1 ) ) ; Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastDivOp ( array , filteredStd ( stats ) , array , 1 ) ) ; } if ( maskArray != null ) { DataSetUtil . setMaskedValuesToZero ( array , maskArray ) ; }


signature:
public class StandardizeStrategy { /** * Denormalize a data array
 * @ param array the data to denormalize
 * @ param stats statistics of the data population */
@ Override public void revert ( INDArray array , INDArray maskArray , DistributionStats stats ) { } }

implementation: if ( array . rank ( ) <= 2 ) { array . muliRowVector ( filteredStd ( stats ) ) ; array . addiRowVector ( stats . getMean ( ) ) ; } else { Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastMulOp ( array , filteredStd ( stats ) , array , 1 ) ) ; Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastAddOp ( array , stats . getMean ( ) , array , 1 ) ) ; } if ( maskArray != null ) { DataSetUtil . setMaskedValuesToZero ( array , maskArray ) ; }


signature:
public class TFGraphMapper { /** * Map a tensorflow node name
 * to the samediff equivalent
 * for import
 * @ param name the name to change
 * @ return the input tensorflow name */
public String getNodeName ( String name ) { } }

implementation:
// tensorflow adds colons to the end of variables representing input index , this strips those off
String ret = name ; if ( ret . startsWith ( "^" ) ) ret = ret . substring ( 1 ) ; if ( ret . endsWith ( "/read" ) ) { ret = ret . replace ( "/read" , "" ) ; } return ret ;


signature:
public class NativeOpExecutioner { /** * This method takes arbitrary
 * sized list of { @ link Aggregate } ,
 * and packs them into batches
 * Note here that this is mainly used for random number generation
 * for { @ link RandomOp } and things like { @ link org . nd4j . linalg . api . rng . distribution . Distribution }
 * @ param op the list of { @ link Aggregate } to
 * execute upon */
@ Override public void exec ( Aggregate op ) { } }

implementation:
// long st = profilingHookIn ( op ) ;
if ( memoryBlocks . get ( ) == null ) memoryBlocks . set ( new HashMap < Integer , AggregateMemoryBlock > ( ) ) ; if ( memoryBlocks . get ( ) . get ( op . opNum ( ) ) == null ) memoryBlocks . get ( ) . put ( op . opNum ( ) , new AggregateMemoryBlock ( op ) ) ; AggregateMemoryBlock block = memoryBlocks . get ( ) . get ( op . opNum ( ) ) ; int numArguments = op . getArguments ( ) . size ( ) ; int numIndexArguments = op . getIndexingArguments ( ) . size ( ) ; int numRealArguments = op . getRealArguments ( ) . size ( ) ; int numShapes = op . getShapes ( ) . size ( ) ; int numIntArrays = op . getIntArrayArguments ( ) . size ( ) ; PointerPointer arguments = block . getArgumentsPointer ( ) ; // new PointerPointer ( numArguments ) ;
List < IntPointer > pointers = new ArrayList < > ( ) ; PointerPointer intArrays = block . getArraysPointer ( ) ; // new PointerPointer ( numIntArrays ) ;
for ( int x = 0 ; x < numArguments ; x ++ ) { arguments . put ( x , op . getArguments ( ) . get ( x ) == null ? null : op . getArguments ( ) . get ( x ) . data ( ) . addressPointer ( ) ) ; } PointerPointer shapes = block . getShapesPointer ( ) ; // new PointerPointer ( numShapes ) ;
for ( int x = 0 ; x < numShapes ; x ++ ) { if ( op . getShapes ( ) . get ( x ) . dataType ( ) != DataBuffer . Type . INT ) throw new RuntimeException ( "ShapeBuffers should have INT data opType" ) ; shapes . put ( x , op . getShapes ( ) . get ( x ) == null ? null : op . getShapes ( ) . get ( x ) . addressPointer ( ) ) ; } // int [ ] indexes = new int [ numIndexArguments ] ;
IntPointer pointer = block . getIndexingPointer ( ) ; for ( int x = 0 ; x < numIndexArguments ; x ++ ) { pointer . put ( x , op . getIndexingArguments ( ) . get ( x ) ) ; } // IntPointer pointer = new IntPointer ( indexes ) ;
double [ ] reals = new double [ numRealArguments ] ; for ( int x = 0 ; x < numRealArguments ; x ++ ) { // reals [ x ] = op . getRealArguments ( ) . get ( x ) . doubleValue ( ) ;
if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT ) ( ( FloatPointer ) block . getRealArgumentsPointer ( ) ) . put ( x , op . getRealArguments ( ) . get ( x ) . floatValue ( ) ) ; else ( ( DoublePointer ) block . getRealArgumentsPointer ( ) ) . put ( x , op . getRealArguments ( ) . get ( x ) . doubleValue ( ) ) ; } for ( int x = 0 ; x < numIntArrays ; x ++ ) { IntPointer intPtr = block . getIntArrays ( ) . get ( x ) ; // new IntPointer ( op . getIntArrayArguments ( ) . get ( x ) ) ;
intPtr . put ( op . getIntArrayArguments ( ) . get ( x ) , 0 , op . getIntArrayArguments ( ) . get ( x ) . length ) ; intArrays . put ( x , intPtr ) ; pointers . add ( intPtr ) ; } // INDArray realsBuffer = Nd4j . create ( reals ) ;
if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT ) { loop . execAggregateFloat ( null , op . opNum ( ) , arguments , numArguments , shapes , numShapes , pointer , numIndexArguments , intArrays , numIntArrays , ( FloatPointer ) block . getRealArgumentsPointer ( ) , numRealArguments ) ; } else if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) { loop . execAggregateDouble ( null , op . opNum ( ) , arguments , numArguments , shapes , numShapes , pointer , numIndexArguments , intArrays , numIntArrays , ( DoublePointer ) block . getRealArgumentsPointer ( ) , numRealArguments ) ; } else { throw new UnsupportedOperationException ( "Half precision isn't supported on CPU" ) ; }


signature:
public class NativeOpExecutioner { /** * This method return set of key / value and
 * key / key / value objects ,
 * describing current environment
 * @ return */
@ Override public Properties getEnvironmentInformation ( ) { } }

implementation:
Properties properties = super . getEnvironmentInformation ( ) ; properties . put ( Nd4jEnvironment . BACKEND_KEY , "CPU" ) ; properties . put ( Nd4jEnvironment . OMP_THREADS_KEY , loop . ompGetMaxThreads ( ) ) ; properties . put ( Nd4jEnvironment . BLAS_THREADS_KEY , Nd4j . factory ( ) . blas ( ) . getMaxThreads ( ) ) ; properties . put ( Nd4jEnvironment . BLAS_VENDOR_KEY , ( Nd4j . factory ( ) . blas ( ) ) . getBlasVendor ( ) . toString ( ) ) ; properties . put ( Nd4jEnvironment . HOST_FREE_MEMORY_KEY , Pointer . maxBytes ( ) - Pointer . totalBytes ( ) ) ; // fill bandwidth information
properties . put ( Nd4jEnvironment . MEMORY_BANDWIDTH_KEY , PerformanceTracker . getInstance ( ) . getCurrentBandwidth ( ) ) ; return properties ;


signature:
public class NativeOpExecutioner { /** * This method executes specific
 * RandomOp against specified RNG
 * @ param op
 * @ param rng */
@ Override public INDArray exec ( RandomOp op , Random rng ) { } }

implementation:
if ( rng . getStateBuffer ( ) == null ) throw new IllegalStateException ( "You should use one of NativeRandom classes for NativeOperations execution" ) ; long st = profilingHookIn ( op ) ; validateDataType ( Nd4j . dataType ( ) , op ) ; if ( op . x ( ) != null && op . y ( ) != null && op . z ( ) != null ) { // triple arg call
if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT ) { loop . execRandomFloat ( null , op . opNum ( ) , rng . getStatePointer ( ) , // rng state ptr
( FloatPointer ) op . x ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . x ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( FloatPointer ) op . y ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . y ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( FloatPointer ) op . z ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . z ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( FloatPointer ) op . extraArgsDataBuff ( ) . addressPointer ( ) ) ; } else if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) { loop . execRandomDouble ( null , op . opNum ( ) , rng . getStatePointer ( ) , // rng state ptr
( DoublePointer ) op . x ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . x ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( DoublePointer ) op . y ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . y ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( DoublePointer ) op . z ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . z ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( DoublePointer ) op . extraArgsDataBuff ( ) . addressPointer ( ) ) ; } } else if ( op . x ( ) != null && op . z ( ) != null ) { // double arg call
if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT ) { loop . execRandomFloat ( null , op . opNum ( ) , rng . getStatePointer ( ) , // rng state ptr
( FloatPointer ) op . x ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . x ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( FloatPointer ) op . z ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . z ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( FloatPointer ) op . extraArgsDataBuff ( ) . addressPointer ( ) ) ; } else if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) { loop . execRandomDouble ( null , op . opNum ( ) , rng . getStatePointer ( ) , // rng state ptr
( DoublePointer ) op . x ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . x ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( DoublePointer ) op . z ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . z ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( DoublePointer ) op . extraArgsDataBuff ( ) . addressPointer ( ) ) ; } } else { // single arg call
if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT ) { loop . execRandomFloat ( null , op . opNum ( ) , rng . getStatePointer ( ) , // rng state ptr
( FloatPointer ) op . z ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . z ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( FloatPointer ) op . extraArgsDataBuff ( ) . addressPointer ( ) ) ; } else if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) { loop . execRandomDouble ( null , op . opNum ( ) , rng . getStatePointer ( ) , // rng state ptr
( DoublePointer ) op . z ( ) . data ( ) . addressPointer ( ) , ( LongPointer ) op . z ( ) . shapeInfoDataBuffer ( ) . addressPointer ( ) , ( DoublePointer ) op . extraArgsDataBuff ( ) . addressPointer ( ) ) ; } } profilingHookOut ( op , st ) ; return op . z ( ) ;


signature:
public class NativeOpExecutioner { /** * This method executes given CustomOp
 * PLEASE NOTE : You ' re responsible for input / output validation
 * @ param op */
public void exec ( @ NonNull CustomOp op ) { } }

implementation: long st = profilingHookIn ( op ) ; if ( op . numOutputArguments ( ) == 0 && ! op . isInplaceCall ( ) ) throw new ND4JIllegalStateException ( "Op name " + op . opName ( ) + " failed to execute. You can't execute non-inplace CustomOp without outputs being specified" ) ; val name = op . opName ( ) . toLowerCase ( ) ; val hash = op . opHash ( ) ; val inputShapes = getInputShapes ( op . numInputArguments ( ) ) ; val inputBuffers = getInputBuffers ( op . numInputArguments ( ) ) ; int cnt = 0 ; val inputArgs = op . inputArguments ( ) ; for ( val in : inputArgs ) { if ( in == null ) { throw new NullPointerException ( "Input argument is null" ) ; } inputBuffers . put ( cnt , in . data ( ) . addressPointer ( ) ) ; inputShapes . put ( cnt ++ , in . shapeInfoDataBuffer ( ) . addressPointer ( ) ) ; } val outputArgs = op . outputArguments ( ) ; for ( int i = 0 ; i < outputArgs . length ; i ++ ) { if ( outputArgs [ i ] == null ) throw new ND4JIllegalStateException ( "Op output arguments must not be null!" ) ; } val outputShapes = getOutputShapes ( op . numOutputArguments ( ) ) ; val outputBuffers = getOutputBuffers ( op . numOutputArguments ( ) ) ; cnt = 0 ; for ( val out : outputArgs ) { outputBuffers . put ( cnt , out . data ( ) . addressPointer ( ) ) ; outputShapes . put ( cnt ++ , out . shapeInfoDataBuffer ( ) . addressPointer ( ) ) ; } val iArgs = op . numIArguments ( ) > 0 ? new LongPointer ( op . numIArguments ( ) ) : null ; cnt = 0 ; val iArgs1 = op . iArgs ( ) ; for ( val i : iArgs1 ) iArgs . put ( cnt ++ , i ) ; if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT ) { val tArgs = op . numTArguments ( ) > 0 ? new FloatPointer ( op . numTArguments ( ) ) : null ; val tArgs1 = op . tArgs ( ) ; cnt = 0 ; for ( val t : tArgs1 ) tArgs . put ( cnt ++ , ( float ) t ) ; OpStatus status = OpStatus . byNumber ( loop . execCustomOpFloat ( null , hash , inputBuffers , inputShapes , op . numInputArguments ( ) , outputBuffers , outputShapes , op . numOutputArguments ( ) , tArgs , op . numTArguments ( ) , iArgs , op . numIArguments ( ) , op . isInplaceCall ( ) ) ) ; if ( status != OpStatus . ND4J_STATUS_OK ) throw new ND4JIllegalStateException ( "Op execution failed: " + status ) ; } else if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) { val tArgs = op . numTArguments ( ) > 0 ? getDoublePointerFrom ( tArgsPointer , op . numTArguments ( ) ) : null ; val tArgs1 = op . tArgs ( ) ; cnt = 0 ; for ( val t : tArgs1 ) tArgs . put ( cnt ++ , t ) ; val t = op . numInputArguments ( ) ; OpStatus status = OpStatus . ND4J_STATUS_OK ; try { status = OpStatus . byNumber ( loop . execCustomOpDouble ( null , hash , inputBuffers , inputShapes , op . numInputArguments ( ) , outputBuffers , outputShapes , op . numOutputArguments ( ) , tArgs , op . numTArguments ( ) , iArgs , op . numIArguments ( ) , op . isInplaceCall ( ) ) ) ; } catch ( Exception e ) { log . error ( "Failed to execute. Please see above message (printed out from c++) for a possible cause of error." ) ; throw e ; } } else if ( Nd4j . dataType ( ) == DataBuffer . Type . HALF ) { val tArgs = op . numTArguments ( ) > 0 ? getShortPointerFrom ( halfArgsPointer , op . numTArguments ( ) ) : null ; cnt = 0 ; val tArgs1 = op . tArgs ( ) ; for ( val t : tArgs1 ) tArgs . put ( cnt ++ , ArrayUtil . toHalf ( t ) ) ; OpStatus status = OpStatus . byNumber ( loop . execCustomOpHalf ( null , hash , inputBuffers , inputShapes , op . numInputArguments ( ) , outputBuffers , outputShapes , op . numOutputArguments ( ) , tArgs , op . numTArguments ( ) , iArgs , op . numIArguments ( ) , op . isInplaceCall ( ) ) ) ; if ( status != OpStatus . ND4J_STATUS_OK ) throw new ND4JIllegalStateException ( "Op execution failed: " + status ) ; } profilingHookOut ( op , st ) ;


signature:
public class MulticastTransport { /** * This command is possible to issue only from Shard
 * @ param message */
@ Override protected synchronized void sendCoordinationCommand ( VoidMessage message ) { } }

implementation:
if ( nodeRole == NodeRole . SHARD && voidConfiguration . getNumberOfShards ( ) == 1 ) { message . setTargetId ( ( short ) - 1 ) ; messages . add ( message ) ; return ; } // log . info ( " Sending CC : { } " , message . getClass ( ) . getCanonicalName ( ) ) ;
message . setTargetId ( ( short ) - 1 ) ; publicationForShards . offer ( message . asUnsafeBuffer ( ) ) ;


signature:
public class MulticastTransport { /** * This command is possible to issue only from Shard
 * @ param message */
@ Override protected synchronized void sendFeedbackToClient ( VoidMessage message ) { } }

implementation:
if ( nodeRole == NodeRole . SHARD && voidConfiguration . getNumberOfShards ( ) == 1 && message instanceof MeaningfulMessage ) { message . setTargetId ( ( short ) - 1 ) ; completed . put ( message . getTaskId ( ) , ( MeaningfulMessage ) message ) ; return ; } // log . info ( " Sending FC : { } " , message . getClass ( ) . getCanonicalName ( ) ) ;
message . setTargetId ( ( short ) - 1 ) ; publicationForClients . offer ( message . asUnsafeBuffer ( ) ) ;


signature:
public class WorkspaceUtils { /** * Assert that no workspaces are currently open
 * @ param msg Message to include in the exception , if required */
public static void assertNoWorkspacesOpen ( String msg ) throws ND4JWorkspaceException { } }

implementation: if ( Nd4j . getWorkspaceManager ( ) . anyWorkspaceActiveForCurrentThread ( ) ) { List < MemoryWorkspace > l = Nd4j . getWorkspaceManager ( ) . getAllWorkspacesForCurrentThread ( ) ; List < String > workspaces = new ArrayList < > ( l . size ( ) ) ; for ( MemoryWorkspace ws : l ) { if ( ws . isScopeActive ( ) ) { workspaces . add ( ws . getId ( ) ) ; } } throw new ND4JWorkspaceException ( msg + " - Open/active workspaces: " + workspaces ) ; }


signature:
public class DefaultConvolutionInstance { /** * ND Convolution
 * @ param input the input to op
 * @ param kernel the kernel to op with
 * @ param type the opType of convolution
 * @ param axes the axes to do the convolution along
 * @ return the convolution of the given input and kernel */
@ Override public IComplexNDArray convn ( IComplexNDArray input , IComplexNDArray kernel , Convolution . Type type , int [ ] axes ) { } }

implementation: throw new UnsupportedOperationException ( ) ;


signature:
public class LossMixtureDensity { /** * This method returns an array consisting of each of the training samples ,
 * for each label in each sample , the negative log likelihood of that
 * value falling within the given gaussian mixtures .
 * @ param alpha
 * @ param mu
 * @ param sigma
 * @ param labels
 * @ return */
private INDArray negativeLogLikelihood ( INDArray labels , INDArray alpha , INDArray mu , INDArray sigma ) { } }

implementation:
INDArray labelsMinusMu = labelsMinusMu ( labels , mu ) ; INDArray diffsquared = labelsMinusMu . mul ( labelsMinusMu ) . sum ( 2 ) ; INDArray phitimesalphasum = phi ( diffsquared , sigma ) . muli ( alpha ) . sum ( 1 ) ; // result = See Bishop ( 28,29)
INDArray result = Transforms . log ( phitimesalphasum ) . negi ( ) ; return result ;


signature:
public class AtomicState { /** * This method requests to change state to Tick .
 * PLEASE NOTE : this method is blocking , if memory is in Toe state .
 * PLEASE NOTE : if Tick can ' t be acquired within specified timeframe , exception will be thrown
 * @ param time
 * @ param timeUnit */
public void requestTick ( long time , TimeUnit timeUnit ) { } }

implementation:
long timeframeMs = TimeUnit . MILLISECONDS . convert ( time , timeUnit ) ; long currentTime = System . currentTimeMillis ( ) ; boolean isWaiting = false ; // if we have Toe request queued - we ' have to wait till it finishes .
try { while ( isToeScheduled . get ( ) || isToeWaiting . get ( ) || getCurrentState ( ) == AccessState . TOE ) { if ( ! isWaiting ) { isWaiting = true ; waitingTicks . incrementAndGet ( ) ; } Thread . sleep ( 50 ) ; } currentState . set ( AccessState . TICK . ordinal ( ) ) ; waitingTicks . decrementAndGet ( ) ; tickRequests . incrementAndGet ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; }


signature:
public class AtomicState { /** * This method requests to change state to Toe
 * PLEASE NOTE : this method is non - blocking , if Toe request is impossible atm , it will return false .
 * @ return TRUE , if Toe state entered , FALSE otherwise */
public boolean tryRequestToe ( ) { } }

implementation:
scheduleToe ( ) ; if ( isToeWaiting . get ( ) || getCurrentState ( ) == AccessState . TOE ) { // System . out . println ( " discarding TOE " ) ;
discardScheduledToe ( ) ; return false ; } else { // System . out . println ( " requesting TOE " ) ;
discardScheduledToe ( ) ; requestToe ( ) ; return true ; }


signature:
public class AtomicState { /** * This method requests release Toe status back to Tack .
 * PLEASE NOTE : only the thread originally entered Toe state is able to release it . */
public void releaseToe ( ) { } }

implementation:
if ( getCurrentState ( ) == AccessState . TOE ) { if ( 1 > 0 ) { // if ( toeThread . get ( ) = = Thread . currentThread ( ) . getId ( ) ) {
if ( toeRequests . decrementAndGet ( ) == 0 ) { tickRequests . set ( 0 ) ; tackRequests . set ( 0 ) ; currentState . set ( AccessState . TACK . ordinal ( ) ) ; } } else throw new IllegalStateException ( "releaseToe() is called from different thread." ) ; } else throw new IllegalStateException ( "Object is NOT in Toe state!" ) ;


signature:
public class AtomicState { /** * This method returns the current memory state
 * @ return */
public AccessState getCurrentState ( ) { } }

implementation:
if ( AccessState . values ( ) [ currentState . get ( ) ] == AccessState . TOE ) { return AccessState . TOE ; } else { if ( tickRequests . get ( ) <= tackRequests . get ( ) ) { // TODO : looks like this piece of code should be locked : /
tickRequests . set ( 0 ) ; tackRequests . set ( 0 ) ; return AccessState . TACK ; } else return AccessState . TICK ; }


signature:
public class EnvironmentUtils { /** * This method build
 * @ return */
public static Environment buildEnvironment ( ) { } }

implementation: Environment environment = new Environment ( ) ; environment . setJavaVersion ( System . getProperty ( "java.specification.version" ) ) ; environment . setNumCores ( Runtime . getRuntime ( ) . availableProcessors ( ) ) ; environment . setAvailableMemory ( Runtime . getRuntime ( ) . maxMemory ( ) ) ; environment . setOsArch ( System . getProperty ( "os.arch" ) ) ; environment . setOsName ( System . getProperty ( "os.opName" ) ) ; environment . setBackendUsed ( Nd4j . getExecutioner ( ) . getClass ( ) . getSimpleName ( ) ) ; return environment ;


signature:
public class VectorAggregation { /** * Vector aggregations are saved only by Shards started aggregation process . All other Shards are ignoring this meesage */
@ Override public void processMessage ( ) { } }

implementation:
if ( clipboard . isTracking ( this . originatorId , this . getTaskId ( ) ) ) { clipboard . pin ( this ) ; if ( clipboard . isReady ( this . originatorId , taskId ) ) { VoidAggregation aggregation = clipboard . unpin ( this . originatorId , taskId ) ; // FIXME : probably there ' s better solution , then " screw - and - forget " one
if ( aggregation == null ) return ; VectorCompleteMessage msg = new VectorCompleteMessage ( taskId , aggregation . getAccumulatedResult ( ) ) ; msg . setOriginatorId ( aggregation . getOriginatorId ( ) ) ; transport . sendMessage ( msg ) ; } }


signature:
public class BaseDataFetcher { /** * Initializes this data transform fetcher from the passed in datasets
 * @ param examples the examples to use */
protected void initializeCurrFromList ( List < DataSet > examples ) { } }

implementation: if ( examples . isEmpty ( ) ) log . warn ( "Warning: empty dataset from the fetcher" ) ; INDArray inputs = createInputMatrix ( examples . size ( ) ) ; INDArray labels = createOutputMatrix ( examples . size ( ) ) ; for ( int i = 0 ; i < examples . size ( ) ; i ++ ) { inputs . putRow ( i , examples . get ( i ) . getFeatureMatrix ( ) ) ; labels . putRow ( i , examples . get ( i ) . getLabels ( ) ) ; } curr = new DataSet ( inputs , labels ) ;


signature:
public class BaseConvolutionConfig { /** * Set the value for this function .
 * Note that if value is null an { @ link ND4JIllegalStateException }
 * will be thrown .
 * @ param target the target field
 * @ param value the value to set */
public void setValueFor ( Field target , Object value ) { } }

implementation: if ( value == null ) { throw new ND4JIllegalStateException ( "Unable to set field " + target + " using null value!" ) ; } value = ensureProperType ( target , value ) ; try { target . set ( this , value ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; }


signature:
public class AtomicAllocator { /** * This method executes preconfigured number of host memory garbage collectors */
protected void initHostCollectors ( ) { } }

implementation:
for ( int i = 0 ; i < configuration . getNumberOfGcThreads ( ) ; i ++ ) { ReferenceQueue < BaseDataBuffer > queue = new ReferenceQueue < > ( ) ; UnifiedGarbageCollectorThread uThread = new UnifiedGarbageCollectorThread ( i , queue ) ; // all GC threads should be attached to default device
Nd4j . getAffinityManager ( ) . attachThreadToDevice ( uThread , getDeviceId ( ) ) ; queueMap . put ( i , queue ) ; uThread . start ( ) ; collectorsUnified . put ( i , uThread ) ; /* ZeroGarbageCollectorThread zThread = new ZeroGarbageCollectorThread ( ( long ) i , shouldStop ) ;
 zThread . start ( ) ;
 collectorsZero . put ( ( long ) i , zThread ) ; */
}


signature:
public class AtomicAllocator { /** * This method returns actual device pointer valid for current object
 * @ param buffer */
@ Override public Pointer getPointer ( DataBuffer buffer , CudaContext context ) { } }

implementation: return memoryHandler . getDevicePointer ( buffer , context ) ;


signature:
public class AtomicAllocator { /** * This method should be called to make sure that data on host side is actualized
 * @ param buffer */
@ Override public void synchronizeHostData ( DataBuffer buffer ) { } }

implementation:
// we don ' t want non - committed ops left behind
// Nd4j . getExecutioner ( ) . push ( ) ;
// we don ' t synchronize constant buffers , since we assume they are always valid on host side
if ( buffer . isConstant ( ) ) { return ; } // we actually need synchronization only in device - dependant environment . no - op otherwise
if ( memoryHandler . isDeviceDependant ( ) ) { AllocationPoint point = getAllocationPoint ( buffer . getTrackingPoint ( ) ) ; if ( point == null ) throw new RuntimeException ( "AllocationPoint is NULL" ) ; memoryHandler . synchronizeThreadDevice ( Thread . currentThread ( ) . getId ( ) , memoryHandler . getDeviceId ( ) , point ) ; }