signature:
public class BaseLevel3 { /** * gemm performs a matrix - matrix operation
 * c : = alpha * op ( a ) * op ( b ) + beta * c ,
 * where c is an m - by - n matrix ,
 * op ( a ) is an m - by - k matrix ,
 * op ( b ) is a k - by - n matrix .
 * @ param Order
 * @ param TransA
 * @ param TransB
 * @ param alpha
 * @ param A
 * @ param B
 * @ param beta
 * @ param C */
@ Override public void gemm ( char Order , char TransA , char TransB , double alpha , INDArray A , INDArray B , double beta , INDArray C ) { } }

implementation: if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( true , A , B , C ) ; GemmParams params = new GemmParams ( A , B , C ) ; int charOder = Order ; if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . DOUBLE , params . getA ( ) , params . getB ( ) , params . getC ( ) ) ; dgemm ( Order , params . getTransA ( ) , params . getTransB ( ) , params . getM ( ) , params . getN ( ) , params . getK ( ) , 1.0 , params . getA ( ) , params . getLda ( ) , params . getB ( ) , params . getLdb ( ) , 0 , C , params . getLdc ( ) ) ; } else if ( A . data ( ) . dataType ( ) == DataBuffer . Type . FLOAT ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . FLOAT , params . getA ( ) , params . getB ( ) , params . getC ( ) ) ; sgemm ( Order , params . getTransA ( ) , params . getTransB ( ) , params . getM ( ) , params . getN ( ) , params . getK ( ) , 1.0f , params . getA ( ) , params . getLda ( ) , params . getB ( ) , params . getLdb ( ) , 0 , C , params . getLdc ( ) ) ; } else { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . HALF , params . getA ( ) , params . getB ( ) , params . getC ( ) ) ; hgemm ( Order , params . getTransA ( ) , params . getTransB ( ) , params . getM ( ) , params . getN ( ) , params . getK ( ) , 1.0f , params . getA ( ) , params . getLda ( ) , params . getB ( ) , params . getLdb ( ) , 0 , C , params . getLdc ( ) ) ; } OpExecutionerUtil . checkForAny ( C ) ;


signature:
public class BaseLevel3 { /** * her2k performs a rank - 2k update of an n - by - n Hermitian matrix c , that is , one of the following operations :
 * c : = alpha * a * conjg ( b ' ) + conjg ( alpha ) * b * conjg ( a ' ) + beta * c , for trans = ' N ' or ' n '
 * c : = alpha * conjg ( b ' ) * a + conjg ( alpha ) * conjg ( a ' ) * b + beta * c , for trans = ' C ' or ' c '
 * where c is an n - by - n Hermitian matrix ;
 * a and b are n - by - k matrices if trans = ' N ' or ' n ' ,
 * a and b are k - by - n matrices if trans = ' C ' or ' c ' .
 * @ param Order
 * @ param Side
 * @ param Uplo
 * @ param alpha
 * @ param A
 * @ param B
 * @ param beta
 * @ param C */
@ Override public void symm ( char Order , char Side , char Uplo , double alpha , INDArray A , INDArray B , double beta , INDArray C ) { } }

implementation:
if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( false , A , B , C ) ; // FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . DOUBLE , A , B , C ) ; dsymm ( Order , Side , Uplo , ( int ) C . rows ( ) , ( int ) C . columns ( ) , alpha , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , beta , C , ( int ) C . size ( 0 ) ) ; } else { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . FLOAT , A , B , C ) ; ssymm ( Order , Side , Uplo , ( int ) C . rows ( ) , ( int ) C . columns ( ) , ( float ) alpha , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , ( float ) beta , C , ( int ) C . size ( 0 ) ) ; } OpExecutionerUtil . checkForAny ( C ) ;


signature:
public class BaseLevel3 { /** * syrk performs a rank - n update of an n - by - n symmetric matrix c , that is , one of the following operations :
 * c : = alpha * a * a ' + beta * c for trans = ' N ' or ' n '
 * c : = alpha * a ' * a + beta * c for trans = ' T ' or ' t ' , ' C ' or ' c ' ,
 * where c is an n - by - n symmetric matrix ;
 * a is an n - by - k matrix , if trans = ' N ' or ' n ' ,
 * a is a k - by - n matrix , if trans = ' T ' or ' t ' , ' C ' or ' c ' .
 * @ param Order
 * @ param Uplo
 * @ param Trans
 * @ param alpha
 * @ param A
 * @ param beta
 * @ param C */
@ Override public void syrk ( char Order , char Uplo , char Trans , double alpha , INDArray A , double beta , INDArray C ) { } }

implementation:
if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( false , A , C ) ; // FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . DOUBLE , A , C ) ; dsyrk ( Order , Uplo , Trans , ( int ) C . rows ( ) , 1 , alpha , A , ( int ) A . size ( 0 ) , beta , C , ( int ) C . size ( 0 ) ) ; } else { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . FLOAT , A , C ) ; ssyrk ( Order , Uplo , Trans , ( int ) C . rows ( ) , 1 , ( float ) alpha , A , ( int ) A . size ( 0 ) , ( float ) beta , C , ( int ) C . size ( 0 ) ) ; } OpExecutionerUtil . checkForAny ( C ) ;


signature:
public class BaseLevel3 { /** * gemm performs a matrix - matrix operation
 * c : = alpha * op ( a ) * op ( b ) + beta * c ,
 * where c is an m - by - n matrix ,
 * op ( a ) is an m - by - k matrix ,
 * op ( b ) is a k - by - n matrix .
 * @ param Order
 * @ param TransA
 * @ param TransB
 * @ param alpha
 * @ param A
 * @ param B
 * @ param beta
 * @ param C */
@ Override public void gemm ( char Order , char TransA , char TransB , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray B , IComplexNumber beta , IComplexNDArray C ) { } }

implementation: if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( true , A , B , C ) ; GemmParams params = new GemmParams ( A , B , C ) ; if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { zgemm ( Order , TransA , TransB , params . getM ( ) , params . getN ( ) , params . getK ( ) , alpha . asDouble ( ) , A . ordering ( ) == NDArrayFactory . C ? B : A , params . getLda ( ) , B . ordering ( ) == NDArrayFactory . C ? A : B , params . getLdb ( ) , beta . asDouble ( ) , C , params . getLdc ( ) ) ; } else cgemm ( Order , TransA , TransB , params . getM ( ) , params . getN ( ) , params . getK ( ) , alpha . asFloat ( ) , A . ordering ( ) == NDArrayFactory . C ? B : A , params . getLda ( ) , B . ordering ( ) == NDArrayFactory . C ? A : B , params . getLdb ( ) , beta . asFloat ( ) , C , params . getLdc ( ) ) ;


signature:
public class BaseLevel3 { /** * hemm performs one of the following matrix - matrix operations :
 * c : = alpha * a * b + beta * c for side = ' L ' or ' l '
 * c : = alpha * b * a + beta * c for side = ' R ' or ' r ' ,
 * where a is a Hermitian matrix ,
 * b and c are m - by - n matrices .
 * @ param Order
 * @ param Side
 * @ param Uplo
 * @ param alpha
 * @ param A
 * @ param B
 * @ param beta
 * @ param C */
@ Override public void hemm ( char Order , char Side , char Uplo , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray B , IComplexNumber beta , IComplexNDArray C ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zhemm ( Order , Side , Uplo , ( int ) B . rows ( ) , ( int ) B . columns ( ) , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , beta . asDouble ( ) , C , ( int ) C . size ( 0 ) ) ; else chemm ( Order , Side , Uplo , ( int ) B . rows ( ) , ( int ) B . columns ( ) , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , beta . asFloat ( ) , C , ( int ) C . size ( 0 ) ) ;


signature:
public class BaseLevel3 { /** * herk performs a rank - n update of a Hermitian matrix , that is , one of the following operations :
 * c : = alpha * a * conjug ( a ' ) + beta * c for trans = ' N ' or ' n '
 * c : = alpha * conjug ( a ' ) * a + beta * c for trans = ' C ' or ' c ' ,
 * where c is an n - by - n Hermitian matrix ;
 * a is an n - by - k matrix , if trans = ' N ' or ' n ' ,
 * a is a k - by - n matrix , if trans = ' C ' or ' c ' .
 * @ param Order
 * @ param Uplo
 * @ param Trans
 * @ param alpha
 * @ param A
 * @ param beta
 * @ param C */
@ Override public void herk ( char Order , char Uplo , char Trans , IComplexNumber alpha , IComplexNDArray A , IComplexNumber beta , IComplexNDArray C ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zherk ( Order , Uplo , Trans , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , beta . asDouble ( ) , C , ( int ) C . size ( 0 ) ) ; else cherk ( Order , Uplo , Trans , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , beta . asFloat ( ) , C , ( int ) C . size ( 0 ) ) ;


signature:
public class BaseLevel3 { /** * her2k performs a rank - 2k update of an n - by - n Hermitian matrix c , that is , one of the following operations :
 * c : = alpha * a * conjg ( b ' ) + conjg ( alpha ) * b * conjg ( a ' ) + beta * c , for trans = ' N ' or ' n '
 * c : = alpha * conjg ( b ' ) * a + conjg ( alpha ) * conjg ( a ' ) * b + beta * c , for trans = ' C ' or ' c '
 * where c is an n - by - n Hermitian matrix ;
 * a and b are n - by - k matrices if trans = ' N ' or ' n ' ,
 * a and b are k - by - n matrices if trans = ' C ' or ' c ' .
 * @ param Order
 * @ param Side
 * @ param Uplo
 * @ param alpha
 * @ param A
 * @ param B
 * @ param beta
 * @ param C */
@ Override public void symm ( char Order , char Side , char Uplo , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray B , IComplexNumber beta , IComplexNDArray C ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zsymm ( Order , Side , Uplo , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , beta . asDouble ( ) , C , ( int ) C . size ( 0 ) ) ; else csymm ( Order , Side , Uplo , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , beta . asFloat ( ) , C , ( int ) C . size ( 0 ) ) ;


signature:
public class BaseLevel3 { /** * syrk performs a rank - n update of an n - by - n symmetric matrix c , that is , one of the following operations :
 * c : = alpha * a * a ' + beta * c for trans = ' N ' or ' n '
 * c : = alpha * a ' * a + beta * c for trans = ' T ' or ' t ' , ' C ' or ' c ' ,
 * where c is an n - by - n symmetric matrix ;
 * a is an n - by - k matrix , if trans = ' N ' or ' n ' ,
 * a is a k - by - n matrix , if trans = ' T ' or ' t ' , ' C ' or ' c ' .
 * @ param Order
 * @ param Uplo
 * @ param Trans
 * @ param alpha
 * @ param A
 * @ param beta
 * @ param C */
@ Override public void syrk ( char Order , char Uplo , char Trans , IComplexNumber alpha , IComplexNDArray A , IComplexNumber beta , IComplexNDArray C ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zsyrk ( Order , Uplo , Trans , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , beta . asDouble ( ) , C , ( int ) C . size ( 0 ) ) ; else csyrk ( Order , Uplo , Trans , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , beta . asFloat ( ) , C , ( int ) C . size ( 0 ) ) ;


signature:
public class BaseLevel3 { /** * yr2k performs a rank - 2k update of an n - by - n symmetric matrix c , that is , one of the following operations :
 * c : = alpha * a * b ' + alpha * b * a ' + beta * c for trans = ' N ' or ' n '
 * c : = alpha * a ' * b + alpha * b ' * a + beta * c for trans = ' T ' or ' t ' ,
 * where c is an n - by - n symmetric matrix ;
 * a and b are n - by - k matrices , if trans = ' N ' or ' n ' ,
 * a and b are k - by - n matrices , if trans = ' T ' or ' t ' .
 * @ param Order
 * @ param Uplo
 * @ param Trans
 * @ param alpha
 * @ param A
 * @ param B
 * @ param beta
 * @ param C */
@ Override public void syr2k ( char Order , char Uplo , char Trans , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray B , IComplexNumber beta , IComplexNDArray C ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zsyr2k ( Order , Uplo , Trans , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , beta . asDouble ( ) , C , ( int ) C . size ( 0 ) ) ; else csyr2k ( Order , Uplo , Trans , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , beta . asFloat ( ) , C , ( int ) C . size ( 0 ) ) ;


signature:
public class BaseLevel3 { /** * syr2k performs a rank - 2k update of an n - by - n symmetric matrix c , that is , one of the following operations :
 * c : = alpha * a * b ' + alpha * b * a ' + beta * c for trans = ' N ' or ' n '
 * c : = alpha * a ' * b + alpha * b ' * a + beta * c for trans = ' T ' or ' t ' ,
 * where c is an n - by - n symmetric matrix ;
 * a and b are n - by - k matrices , if trans = ' N ' or ' n ' ,
 * a and b are k - by - n matrices , if trans = ' T ' or ' t ' .
 * @ param Order
 * @ param Side
 * @ param Uplo
 * @ param TransA
 * @ param Diag
 * @ param alpha
 * @ param A
 * @ param B
 * @ param C */
@ Override public void trmm ( char Order , char Side , char Uplo , char TransA , char Diag , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray B , IComplexNDArray C ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) ztrmm ( Order , Side , Uplo , TransA , Diag , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , C , ( int ) C . size ( 0 ) ) ; else ctrmm ( Order , Side , Uplo , TransA , Diag , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) , C , ( int ) C . size ( 0 ) ) ;


signature:
public class BaseLevel3 { /** * ? trsm solves one of the following matrix equations :
 * op ( a ) * x = alpha * b or x * op ( a ) = alpha * b ,
 * where x and b are m - by - n general matrices , and a is triangular ;
 * op ( a ) must be an m - by - m matrix , if side = ' L ' or ' l '
 * op ( a ) must be an n - by - n matrix , if side = ' R ' or ' r ' .
 * For the definition of op ( a ) , see Matrix Arguments .
 * The routine overwrites x on b .
 * @ param Order
 * @ param Side
 * @ param Uplo
 * @ param TransA
 * @ param Diag
 * @ param alpha
 * @ param A
 * @ param B */
@ Override public void trsm ( char Order , char Side , char Uplo , char TransA , char Diag , IComplexNumber alpha , IComplexNDArray A , IComplexNDArray B ) { } }

implementation:
// FIXME : int cast
if ( A . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) ztrsm ( Order , Side , Uplo , TransA , Diag , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asDouble ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) ) ; else ctrsm ( Order , Side , Uplo , TransA , Diag , ( int ) A . rows ( ) , ( int ) A . columns ( ) , alpha . asFloat ( ) , A , ( int ) A . size ( 0 ) , B , ( int ) B . size ( 0 ) ) ;


signature:
public class OnnxDescriptorParser { /** * Get the onnx op descriptors by name
 * @ return the onnx op descriptors by name
 * @ throws Exception */
public static Map < String , OpDescriptor > onnxOpDescriptors ( ) throws Exception { } }

implementation: try ( InputStream is = new ClassPathResource ( "onnxops.json" ) . getInputStream ( ) ) { ObjectMapper objectMapper = new ObjectMapper ( ) ; OnnxDescriptor opDescriptor = objectMapper . readValue ( is , OnnxDescriptor . class ) ; Map < String , OpDescriptor > descriptorMap = new HashMap < > ( ) ; for ( OpDescriptor descriptor : opDescriptor . getDescriptors ( ) ) { descriptorMap . put ( descriptor . getName ( ) , descriptor ) ; } return descriptorMap ; }


signature:
public class AllocUtil { /** * Get the allocation mode from the context
 * @ return */
public static DataBuffer . AllocationMode getAllocationModeFromContext ( String allocMode ) { } }

implementation: switch ( allocMode ) { case "heap" : return DataBuffer . AllocationMode . HEAP ; case "javacpp" : return DataBuffer . AllocationMode . JAVACPP ; case "direct" : return DataBuffer . AllocationMode . DIRECT ; default : return DataBuffer . AllocationMode . JAVACPP ; }


signature:
public class AllocUtil { /** * 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 setAllocationModeForContext ( String allocationModeForContext ) { } }

implementation: if ( ! allocationModeForContext . equals ( "heap" ) && ! allocationModeForContext . equals ( "javacpp" ) && ! allocationModeForContext . equals ( "direct" ) ) throw new IllegalArgumentException ( "Allocation mode must be one of: heap,javacpp, or direct" ) ; Nd4jContext . getInstance ( ) . getConf ( ) . put ( "alloc" , allocationModeForContext ) ;


signature:
public class CpuMemoryManager { /** * This method releases previously allocated memory chunk
 * @ param pointer
 * @ param kind
 * @ return */
@ Override public void release ( @ NonNull Pointer pointer , MemoryKind kind ) { } }

implementation: Pointer . free ( pointer ) ;


signature:
public class BaseBroadcastOp { /** * Calculate the output shape for this op
 * @ return */
public List < long [ ] > calculateOutputShape ( ) { } }

implementation: List < long [ ] > ret = new ArrayList < > ( ) ; if ( larg ( ) . getShape ( ) != null && rarg ( ) . getShape ( ) != null ) ret . add ( Shape . broadcastOutputShape ( larg ( ) . getShape ( ) , rarg ( ) . getShape ( ) ) ) ; else if ( larg ( ) . getShape ( ) != null ) ret . add ( larg ( ) . getShape ( ) ) ; return ret ;


signature:
public class UniformDistribution { /** * { @ inheritDoc } */
public double cumulativeProbability ( double x ) { } }

implementation: if ( x <= lower ) { return 0 ; } if ( x >= upper ) { return 1 ; } return ( x - lower ) / ( upper - lower ) ;


signature:
public class NativeGraphExecutioner { /** * This method executes given graph and returns results
 * @ param sd
 * @ return */
@ Override public INDArray [ ] executeGraph ( SameDiff sd , ExecutorConfiguration configuration ) { } }

implementation:
Map < Integer , Node > intermediate = new HashMap < > ( ) ; ByteBuffer buffer = convertToFlatBuffers ( sd , configuration , intermediate ) ; BytePointer bPtr = new BytePointer ( buffer ) ; log . info ( "Buffer length: {}" , buffer . limit ( ) ) ; Pointer res = NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) . executeFlatGraphFloat ( null , bPtr ) ; if ( res == null ) throw new ND4JIllegalStateException ( "Graph execution failed" ) ; // FIXME : this is BAD
PagedPointer pagedPointer = new PagedPointer ( res , 1024 * 1024L ) ; FlatResult fr = FlatResult . getRootAsFlatResult ( pagedPointer . asBytePointer ( ) . asByteBuffer ( ) ) ; log . info ( "VarMap: {}" , sd . variableMap ( ) ) ; INDArray [ ] results = new INDArray [ fr . variablesLength ( ) ] ; for ( int e = 0 ; e < fr . variablesLength ( ) ; e ++ ) { FlatVariable var = fr . variables ( e ) ; log . info ( "Var received: id: [{}:{}/<{}>];" , var . id ( ) . first ( ) , var . id ( ) . second ( ) , var . name ( ) ) ; FlatArray ndarray = var . ndarray ( ) ; INDArray val = Nd4j . createFromFlatArray ( ndarray ) ; results [ e ] = val ; if ( var . name ( ) != null && sd . variableMap ( ) . containsKey ( var . name ( ) ) ) { // log . info ( " VarName : { } ; Exists : { } ; NDArrayInfo : { } ; " , var . opName ( ) , sd . variableMap ( ) . containsKey ( var . opName ( ) ) , sd . getVertexToArray ( ) . containsKey ( var . opName ( ) ) ) ;
// log . info ( " storing : { } ; array : { } " , var . name ( ) , val ) ;
sd . associateArrayWithVariable ( val , sd . variableMap ( ) . get ( var . name ( ) ) ) ; } else { // log . info ( " Original id : { } ; out : { } ; out2 : { } " , original , sd . getVertexIdxToInfo ( ) . get ( original ) , graph . getVariableForVertex ( original ) ) ;
if ( sd . variableMap ( ) . get ( var . name ( ) ) != null ) { sd . associateArrayWithVariable ( val , sd . getVariable ( var . name ( ) ) ) ; } else { // log . info ( " BAD " ) ;
// sd . var ( " " , val ) ;
throw new ND4JIllegalStateException ( "Unknown variable received as result: [" + var . name ( ) + "]" ) ; } } } return results ;


signature:
public class BooleanIndexing { /** * And
 * @ param n
 * @ param cond
 * @ return */
public static boolean and ( IComplexNDArray n , Condition cond ) { } }

implementation: boolean ret = true ; IComplexNDArray linear = n . linearView ( ) ; for ( int i = 0 ; i < linear . length ( ) ; i ++ ) { ret = ret && cond . apply ( linear . getComplex ( i ) ) ; } return ret ;


signature:
public class BooleanIndexing { /** * Or over the whole ndarray given some condition
 * @ param n
 * @ param cond
 * @ return */
public static boolean or ( IComplexNDArray n , Condition cond ) { } }

implementation: boolean ret = false ; IComplexNDArray linear = n . linearView ( ) ; for ( int i = 0 ; i < linear . length ( ) ; i ++ ) { ret = ret || cond . apply ( linear . getComplex ( i ) ) ; } return ret ;


signature:
public class BooleanIndexing { /** * And over the whole ndarray given some condition
 * @ param n the ndarray to test
 * @ param cond the condition to test against
 * @ return true if all of the elements meet the specified
 * condition false otherwise */
public static boolean and ( final INDArray n , final Condition cond ) { } }

implementation: if ( cond instanceof BaseCondition ) { long val = ( long ) Nd4j . getExecutioner ( ) . exec ( new MatchCondition ( n , cond ) , Integer . MAX_VALUE ) . getDouble ( 0 ) ; if ( val == n . lengthLong ( ) ) return true ; else return false ; } else { boolean ret = true ; final AtomicBoolean a = new AtomicBoolean ( ret ) ; Shape . iterate ( n , new CoordinateFunction ( ) { @ Override public void process ( long [ ] ... coord ) { if ( a . get ( ) ) a . compareAndSet ( true , a . get ( ) && cond . apply ( n . getDouble ( coord [ 0 ] ) ) ) ; } } ) ; return a . get ( ) ; }


signature:
public class BooleanIndexing { /** * And over the whole ndarray given some condition , with respect to dimensions
 * @ param n the ndarray to test
 * @ param condition the condition to test against
 * @ return true if all of the elements meet the specified
 * condition false otherwise */
public static boolean [ ] and ( final INDArray n , final Condition condition , int ... dimension ) { } }

implementation: if ( ! ( condition instanceof BaseCondition ) ) throw new UnsupportedOperationException ( "Only static Conditions are supported" ) ; MatchCondition op = new MatchCondition ( n , condition ) ; INDArray arr = Nd4j . getExecutioner ( ) . exec ( op , dimension ) ; boolean [ ] result = new boolean [ ( int ) arr . length ( ) ] ; long tadLength = Shape . getTADLength ( n . shape ( ) , dimension ) ; for ( int i = 0 ; i < arr . length ( ) ; i ++ ) { if ( arr . getDouble ( i ) == tadLength ) result [ i ] = true ; else result [ i ] = false ; } return result ;


signature:
public class BooleanIndexing { /** * Or over the whole ndarray given some condition , with respect to dimensions
 * @ param n the ndarray to test
 * @ param condition the condition to test against
 * @ return true if all of the elements meet the specified
 * condition false otherwise */
public static boolean [ ] or ( final INDArray n , final Condition condition , int ... dimension ) { } }

implementation:
if ( ! ( condition instanceof BaseCondition ) ) throw new UnsupportedOperationException ( "Only static Conditions are supported" ) ; MatchCondition op = new MatchCondition ( n , condition ) ; INDArray arr = Nd4j . getExecutioner ( ) . exec ( op , dimension ) ; // FIXME : int cast
boolean [ ] result = new boolean [ ( int ) arr . length ( ) ] ; for ( int i = 0 ; i < arr . length ( ) ; i ++ ) { if ( arr . getDouble ( i ) > 0 ) result [ i ] = true ; else result [ i ] = false ; } return result ;


signature:
public class BooleanIndexing { /** * Based on the matching elements
 * op to based on condition to with function function
 * @ param to the ndarray to op
 * @ param condition the condition on op
 * @ param function the function to apply the op to */
public static void applyWhere ( final INDArray to , final Condition condition , final Function < Number , Number > function ) { } }

implementation:
// keep original java implementation for dynamic
Shape . iterate ( to , new CoordinateFunction ( ) { @ Override public void process ( long [ ] ... coord ) { if ( condition . apply ( to . getDouble ( coord [ 0 ] ) ) ) to . putScalar ( coord [ 0 ] , function . apply ( to . getDouble ( coord [ 0 ] ) ) . doubleValue ( ) ) ; } } ) ;


signature:
public class BooleanIndexing { /** * This method sets provided number to all elements which match specified condition
 * @ param to
 * @ param condition
 * @ param number */
public static void applyWhere ( final INDArray to , final Condition condition , final Number number ) { } }

implementation:
if ( condition instanceof BaseCondition ) { // for all static conditions we go native
Nd4j . getExecutioner ( ) . exec ( new CompareAndSet ( to , number . doubleValue ( ) , condition ) ) ; } else { final double value = number . doubleValue ( ) ; final Function < Number , Number > dynamic = new Function < Number , Number > ( ) { @ Override public Number apply ( Number number ) { return value ; } } ; Shape . iterate ( to , new CoordinateFunction ( ) { @ Override public void process ( long [ ] ... coord ) { if ( condition . apply ( to . getDouble ( coord [ 0 ] ) ) ) to . putScalar ( coord [ 0 ] , dynamic . apply ( to . getDouble ( coord [ 0 ] ) ) . doubleValue ( ) ) ; } } ) ; }


signature:
public class BooleanIndexing { /** * Choose from the inputs based on the given condition .
 * This returns a row vector of all elements fulfilling the
 * condition listed within the array for input
 * @ param input the input to filter
 * @ param condition the condition to filter based on
 * @ return a row vector of the input elements that are true
 * ffor the given conditions */
public static INDArray chooseFrom ( @ NonNull INDArray [ ] input , @ NonNull Condition condition ) { } }

implementation: Choose choose = new Choose ( input , condition ) ; Nd4j . getExecutioner ( ) . exec ( choose ) ; int secondOutput = choose . getOutputArgument ( 1 ) . getInt ( 0 ) ; if ( secondOutput < 1 ) { return null ; } return choose . getOutputArgument ( 0 ) ;


signature:
public class BooleanIndexing { /** * Choose from the inputs based on the given condition .
 * This returns a row vector of all elements fulfilling the
 * condition listed within the array for input .
 * The double and integer arguments are only relevant
 * for scalar operations ( like when you have a scalar
 * you are trying to compare each element in your input against )
 * @ param input the input to filter
 * @ param tArgs the double args
 * @ param iArgs the integer args
 * @ param condition the condition to filter based on
 * @ return a row vector of the input elements that are true
 * ffor the given conditions */
public static INDArray chooseFrom ( @ NonNull INDArray [ ] input , @ NonNull List < Double > tArgs , @ NonNull List < Integer > iArgs , @ NonNull Condition condition ) { } }

implementation: Choose choose = new Choose ( input , iArgs , tArgs , condition ) ; Nd4j . getExecutioner ( ) . exec ( choose ) ; int secondOutput = choose . getOutputArgument ( 1 ) . getInt ( 0 ) ; if ( secondOutput < 1 ) { return null ; } INDArray ret = choose . getOutputArgument ( 0 ) . get ( NDArrayIndex . interval ( 0 , secondOutput ) ) ; ret = ret . reshape ( ret . length ( ) ) ; return ret ;


signature:
public class BooleanIndexing { /** * Based on the matching elements
 * op to based on condition to with function function
 * @ param to the ndarray to op
 * @ param condition the condition on op
 * @ param function the function to apply the op to */
public static void applyWhere ( final INDArray to , final Condition condition , final Function < Number , Number > function , final Function < Number , Number > alternativeFunction ) { } }

implementation: Shape . iterate ( to , new CoordinateFunction ( ) { @ Override public void process ( long [ ] ... coord ) { if ( condition . apply ( to . getDouble ( coord [ 0 ] ) ) ) { to . putScalar ( coord [ 0 ] , function . apply ( to . getDouble ( coord [ 0 ] ) ) . doubleValue ( ) ) ; } else { to . putScalar ( coord [ 0 ] , alternativeFunction . apply ( to . getDouble ( coord [ 0 ] ) ) . doubleValue ( ) ) ; } } } ) ;


signature:
public class BooleanIndexing { /** * Based on the matching elements
 * op to based on condition to with function function
 * @ param to the ndarray to op
 * @ param condition the condition on op
 * @ param function the function to apply the op to */
public static void applyWhere ( IComplexNDArray to , Condition condition , Function < IComplexNumber , IComplexNumber > function ) { } }

implementation: IComplexNDArray linear = to . linearView ( ) ; for ( int i = 0 ; i < linear . linearView ( ) . length ( ) ; i ++ ) { if ( condition . apply ( linear . getDouble ( i ) ) ) { linear . putScalar ( i , function . apply ( linear . getComplex ( i ) ) ) ; } }


signature:
public class BooleanIndexing { /** * This method returns first index matching given condition
 * PLEASE NOTE : This method will return - 1 value if condition wasn ' t met
 * @ param array
 * @ param condition
 * @ return */
public static INDArray firstIndex ( INDArray array , Condition condition ) { } }

implementation: if ( ! ( condition instanceof BaseCondition ) ) throw new UnsupportedOperationException ( "Only static Conditions are supported" ) ; FirstIndex idx = new FirstIndex ( array , condition ) ; Nd4j . getExecutioner ( ) . exec ( idx ) ; return Nd4j . scalar ( ( double ) idx . getFinalResult ( ) ) ;


signature:
public class FunctionProperties { /** * This method converts this FunctionProperties instance to FlatBuffers representation
 * @ param bufferBuilder
 * @ return */
public int asFlatProperties ( FlatBufferBuilder bufferBuilder ) { } }

implementation: int iname = bufferBuilder . createString ( name ) ; int ii = FlatProperties . createIVector ( bufferBuilder , Ints . toArray ( i ) ) ; int il = FlatProperties . createLVector ( bufferBuilder , Longs . toArray ( l ) ) ; int id = FlatProperties . createDVector ( bufferBuilder , Doubles . toArray ( d ) ) ; int arrays [ ] = new int [ a . size ( ) ] ; int cnt = 0 ; for ( val array : a ) { int off = array . toFlatArray ( bufferBuilder ) ; arrays [ cnt ++ ] = off ; } int ia = FlatProperties . createAVector ( bufferBuilder , arrays ) ; return FlatProperties . createFlatProperties ( bufferBuilder , iname , ii , il , id , ia ) ;


signature:
public class FunctionProperties { /** * This method creates new FunctionProperties instance from FlatBuffers representation
 * @ param properties
 * @ return */
public static FunctionProperties fromFlatProperties ( FlatProperties properties ) { } }

implementation: val props = new FunctionProperties ( ) ; for ( int e = 0 ; e < properties . iLength ( ) ; e ++ ) props . getI ( ) . add ( properties . i ( e ) ) ; for ( int e = 0 ; e < properties . lLength ( ) ; e ++ ) props . getL ( ) . add ( properties . l ( e ) ) ; for ( int e = 0 ; e < properties . dLength ( ) ; e ++ ) props . getD ( ) . add ( properties . d ( e ) ) ; for ( int e = 0 ; e < properties . iLength ( ) ; e ++ ) props . getA ( ) . add ( Nd4j . createFromFlatArray ( properties . a ( e ) ) ) ; return props ;


signature:
public class FunctionProperties { /** * This method converts multiple FunctionProperties to FlatBuffers representation
 * @ param bufferBuilder
 * @ param properties
 * @ return */
public static int asFlatProperties ( FlatBufferBuilder bufferBuilder , Collection < FunctionProperties > properties ) { } }

implementation: int props [ ] = new int [ properties . size ( ) ] ; int cnt = 0 ; for ( val p : properties ) props [ cnt ++ ] = p . asFlatProperties ( bufferBuilder ) ; return FlatNode . createPropertiesVector ( bufferBuilder , props ) ;


signature:
public class AtomicThrowable { /** * This method updates state with given Throwable
 * @ param t */
public void set ( Throwable t ) { } }

implementation: try { lock . writeLock ( ) . lock ( ) ; this . t = t ; } finally { lock . writeLock ( ) . unlock ( ) ; }


signature:
public class AtomicThrowable { /** * This method updates state only if it wasn ' t set before
 * @ param t */
public void setIfFirst ( Throwable t ) { } }

implementation: try { lock . writeLock ( ) . lock ( ) ; if ( this . t == null ) this . t = t ; } finally { lock . writeLock ( ) . unlock ( ) ; }


signature:
public class MathUtils { /** * Normalize a value
 * ( val - min ) / ( max - min )
 * @ param val value to normalize
 * @ param max max value
 * @ param min min value
 * @ return the normalized value */
public static double normalize ( double val , double min , double max ) { } }

implementation: if ( max < min ) throw new IllegalArgumentException ( "Max must be greather than min" ) ; return ( val - min ) / ( max - min ) ;


signature:
public class MathUtils { /** * This will merge the coordinates of the given coordinate system .
 * @ param x the x coordinates
 * @ param y the y coordinates
 * @ return a vector such that each ( x , y ) pair is at ret [ i ] , ret [ i + 1] */
public static List < Double > mergeCoords ( List < Double > x , List < Double > y ) { } }

implementation: if ( x . size ( ) != y . size ( ) ) throw new IllegalArgumentException ( "Sample sizes must be the same for each data applyTransformToDestination." ) ; List < Double > ret = new ArrayList < Double > ( ) ; for ( int i = 0 ; i < x . size ( ) ; i ++ ) { ret . add ( x . get ( i ) ) ; ret . add ( y . get ( i ) ) ; } return ret ;


signature:
public class MathUtils { /** * This returns the coordinate split in a list of coordinates
 * such that the values for ret [ 0 ] are the x values
 * and ret [ 1 ] are the y values
 * @ param vector the vector to split with x and y values /
 * @ return a coordinate split for the given vector of values .
 * if null , is passed in null is returned */
public static List < double [ ] > coordSplit ( double [ ] vector ) { } }

implementation:
if ( vector == null ) return null ; List < double [ ] > ret = new ArrayList < double [ ] > ( ) ; /* x coordinates */
double [ ] xVals = new double [ vector . length / 2 ] ; /* y coordinates */
double [ ] yVals = new double [ vector . length / 2 ] ; /* current points */
int xTracker = 0 ; int yTracker = 0 ; for ( int i = 0 ; i < vector . length ; i ++ ) { // even value , x coordinate
if ( i % 2 == 0 ) xVals [ xTracker ++ ] = vector [ i ] ; // y coordinate
else yVals [ yTracker ++ ] = vector [ i ] ; } ret . add ( xVals ) ; ret . add ( yVals ) ; return ret ;


signature:
public class MathUtils { /** * This will partition the given whole variable data applyTransformToDestination in to the specified chunk number .
 * @ param arr the data applyTransformToDestination to pass in
 * @ param chunk the number to separate by
 * @ return a partition data applyTransformToDestination relative to the passed in chunk number */
public static List < List < Double > > partitionVariable ( List < Double > arr , int chunk ) { } }

implementation:
int count = 0 ; List < List < Double > > ret = new ArrayList < List < Double > > ( ) ; while ( count < arr . size ( ) ) { List < Double > sublist = arr . subList ( count , count + chunk ) ; count += chunk ; ret . add ( sublist ) ; } // All data sets must be same size
for ( List < Double > lists : ret ) { if ( lists . size ( ) < chunk ) ret . remove ( lists ) ; } return ret ;


signature:
public class MathUtils { /** * This returns the coordinate split in a list of coordinates
 * such that the values for ret [ 0 ] are the x values
 * and ret [ 1 ] are the y values
 * @ param vector the vector to split with x and y values
 * Note that the list will be more stable due to the size operator .
 * The array version will have extraneous values if not monitored
 * properly .
 * @ return a coordinate split for the given vector of values .
 * if null , is passed in null is returned */
public static List < double [ ] > coordSplit ( List < Double > vector ) { } }

implementation:
if ( vector == null ) return null ; List < double [ ] > ret = new ArrayList < double [ ] > ( ) ; /* x coordinates */
double [ ] xVals = new double [ vector . size ( ) / 2 ] ; /* y coordinates */
double [ ] yVals = new double [ vector . size ( ) / 2 ] ; /* current points */
int xTracker = 0 ; int yTracker = 0 ; for ( int i = 0 ; i < vector . size ( ) ; i ++ ) { // even value , x coordinate
if ( i % 2 == 0 ) xVals [ xTracker ++ ] = vector . get ( i ) ; // y coordinate
else yVals [ yTracker ++ ] = vector . get ( i ) ; } ret . add ( xVals ) ; ret . add ( yVals ) ; return ret ;


signature:
public class OnnxGraphMapper { /** * Convert an onnx type to the proper nd4j type
 * @ param dataType the data type to convert
 * @ return the nd4j type for the onnx type */
public DataBuffer . Type nd4jTypeFromOnnxType ( OnnxProto3 . TensorProto . DataType dataType ) { } }

implementation: switch ( dataType ) { case DOUBLE : return DataBuffer . Type . DOUBLE ; case FLOAT : return DataBuffer . Type . FLOAT ; case FLOAT16 : return DataBuffer . Type . HALF ; case INT32 : case INT64 : return DataBuffer . Type . INT ; default : return DataBuffer . Type . UNKNOWN ; }


signature:
public class InfoLine { /** * Returns titles line as string appointed by title index ( 0 . . 5 ) . < br >
 * Columns are separated with char ' | ' . < br >
 * If title index is < 0 returns " ? " . < br >
 * If title index is > 5 returns " ? " . < br >
 * @ param mtLv - method level
 * @ param title _ I - title index
 * @ return titles line as string */
public String getTitleLine ( int mtLv , int title_I ) { } }

implementation: String info = "" ; if ( title_I < 0 ) return "?" ; if ( title_I > 5 ) return "?" ; info = "" ; info += BTools . getMtLvESS ( mtLv ) ; info += BTools . getMtLvISS ( ) ; info += "|" ; InfoValues i_IV ; String i_ValuesS = "" ; int i_VSLen = - 1 ; String i_TitleS = "" ; for ( int i = 0 ; i < ivL . size ( ) ; i ++ ) { i_IV = ivL . get ( i ) ; i_ValuesS = i_IV . getValues ( ) ; i_VSLen = i_ValuesS . length ( ) ; i_TitleS = ( title_I < i_IV . titleA . length ) ? i_IV . titleA [ title_I ] : "" ; i_TitleS = i_TitleS + BTools . getSpaces ( i_VSLen ) ; info += i_TitleS . substring ( 0 , i_VSLen - 1 ) ; info += "|" ; } return info ;


signature:
public class InfoLine { /** * Returns values line as string . < br >
 * Columns are separated with char ' | ' . < br >
 * @ param mtLv - method level
 * @ return values line as string */
public String getValuesLine ( int mtLv ) { } }

implementation: String info = "" ; info += BTools . getMtLvESS ( mtLv ) ; info += BTools . getMtLvISS ( ) ; info += "|" ; InfoValues i_IV ; for ( int i = 0 ; i < ivL . size ( ) ; i ++ ) { i_IV = ivL . get ( i ) ; info += i_IV . getValues ( ) ; } return info ;


signature:
public class CudaEnvironment { /** * Get the current device architecture
 * @ return the major / minor version of
 * the current device */
public int getCurrentDeviceArchitecture ( ) { } }

implementation: int deviceId = Nd4j . getAffinityManager ( ) . getDeviceForCurrentThread ( ) ; if ( ! arch . containsKey ( deviceId ) ) { int major = NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) . getDeviceMajor ( new CudaPointer ( deviceId ) ) ; int minor = NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) . getDeviceMinor ( new CudaPointer ( deviceId ) ) ; Integer cc = Integer . parseInt ( new String ( "" + major + minor ) ) ; arch . put ( deviceId , cc ) ; return cc ; } return arch . get ( deviceId ) ;


signature:
public class BaseSparseNDArrayCOO { /** * Returns a subset of this array based on the specified
 * indexes
 * @ param indexes the indexes in to the array
 * @ return a view of the array with the specified indices */
@ Override public INDArray get ( INDArrayIndex ... indexes ) { } }

implementation:
sort ( ) ; if ( indexes . length == 1 && indexes [ 0 ] instanceof NDArrayIndexAll || ( indexes . length == 2 && ( isRowVector ( ) && indexes [ 0 ] instanceof PointIndex && indexes [ 0 ] . offset ( ) == 0 && indexes [ 1 ] instanceof NDArrayIndexAll || isColumnVector ( ) && indexes [ 1 ] instanceof PointIndex && indexes [ 0 ] . offset ( ) == 0 && indexes [ 0 ] instanceof NDArrayIndexAll ) ) ) return this ; indexes = NDArrayIndex . resolve ( shapeInfoDataBuffer ( ) , indexes ) ; ShapeOffsetResolution resolution = new ShapeOffsetResolution ( this ) ; resolution . exec ( indexes ) ; if ( indexes . length < 1 ) throw new IllegalStateException ( "Invalid index found of zero length" ) ; // FIXME : LONG
int [ ] shape = LongUtils . toInts ( resolution . getShapes ( ) ) ; int numSpecifiedIndex = 0 ; for ( int i = 0 ; i < indexes . length ; i ++ ) if ( indexes [ i ] instanceof SpecifiedIndex ) numSpecifiedIndex ++ ; if ( shape != null && numSpecifiedIndex > 0 ) { Generator < List < List < Long > > > gen = SpecifiedIndex . iterateOverSparse ( indexes ) ; INDArray ret = Nd4j . createSparseCOO ( new double [ ] { } , new int [ ] [ ] { } , shape ) ; int count = 0 ; int maxValue = ArrayUtil . prod ( shape ( ) ) ; while ( count < maxValue ) { try { List < List < Long > > next = gen . next ( ) ; List < Integer > coordsCombo = new ArrayList < > ( ) ; List < Integer > cooIdx = new ArrayList < > ( ) ; for ( int i = 0 ; i < next . size ( ) ; i ++ ) { if ( next . get ( i ) . size ( ) != 2 ) throw new IllegalStateException ( "Illegal entry returned" ) ; coordsCombo . add ( next . get ( i ) . get ( 0 ) . intValue ( ) ) ; cooIdx . add ( next . get ( i ) . get ( 1 ) . intValue ( ) ) ; } count ++ ; /* * if the coordinates are in the original array
 * - > add it in the new sparse ndarray
 * else
 * - > do nothing */
int [ ] idx = Ints . toArray ( coordsCombo ) ; if ( ! isZero ( idx ) ) { double val = getDouble ( idx ) ; ret . putScalar ( filterOutFixedDimensions ( resolution . getFixed ( ) , cooIdx ) , val ) ; } } catch ( NoSuchElementException e ) { break ; } } return ret ; } int numNewAxis = 0 ; for ( int i = 0 ; i < indexes . length ; i ++ ) if ( indexes [ i ] instanceof NewAxis ) numNewAxis ++ ; if ( numNewAxis != 0 ) { } INDArray ret = subArray ( resolution ) ; return ret ;


signature:
public class BaseSparseNDArrayCOO { /** * Adjust the flags array according on the current context :
 * - In case of a vector or a scalar , we need to keep flags to 0
 * - There must always be at least 2 non - flags dimensions
 * - We must keep the flags dimensions of the original array
 * @ param viewFlags the Fixed array calculate within the view
 * @ param newShape the shape of the view */
private int [ ] updateFlags ( int [ ] viewFlags , int [ ] newShape ) { } }

implementation:
// Check if flags is well - formed
int count = 0 ; for ( int i = 0 ; i < viewFlags . length ; i ++ ) { if ( viewFlags [ i ] == 0 ) { count ++ ; } } for ( int dim = 0 ; dim < viewFlags . length ; dim ++ ) { if ( viewFlags [ dim ] == 1 ) { if ( newShape [ dim ] == 1 && count < 2 ) { viewFlags [ dim ] = 0 ; } } } // Take the original Fixed into account
int [ ] extendedFlags = new int [ underlyingRank ( ) ] ; int notFixedDim = 0 ; for ( int dim = 0 ; dim < underlyingRank ( ) ; dim ++ ) { int [ ] temp = flags ( ) ; if ( flags ( ) [ dim ] == 0 ) { extendedFlags [ dim ] = viewFlags [ notFixedDim ] ; notFixedDim ++ ; } else { extendedFlags [ dim ] = 1 ; } } return extendedFlags ;


signature:
public class Convolution { /** * Rearrange matrix
 * columns into blocks
 * @ param col the column
 * transposed image to convert
 * @ param sy stride y
 * @ param sx stride x
 * @ param ph padding height
 * @ param pw padding width
 * @ param h height
 * @ param w width
 * @ return */
public static INDArray col2im ( INDArray col , int sy , int sx , int ph , int pw , int h , int w ) { } }

implementation: if ( col . rank ( ) != 6 ) throw new IllegalArgumentException ( "col2im input array must be rank 6" ) ; INDArray output = Nd4j . create ( new long [ ] { col . size ( 0 ) , col . size ( 1 ) , h , w } ) ; Col2Im col2Im = Col2Im . builder ( ) . inputArrays ( new INDArray [ ] { col } ) . outputs ( new INDArray [ ] { output } ) . conv2DConfig ( Conv2DConfig . builder ( ) . sy ( sy ) . sx ( sx ) . dw ( 1 ) . dh ( 1 ) . kh ( h ) . kw ( w ) . ph ( ph ) . pw ( pw ) . build ( ) ) . build ( ) ; Nd4j . getExecutioner ( ) . exec ( col2Im ) ; return col2Im . outputArguments ( ) [ 0 ] ;


signature:
public class Convolution { /** * Pooling 2d implementation
 * @ param img
 * @ param kh
 * @ param kw
 * @ param sy
 * @ param sx
 * @ param ph
 * @ param pw
 * @ param dh
 * @ param dw
 * @ param isSameMode
 * @ param type
 * @ param extra optional argument . I . e . used in pnorm pooling .
 * @ param virtualHeight
 * @ param virtualWidth
 * @ param out
 * @ return */
public static INDArray pooling2D ( INDArray img , int kh , int kw , int sy , int sx , int ph , int pw , int dh , int dw , boolean isSameMode , Pooling2D . Pooling2DType type , Pooling2D . Divisor divisor , double extra , int virtualHeight , int virtualWidth , INDArray out ) { } }

implementation: Pooling2D pooling = Pooling2D . builder ( ) . arrayInputs ( new INDArray [ ] { img } ) . arrayOutputs ( new INDArray [ ] { out } ) . config ( Pooling2DConfig . builder ( ) . dh ( dh ) . dw ( dw ) . extra ( extra ) . kh ( kh ) . kw ( kw ) . ph ( ph ) . pw ( pw ) . isSameMode ( isSameMode ) . sx ( sx ) . sy ( sy ) . virtualHeight ( virtualHeight ) . virtualWidth ( virtualWidth ) . type ( type ) . divisor ( divisor ) . build ( ) ) . build ( ) ; Nd4j . getExecutioner ( ) . exec ( pooling ) ; return out ;


signature:
public class Convolution { /** * Implement column formatted images
 * @ param img the image to process
 * @ param kh the kernel height
 * @ param kw the kernel width
 * @ param sy the stride along y
 * @ param sx the stride along x
 * @ param ph the padding width
 * @ param pw the padding height
 * @ param pval the padding value ( not used )
 * @ param isSameMode whether padding mode is ' same '
 * @ return the column formatted image */
public static INDArray im2col ( INDArray img , int kh , int kw , int sy , int sx , int ph , int pw , int pval , boolean isSameMode ) { } }

implementation:
INDArray output = null ; if ( isSameMode ) { int oH = ( int ) Math . ceil ( img . size ( 2 ) * 1.f / sy ) ; int oW = ( int ) Math . ceil ( img . size ( 3 ) * 1.f / sx ) ; output = Nd4j . createUninitialized ( new long [ ] { img . size ( 0 ) , img . size ( 1 ) , kh , kw , oH , oW } , 'c' ) ; } else { // FIXME : int cast
int oH = ( ( int ) img . size ( 2 ) - ( kh + ( kh - 1 ) * ( 1 - 1 ) ) + 2 * ph ) / sy + 1 ; int oW = ( ( int ) img . size ( 3 ) - ( kw + ( kw - 1 ) * ( 1 - 1 ) ) + 2 * pw ) / sx + 1 ; output = Nd4j . createUninitialized ( new long [ ] { img . size ( 0 ) , img . size ( 1 ) , kh , kw , oH , oW } , 'c' ) ; } Im2col im2col = Im2col . builder ( ) . inputArrays ( new INDArray [ ] { img } ) . outputs ( new INDArray [ ] { output } ) . conv2DConfig ( Conv2DConfig . builder ( ) . kh ( kh ) . pw ( pw ) . ph ( ph ) . sy ( sy ) . sx ( sx ) . kw ( kw ) . kh ( kh ) . dw ( 1 ) . dh ( 1 ) . isSameMode ( isSameMode ) . build ( ) ) . build ( ) ; Nd4j . getExecutioner ( ) . exec ( im2col ) ; return im2col . outputArguments ( ) [ 0 ] ;


signature:
public class Convolution { /** * 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 */
public static IComplexNDArray convn ( IComplexNDArray input , IComplexNDArray kernel , Type type , int [ ] axes ) { } }

implementation: return Nd4j . getConvolution ( ) . convn ( input , kernel , type , axes ) ;


signature:
public class CompressionDescriptor { /** * Instantiate a compression descriptor from
 * the given bytebuffer
 * @ param byteBuffer the bytebuffer to instantiate
 * the descriptor from
 * @ return the instantiated descriptor based on the given
 * bytebuffer */
public static CompressionDescriptor fromByteBuffer ( ByteBuffer byteBuffer ) { } }

implementation:
CompressionDescriptor compressionDescriptor = new CompressionDescriptor ( ) ; // compression opType
int compressionTypeOrdinal = byteBuffer . getInt ( ) ; CompressionType compressionType = CompressionType . values ( ) [ compressionTypeOrdinal ] ; compressionDescriptor . setCompressionType ( compressionType ) ; // compression algo
int compressionAlgoOrdinal = byteBuffer . getInt ( ) ; CompressionAlgorithm compressionAlgorithm = CompressionAlgorithm . values ( ) [ compressionAlgoOrdinal ] ; compressionDescriptor . setCompressionAlgorithm ( compressionAlgorithm . name ( ) ) ; // from here everything is longs
compressionDescriptor . setOriginalLength ( byteBuffer . getLong ( ) ) ; compressionDescriptor . setCompressedLength ( byteBuffer . getLong ( ) ) ; compressionDescriptor . setNumberOfElements ( byteBuffer . getLong ( ) ) ; compressionDescriptor . setOriginalElementSize ( byteBuffer . getLong ( ) ) ; return compressionDescriptor ;


signature:
public class CompressionDescriptor { /** * Return a direct allocated
 * bytebuffer from the compression codec .
 * The size of the bytebuffer is calculated to be :
 * 40 : 8 + 32
 * two ints representing their enum values
 * for the compression algorithm and opType
 * and 4 longs for the compressed and
 * original sizes
 * @ return the bytebuffer described above */
public ByteBuffer toByteBuffer ( ) { } }

implementation:
// 2 ints at 4 bytes a piece , this includes the compression algorithm
// that we convert to enum
int enumSize = 2 * 4 ; // 4 longs at 8 bytes a piece
int sizesLength = 4 * 8 ; ByteBuffer directAlloc = ByteBuffer . allocateDirect ( enumSize + sizesLength ) . order ( ByteOrder . nativeOrder ( ) ) ; directAlloc . putInt ( compressionType . ordinal ( ) ) ; directAlloc . putInt ( CompressionAlgorithm . valueOf ( compressionAlgorithm ) . ordinal ( ) ) ; directAlloc . putLong ( originalLength ) ; directAlloc . putLong ( compressedLength ) ; directAlloc . putLong ( numberOfElements ) ; directAlloc . putLong ( originalElementSize ) ; directAlloc . rewind ( ) ; return directAlloc ;


signature:
public class Batch { /** * Helper method to create batch from list of aggregates , for cases when list of aggregates is higher then batchLimit
 * @ param list
 * @ param < U >
 * @ return */
public static < U extends Aggregate > List < Batch < U > > getBatches ( List < U > list , int partitionSize ) { } }

implementation: List < List < U > > partitions = Lists . partition ( list , partitionSize ) ; List < Batch < U > > split = new ArrayList < > ( ) ; for ( List < U > partition : partitions ) { split . add ( new Batch < U > ( partition ) ) ; } return split ;


signature:
public class AdaMaxUpdater { /** * Calculate the update based on the given gradient
 * @ param gradient the gradient to get the update for
 * @ param iteration
 * @ return the gradient */
@ Override public void applyUpdater ( INDArray gradient , int iteration , int epoch ) { } }

implementation:
if ( m == null || u == null ) throw new IllegalStateException ( "Updater has not been initialized with view state" ) ; // m = B _ 1 * m + ( 1 - B _ 1 ) * grad
m . muli ( config . getBeta1 ( ) ) . addi ( gradient . mul ( 1 - config . getBeta1 ( ) ) ) ; // u = max ( B _ 2 * u , | grad | )
u . muli ( config . getBeta2 ( ) ) ; Transforms . abs ( gradient , false ) ; // In - place should be OK here , original gradient values aren ' t used again later
Nd4j . getExecutioner ( ) . exec ( new OldMax ( u , gradient , u , u . length ( ) ) ) ; double beta1t = FastMath . pow ( config . getBeta1 ( ) , iteration + 1 ) ; double learningRate = config . getLearningRate ( iteration , epoch ) ; double alphat = learningRate / ( 1.0 - beta1t ) ; if ( Double . isNaN ( alphat ) || Double . isInfinite ( alphat ) || alphat == 0.0 ) { alphat = config . getEpsilon ( ) ; } u . addi ( 1e-32 ) ; // prevent NaNs in params
gradient . assign ( m ) . muli ( alphat ) . divi ( u ) ;


signature:
public class BaseNDArrayFactory { /** * input arrays must have same number of dimensions */
protected static void validateConcat ( int dimension , INDArray ... arrs ) { } }

implementation: if ( arrs [ 0 ] . isScalar ( ) ) { for ( int i = 1 ; i < arrs . length ; i ++ ) if ( ! arrs [ i ] . isScalar ( ) ) throw new IllegalArgumentException ( "All arrays must have same dimensions" ) ; } else { int dims = arrs [ 0 ] . shape ( ) . length ; long [ ] shape = ArrayUtil . removeIndex ( arrs [ 0 ] . shape ( ) , dimension ) ; for ( int i = 1 ; i < arrs . length ; i ++ ) { assert Arrays . equals ( shape , ArrayUtil . removeIndex ( arrs [ i ] . shape ( ) , dimension ) ) ; assert arrs [ i ] . shape ( ) . length == dims ; } }


signature:
public class BaseNDArrayFactory { /** * Sets the data opType
 * @ param dtype */
@ Override public void setDType ( DataBuffer . Type dtype ) { } }

implementation: assert dtype == DataBuffer . Type . DOUBLE || dtype == DataBuffer . Type . FLOAT || dtype == DataBuffer . Type . INT : "Invalid opType passed, must be float or double" ; // this . dtype = dtype ;


signature:
public class BaseNDArrayFactory { /** * Generate a linearly spaced vector
 * @ param lower upper bound
 * @ param upper lower bound
 * @ param num the step size
 * @ return the linearly spaced vector */
@ Override public INDArray linspace ( int lower , int upper , int num ) { } }

implementation:
double [ ] data = new double [ num ] ; for ( int i = 0 ; i < num ; i ++ ) { double t = ( double ) i / ( num - 1 ) ; data [ i ] = lower * ( 1 - t ) + t * upper ; } // edge case for scalars
INDArray ret = Nd4j . create ( data . length ) ; if ( ret . isScalar ( ) ) return ret ; for ( int i = 0 ; i < ret . length ( ) ; i ++ ) ret . putScalar ( i , data [ i ] ) ; return ret ;


signature:
public class BaseNDArrayFactory { /** * Returns a vector with all of the elements in every nd array
 * equal to the sum of the lengths of the ndarrays
 * @ param matrices the ndarrays to getFloat a flattened representation of
 * @ return the flattened ndarray */
@ Override public INDArray toFlattened ( Collection < INDArray > matrices ) { } }

implementation: int length = 0 ; for ( INDArray m : matrices ) length += m . length ( ) ; INDArray ret = Nd4j . create ( 1 , length ) ; int linearIndex = 0 ; for ( INDArray d : matrices ) { ret . put ( new INDArrayIndex [ ] { NDArrayIndex . interval ( linearIndex , linearIndex + d . length ( ) ) } , d ) ; linearIndex += d . length ( ) ; } return ret ;


signature:
public class BaseNDArrayFactory { /** * Returns a column vector where each entry is the nth bilinear
 * product of the nth slices of the two tensors . */
@ Override public INDArray bilinearProducts ( INDArray curr , INDArray in ) { } }

implementation: assert curr . shape ( ) . length == 3 ; if ( in . columns ( ) != 1 ) { throw new AssertionError ( "Expected a column vector" ) ; } if ( in . rows ( ) != curr . size ( curr . shape ( ) . length - 1 ) ) { throw new AssertionError ( "Number of rows in the input does not match number of columns in tensor" ) ; } if ( curr . size ( curr . shape ( ) . length - 2 ) != curr . size ( curr . shape ( ) . length - 1 ) ) { throw new AssertionError ( "Can only perform this operation on a SimpleTensor with square slices" ) ; } INDArray ret = Nd4j . create ( curr . slices ( ) , 1 ) ; INDArray inT = in . transpose ( ) ; for ( int i = 0 ; i < curr . slices ( ) ; i ++ ) { INDArray slice = curr . slice ( i ) ; INDArray inTTimesSlice = inT . mmul ( slice ) ; ret . putScalar ( i , Nd4j . getBlasWrapper ( ) . dot ( inTTimesSlice , in ) ) ; } return ret ;


signature:
public class BaseNDArrayFactory { /** * Reverses the passed in matrix such that m [ 0 ] becomes m [ m . length - 1 ] etc
 * @ param reverse the matrix to reverse
 * @ return the reversed matrix */
@ Override public INDArray reverse ( INDArray reverse ) { } }

implementation:
// FIXME : native method should be used instead
INDArray rev = reverse . linearView ( ) ; INDArray ret = Nd4j . create ( rev . shape ( ) ) ; int count = 0 ; for ( long i = rev . length ( ) - 1 ; i >= 0 ; i -- ) { ret . putScalar ( count ++ , rev . getFloat ( i ) ) ; } return ret . reshape ( reverse . shape ( ) ) ;


signature:
public class BaseNDArrayFactory { /** * Merge the vectors and append a bias .
 * Each vector must be either row or column vectors .
 * An exception is thrown for inconsistency ( mixed row and column vectors )
 * @ param vectors the vectors to merge
 * @ return the merged ndarray appended with the bias */
@ Override public INDArray appendBias ( INDArray ... vectors ) { } }

implementation: int size = 0 ; for ( INDArray vector : vectors ) { size += vector . rows ( ) ; } INDArray result = Nd4j . create ( size + 1 , vectors [ 0 ] . columns ( ) ) ; int index = 0 ; for ( INDArray vector : vectors ) { INDArray put = toFlattened ( vector , Nd4j . ones ( 1 ) ) ; result . put ( new INDArrayIndex [ ] { NDArrayIndex . interval ( index , index + vector . rows ( ) + 1 ) , NDArrayIndex . interval ( 0 , vectors [ 0 ] . columns ( ) ) } , put ) ; index += vector . rows ( ) ; } return result ;


signature:
public class BaseNDArrayFactory { /** * Create a random ( uniform 0-1 ) NDArray with the specified shape and order
 * @ param order Order ( ' c ' or ' f ' ) of the output array
 * @ param rows Number of rows of the output array
 * @ param columns Number of columns of the output array */
@ Override public INDArray rand ( char order , long rows , long columns ) { } }

implementation: return Nd4j . getRandom ( ) . nextDouble ( order , new long [ ] { rows , columns } ) ;


signature:
public class BaseNDArrayFactory { /** * Generate a random normal N ( 0,1 ) with the specified order and shape
 * @ param order Order of the output array
 * @ param rows the number of rows in the matrix
 * @ param columns the number of columns in the matrix
 * @ return */
@ Override public INDArray randn ( char order , long rows , long columns ) { } }

implementation: return Nd4j . getRandom ( ) . nextGaussian ( order , new long [ ] { rows , columns } ) ;


signature:
public class BaseNDArrayFactory { /** * Creates an ndarray with the specified data
 * @ param data the number of columns in the row vector
 * @ return ndarray */
@ Override public IComplexNDArray createComplex ( double [ ] data ) { } }

implementation: assert data . length % 2 == 0 : "Length of data must be even. A complex ndarray is made up of pairs of real and imaginary components" ; return createComplex ( data , new int [ ] { 1 , data . length / 2 } ) ;


signature:
public class BaseNDArrayFactory { /** * Creates an 1 x num ndarray with the specified value
 * @ param num the number of columns
 * @ param value the value to assign
 * @ return a complex ndarray of the specified size
 * and value */
@ Override public IComplexNDArray complexValueOf ( int num , double value ) { } }

implementation: IComplexNDArray ones = complexOnes ( num ) ; ones . assign ( Nd4j . createDouble ( value , 0.0 ) ) ; return ones ;


signature:
public class BaseNDArrayFactory { /** * Creates an shape ndarray with the specified value
 * @ param shape the shape of the ndarray
 * @ param value the value to assign
 * @ return a complex ndarray of the specified size
 * and value */
@ Override public IComplexNDArray complexValueOf ( int [ ] shape , double value ) { } }

implementation: IComplexNDArray ones = complexOnes ( shape ) ; ones . assign ( Nd4j . scalar ( value ) ) ; return ones ;


signature:
public class BaseNDArrayFactory { /** * concatenate ndarrays along a dimension
 * @ param dimension the dimension to concatenate along
 * @ param toConcat the ndarrays to concatenate
 * @ return the concatenate ndarrays */
@ Override public INDArray concat ( int dimension , INDArray ... toConcat ) { } }

implementation:
if ( toConcat . length == 1 ) return toConcat [ 0 ] ; int sumAlongDim = 0 ; boolean allC = toConcat [ 0 ] . ordering ( ) == 'c' ; long [ ] outputShape = ArrayUtil . copy ( toConcat [ 0 ] . shape ( ) ) ; outputShape [ dimension ] = sumAlongDim ; for ( int i = 0 ; i < toConcat . length ; i ++ ) { sumAlongDim += toConcat [ i ] . size ( dimension ) ; allC = allC && toConcat [ i ] . ordering ( ) == 'c' ; for ( int j = 0 ; j < toConcat [ i ] . rank ( ) ; j ++ ) { if ( j != dimension && toConcat [ i ] . size ( j ) != outputShape [ j ] && ! toConcat [ i ] . isVector ( ) ) { throw new IllegalArgumentException ( "Illegal concatenation at array " + i + " and shape element " + j ) ; } } } long [ ] sortedStrides = Nd4j . getStrides ( outputShape ) ; INDArray ret = Nd4j . create ( outputShape , sortedStrides ) ; allC &= ( ret . ordering ( ) == 'c' ) ; if ( toConcat [ 0 ] . isScalar ( ) ) { INDArray retLinear = ret . linearView ( ) ; for ( int i = 0 ; i < retLinear . length ( ) ; i ++ ) retLinear . putScalar ( i , toConcat [ i ] . getDouble ( 0 ) ) ; return ret ; } if ( dimension == 0 && allC ) { int currBuffer = 0 ; int currBufferOffset = 0 ; for ( int i = 0 ; i < ret . length ( ) ; i ++ ) { ret . data ( ) . put ( i , toConcat [ currBuffer ] . data ( ) . getDouble ( toConcat [ currBuffer ] . offset ( ) + currBufferOffset ++ ) ) ; if ( currBufferOffset >= toConcat [ currBuffer ] . length ( ) ) { currBuffer ++ ; currBufferOffset = 0 ; } } return ret ; } int arrOffset = 0 ; // FIXME : int cast
INDArray [ ] retAlongDimensionArrays = new INDArray [ ( int ) ret . tensorssAlongDimension ( dimension ) ] ; for ( int i = 0 ; i < retAlongDimensionArrays . length ; i ++ ) retAlongDimensionArrays [ i ] = ret . tensorAlongDimension ( i , dimension ) ; for ( INDArray arr : toConcat ) { long arrTensorLength = - 1 ; if ( arr . tensorssAlongDimension ( dimension ) != ret . tensorssAlongDimension ( dimension ) ) throw new IllegalStateException ( "Illegal concatenate. Tensors along dimension must be same length." ) ; for ( int i = 0 ; i < arr . tensorssAlongDimension ( dimension ) ; i ++ ) { INDArray retLinear = retAlongDimensionArrays [ i ] ; INDArray arrTensor = arr . tensorAlongDimension ( i , dimension ) ; arrTensorLength = arrTensor . length ( ) ; for ( int j = 0 ; j < arrTensor . length ( ) ; j ++ ) { int idx = j + arrOffset ; retLinear . putScalar ( idx , arrTensor . getDouble ( j ) ) ; } } // bump the sliding window
arrOffset += arrTensorLength ; } return ret ;


signature:
public class BaseNDArrayFactory { /** * Create an ndarray of ones
 * @ param shape the shape of the ndarray
 * @ return an ndarray with ones filled in */
@ Override public INDArray ones ( int [ ] shape ) { } }

implementation:
// ensure shapes that wind up being scalar end up with the write shape
if ( shape . length == 1 && shape [ 0 ] == 0 ) { shape = new int [ ] { 1 , 1 } ; } INDArray ret = create ( shape ) ; ret . assign ( 1 ) ; return ret ;


signature:
public class BaseNDArrayFactory { /** * Create an ndarray of ones
 * @ param shape the shape of the ndarray
 * @ return an ndarray with ones filled in */
@ Override public IComplexNDArray complexOnes ( int [ ] shape ) { } }

implementation: IComplexNDArray ret = createComplex ( shape ) ; ret . assign ( 1 ) ; return ret ;


signature:
public class BaseNDArrayFactory { /** * Creates a complex ndarray with the specified shape
 * @ param data the data to use with the ndarray
 * @ param shape the shape of the ndarray
 * @ param stride the stride for the ndarray
 * @ param offset the offset of the ndarray
 * @ return the instance */
public IComplexNDArray createComplex ( float [ ] data , int [ ] shape , int [ ] stride , long offset ) { } }

implementation:
// ensure shapes that wind up being scalar end up with the write shape
if ( shape . length == 1 && shape [ 0 ] == 0 ) { shape = new int [ ] { 1 , 1 } ; } return createComplex ( Nd4j . createBuffer ( data ) , shape , stride , offset , Nd4j . order ( ) ) ;


signature:
public class BaseNDArrayFactory { /** * Create an ndrray with the specified shape
 * @ param data the data to use with tne ndarray
 * @ param shape the shape of the ndarray
 * @ return the created ndarray */
@ Override public INDArray create ( float [ ] data , int [ ] shape ) { } }

implementation:
// ensure shapes that wind up being scalar end up with the write shape
if ( shape . length == 1 && shape [ 0 ] == 0 ) { shape = new int [ ] { 1 , 1 } ; } return create ( data , shape , Nd4j . getStrides ( shape ) , 0 ) ;


signature:
public class BaseNDArrayFactory { /** * Create an ndrray with the specified shape
 * @ param data the data to use with tne ndarray
 * @ param shape the shape of the ndarray
 * @ return the created ndarray */
@ Override public IComplexNDArray createComplex ( double [ ] data , int [ ] shape ) { } }

implementation:
// ensure shapes that wind up being scalar end up with the write shape
if ( shape . length == 1 && shape [ 0 ] == 0 ) { shape = new int [ ] { 1 , 1 } ; } return createComplex ( data , shape , Nd4j . getComplexStrides ( shape ) , 0 ) ;


signature:
public class BaseNDArrayFactory { /** * Create an ndrray with the specified shape
 * @ param data the data to use with tne ndarray
 * @ param shape the shape of the ndarray
 * @ param stride the stride for the ndarray
 * @ return the created ndarray */
@ Override public IComplexNDArray createComplex ( float [ ] data , int [ ] shape , int [ ] stride ) { } }

implementation: return createComplex ( data , shape , stride , 0 ) ;


signature:
public class BaseNDArrayFactory { /** * Creates a complex ndarray with the specified shape
 * @ param shape the shape of the ndarray
 * @ param stride the stride for the ndarray
 * @ param offset the offset of the ndarray
 * @ return the instance */
public IComplexNDArray createComplex ( int [ ] shape , int [ ] stride , long offset ) { } }

implementation: if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) return createComplex ( new double [ ArrayUtil . prod ( shape ) * 2 ] , shape , stride , offset ) ; if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT || Nd4j . dataType ( ) == DataBuffer . Type . HALF ) return createComplex ( new float [ ArrayUtil . prod ( shape ) * 2 ] , shape , stride , offset ) ; throw new IllegalStateException ( "Illegal data opType " + Nd4j . dataType ( ) ) ;


signature:
public class BaseNDArrayFactory { /** * Create a scalar ndarray with the specified offset
 * @ param value the value to initialize the scalar with
 * @ param offset the offset of the ndarray
 * @ return the created ndarray */
@ Override public IComplexNDArray complexScalar ( Number value , long offset ) { } }

implementation: if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) return scalar ( createDouble ( value . doubleValue ( ) , 0 ) , offset ) ; if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT || Nd4j . dataType ( ) == DataBuffer . Type . INT || Nd4j . dataType ( ) == DataBuffer . Type . HALF ) return scalar ( createFloat ( value . floatValue ( ) , 0 ) , offset ) ; throw new IllegalStateException ( "Illegal data opType " + Nd4j . dataType ( ) ) ;


signature:
public class BaseNDArrayFactory { /** * Create a scalar nd array with the specified value and offset
 * @ param value the value of the scalar
 * = * @ return the scalar nd array */
@ Override public INDArray scalar ( float value ) { } }

implementation: if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT || Nd4j . dataType ( ) == DataBuffer . Type . HALF ) return create ( new float [ ] { value } , new int [ ] { 1 , 1 } , new int [ ] { 1 , 1 } , 0 ) ; else if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) return scalar ( ( double ) value ) ; else return scalar ( ( int ) value ) ;


signature:
public class BaseNDArrayFactory { /** * Create a scalar nd array with the specified value and offset
 * @ param value the value of the scalar
 * @ return the scalar nd array */
@ Override public INDArray scalar ( double value ) { } }

implementation: if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) return create ( new double [ ] { value } , new int [ ] { 1 , 1 } , new int [ ] { 1 , 1 } , 0 ) ; else return scalar ( ( float ) value ) ;


signature:
public class BaseNDArrayFactory { /** * Create a scalar ndarray with the specified offset
 * @ param value the value to initialize the scalar with
 * @ param offset the offset of the ndarray
 * @ return the created ndarray */
@ Override public IComplexNDArray scalar ( IComplexNumber value , long offset ) { } }

implementation: if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) return scalar ( value . asDouble ( ) , offset ) ; if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT || Nd4j . dataType ( ) == DataBuffer . Type . HALF ) return scalar ( value . asFloat ( ) , offset ) ; throw new IllegalStateException ( "Illegal data opType " + Nd4j . dataType ( ) ) ;


signature:
public class BaseNDArrayFactory { /** * Create a scalar nd array with the specified value and offset
 * @ param value the value of the scalar
 * @ return the scalar nd array */
@ Override public IComplexNDArray scalar ( IComplexFloat value ) { } }

implementation: return createComplex ( new float [ ] { value . realComponent ( ) , value . imaginaryComponent ( ) } , new int [ ] { 1 } , new int [ ] { 1 } , 0 ) ;


signature:
public class TimeDelayedParameterUpdater { /** * Returns true if
 * the updater has accumulated enough ndarrays to
 * replicate to the workers
 * @ return true if replication should happen , false otherwise */
@ Override public boolean shouldReplicate ( ) { } }

implementation: long now = System . currentTimeMillis ( ) ; long diff = Math . abs ( now - lastSynced ) ; return diff > syncTime ;


signature:
public class BaseComplexDouble { /** * Subtract two complex numbers , in - place
 * @ param c
 * @ param result */
@ Override public IComplexNumber subi ( IComplexNumber c , IComplexNumber result ) { } }

implementation: return result . set ( realComponent ( ) . doubleValue ( ) - c . realComponent ( ) . doubleValue ( ) , imaginaryComponent ( ) . doubleValue ( ) - c . imaginaryComponent ( ) . doubleValue ( ) ) ;


signature:
public class BaseComplexDouble { /** * Multiply two complex numbers , inplace
 * @ param c
 * @ param result */
@ Override public IComplexNumber muli ( IComplexNumber c , IComplexNumber result ) { } }

implementation: double newR = real * c . realComponent ( ) . doubleValue ( ) - imag * c . imaginaryComponent ( ) . doubleValue ( ) ; double newI = real * c . imaginaryComponent ( ) . doubleValue ( ) + imag * c . realComponent ( ) . doubleValue ( ) ; result . set ( newR , newI ) ; return result ;


signature:
public class BaseComplexDouble { /** * Divide two complex numbers , in - place
 * @ param c
 * @ param result */
@ Override public IComplexNumber divi ( IComplexNumber c , IComplexNumber result ) { } }

implementation: double d = c . realComponent ( ) . doubleValue ( ) * c . realComponent ( ) . doubleValue ( ) + c . imaginaryComponent ( ) . doubleValue ( ) * c . imaginaryComponent ( ) . doubleValue ( ) ; double newR = ( realComponent ( ) * c . realComponent ( ) . doubleValue ( ) + imaginaryComponent ( ) * c . imaginaryComponent ( ) . doubleValue ( ) ) / d ; double newI = ( imaginaryComponent ( ) * c . realComponent ( ) . doubleValue ( ) - realComponent ( ) * c . imaginaryComponent ( ) . doubleValue ( ) ) / d ; result . set ( newR , newI ) ; return result ;


signature:
public class ComplexUtil { /** * Create complex number where the
 * @ param realComponents the real components for the complex
 * @ return the complex numbers based on the given real components */
public static IComplexNumber [ ] [ ] complexNumbersFor ( float [ ] [ ] realComponents ) { } }

implementation: IComplexNumber [ ] [ ] ret = new IComplexNumber [ realComponents . length ] [ realComponents [ 0 ] . length ] ; for ( int i = 0 ; i < realComponents . length ; i ++ ) for ( int j = 0 ; j < realComponents [ i ] . length ; j ++ ) ret [ i ] [ j ] = Nd4j . createComplexNumber ( realComponents [ i ] [ j ] , 0 ) ; return ret ;


signature:
public class ComplexUtil { /** * Create complex number where the
 * @ param realComponents the real components for the complex
 * @ return the complex numbers based on the given real components */
public static IComplexNumber [ ] complexNumbersFor ( float [ ] realComponents ) { } }

implementation: IComplexNumber [ ] ret = new IComplexNumber [ realComponents . length ] ; for ( int i = 0 ; i < realComponents . length ; i ++ ) ret [ i ] = Nd4j . createComplexNumber ( realComponents [ i ] , 0 ) ; return ret ;


signature:
public class ComplexUtil { /** * Return the sin value of the given complex number
 * @ param num the number to getScalar the absolute value for
 * @ return the absolute value of this complex number */
public static IComplexNumber atan ( IComplexNumber num ) { } }

implementation: Complex c = new Complex ( num . realComponent ( ) . doubleValue ( ) , num . imaginaryComponent ( ) . doubleValue ( ) ) . atan ( ) ; return Nd4j . createDouble ( c . getReal ( ) , c . getImaginary ( ) ) ;


signature:
public class ComplexUtil { /** * Return the ceiling value of the given complex number
 * @ param num the number to getScalar the absolute value for
 * @ return the absolute value of this complex number */
public static IComplexNumber ceil ( IComplexNumber num ) { } }

implementation: Complex c = new Complex ( FastMath . ceil ( num . realComponent ( ) . doubleValue ( ) ) , FastMath . ceil ( num . imaginaryComponent ( ) . doubleValue ( ) ) ) ; return Nd4j . createDouble ( c . getReal ( ) , c . getImaginary ( ) ) ;


signature:
public class ComplexUtil { /** * Return the log value of the given complex number
 * @ param num the number to getScalar the absolute value for
 * @ return the absolute value of this complex number */
public static IComplexNumber neg ( IComplexNumber num ) { } }

implementation: Complex c = new Complex ( num . realComponent ( ) . doubleValue ( ) , num . imaginaryComponent ( ) . doubleValue ( ) ) . negate ( ) ; return Nd4j . createDouble ( c . getReal ( ) , c . getImaginary ( ) ) ;


signature:
public class ComplexUtil { /** * Return the absolute value of the given complex number
 * @ param num the number to getScalar the absolute value for
 * @ return the absolute value of this complex number */
public static IComplexNumber abs ( IComplexNumber num ) { } }

implementation: double c = new Complex ( num . realComponent ( ) . doubleValue ( ) , num . imaginaryComponent ( ) . doubleValue ( ) ) . abs ( ) ; return Nd4j . createDouble ( c , 0 ) ;


signature:
public class ComplexUtil { /** * Raise a complex number to a power
 * @ param num the number to raise
 * @ param power the power to raise to
 * @ return the number raised to a power */
public static IComplexNumber pow ( IComplexNumber num , IComplexNumber power ) { } }

implementation: Complex c = new Complex ( num . realComponent ( ) . doubleValue ( ) , num . imaginaryComponent ( ) . doubleValue ( ) ) . pow ( new Complex ( power . realComponent ( ) . doubleValue ( ) , power . imaginaryComponent ( ) . doubleValue ( ) ) ) ; if ( c . isNaN ( ) ) c = new Complex ( Nd4j . EPS_THRESHOLD , 0.0 ) ; return Nd4j . createDouble ( c . getReal ( ) , c . getImaginary ( ) ) ;


signature:
public class ComplexUtil { /** * Returns the exp of a complex number :
 * Let r be the realComponent component and i be the imaginary
 * Let ret be the complex number returned
 * ret - > exp ( r ) * cos ( i ) , exp ( r ) * sin ( i )
 * where the first number is the realComponent component
 * and the second number is the imaginary component
 * @ param d the number to getFromOrigin the exp of
 * @ return the exponential of this complex number */
public static IComplexNumber exp ( IComplexNumber d ) { } }

implementation: if ( d instanceof IComplexFloat ) return exp ( ( IComplexFloat ) d ) ; return exp ( ( IComplexDouble ) d ) ;


signature:
public class ComplexUtil { /** * Returns the exp of a complex number :
 * Let r be the realComponent component and i be the imaginary
 * Let ret be the complex number returned
 * ret - > exp ( r ) * cos ( i ) , exp ( r ) * sin ( i )
 * where the first number is the realComponent component
 * and the second number is the imaginary component
 * @ param d the number to getFromOrigin the exp of
 * @ return the exponential of this complex number */
public static IComplexDouble exp ( IComplexDouble d ) { } }

implementation: return Nd4j . createDouble ( FastMath . exp ( d . realComponent ( ) ) * FastMath . cos ( d . imaginaryComponent ( ) ) , FastMath . exp ( d . realComponent ( ) ) * FastMath . sin ( d . imaginaryComponent ( ) ) ) ;


signature:
public class ComplexUtil { /** * Returns the exp of a complex number :
 * Let r be the realComponent component and i be the imaginary
 * Let ret be the complex number returned
 * ret - > exp ( r ) * cos ( i ) , exp ( r ) * sin ( i )
 * where the first number is the realComponent component
 * and the second number is the imaginary component
 * @ param d the number to getFromOrigin the exp of
 * @ return the exponential of this complex number */
public static IComplexFloat exp ( IComplexFloat d ) { } }

implementation: return Nd4j . createFloat ( ( float ) FastMath . exp ( d . realComponent ( ) ) * ( float ) FastMath . cos ( d . imaginaryComponent ( ) ) , ( float ) FastMath . exp ( d . realComponent ( ) ) * ( float ) FastMath . sin ( d . imaginaryComponent ( ) ) ) ;


signature:
public class ParameterServerSubscriber { /** * get a context */
public Aeron . Context getContext ( ) { } }

implementation: Aeron . Context ctx = new Aeron . Context ( ) . publicationConnectionTimeout ( - 1 ) . availableImageHandler ( AeronUtil :: printAvailableImage ) . unavailableImageHandler ( AeronUtil :: printUnavailableImage ) . aeronDirectoryName ( mediaDriverDirectoryName ) . keepAliveInterval ( 100000 ) . errorHandler ( e -> log . error ( e . toString ( ) , e ) ) ; return ctx ;


signature:
public class CudaFullCachingProvider { /** * This method frees specific chunk of memory , described by AllocationPoint passed in
 * PLEASE NOTE : This method can actually ignore free , and keep released memory chunk for future reuse .
 * @ param point */
@ Override public void free ( AllocationPoint point ) { } }

implementation:
if ( point . getAllocationStatus ( ) == AllocationStatus . DEVICE ) { if ( point . isConstant ( ) ) return ; AllocationShape shape = point . getShape ( ) ; int deviceId = point . getDeviceId ( ) ; long address = point . getDevicePointer ( ) . address ( ) ; long reqMemory = AllocationUtils . getRequiredMemory ( shape ) ; // we don ' t cache too big objects
if ( reqMemory > CudaEnvironment . getInstance ( ) . getConfiguration ( ) . getMaximumDeviceCacheableLength ( ) || deviceCachedAmount . get ( deviceId ) . get ( ) >= CudaEnvironment . getInstance ( ) . getConfiguration ( ) . getMaximumHostCache ( ) ) { // log . info ( " DEVICE _ { } memory purging : { } bytes ; MS : { } ; MT : { } " , deviceId , reqMemory , MAX _ GPU _ ALLOCATION , MAX _ GPU _ CACHE ) ;
super . free ( point ) ; return ; } // log . info ( " Saving HOST memory into cache . . . " ) ;
ensureDeviceCacheHolder ( deviceId , shape ) ; CacheHolder cache = deviceCache . get ( deviceId ) . get ( shape ) ; if ( point . getDeviceId ( ) != deviceId ) throw new RuntimeException ( "deviceId changed!" ) ; // memory chunks < threshold will be cached no matter what
if ( reqMemory <= FORCED_CACHE_THRESHOLD ) { cache . put ( new CudaPointer ( point . getDevicePointer ( ) . address ( ) ) ) ; return ; } else { long cacheEntries = cache . size ( ) ; long cacheHeight = deviceCache . get ( deviceId ) . size ( ) ; // total memory allocated within this bucket
long cacheDepth = cacheEntries * reqMemory ; // if ( cacheDepth < MAX _ CACHED _ MEMORY / cacheHeight ) {
cache . put ( new CudaPointer ( point . getDevicePointer ( ) . address ( ) ) ) ; return ; // } else {
// super . free ( point ) ;
} } super . free ( point ) ;


signature:
public class BaseSparseNDArrayCSR { /** * Returns a subset of this array based on the specified
 * indexes
 * @ param indexes the indexes in to the array
 * @ return a view of the array with the specified indices */
@ Override public INDArray get ( INDArrayIndex ... indexes ) { } }

implementation:
// check for row / column vector and point index being 0
if ( indexes . length == 1 && indexes [ 0 ] instanceof NDArrayIndexAll || ( indexes . length == 2 && ( isRowVector ( ) && indexes [ 0 ] instanceof PointIndex && indexes [ 0 ] . offset ( ) == 0 && indexes [ 1 ] instanceof NDArrayIndexAll || isColumnVector ( ) && indexes [ 1 ] instanceof PointIndex && indexes [ 0 ] . offset ( ) == 0 && indexes [ 0 ] instanceof NDArrayIndexAll ) ) ) return this ; indexes = NDArrayIndex . resolve ( shapeInfoDataBuffer ( ) , indexes ) ; ShapeOffsetResolution resolution = new ShapeOffsetResolution ( this ) ; resolution . exec ( indexes ) ; if ( indexes . length < 1 ) throw new IllegalStateException ( "Invalid index found of zero length" ) ; // FIXME : LONG
int [ ] shape = LongUtils . toInts ( resolution . getShapes ( ) ) ; int numSpecifiedIndex = 0 ; for ( int i = 0 ; i < indexes . length ; i ++ ) if ( indexes [ i ] instanceof SpecifiedIndex ) numSpecifiedIndex ++ ; if ( shape != null && numSpecifiedIndex > 0 ) { // TODO create a new ndarray with the specified indexes
return null ; } INDArray ret = subArray ( resolution ) ; return ret ;


signature:
public class DataSet { /** * Merge the list of datasets in to one list .
 * All the rows are merged in to one dataset
 * @ param data the data to merge
 * @ return a single dataset */
public static DataSet merge ( List < DataSet > data ) { } }

implementation: if ( data . isEmpty ( ) ) throw new IllegalArgumentException ( "Unable to merge empty dataset" ) ; int nonEmpty = 0 ; boolean anyFeaturesPreset = false ; boolean anyLabelsPreset = false ; boolean first = true ; for ( DataSet ds : data ) { if ( ds . isEmpty ( ) ) { continue ; } nonEmpty ++ ; if ( anyFeaturesPreset && ds . getFeatures ( ) == null || ( ! first && ! anyFeaturesPreset && ds . getFeatures ( ) != null ) ) { throw new IllegalStateException ( "Cannot merge features: encountered null features in one or more DataSets" ) ; } if ( anyLabelsPreset && ds . getLabels ( ) == null || ( ! first && ! anyLabelsPreset && ds . getLabels ( ) != null ) ) { throw new IllegalStateException ( "Cannot merge labels: enountered null labels in one or more DataSets" ) ; } anyFeaturesPreset |= ds . getFeatures ( ) != null ; anyLabelsPreset |= ds . getLabels ( ) != null ; first = false ; } INDArray [ ] featuresToMerge = new INDArray [ nonEmpty ] ; INDArray [ ] labelsToMerge = new INDArray [ nonEmpty ] ; INDArray [ ] featuresMasksToMerge = null ; INDArray [ ] labelsMasksToMerge = null ; int count = 0 ; for ( DataSet ds : data ) { if ( ds . isEmpty ( ) ) continue ; featuresToMerge [ count ] = ds . getFeatureMatrix ( ) ; labelsToMerge [ count ] = ds . getLabels ( ) ; if ( ds . getFeaturesMaskArray ( ) != null ) { if ( featuresMasksToMerge == null ) { featuresMasksToMerge = new INDArray [ data . size ( ) ] ; } featuresMasksToMerge [ count ] = ds . getFeaturesMaskArray ( ) ; } if ( ds . getLabelsMaskArray ( ) != null ) { if ( labelsMasksToMerge == null ) { labelsMasksToMerge = new INDArray [ data . size ( ) ] ; } labelsMasksToMerge [ count ] = ds . getLabelsMaskArray ( ) ; } count ++ ; } INDArray featuresOut ; INDArray labelsOut ; INDArray featuresMaskOut ; INDArray labelsMaskOut ; Pair < INDArray , INDArray > fp = DataSetUtil . mergeFeatures ( featuresToMerge , featuresMasksToMerge ) ; featuresOut = fp . getFirst ( ) ; featuresMaskOut = fp . getSecond ( ) ; Pair < INDArray , INDArray > lp = DataSetUtil . mergeLabels ( labelsToMerge , labelsMasksToMerge ) ; labelsOut = lp . getFirst ( ) ; labelsMaskOut = lp . getSecond ( ) ; DataSet dataset = new DataSet ( featuresOut , labelsOut , featuresMaskOut , labelsMaskOut ) ; List < Serializable > meta = null ; for ( DataSet ds : data ) { if ( ds . getExampleMetaData ( ) == null || ds . getExampleMetaData ( ) . size ( ) != ds . numExamples ( ) ) { meta = null ; break ; } if ( meta == null ) meta = new ArrayList < > ( ) ; meta . addAll ( ds . getExampleMetaData ( ) ) ; } if ( meta != null ) { dataset . setExampleMetaData ( meta ) ; } return dataset ;


signature:
public class DataSet { /** * Binarizes the dataset such that any number greater than cutoff is 1 otherwise zero
 * @ param cutoff the cutoff point */
@ Override public void binarize ( double cutoff ) { } }

implementation: INDArray linear = getFeatureMatrix ( ) . linearView ( ) ; for ( int i = 0 ; i < getFeatures ( ) . length ( ) ; i ++ ) { double curr = linear . getDouble ( i ) ; if ( curr > cutoff ) getFeatures ( ) . putScalar ( i , 1 ) ; else getFeatures ( ) . putScalar ( i , 0 ) ; }


signature:
public class DataSet { /** * Gets a copy of example i
 * @ param i the example to getFromOrigin
 * @ return the example at i ( one example ) */
@ Override public DataSet get ( int i ) { } }

implementation:
if ( i > numExamples ( ) || i < 0 ) throw new IllegalArgumentException ( "invalid example number" ) ; if ( i == 0 && numExamples ( ) == 1 ) return this ; if ( getFeatureMatrix ( ) . rank ( ) == 4 ) { // ensure rank is preserved
INDArray slice = getFeatureMatrix ( ) . slice ( i ) ; return new DataSet ( slice . reshape ( ArrayUtil . combine ( new long [ ] { 1 } , slice . shape ( ) ) ) , getLabels ( ) . slice ( i ) ) ; } return new DataSet ( getFeatures ( ) . slice ( i ) , getLabels ( ) . slice ( i ) ) ;


signature:
public class DataSet { /** * Gets a copy of example i
 * @ param i the example to getFromOrigin
 * @ return the example at i ( one example ) */
@ Override public DataSet get ( int [ ] i ) { } }

implementation: return new DataSet ( getFeatures ( ) . getRows ( i ) , getLabels ( ) . getRows ( i ) ) ;


signature:
public class DataSet { /** * Sample a dataset
 * @ param numSamples the number of samples to getFromOrigin
 * @ param rng the rng to use
 * @ param withReplacement whether to allow duplicates ( only tracked by example row number )
 * @ return the sample dataset */
@ Override public DataSet sample ( int numSamples , org . nd4j . linalg . api . rng . Random rng , boolean withReplacement ) { } }

implementation: INDArray examples = Nd4j . create ( numSamples , getFeatures ( ) . columns ( ) ) ; INDArray outcomes = Nd4j . create ( numSamples , numOutcomes ( ) ) ; Set < Integer > added = new HashSet < > ( ) ; for ( int i = 0 ; i < numSamples ; i ++ ) { int picked = rng . nextInt ( numExamples ( ) ) ; if ( ! withReplacement ) while ( added . contains ( picked ) ) picked = rng . nextInt ( numExamples ( ) ) ; examples . putRow ( i , get ( picked ) . getFeatures ( ) ) ; outcomes . putRow ( i , get ( picked ) . getLabels ( ) ) ; } return new DataSet ( examples , outcomes ) ;


signature:
public class DataSet { /** * This method returns memory used by this DataSet
 * @ return */
@ Override public long getMemoryFootprint ( ) { } }

implementation: long reqMem = features . lengthLong ( ) * Nd4j . sizeOfDataType ( ) ; reqMem += labels == null ? 0 : labels . lengthLong ( ) * Nd4j . sizeOfDataType ( ) ; reqMem += featuresMask == null ? 0 : featuresMask . lengthLong ( ) * Nd4j . sizeOfDataType ( ) ; reqMem += labelsMask == null ? 0 : labelsMask . lengthLong ( ) * Nd4j . sizeOfDataType ( ) ; return reqMem ;


signature:
public class StringUtils { /** * Make a string representation of the exception .
 * @ param e The exception to stringify
 * @ return A string with exception name and call stack . */
public static String stringifyException ( Throwable e ) { } }

implementation: StringWriter stm = new StringWriter ( ) ; PrintWriter wrt = new PrintWriter ( stm ) ; e . printStackTrace ( wrt ) ; wrt . close ( ) ; return stm . toString ( ) ;


signature:
public class StringUtils { /** * Given a full hostname , return the word upto the first dot .
 * @ param fullHostname the full hostname
 * @ return the hostname to the first dot */
public static String simpleHostname ( String fullHostname ) { } }

implementation: if ( InetAddresses . isInetAddress ( fullHostname ) ) { return fullHostname ; } int offset = fullHostname . indexOf ( '.' ) ; if ( offset != - 1 ) { return fullHostname . substring ( 0 , offset ) ; } return fullHostname ;


signature:
public class StringUtils { /** * The same as String . format ( Locale . ENGLISH , format , objects ) . */
public static String format ( final String format , final Object ... objects ) { } }

implementation: return String . format ( Locale . ENGLISH , format , objects ) ;


signature:
public class StringUtils { /** * Given an array of strings , return a comma - separated list of its elements .
 * @ param strs Array of strings
 * @ return Empty string if strs . length is 0 , comma separated list of strings
 * otherwise */
public static String arrayToString ( String [ ] strs ) { } }

implementation: if ( strs . length == 0 ) { return "" ; } StringBuilder sbuf = new StringBuilder ( ) ; sbuf . append ( strs [ 0 ] ) ; for ( int idx = 1 ; idx < strs . length ; idx ++ ) { sbuf . append ( "," ) ; sbuf . append ( strs [ idx ] ) ; } return sbuf . toString ( ) ;


signature:
public class StringUtils { /** * Given an array of bytes it will convert the bytes to a hex string
 * representation of the bytes
 * @ param bytes
 * @ param start start index , inclusively
 * @ param end end index , exclusively
 * @ return hex string representation of the byte array */
public static String byteToHexString ( byte [ ] bytes , int start , int end ) { } }

implementation: if ( bytes == null ) { throw new IllegalArgumentException ( "bytes == null" ) ; } StringBuilder s = new StringBuilder ( ) ; for ( int i = start ; i < end ; i ++ ) { s . append ( format ( "%02x" , bytes [ i ] ) ) ; } return s . toString ( ) ;


signature:
public class StringUtils { /** * Formats time in ms and appends difference ( finishTime - startTime )
 * as returned by formatTimeDiff ( ) .
 * If finish time is 0 , empty string is returned , if start time is 0
 * then difference is not appended to return value .
 * @ param formattedFinishTime formattedFinishTime to use
 * @ param finishTime finish time
 * @ param startTime start time
 * @ return formatted value . */
public static String getFormattedTimeWithDiff ( String formattedFinishTime , long finishTime , long startTime ) { } }

implementation: StringBuilder buf = new StringBuilder ( ) ; if ( 0 != finishTime ) { buf . append ( formattedFinishTime ) ; if ( 0 != startTime ) { buf . append ( " (" + formatTimeDiff ( finishTime , startTime ) + ")" ) ; } } return buf . toString ( ) ;


signature:
public class StringUtils { /** * Returns an arraylist of strings .
 * @ param str the string values
 * @ param delim delimiter to separate the values
 * @ return the arraylist of the separated string values */
public static String [ ] getStrings ( String str , String delim ) { } }

implementation: Collection < String > values = getStringCollection ( str , delim ) ; if ( values . size ( ) == 0 ) { return null ; } return values . toArray ( new String [ values . size ( ) ] ) ;


signature:
public class StringUtils { /** * Returns a collection of strings .
 * @ param str comma separated string values
 * @ return an < code > ArrayList < / code > of string values */
public static Collection < String > getStringCollection ( String str ) { } }

implementation: String delim = "," ; return getStringCollection ( str , delim ) ;


signature:
public class StringUtils { /** * Returns a collection of strings .
 * @ param str
 * String to parse
 * @ param delim
 * delimiter to separate the values
 * @ return Collection of parsed elements . */
public static Collection < String > getStringCollection ( String str , String delim ) { } }

implementation: List < String > values = new ArrayList < String > ( ) ; if ( str == null ) return values ; StringTokenizer tokenizer = new StringTokenizer ( str , delim ) ; while ( tokenizer . hasMoreTokens ( ) ) { values . add ( tokenizer . nextToken ( ) ) ; } return values ;


signature:
public class StringUtils { /** * Splits a comma separated value < code > String < / code > , trimming leading and
 * trailing whitespace on each value . Duplicate and empty values are removed .
 * @ param str a comma separated < String > with values , may be null
 * @ return a < code > Collection < / code > of < code > String < / code > values , empty
 * Collection if null String input */
public static Collection < String > getTrimmedStringCollection ( String str ) { } }

implementation: Set < String > set = new LinkedHashSet < String > ( Arrays . asList ( getTrimmedStrings ( str ) ) ) ; set . remove ( "" ) ; return set ;


signature:
public class StringUtils { /** * Splits a comma or newline separated value < code > String < / code > , trimming
 * leading and trailing whitespace on each value .
 * @ param str a comma or newline separated < code > String < / code > with values ,
 * may be null
 * @ return an array of < code > String < / code > values , empty array if null String
 * input */
public static String [ ] getTrimmedStrings ( String str ) { } }

implementation: if ( null == str || str . trim ( ) . isEmpty ( ) ) { return emptyStringArray ; } return str . trim ( ) . split ( "\\s*[,\n]\\s*" ) ;


signature:
public class StringUtils { /** * Split a string using the given separator
 * @ param str a string that may have escaped separator
 * @ param escapeChar a char that be used to escape the separator
 * @ param separator a separator char
 * @ return an array of strings */
public static String [ ] split ( String str , char escapeChar , char separator ) { } }

implementation:
if ( str == null ) { return null ; } ArrayList < String > strList = new ArrayList < String > ( ) ; StringBuilder split = new StringBuilder ( ) ; int index = 0 ; while ( ( index = findNext ( str , separator , escapeChar , index , split ) ) >= 0 ) { ++ index ; // move over the separator for next search
strList . add ( split . toString ( ) ) ; split . setLength ( 0 ) ; // reset the buffer
} strList . add ( split . toString ( ) ) ; // remove trailing empty split ( s )
int last = strList . size ( ) ; // last split
while ( -- last >= 0 && "" . equals ( strList . get ( last ) ) ) { strList . remove ( last ) ; } return strList . toArray ( new String [ strList . size ( ) ] ) ;


signature:
public class StringUtils { /** * Split a string using the given separator , with no escaping performed .
 * @ param str a string to be split . Note that this may not be null .
 * @ param separator a separator char
 * @ return an array of strings */
public static String [ ] split ( String str , char separator ) { } }

implementation:
// String . split returns a single empty result for splitting the empty
// string .
if ( str . isEmpty ( ) ) { return new String [ ] { "" } ; } ArrayList < String > strList = new ArrayList < String > ( ) ; int startIndex = 0 ; int nextIndex = 0 ; while ( ( nextIndex = str . indexOf ( separator , startIndex ) ) != - 1 ) { strList . add ( str . substring ( startIndex , nextIndex ) ) ; startIndex = nextIndex + 1 ; } strList . add ( str . substring ( startIndex ) ) ; // remove trailing empty split ( s )
int last = strList . size ( ) ; // last split
while ( -- last >= 0 && "" . equals ( strList . get ( last ) ) ) { strList . remove ( last ) ; } return strList . toArray ( new String [ strList . size ( ) ] ) ;


signature:
public class StringUtils { /** * Finds the first occurrence of the separator character ignoring the escaped
 * separators starting from the index . Note the substring between the index
 * and the position of the separator is passed .
 * @ param str the source string
 * @ param separator the character to find
 * @ param escapeChar character used to escape
 * @ param start from where to search
 * @ param split used to pass back the extracted string */
public static int findNext ( String str , char separator , char escapeChar , int start , StringBuilder split ) { } }

implementation:
int numPreEscapes = 0 ; for ( int i = start ; i < str . length ( ) ; i ++ ) { char curChar = str . charAt ( i ) ; if ( numPreEscapes == 0 && curChar == separator ) { // separator
return i ; } else { split . append ( curChar ) ; numPreEscapes = ( curChar == escapeChar ) ? ( ++ numPreEscapes ) % 2 : 0 ; } } return - 1 ;


signature:
public class StringUtils { /** * Escape < code > charToEscape < / code > in the string
 * with the escape char < code > escapeChar < / code >
 * @ param str string
 * @ param escapeChar escape char
 * @ param charToEscape the char to be escaped
 * @ return an escaped string */
public static String escapeString ( String str , char escapeChar , char charToEscape ) { } }

implementation: return escapeString ( str , escapeChar , new char [ ] { charToEscape } ) ;


signature:
public class StringUtils { /** * Unescape < code > charToEscape < / code > in the string
 * with the escape char < code > escapeChar < / code >
 * @ param str string
 * @ param escapeChar escape char
 * @ param charToEscape the escaped char
 * @ return an unescaped string */
public static String unEscapeString ( String str , char escapeChar , char charToEscape ) { } }

implementation: return unEscapeString ( str , escapeChar , new char [ ] { charToEscape } ) ;


signature:
public class StringUtils { /** * Escapes HTML Special characters present in the string .
 * @ param string
 * @ return HTML Escaped String representation */
public static String escapeHTML ( String string ) { } }

implementation: if ( string == null ) { return null ; } StringBuilder sb = new StringBuilder ( ) ; boolean lastCharacterWasSpace = false ; char [ ] chars = string . toCharArray ( ) ; for ( char c : chars ) { if ( c == ' ' ) { if ( lastCharacterWasSpace ) { lastCharacterWasSpace = false ; sb . append ( " " ) ; } else { lastCharacterWasSpace = true ; sb . append ( " " ) ; } } else { lastCharacterWasSpace = false ; switch ( c ) { case '<' : sb . append ( "<" ) ; break ; case '>' : sb . append ( ">" ) ; break ; case '&' : sb . append ( "&" ) ; break ; case '"' : sb . append ( """ ) ; break ; default : sb . append ( c ) ; break ; } } } return sb . toString ( ) ;


signature:
public class StringUtils { /** * Concatenates strings , using a separator .
 * @ param separator Separator to join with .
 * @ param strings Strings to join . */
public static String join ( CharSequence separator , Iterable < ? > strings ) { } }

implementation: Iterator < ? > i = strings . iterator ( ) ; if ( ! i . hasNext ( ) ) { return "" ; } StringBuilder sb = new StringBuilder ( i . next ( ) . toString ( ) ) ; while ( i . hasNext ( ) ) { sb . append ( separator ) ; sb . append ( i . next ( ) . toString ( ) ) ; } return sb . toString ( ) ;


signature:
public class StringUtils { /** * Convert SOME _ STUFF to SomeStuff
 * @ param s input string
 * @ return camelized string */
public static String camelize ( String s ) { } }

implementation: StringBuilder sb = new StringBuilder ( ) ; String [ ] words = split ( StringUtils . toLowerCase ( s ) , ESCAPE_CHAR , '_' ) ; for ( String word : words ) sb . append ( org . apache . commons . lang3 . StringUtils . capitalize ( word ) ) ; return sb . toString ( ) ;