signature:
public class AtomicAllocator { /** * This method allocates required chunk of memory in specific location
 * PLEASE NOTE : Do not use this method , unless you ' re 100 % sure what you ' re doing
 * @ param requiredMemory
 * @ param location */
@ Override public AllocationPoint allocateMemory ( DataBuffer buffer , AllocationShape requiredMemory , AllocationStatus location , boolean initialize ) { } }

implementation:
AllocationPoint point = new AllocationPoint ( ) ; useTracker . set ( System . currentTimeMillis ( ) ) ; // we use these longs as tracking codes for memory tracking
Long allocId = objectsTracker . getAndIncrement ( ) ; // point . attachBuffer ( buffer ) ;
point . setObjectId ( allocId ) ; point . setShape ( requiredMemory ) ; /* if ( buffer instanceof CudaIntDataBuffer ) {
 buffer . setConstant ( true ) ;
 point . setConstant ( true ) ; */
int numBuckets = configuration . getNumberOfGcThreads ( ) ; int bucketId = RandomUtils . nextInt ( 0 , numBuckets ) ; GarbageBufferReference reference = new GarbageBufferReference ( ( BaseDataBuffer ) buffer , queueMap . get ( bucketId ) , point ) ; point . attachReference ( reference ) ; point . setDeviceId ( - 1 ) ; if ( buffer . isAttached ( ) ) { long reqMem = AllocationUtils . getRequiredMemory ( requiredMemory ) ; // log . info ( " Allocating { } bytes from attached memory . . . " , reqMem ) ;
// workaround for init order
getMemoryHandler ( ) . getCudaContext ( ) ; point . setDeviceId ( Nd4j . getAffinityManager ( ) . getDeviceForCurrentThread ( ) ) ; CudaWorkspace workspace = ( CudaWorkspace ) Nd4j . getMemoryManager ( ) . getCurrentWorkspace ( ) ; PointersPair pair = new PointersPair ( ) ; PagedPointer ptrDev = workspace . alloc ( reqMem , MemoryKind . DEVICE , requiredMemory . getDataType ( ) , initialize ) ; PagedPointer ptrHost = workspace . alloc ( reqMem , MemoryKind . HOST , requiredMemory . getDataType ( ) , initialize ) ; pair . setHostPointer ( ptrHost ) ; if ( ptrDev != null ) { pair . setDevicePointer ( ptrDev ) ; point . setAllocationStatus ( AllocationStatus . DEVICE ) ; } else { pair . setDevicePointer ( ptrHost ) ; point . setAllocationStatus ( AllocationStatus . HOST ) ; } // if ( ! ptrDev . isLeaked ( ) )
point . setAttached ( true ) ; point . setPointers ( pair ) ; } else { // we stay naive on PointersPair , we just don ' t know on this level , which pointers are set . MemoryHandler will be used for that
PointersPair pair = memoryHandler . alloc ( location , point , requiredMemory , initialize ) ; point . setPointers ( pair ) ; } allocationsMap . put ( allocId , point ) ; point . tickHostRead ( ) ; point . tickDeviceWrite ( ) ; return point ;


signature:
public class ArrowSerde { /** * Convert a { @ link Tensor }
 * to an { @ link INDArray }
 * @ param tensor the input tensor
 * @ return the equivalent { @ link INDArray } */
public static INDArray fromTensor ( Tensor tensor ) { } }

implementation:
byte b = tensor . typeType ( ) ; int [ ] shape = new int [ tensor . shapeLength ( ) ] ; int [ ] stride = new int [ tensor . stridesLength ( ) ] ; for ( int i = 0 ; i < shape . length ; i ++ ) { shape [ i ] = ( int ) tensor . shape ( i ) . size ( ) ; stride [ i ] = ( int ) tensor . strides ( i ) ; } int length = ArrayUtil . prod ( shape ) ; Buffer buffer = tensor . data ( ) ; if ( buffer == null ) { throw new ND4JIllegalStateException ( "Buffer was not serialized properly." ) ; } // deduce element size
int elementSize = ( int ) buffer . length ( ) / length ; // nd4j strides aren ' t based on element size
for ( int i = 0 ; i < stride . length ; i ++ ) { stride [ i ] /= elementSize ; } DataBuffer . Type type = typeFromTensorType ( b , elementSize ) ; DataBuffer dataBuffer = DataBufferStruct . createFromByteBuffer ( tensor . getByteBuffer ( ) , ( int ) tensor . data ( ) . offset ( ) , type , length , elementSize ) ; INDArray arr = Nd4j . create ( dataBuffer , shape ) ; arr . setShapeAndStride ( shape , stride ) ; return arr ;


signature:
public class ArrowSerde { /** * Create a { @ link Buffer }
 * representing the location metadata of the actual data
 * contents for the ndarrays ' { @ link DataBuffer }
 * @ param bufferBuilder the buffer builder in use
 * @ param arr the array to add the underlying data for
 * @ return the offset added */
public static int addDataForArr ( FlatBufferBuilder bufferBuilder , INDArray arr ) { } }

implementation: int offset = DataBufferStruct . createDataBufferStruct ( bufferBuilder , arr . data ( ) ) ; int ret = Buffer . createBuffer ( bufferBuilder , offset , arr . data ( ) . length ( ) * arr . data ( ) . getElementSize ( ) ) ; return ret ;


signature:
public class ArrowSerde { /** * Create thee databuffer type frm the given type ,
 * relative to the bytes in arrow in class :
 * { @ link Type }
 * @ param type the type to create the nd4j { @ link DataBuffer . Type } from
 * @ param elementSize the element size
 * @ return the data buffer type */
public static DataBuffer . Type typeFromTensorType ( byte type , int elementSize ) { } }

implementation: if ( type == Type . Decimal || type == Type . FloatingPoint ) { if ( elementSize == 4 ) { return DataBuffer . Type . FLOAT ; } else if ( elementSize == 8 ) { return DataBuffer . Type . DOUBLE ; } } else if ( type == Type . Int ) { if ( elementSize == 4 ) { return DataBuffer . Type . INT ; } else if ( elementSize == 8 ) { return DataBuffer . Type . LONG ; } } else { throw new IllegalArgumentException ( "Only valid types are Type.Decimal and Type.Int" ) ; } throw new IllegalArgumentException ( "Unable to determine data type" ) ;


signature:
public class CudaDirectProvider { /** * This method provides PointersPair to memory chunk specified by AllocationShape
 * @ param shape shape of desired memory chunk
 * @ param point target AllocationPoint structure
 * @ param location either HOST or DEVICE
 * @ return */
@ Override public PointersPair malloc ( AllocationShape shape , AllocationPoint point , AllocationStatus location ) { } }

implementation:
// log . info ( " shape onCreate : { } , target : { } " , shape , location ) ;
switch ( location ) { case HOST : { Pointer devicePointer = new Pointer ( ) ; long reqMem = AllocationUtils . getRequiredMemory ( shape ) ; // FIXME : this is WRONG , and directly leads to memleak
if ( reqMem < 1 ) reqMem = 1 ; Pointer pointer = nativeOps . mallocHost ( reqMem , 0 ) ; if ( pointer == null ) throw new RuntimeException ( "Can't allocate [HOST] memory: " + reqMem + "; threadId: " + Thread . currentThread ( ) . getId ( ) ) ; // log . info ( " Host allocation , Thread id : { } , ReqMem : { } , Pointer : { } " , Thread . currentThread ( ) . getId ( ) , reqMem , pointer ! = null ? pointer . address ( ) : null ) ;
Pointer hostPointer = new CudaPointer ( pointer ) ; PointersPair devicePointerInfo = new PointersPair ( ) ; devicePointerInfo . setDevicePointer ( new CudaPointer ( hostPointer , reqMem ) ) ; devicePointerInfo . setHostPointer ( new CudaPointer ( hostPointer , reqMem ) ) ; point . setPointers ( devicePointerInfo ) ; point . setAllocationStatus ( AllocationStatus . HOST ) ; return devicePointerInfo ; } case DEVICE : { // cudaMalloc call
int deviceId = AtomicAllocator . getInstance ( ) . getDeviceId ( ) ; long reqMem = AllocationUtils . getRequiredMemory ( shape ) ; // FIXME : this is WRONG , and directly leads to memleak
if ( reqMem < 1 ) reqMem = 1 ; // if ( CudaEnvironment . getInstance ( ) . getConfiguration ( ) . getDebugTriggered ( ) = = 119)
// throw new RuntimeException ( " Device allocation happened " ) ;
Pointer pointer = nativeOps . mallocDevice ( reqMem , null , 0 ) ; // log . info ( " Device [ { } ] allocation , Thread id : { } , ReqMem : { } , Pointer : { } " , AtomicAllocator . getInstance ( ) . getDeviceId ( ) , Thread . currentThread ( ) . getId ( ) , reqMem , pointer ! = null ? pointer . address ( ) : null ) ;
if ( pointer == null ) return null ; // throw new RuntimeException ( " Can ' t allocate [ DEVICE ] memory ! " ) ;
Pointer devicePointer = new CudaPointer ( pointer ) ; PointersPair devicePointerInfo = point . getPointers ( ) ; if ( devicePointerInfo == null ) devicePointerInfo = new PointersPair ( ) ; devicePointerInfo . setDevicePointer ( new CudaPointer ( devicePointer , reqMem ) ) ; point . setAllocationStatus ( AllocationStatus . DEVICE ) ; point . setDeviceId ( deviceId ) ; return devicePointerInfo ; } default : throw new IllegalStateException ( "Unsupported location for malloc: [" + location + "]" ) ; }


signature:
public class CudaDirectProvider { /** * This method frees specific chunk of memory , described by AllocationPoint passed in
 * @ param point */
@ Override public void free ( AllocationPoint point ) { } }

implementation:
switch ( point . getAllocationStatus ( ) ) { case HOST : { // cudaFreeHost call here
// FIXME : it would be nice to get rid of typecasting here
long reqMem = AllocationUtils . getRequiredMemory ( point . getShape ( ) ) ; // log . info ( " Deallocating { } bytes on [ HOST ] " , reqMem ) ;
NativeOps nativeOps = NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) ; long result = nativeOps . freeHost ( point . getPointers ( ) . getHostPointer ( ) ) ; // JCuda . cudaFreeHost ( new Pointer ( point . getPointers ( ) . getHostPointer ( ) ) ) ;
if ( result == 0 ) throw new RuntimeException ( "Can't deallocate [HOST] memory..." ) ; } break ; case DEVICE : { // cudaFree call
// JCuda . cudaFree ( new Pointer ( point . getPointers ( ) . getDevicePointer ( ) . address ( ) ) ) ;
if ( point . isConstant ( ) ) return ; long reqMem = AllocationUtils . getRequiredMemory ( point . getShape ( ) ) ; // log . info ( " Deallocating { } bytes on [ DEVICE ] " , reqMem ) ;
NativeOps nativeOps = NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) ; long result = nativeOps . freeDevice ( point . getPointers ( ) . getDevicePointer ( ) , new CudaPointer ( 0 ) ) ; if ( result == 0 ) throw new RuntimeException ( "Can't deallocate [DEVICE] memory..." ) ; } break ; default : throw new IllegalStateException ( "Can't free memory on target [" + point . getAllocationStatus ( ) + "]" ) ; }


signature:
public class AdaGradUpdater { /** * Gets feature specific learning rates
 * Adagrad keeps a history of gradients being passed in .
 * Note that each gradient passed in becomes adapted over time , hence the opName adagrad
 * @ param gradient the gradient to get learning rates for
 * @ param iteration */
@ Override public void applyUpdater ( INDArray gradient , int iteration , int epoch ) { } }

implementation:
if ( historicalGradient == null ) throw new IllegalStateException ( "Updater has not been initialized with view state" ) ; double learningRate = config . getLearningRate ( iteration , epoch ) ; double epsilon = config . getEpsilon ( ) ; historicalGradient . addi ( gradient . mul ( gradient ) ) ; INDArray sqrtHistory = sqrt ( historicalGradient . dup ( gradientReshapeOrder ) , false ) . addi ( epsilon ) ; // lr * gradient / ( sqrt ( sumSquaredGradients ) + epsilon )
gradient . muli ( sqrtHistory . rdivi ( learningRate ) ) ;


signature:
public class GridFlowController { /** * This method makes sure HOST memory contains latest data from GPU
 * Additionally , this method checks , that there ' s no ops pending execution for this array
 * @ param point */
@ Override public void synchronizeToHost ( AllocationPoint point ) { } }

implementation: if ( ! point . isConstant ( ) && point . isEnqueued ( ) ) { waitTillFinished ( point ) ; } super . synchronizeToHost ( point ) ;


signature:
public class NDArrayIndex { /** * Create from a matrix . The rows are the indices
 * The columns are the individual element in each ndarrayindex
 * @ param index the matrix to getFloat indices from
 * @ return the indices to getFloat */
public static INDArrayIndex [ ] create ( INDArray index ) { } }

implementation: if ( index . isMatrix ( ) ) { if ( index . rows ( ) > Integer . MAX_VALUE ) throw new ND4JArraySizeException ( ) ; NDArrayIndex [ ] ret = new NDArrayIndex [ ( int ) index . rows ( ) ] ; for ( int i = 0 ; i < index . rows ( ) ; i ++ ) { INDArray row = index . getRow ( i ) ; val nums = new long [ ( int ) index . getRow ( i ) . columns ( ) ] ; for ( int j = 0 ; j < row . columns ( ) ; j ++ ) { nums [ j ] = ( int ) row . getFloat ( j ) ; } NDArrayIndex idx = new NDArrayIndex ( nums ) ; ret [ i ] = idx ; } return ret ; } else if ( index . isVector ( ) ) { long [ ] indices = NDArrayUtil . toLongs ( index ) ; return new NDArrayIndex [ ] { new NDArrayIndex ( indices ) } ; } throw new IllegalArgumentException ( "Passed in ndarray must be a matrix or a vector" ) ;


signature:
public class Broadcast { /** * Broadcast add op . See : { @ link BroadcastAddOp } */
public static INDArray add ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldAddOp ( x , y , z ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastAddOp ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast copy op . See : { @ link BroadcastCopyOp } */
public static INDArray copy ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new CopyOp ( x , y , z ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastCopyOp ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast divide op . See : { @ link BroadcastDivOp } */
public static INDArray div ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldDivOp ( x , y , z ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastDivOp ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast equal to op . See : { @ link BroadcastEqualTo } */
public static INDArray eq ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldEqualTo ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastEqualTo ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast greater than op . See : { @ link BroadcastGreaterThan } */
public static INDArray gt ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldGreaterThan ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastGreaterThan ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast greater than or equal to op . See : { @ link BroadcastGreaterThanOrEqual } */
public static INDArray gte ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldGreaterThanOrEqual ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastGreaterThanOrEqual ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast less than op . See : { @ link BroadcastLessThan } */
public static INDArray lt ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldLessThan ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastLessThan ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast less than or equal to op . See : { @ link BroadcastLessThanOrEqual } */
public static INDArray lte ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldLessThanOrEqual ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastLessThanOrEqual ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast not equal to op . See : { @ link BroadcastNotEqual } */
public static INDArray neq ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldNotEqualTo ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastNotEqual ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast reverse division op . See : { @ link BroadcastRDivOp } */
public static INDArray rdiv ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldRDivOp ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastRDivOp ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast reverse subtraction op . See : { @ link BroadcastRSubOp } */
public static INDArray rsub ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldSubOp ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastRSubOp ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast max op . See : { @ link BroadcastMax } */
public static INDArray max ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldMax ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastMax ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast min op . See : { @ link BroadcastMin } */
public static INDArray min ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new OldMin ( x , y , z , x . length ( ) ) ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastMin ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast absolute max op . See : { @ link BroadcastAMax } */
public static INDArray amax ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new AMax ( x , y , z , x . length ( ) ) ) . z ( ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastAMax ( x , y , z , dimensions ) ) ;


signature:
public class Broadcast { /** * Broadcast absolute min op . See : { @ link BroadcastAMax } */
public static INDArray amin ( INDArray x , INDArray y , INDArray z , int ... dimensions ) { } }

implementation: if ( dimensions == null ) { Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , y . shape ( ) ) , getFormattedShapeErrorMessageXy ( x , y ) ) ; Preconditions . checkArgument ( Arrays . equals ( x . shape ( ) , z . shape ( ) ) , getFormattedShapeErrorMessageXResult ( x , z ) ) ; return Nd4j . getExecutioner ( ) . execAndReturn ( new AMin ( x , y , z , x . length ( ) ) ) . z ( ) ; } return Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastAMin ( x , y , z , dimensions ) ) ;


signature:
public class DifferentialFunction { /** * Returns the properties for a given function
 * @ return */
public Map < String , Object > propertiesForFunction ( ) { } }

implementation: val fields = DifferentialFunctionClassHolder . getInstance ( ) . getFieldsForFunction ( this ) ; Map < String , Object > ret = new LinkedHashMap < > ( ) ; for ( val entry : fields . entrySet ( ) ) { try { ret . put ( entry . getKey ( ) , fields . get ( entry . getKey ( ) ) . get ( this ) ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } } return ret ;


signature:
public class DifferentialFunction { /** * Returns true if this
 * function has place holder inputs
 * @ return */
public boolean hasPlaceHolderInputs ( ) { } }

implementation: val args = args ( ) ; for ( val arg : args ) if ( sameDiff . hasPlaceHolderVariables ( arg ( ) . getVarName ( ) ) ) return true ; return false ;


signature:
public class DifferentialFunction { /** * Perform automatic differentiation
 * wrt the input variables
 * @ param i _ v1 the input variables
 * @ return the differentiated output
 * wrt each input variable */
public List < SDVariable > diff ( List < SDVariable > i_v1 ) { } }

implementation: List < SDVariable > vals = doDiff ( i_v1 ) ; if ( vals == null ) { throw new IllegalStateException ( "Error executing diff operation: doDiff returned null for op: " + this . opName ( ) ) ; } val outputVars = args ( ) ; for ( int i = 0 ; i < vals . size ( ) ; i ++ ) { SDVariable var = outputVars [ i ] ; SDVariable grad = var . getGradient ( ) ; if ( grad != null ) { SDVariable gradVar = f ( ) . add ( grad , vals . get ( i ) ) ; try { vals . set ( i , gradVar ) ; } catch ( UnsupportedOperationException e ) { throw new UnsupportedOperationException ( "Use a mutable list when returning values from " + this . getClass ( ) . getSimpleName ( ) + ".doDiff (e.g. Arrays.asList instead of Collections.singletonList)" , e ) ; } sameDiff . setGradientForVariableName ( var . getVarName ( ) , gradVar ) ; } else { SDVariable gradVar = vals . get ( i ) ; sameDiff . updateVariableNameAndReference ( gradVar , var . getVarName ( ) + "-grad" ) ; sameDiff . setGradientForVariableName ( var . getVarName ( ) , gradVar ) ; sameDiff . setForwardVariableForVarName ( gradVar . getVarName ( ) , var ) ; } } return vals ;


signature:
public class Indices { /** * The offsets ( begin index ) for each index
 * @ param indices the indices
 * @ return the offsets for the given set of indices */
public static long [ ] offsets ( long [ ] shape , INDArrayIndex ... indices ) { } }

implementation:
// offset of zero for every new axes
long [ ] ret = new long [ shape . length ] ; if ( indices . length == shape . length ) { for ( int i = 0 ; i < indices . length ; i ++ ) { if ( indices [ i ] instanceof NDArrayIndexEmpty ) ret [ i ] = 0 ; else { ret [ i ] = indices [ i ] . offset ( ) ; } } if ( ret . length == 1 ) { ret = new long [ ] { ret [ 0 ] , 0 } ; } } else { int numPoints = NDArrayIndex . numPoints ( indices ) ; if ( numPoints > 0 ) { List < Long > nonZeros = new ArrayList < > ( ) ; for ( int i = 0 ; i < indices . length ; i ++ ) if ( indices [ i ] . offset ( ) > 0 ) nonZeros . add ( indices [ i ] . offset ( ) ) ; if ( nonZeros . size ( ) > shape . length ) throw new IllegalStateException ( "Non zeros greater than shape unable to continue" ) ; else { // push all zeros to the back
for ( int i = 0 ; i < nonZeros . size ( ) ; i ++ ) ret [ i ] = nonZeros . get ( i ) ; } } else { int shapeIndex = 0 ; for ( int i = 0 ; i < indices . length ; i ++ ) { if ( indices [ i ] instanceof NDArrayIndexEmpty ) ret [ i ] = 0 ; else { ret [ i ] = indices [ shapeIndex ++ ] . offset ( ) ; } } } if ( ret . length == 1 ) { ret = new long [ ] { ret [ 0 ] , 0 } ; } } return ret ;


signature:
public class NDArrayStrings { /** * Format the given ndarray as a string
 * @ param arr the array to format
 * @ param summarize If true and the number of elements in the array is greater than > 1000 only the first three and last elements in any dimension will print
 * @ return the formatted array */
public String format ( INDArray arr , boolean summarize ) { } }

implementation: this . scientificFormat = "0." ; int addPrecision = this . precision ; while ( addPrecision > 0 ) { this . scientificFormat += "#" ; addPrecision -= 1 ; } this . scientificFormat = this . scientificFormat + "E0" ; if ( this . scientificFormat . length ( ) + 2 > this . padding ) this . padding = this . scientificFormat . length ( ) + 2 ; this . maxToPrintWithoutSwitching = Math . pow ( 10 , this . precision ) ; this . minToPrintWithoutSwitching = 1.0 / ( this . maxToPrintWithoutSwitching ) ; if ( summarize && arr . length ( ) > 1000 ) return format ( arr , 0 , true ) ; return format ( arr , 0 , false ) ;


signature:
public class BaseGraphMapper { /** * This method converts given TF
 * @ param tfGraph
 * @ return */
@ Override public SameDiff importGraph ( GRAPH_TYPE tfGraph ) { } }

implementation:
SameDiff diff = SameDiff . create ( ) ; ImportState < GRAPH_TYPE , TENSOR_TYPE > importState = new ImportState < > ( ) ; importState . setSameDiff ( diff ) ; importState . setGraph ( tfGraph ) ; val variablesForGraph = variablesForGraph ( tfGraph ) ; importState . setVariables ( variablesForGraph ) ; // map the names of the nodes while accumulating the vertex ids
// for each variable
for ( Map . Entry < String , TENSOR_TYPE > entry : variablesForGraph . entrySet ( ) ) { if ( dataTypeForTensor ( entry . getValue ( ) ) == DataBuffer . Type . UNKNOWN ) { val var = importState . getSameDiff ( ) . var ( entry . getKey ( ) , null , new ZeroInitScheme ( 'c' ) ) ; // mark as place holder for validating resolution later .
if ( isPlaceHolder ( entry . getValue ( ) ) ) { importState . getSameDiff ( ) . addAsPlaceHolder ( var . getVarName ( ) ) ; if ( var . getShape ( ) != null ) importState . getSameDiff ( ) . setOriginalPlaceHolderShape ( var . getVarName ( ) , var . getShape ( ) ) ; } continue ; } val arr = getNDArrayFromTensor ( entry . getKey ( ) , entry . getValue ( ) , tfGraph ) ; if ( arr != null ) { val var = importState . getSameDiff ( ) . var ( entry . getKey ( ) , arr ) ; // ensure the array is made available for later processing
diff . associateArrayWithVariable ( arr , var ) ; } else if ( getShapeFromTensor ( entry . getValue ( ) ) == null ) { val var = importState . getSameDiff ( ) . var ( entry . getKey ( ) , null , new ZeroInitScheme ( 'c' ) ) ; // mark as place holder for validating resolution later .
// note that this vertex id can still be a place holder
// with a - 1 shape . Just because a shape is " known " doesn ' t mean
// that it isn ' t a place holder .
if ( isPlaceHolder ( entry . getValue ( ) ) ) { val originalShape = getShapeFromTensor ( entry . getValue ( ) ) ; importState . getSameDiff ( ) . addAsPlaceHolder ( var . getVarName ( ) ) ; if ( var . getShape ( ) != null ) importState . getSameDiff ( ) . setOriginalPlaceHolderShape ( var . getVarName ( ) , originalShape ) ; } } else { val originalShape = getShapeFromTensor ( entry . getValue ( ) ) ; val var = importState . getSameDiff ( ) . var ( entry . getKey ( ) , originalShape ) ; // mark as place holder for validating resolution later .
// note that this vertex id can still be a place holder
// with a - 1 shape . Just because a shape is " known " doesn ' t mean
// that it isn ' t a place holder .
if ( isPlaceHolder ( entry . getValue ( ) ) ) { importState . getSameDiff ( ) . addAsPlaceHolder ( var . getVarName ( ) ) ; importState . getSameDiff ( ) . setOriginalPlaceHolderShape ( var . getVarName ( ) , originalShape ) ; } } } // setup vertex ids for names
// handle mapping vertex ids properly
val tfNodesList = getNodeList ( tfGraph ) ; for ( NODE_TYPE tfNode : tfNodesList ) { if ( ! opsToIgnore ( ) . contains ( getOpType ( tfNode ) ) || isOpIgnoreException ( tfNode ) ) mapNodeType ( tfNode , importState ) ; } return diff ;


signature:
public class BaseLoader { /** * Convert an ndarray to a blob
 * @ param toConvert the complex ndarray to convert
 * @ return the converted complex ndarray */
@ Override public Blob convert ( IComplexNDArray toConvert ) throws IOException , SQLException { } }

implementation: ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; DataOutputStream dos = new DataOutputStream ( bos ) ; Nd4j . writeComplex ( toConvert , dos ) ; byte [ ] bytes = bos . toByteArray ( ) ; Connection c = dataSource . getConnection ( ) ; Blob b = c . createBlob ( ) ; b . setBytes ( 1 , bytes ) ; return b ;


signature:
public class BaseLoader { /** * Load a complex ndarray from a blob
 * @ param blob the blob to load from
 * @ return the complex ndarray */
@ Override public IComplexNDArray loadComplex ( Blob blob ) throws SQLException , IOException { } }

implementation: DataInputStream dis = new DataInputStream ( blob . getBinaryStream ( ) ) ; return Nd4j . readComplex ( dis ) ;


signature:
public class BaseLoader { /** * Save the ndarray
 * @ param save the ndarray to save */
@ Override public void save ( IComplexNDArray save , String id ) throws IOException , SQLException { } }

implementation: doSave ( save , id ) ;


signature:
public class BaseComplexNDArray { /** * Copy real numbers to arr
 * @ param arr the arr to copy to */
protected void copyRealTo ( INDArray arr ) { } }

implementation: INDArray linear = arr . linearView ( ) ; IComplexNDArray thisLinear = linearView ( ) ; if ( arr . isScalar ( ) ) arr . putScalar ( 0 , getReal ( 0 ) ) ; else for ( int i = 0 ; i < linear . length ( ) ; i ++ ) { arr . putScalar ( i , thisLinear . getReal ( i ) ) ; }


signature:
public class BaseComplexNDArray { /** * Copy imaginary numbers to the given
 * ndarray
 * @ param arr the array to copy imaginary numbers to */
protected void copyImagTo ( INDArray arr ) { } }

implementation: INDArray linear = arr . linearView ( ) ; IComplexNDArray thisLinear = linearView ( ) ; if ( arr . isScalar ( ) ) arr . putScalar ( 0 , getReal ( 0 ) ) ; else for ( int i = 0 ; i < linear . length ( ) ; i ++ ) { arr . putScalar ( i , thisLinear . getImag ( i ) ) ; }


signature:
public class BaseComplexNDArray { /** * Returns an ndarray with 1 if the element is epsilon equals
 * @ param other the number to compare
 * @ return a copied ndarray with the given
 * binary conditions */
@ Override public IComplexNDArray epsi ( Number other ) { } }

implementation: IComplexNDArray linear = linearView ( ) ; double otherVal = other . doubleValue ( ) ; for ( int i = 0 ; i < linearView ( ) . length ( ) ; i ++ ) { IComplexNumber n = linear . getComplex ( i ) ; double real = n . realComponent ( ) . doubleValue ( ) ; double diff = Math . abs ( real - otherVal ) ; if ( diff <= Nd4j . EPS_THRESHOLD ) linear . putScalar ( i , Nd4j . createDouble ( 1 , 0 ) ) ; else linear . putScalar ( i , Nd4j . createDouble ( 0 , 0 ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * In place epsilon equals than comparison :
 * If the given number is less than the
 * comparison number the item is 0 otherwise 1
 * @ param other the number to compare
 * @ return */
@ Override public IComplexNDArray epsi ( INDArray other ) { } }

implementation: IComplexNDArray linear = linearView ( ) ; if ( other instanceof IComplexNDArray ) { IComplexNDArray otherComplex = ( IComplexNDArray ) other ; IComplexNDArray otherComplexLinear = otherComplex . linearView ( ) ; for ( int i = 0 ; i < linearView ( ) . length ( ) ; i ++ ) { IComplexNumber n = linear . getComplex ( i ) ; IComplexNumber otherComplexNumber = otherComplexLinear . getComplex ( i ) ; double real = n . absoluteValue ( ) . doubleValue ( ) ; double otherAbs = otherComplexNumber . absoluteValue ( ) . doubleValue ( ) ; double diff = Math . abs ( real - otherAbs ) ; if ( diff <= Nd4j . EPS_THRESHOLD ) linear . putScalar ( i , Nd4j . createDouble ( 1 , 0 ) ) ; else linear . putScalar ( i , Nd4j . createDouble ( 0 , 0 ) ) ; } } return this ;


signature:
public class BaseComplexNDArray { /** * Returns the squared ( Euclidean ) distance . */
@ Override public double squaredDistance ( INDArray other ) { } }

implementation: double sd = 0.0 ; if ( other instanceof IComplexNDArray ) { IComplexNDArray n = ( IComplexNDArray ) other ; IComplexNDArray nLinear = n . linearView ( ) ; for ( int i = 0 ; i < length ( ) ; i ++ ) { IComplexNumber diff = linearView ( ) . getComplex ( i ) . sub ( nLinear . getComplex ( i ) ) ; double d = diff . absoluteValue ( ) . doubleValue ( ) ; sd += d * d ; } return sd ; } for ( int i = 0 ; i < length ( ) ; i ++ ) { INDArray linear = other . linearView ( ) ; IComplexNumber diff = linearView ( ) . getComplex ( i ) . sub ( linear . getDouble ( i ) ) ; double d = diff . absoluteValue ( ) . doubleValue ( ) ; sd += d * d ; } return sd ;


signature:
public class BaseComplexNDArray { /** * Returns the ( 1 - norm ) distance . */
@ Override public double distance1 ( INDArray other ) { } }

implementation: float d = 0.0f ; if ( other instanceof IComplexNDArray ) { IComplexNDArray n2 = ( IComplexNDArray ) other ; IComplexNDArray n2Linear = n2 . linearView ( ) ; for ( int i = 0 ; i < length ( ) ; i ++ ) { IComplexNumber n = getComplex ( i ) . sub ( n2Linear . getComplex ( i ) ) ; d += n . absoluteValue ( ) . doubleValue ( ) ; } return d ; } INDArray linear = other . linearView ( ) ; for ( int i = 0 ; i < length ( ) ; i ++ ) { IComplexNumber n = linearView ( ) . getComplex ( i ) . sub ( linear . getDouble ( i ) ) ; d += n . absoluteValue ( ) . doubleValue ( ) ; } return d ;


signature:
public class BaseComplexNDArray { /** * Inserts the element at the specified index
 * @ param i the row insert into
 * @ param j the column to insert into
 * @ param element a scalar ndarray
 * @ return a scalar ndarray of the element at this index */
@ Override public IComplexNDArray put ( int i , int j , Number element ) { } }

implementation: return ( IComplexNDArray ) super . put ( i , j , Nd4j . scalar ( element ) ) ;


signature:
public class BaseComplexNDArray { /** * Assigns the given matrix ( put ) to the specified slice
 * @ param slice the slice to assign
 * @ param put the slice to transform
 * @ return this for chainability */
@ Override public IComplexNDArray putSlice ( int slice , IComplexNDArray put ) { } }

implementation: if ( isScalar ( ) ) { assert put . isScalar ( ) : "Invalid dimension. Can only insert a scalar in to another scalar" ; put ( 0 , put . getScalar ( 0 ) ) ; return this ; } else if ( isVector ( ) ) { assert put . isScalar ( ) || put . isVector ( ) && put . length ( ) == length ( ) : "Invalid dimension on insertion. Can only insert scalars input vectors" ; if ( put . isScalar ( ) ) putScalar ( slice , put . getComplex ( 0 ) ) ; else for ( int i = 0 ; i < length ( ) ; i ++ ) putScalar ( i , put . getComplex ( i ) ) ; return this ; } assertSlice ( put , slice ) ; IComplexNDArray view = slice ( slice ) ; if ( put . length ( ) == 1 ) putScalar ( slice , put . getComplex ( 0 ) ) ; else if ( put . isVector ( ) ) for ( int i = 0 ; i < put . length ( ) ; i ++ ) view . putScalar ( i , put . getComplex ( i ) ) ; else { assert Shape . shapeEquals ( view . shape ( ) , put . shape ( ) ) ; IComplexNDArray linear = view . linearView ( ) ; IComplexNDArray putLinearView = put . linearView ( ) ; for ( int i = 0 ; i < linear . length ( ) ; i ++ ) { linear . putScalar ( i , putLinearView . getComplex ( i ) ) ; } } return this ;


signature:
public class BaseComplexNDArray { /** * Compute complex conj ( in - place ) . */
@ Override public IComplexNDArray conji ( ) { } }

implementation: IComplexNDArray reshaped = linearView ( ) ; IComplexDouble c = Nd4j . createDouble ( 0.0 , 0 ) ; for ( int i = 0 ; i < length ( ) ; i ++ ) { IComplexNumber conj = reshaped . getComplex ( i , c ) . conj ( ) ; reshaped . putScalar ( i , conj ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * Inserts the element at the specified index
 * @ param i the index insert into
 * @ param element a scalar ndarray
 * @ return a scalar ndarray of the element at this index */
@ Override public IComplexNDArray put ( int i , IComplexNDArray element ) { } }

implementation: if ( element == null ) throw new IllegalArgumentException ( "Unable to insert null element" ) ; assert element . isScalar ( ) : "Unable to insert non scalar element" ; long idx = linearIndex ( i ) ; IComplexNumber n = element . getComplex ( 0 ) ; data . put ( idx , n . realComponent ( ) . doubleValue ( ) ) ; data . put ( idx + 1 , n . imaginaryComponent ( ) . doubleValue ( ) ) ; return this ;


signature:
public class BaseComplexNDArray { /** * Assigns the given matrix ( put ) to the specified slice
 * @ param slice the slice to assign
 * @ param put the slice to put
 * @ return this for chainability */
@ Override public IComplexNDArray putSlice ( int slice , INDArray put ) { } }

implementation: return putSlice ( slice , Nd4j . createComplex ( put ) ) ;


signature:
public class BaseComplexNDArray { /** * Inserts the element at the specified index
 * @ param i the row insert into
 * @ param j the column to insert into
 * @ param element a scalar ndarray
 * @ return a scalar ndarray of the element at this index */
@ Override public IComplexNDArray put ( int i , int j , INDArray element ) { } }

implementation: return put ( new int [ ] { i , j } , element ) ;


signature:
public class BaseComplexNDArray { /** * Assign all of the elements in the given
 * ndarray to this ndarray
 * @ param arr the elements to assign
 * @ return this */
@ Override public IComplexNDArray assign ( IComplexNDArray arr ) { } }

implementation: if ( ! arr . isScalar ( ) ) LinAlgExceptions . assertSameLength ( this , arr ) ; IComplexNDArray linear = linearView ( ) ; IComplexNDArray otherLinear = arr . linearView ( ) ; for ( int i = 0 ; i < linear . length ( ) ; i ++ ) { linear . putScalar ( i , otherLinear . getComplex ( i ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * Get whole rows from the passed indices .
 * @ param rindices */
@ Override public IComplexNDArray getRows ( int [ ] rindices ) { } }

implementation: INDArray rows = Nd4j . create ( rindices . length , columns ( ) ) ; for ( int i = 0 ; i < rindices . length ; i ++ ) { rows . putRow ( i , getRow ( rindices [ i ] ) ) ; } return ( IComplexNDArray ) rows ;


signature:
public class BaseComplexNDArray { /** * Dimshuffle : an extension of permute that adds the ability
 * to broadcast various dimensions .
 * See theano for more examples .
 * This will only accept integers and xs .
 * An x indicates a dimension should be broadcasted rather than permuted .
 * @ param rearrange the dimensions to swap to
 * @ return the newly permuted array */
@ Override public IComplexNDArray dimShuffle ( Object [ ] rearrange , int [ ] newOrder , boolean [ ] broadCastable ) { } }

implementation: return ( IComplexNDArray ) super . dimShuffle ( rearrange , newOrder , broadCastable ) ;


signature:
public class BaseComplexNDArray { /** * Insert a row in to this array
 * Will throw an exception if this
 * ndarray is not a matrix
 * @ param row the row insert into
 * @ param toPut the row to insert
 * @ return this */
@ Override public IComplexNDArray putRow ( long row , INDArray toPut ) { } }

implementation: return ( IComplexNDArray ) super . putRow ( row , toPut ) ;


signature:
public class BaseComplexNDArray { /** * Insert a column in to this array
 * Will throw an exception if this
 * ndarray is not a matrix
 * @ param column the column to insert
 * @ param toPut the array to put
 * @ return this */
@ Override public IComplexNDArray putColumn ( int column , INDArray toPut ) { } }

implementation: assert toPut . isVector ( ) && toPut . length ( ) == rows ( ) : "Illegal length for row " + toPut . length ( ) + " should have been " + columns ( ) ; IComplexNDArray r = getColumn ( column ) ; if ( toPut instanceof IComplexNDArray ) { IComplexNDArray putComplex = ( IComplexNDArray ) toPut ; for ( int i = 0 ; i < r . length ( ) ; i ++ ) { IComplexNumber n = putComplex . getComplex ( i ) ; r . putScalar ( i , n ) ; } } else { for ( int i = 0 ; i < r . length ( ) ; i ++ ) r . putScalar ( i , Nd4j . createDouble ( toPut . getDouble ( i ) , 0 ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * Inserts the element at the specified index
 * @ param i the index insert into
 * @ param element a scalar ndarray
 * @ return a scalar ndarray of the element at this index */
@ Override public IComplexNDArray put ( int i , INDArray element ) { } }

implementation: if ( element == null ) throw new IllegalArgumentException ( "Unable to insert null element" ) ; assert element . isScalar ( ) : "Unable to insert non scalar element" ; if ( element instanceof IComplexNDArray ) { IComplexNDArray n1 = ( IComplexNDArray ) element ; IComplexNumber n = n1 . getComplex ( 0 ) ; put ( i , n ) ; } else putScalar ( i , Nd4j . createDouble ( element . getDouble ( 0 ) , 0.0 ) ) ; return this ;


signature:
public class BaseComplexNDArray { /** * In place addition of a column vector
 * @ param columnVector the column vector to add
 * @ return the result of the addition */
@ Override public IComplexNDArray diviColumnVector ( INDArray columnVector ) { } }

implementation: for ( int i = 0 ; i < columns ( ) ; i ++ ) { getColumn ( i ) . divi ( columnVector . getScalar ( i ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * In place addition of a column vector
 * @ param rowVector the column vector to add
 * @ return the result of the addition */
@ Override public IComplexNDArray diviRowVector ( INDArray rowVector ) { } }

implementation: for ( int i = 0 ; i < rows ( ) ; i ++ ) { getRow ( i ) . divi ( rowVector . getScalar ( i ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * In place addition of a column vector
 * @ param columnVector the column vector to add
 * @ return the result of the addition */
@ Override public IComplexNDArray muliColumnVector ( INDArray columnVector ) { } }

implementation: for ( int i = 0 ; i < columns ( ) ; i ++ ) { getColumn ( i ) . muli ( columnVector . getScalar ( i ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * In place addition of a column vector
 * @ param rowVector the column vector to add
 * @ return the result of the addition */
@ Override public IComplexNDArray muliRowVector ( INDArray rowVector ) { } }

implementation: for ( int i = 0 ; i < rows ( ) ; i ++ ) { getRow ( i ) . muli ( rowVector . getScalar ( i ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * In place addition of a column vector
 * @ param columnVector the column vector to add
 * @ return the result of the addition */
@ Override public IComplexNDArray subiColumnVector ( INDArray columnVector ) { } }

implementation: for ( int i = 0 ; i < columns ( ) ; i ++ ) { getColumn ( i ) . subi ( columnVector . getScalar ( i ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * In place addition of a column vector
 * @ param rowVector the column vector to add
 * @ return the result of the addition */
@ Override public IComplexNDArray subiRowVector ( INDArray rowVector ) { } }

implementation: for ( int i = 0 ; i < rows ( ) ; i ++ ) { getRow ( i ) . subi ( rowVector . getScalar ( i ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * In place addition of a column vector
 * @ param columnVector the column vector to add
 * @ return the result of the addition */
@ Override public IComplexNDArray addiColumnVector ( INDArray columnVector ) { } }

implementation: for ( int i = 0 ; i < columns ( ) ; i ++ ) { getColumn ( i ) . addi ( columnVector . getScalar ( i ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * In place addition of a column vector
 * @ param rowVector the column vector to add
 * @ return the result of the addition */
@ Override public IComplexNDArray addiRowVector ( INDArray rowVector ) { } }

implementation: for ( int i = 0 ; i < rows ( ) ; i ++ ) { getRow ( i ) . addi ( rowVector . getScalar ( i ) ) ; } return this ;


signature:
public class BaseComplexNDArray { /** * Perform an copy matrix multiplication
 * @ param other the other matrix to perform matrix multiply with
 * @ param result the result ndarray
 * @ return the result of the matrix multiplication */
@ Override public IComplexNDArray mmul ( INDArray other , INDArray result ) { } }

implementation: return dup ( ) . mmuli ( other , result ) ;


signature:
public class BaseComplexNDArray { /** * copy ( element wise ) division of two matrices
 * @ param other the second ndarray to divide
 * @ param result the result ndarray
 * @ return the result of the divide */
@ Override public IComplexNDArray div ( INDArray other , INDArray result ) { } }

implementation: return dup ( ) . divi ( other , result ) ;


signature:
public class BaseComplexNDArray { /** * copy ( element wise ) multiplication of two matrices
 * @ param other the second ndarray to multiply
 * @ param result the result ndarray
 * @ return the result of the multiplication */
@ Override public IComplexNDArray mul ( INDArray other , INDArray result ) { } }

implementation: return dup ( ) . muli ( other , result ) ;


signature:
public class BaseComplexNDArray { /** * copy subtraction of two matrices
 * @ param other the second ndarray to subtract
 * @ param result the result ndarray
 * @ return the result of the subtraction */
@ Override public IComplexNDArray sub ( INDArray other , INDArray result ) { } }

implementation: return dup ( ) . subi ( other , result ) ;


signature:
public class BaseComplexNDArray { /** * copy addition of two matrices
 * @ param other the second ndarray to add
 * @ param result the result ndarray
 * @ return the result of the addition */
@ Override public IComplexNDArray add ( INDArray other , INDArray result ) { } }

implementation: return dup ( ) . addi ( other , result ) ;


signature:
public class BaseComplexNDArray { /** * Perform an copy matrix multiplication
 * @ param other the other matrix to perform matrix multiply with
 * @ param result the result ndarray
 * @ return the result of the matrix multiplication */
@ Override public IComplexNDArray mmuli ( INDArray other , INDArray result ) { } }

implementation:
IComplexNDArray otherArray = ( IComplexNDArray ) other ; IComplexNDArray resultArray = ( IComplexNDArray ) result ; if ( other . shape ( ) . length > 2 ) { for ( int i = 0 ; i < other . slices ( ) ; i ++ ) { resultArray . putSlice ( i , slice ( i ) . mmul ( otherArray . slice ( i ) ) ) ; } return resultArray ; } LinAlgExceptions . assertMultiplies ( this , other ) ; if ( other . isScalar ( ) ) { return muli ( otherArray . getComplex ( 0 ) , resultArray ) ; } if ( isScalar ( ) ) { return otherArray . muli ( getComplex ( 0 ) , resultArray ) ; } /* check sizes and resize if necessary */
// assertMultipliesWith ( other ) ;
if ( result == this || result == other ) { /* actually , blas cannot do multiplications in - place . Therefore , we will fake by
 * allocating a temporary object on the side and copy the result later . */
IComplexNDArray temp = Nd4j . createComplex ( resultArray . shape ( ) ) ; if ( otherArray . columns ( ) == 1 ) { Nd4j . getBlasWrapper ( ) . level2 ( ) . gemv ( BlasBufferUtil . getCharForTranspose ( temp ) , BlasBufferUtil . getCharForTranspose ( this ) , Nd4j . UNIT , this , otherArray , Nd4j . ZERO , temp ) ; } else { Nd4j . getBlasWrapper ( ) . level3 ( ) . gemm ( BlasBufferUtil . getCharForTranspose ( temp ) , BlasBufferUtil . getCharForTranspose ( this ) , BlasBufferUtil . getCharForTranspose ( other ) , Nd4j . UNIT , this , otherArray , Nd4j . ZERO , temp ) ; } Nd4j . getBlasWrapper ( ) . copy ( temp , resultArray ) ; } else { if ( otherArray . columns ( ) == 1 ) { Nd4j . getBlasWrapper ( ) . level2 ( ) . gemv ( BlasBufferUtil . getCharForTranspose ( resultArray ) , BlasBufferUtil . getCharForTranspose ( this ) , Nd4j . UNIT , this , otherArray , Nd4j . ZERO , resultArray ) ; } else { Nd4j . getBlasWrapper ( ) . level3 ( ) . gemm ( BlasBufferUtil . getCharForTranspose ( resultArray ) , BlasBufferUtil . getCharForTranspose ( this ) , BlasBufferUtil . getCharForTranspose ( other ) , Nd4j . UNIT , this , otherArray , Nd4j . ZERO , resultArray ) ; } } return resultArray ;


signature:
public class BaseComplexNDArray { /** * in place ( element wise ) multiplication of two matrices
 * @ param other the second ndarray to multiply
 * @ param result the result ndarray
 * @ return the result of the multiplication */
@ Override public IComplexNDArray muli ( INDArray other , INDArray result ) { } }

implementation: IComplexNDArray cOther = ( IComplexNDArray ) other ; IComplexNDArray cResult = ( IComplexNDArray ) result ; IComplexNDArray linear = linearView ( ) ; IComplexNDArray cOtherLinear = cOther . linearView ( ) ; IComplexNDArray cResultLinear = cResult . linearView ( ) ; if ( other . isScalar ( ) ) return muli ( cOther . getComplex ( 0 ) , result ) ; IComplexNumber c = Nd4j . createComplexNumber ( 0 , 0 ) ; IComplexNumber d = Nd4j . createComplexNumber ( 0 , 0 ) ; for ( int i = 0 ; i < length ( ) ; i ++ ) cResultLinear . putScalar ( i , linear . getComplex ( i , c ) . muli ( cOtherLinear . getComplex ( i , d ) ) ) ; return cResult ;


signature:
public class BaseComplexNDArray { /** * in place subtraction of two matrices
 * @ param other the second ndarray to subtract
 * @ param result the result ndarray
 * @ return the result of the subtraction */
@ Override public IComplexNDArray subi ( INDArray other , INDArray result ) { } }

implementation: IComplexNDArray cOther = ( IComplexNDArray ) other ; IComplexNDArray cResult = ( IComplexNDArray ) result ; if ( other . isScalar ( ) ) return subi ( cOther . getComplex ( 0 ) , result ) ; if ( result == this ) Nd4j . getBlasWrapper ( ) . axpy ( Nd4j . NEG_UNIT , cOther , cResult ) ; else if ( result == other ) { if ( data . dataType ( ) == ( DataBuffer . Type . DOUBLE ) ) { Nd4j . getBlasWrapper ( ) . scal ( Nd4j . NEG_UNIT . asDouble ( ) , cResult ) ; Nd4j . getBlasWrapper ( ) . axpy ( Nd4j . UNIT , this , cResult ) ; } else { Nd4j . getBlasWrapper ( ) . scal ( Nd4j . NEG_UNIT . asFloat ( ) , cResult ) ; Nd4j . getBlasWrapper ( ) . axpy ( Nd4j . UNIT , this , cResult ) ; } } else { Nd4j . getBlasWrapper ( ) . copy ( this , result ) ; Nd4j . getBlasWrapper ( ) . axpy ( Nd4j . NEG_UNIT , cOther , cResult ) ; } return cResult ;


signature:
public class BaseComplexNDArray { /** * in place addition of two matrices
 * @ param other the second ndarray to add
 * @ param result the result ndarray
 * @ return the result of the addition */
@ Override public IComplexNDArray addi ( INDArray other , INDArray result ) { } }

implementation: IComplexNDArray cOther = ( IComplexNDArray ) other ; IComplexNDArray cResult = ( IComplexNDArray ) result ; if ( cOther . isScalar ( ) ) { return cResult . addi ( cOther . getComplex ( 0 ) , result ) ; } if ( isScalar ( ) ) { return cOther . addi ( getComplex ( 0 ) , result ) ; } if ( result == this ) { Nd4j . getBlasWrapper ( ) . axpy ( Nd4j . UNIT , cOther , cResult ) ; } else if ( result == other ) { Nd4j . getBlasWrapper ( ) . axpy ( Nd4j . UNIT , this , cResult ) ; } else { INDArray resultLinear = result . linearView ( ) ; INDArray otherLinear = other . linearView ( ) ; INDArray linear = linearView ( ) ; for ( int i = 0 ; i < resultLinear . length ( ) ; i ++ ) { resultLinear . putScalar ( i , otherLinear . getDouble ( i ) + linear . getDouble ( i ) ) ; } } return ( IComplexNDArray ) result ;


signature:
public class BaseComplexNDArray { /** * Set the value of the ndarray to the specified value
 * @ param value the value to assign
 * @ return the ndarray with the values */
@ Override public IComplexNDArray assign ( Number value ) { } }

implementation: IComplexNDArray one = linearView ( ) ; for ( int i = 0 ; i < one . length ( ) ; i ++ ) one . putScalar ( i , Nd4j . createDouble ( value . doubleValue ( ) , 0 ) ) ; return this ;


signature:
public class BaseComplexNDArray { /** * Reverse division
 * @ param other the matrix to subtract from
 * @ param result the result ndarray
 * @ return */
@ Override public IComplexNDArray rdiv ( INDArray other , INDArray result ) { } }

implementation: return dup ( ) . rdivi ( other , result ) ;


signature:
public class BaseComplexNDArray { /** * Reverse division ( in - place )
 * @ param other the other ndarray to subtract
 * @ param result the result ndarray
 * @ return the ndarray with the operation applied */
@ Override public IComplexNDArray rdivi ( INDArray other , INDArray result ) { } }

implementation: return ( IComplexNDArray ) other . divi ( this , result ) ;


signature:
public class BaseComplexNDArray { /** * Reverse subtraction
 * @ param other the matrix to subtract from
 * @ param result the result ndarray
 * @ return */
@ Override public IComplexNDArray rsub ( INDArray other , INDArray result ) { } }

implementation: return dup ( ) . rsubi ( other , result ) ;


signature:
public class BaseComplexNDArray { /** * Reverse subtraction ( in - place )
 * @ param other the other ndarray to subtract
 * @ param result the result ndarray
 * @ return the ndarray with the operation applied */
@ Override public IComplexNDArray rsubi ( INDArray other , INDArray result ) { } }

implementation: return ( IComplexNDArray ) other . subi ( this , result ) ;


signature:
public class BaseComplexNDArray { /** * Returns a scalar ( individual element )
 * of a scalar ndarray
 * @ return the individual item in this ndarray */
@ Override public Object element ( ) { } }

implementation: if ( ! isScalar ( ) ) throw new IllegalStateException ( "Unable to getScalar the element of a non scalar" ) ; long idx = linearIndex ( 0 ) ; return Nd4j . createDouble ( data . getDouble ( idx ) , data . getDouble ( idx + 1 ) ) ;


signature:
public class BaseComplexNDArray { /** * Flattens the array for linear indexing
 * @ return the flattened version of this array */
@ Override public IComplexNDArray ravel ( ) { } }

implementation: if ( length ( ) >= Integer . MAX_VALUE ) throw new IllegalArgumentException ( "length() can not be >= Integer.MAX_VALUE" ) ; IComplexNDArray ret = Nd4j . createComplex ( ( int ) length ( ) , ordering ( ) ) ; IComplexNDArray linear = linearView ( ) ; for ( int i = 0 ; i < length ( ) ; i ++ ) { ret . putScalar ( i , linear . getComplex ( i ) ) ; } return ret ;


signature:
public class Eigen { /** * Computes the eigenvalues of a general matrix . */
public static IComplexNDArray eigenvalues ( INDArray A ) { } }

implementation: assert A . rows ( ) == A . columns ( ) ; INDArray WR = Nd4j . create ( A . rows ( ) , A . rows ( ) ) ; INDArray WI = WR . dup ( ) ; Nd4j . getBlasWrapper ( ) . geev ( 'N' , 'N' , A . dup ( ) , WR , WI , dummy , dummy ) ; return Nd4j . createComplex ( WR , WI ) ;


signature:
public class Eigen { /** * Computes the eigenvalues and eigenvectors of a general matrix .
 * For matlab users note the following from their documentation :
 * The columns of V present eigenvectors of A . The diagonal matrix D contains eigenvalues .
 * This is in reverse order of the matlab eig ( A ) call .
 * @ param A the ndarray to getFloat the eigen vectors for
 * @ return 2 arrays representing W ( eigen vectors ) and V ( normalized eigen vectors ) */
public static IComplexNDArray [ ] eigenvectors ( INDArray A ) { } }

implementation:
assert A . columns ( ) == A . rows ( ) ; // setting up result arrays
INDArray WR = Nd4j . create ( A . rows ( ) ) ; INDArray WI = WR . dup ( ) ; INDArray VR = Nd4j . create ( A . rows ( ) , A . rows ( ) ) ; INDArray VL = Nd4j . create ( A . rows ( ) , A . rows ( ) ) ; Nd4j . getBlasWrapper ( ) . geev ( 'v' , 'v' , A . dup ( ) , WR , WI , VL , VR ) ; // transferring the result
IComplexNDArray E = Nd4j . createComplex ( WR , WI ) ; IComplexNDArray V = Nd4j . createComplex ( ( int ) A . rows ( ) , ( int ) A . rows ( ) ) ; for ( int i = 0 ; i < A . rows ( ) ; i ++ ) { if ( E . getComplex ( i ) . isReal ( ) ) { IComplexNDArray column = Nd4j . createComplex ( VR . getColumn ( i ) ) ; V . putColumn ( i , column ) ; } else { IComplexNDArray v = Nd4j . createComplex ( VR . getColumn ( i ) , VR . getColumn ( i + 1 ) ) ; V . putColumn ( i , v ) ; V . putColumn ( i + 1 , v . conji ( ) ) ; i += 1 ; } } return new IComplexNDArray [ ] { Nd4j . diag ( E ) , V } ;


signature:
public class Eigen { /** * Compute generalized eigenvalues of the problem A x = L B x .
 * The data will be unchanged , no eigenvectors returned .
 * @ param A symmetric Matrix A .
 * @ param B symmetric Matrix B .
 * @ return a vector of eigenvalues L . */
public static INDArray symmetricGeneralizedEigenvalues ( INDArray A , INDArray B ) { } }

implementation: assert A . rows ( ) == A . columns ( ) ; assert B . rows ( ) == B . columns ( ) ; INDArray W = Nd4j . create ( A . rows ( ) ) ; A = InvertMatrix . invert ( B , false ) . mmuli ( A ) ; Nd4j . getBlasWrapper ( ) . syev ( 'V' , 'L' , A , W ) ; return W ;


signature:
public class BinomialDistribution { /** * { @ inheritDoc } */
public double probability ( int x ) { } }

implementation: double ret ; if ( x < 0 || x > numberOfTrials ) { ret = 0.0 ; } else { ret = FastMath . exp ( SaddlePointExpansion . logBinomialProbability ( x , numberOfTrials , probabilityOfSuccess , 1.0 - probabilityOfSuccess ) ) ; } return ret ;


signature:
public class BaseLevel1 { /** * finds the element of a vector that has the largest absolute value .
 * @ param arr
 * @ return */
@ Override public int iamax ( IComplexNDArray arr ) { } }

implementation: if ( arr . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) return izamax ( arr . length ( ) , arr , BlasBufferUtil . getBlasStride ( arr ) ) ; return icamax ( arr . length ( ) , arr , BlasBufferUtil . getBlasStride ( arr ) ) ;


signature:
public class BaseLevel1 { /** * copy a vector to another vector .
 * @ param x
 * @ param y */
@ Override public void copy ( IComplexNDArray x , IComplexNDArray y ) { } }

implementation: if ( x . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zcopy ( x . length ( ) , x , BlasBufferUtil . getBlasStride ( x ) , y , BlasBufferUtil . getBlasStride ( y ) ) ; else ccopy ( x . length ( ) , x , BlasBufferUtil . getBlasStride ( x ) , y , BlasBufferUtil . getBlasStride ( y ) ) ;


signature:
public class BaseLevel1 { /** * computes a vector - scalar product and adds the result to a vector .
 * @ param n
 * @ param alpha
 * @ param x
 * @ param y */
@ Override public void axpy ( long n , double alpha , INDArray x , INDArray y ) { } }

implementation: if ( Nd4j . getExecutioner ( ) . getProfilingMode ( ) == OpExecutioner . ProfilingMode . ALL ) OpProfiler . getInstance ( ) . processBlasCall ( false , x , y ) ; if ( x . isSparse ( ) && ! y . isSparse ( ) ) { Nd4j . getSparseBlasWrapper ( ) . level1 ( ) . axpy ( n , alpha , x , y ) ; } else if ( x . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . DOUBLE , x , y ) ; daxpy ( n , alpha , x , BlasBufferUtil . getBlasStride ( x ) , y , BlasBufferUtil . getBlasStride ( y ) ) ; } else if ( x . data ( ) . dataType ( ) == DataBuffer . Type . FLOAT ) { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . FLOAT , x , y ) ; saxpy ( n , ( float ) alpha , x , BlasBufferUtil . getBlasStride ( x ) , y , BlasBufferUtil . getBlasStride ( y ) ) ; } else { DefaultOpExecutioner . validateDataType ( DataBuffer . Type . HALF , x , y ) ; haxpy ( n , ( float ) alpha , x , BlasBufferUtil . getBlasStride ( x ) , y , BlasBufferUtil . getBlasStride ( y ) ) ; }


signature:
public class BaseLevel1 { /** * computes a vector - scalar product and adds the result to a vector .
 * @ param n
 * @ param alpha
 * @ param x
 * @ param y */
@ Override public void axpy ( long n , IComplexNumber alpha , IComplexNDArray x , IComplexNDArray y ) { } }

implementation: if ( x . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zaxpy ( n , alpha . asDouble ( ) , x , BlasBufferUtil . getBlasStride ( x ) , y , BlasBufferUtil . getBlasStride ( y ) ) ; else caxpy ( n , alpha . asFloat ( ) , x , BlasBufferUtil . getBlasStride ( x ) , y , BlasBufferUtil . getBlasStride ( y ) ) ;


signature:
public class BaseLevel1 { /** * computes a vector by a scalar product .
 * @ param N
 * @ param alpha
 * @ param X */
@ Override public void scal ( long N , IComplexNumber alpha , IComplexNDArray X ) { } }

implementation: if ( X . data ( ) . dataType ( ) == DataBuffer . Type . DOUBLE ) zscal ( N , alpha . asDouble ( ) , X , BlasBufferUtil . getBlasStride ( X ) ) ; else cscal ( N , alpha . asFloat ( ) , X , BlasBufferUtil . getBlasStride ( X ) ) ;


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

implementation:
if ( array . rank ( ) <= 2 ) { array . subiRowVector ( stats . getLower ( ) ) ; array . diviRowVector ( stats . getRange ( ) ) ; } // if feature Rank is 3 ( time series ) samplesxfeaturesxtimesteps
// if feature Rank is 4 ( images ) samplesxchannelsxrowsxcols
// both cases operations should be carried out in dimension 1
else { Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastSubOp ( array , stats . getLower ( ) , array , 1 ) ) ; Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastDivOp ( array , stats . getRange ( ) , array , 1 ) ) ; } // Scale by target range
array . muli ( maxRange - minRange ) ; // Add target range minimum values
array . addi ( minRange ) ; if ( maskArray != null ) { DataSetUtil . setMaskedValuesToZero ( array , maskArray ) ; }


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

implementation:
// Subtract target range minimum value
array . subi ( minRange ) ; // Scale by target range
array . divi ( maxRange - minRange ) ; if ( array . rank ( ) <= 2 ) { array . muliRowVector ( stats . getRange ( ) ) ; array . addiRowVector ( stats . getLower ( ) ) ; } else { Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastMulOp ( array , stats . getRange ( ) , array , 1 ) ) ; Nd4j . getExecutioner ( ) . execAndReturn ( new BroadcastAddOp ( array , stats . getLower ( ) , array , 1 ) ) ; } if ( maskArray != null ) { DataSetUtil . setMaskedValuesToZero ( array , maskArray ) ; }


signature:
public class DataSetUtil { /** * Merge the specified labels and label mask arrays ( i . e . , concatenate the examples )
 * @ param labelsToMerge Features to merge
 * @ param labelMasksToMerge Mask arrays to merge . May be null
 * @ return Merged features and mask . Mask may be null */
public static Pair < INDArray , INDArray > mergeLabels ( INDArray [ ] labelsToMerge , INDArray [ ] labelMasksToMerge ) { } }

implementation: int rankFeatures = labelsToMerge [ 0 ] . rank ( ) ; switch ( rankFeatures ) { case 2 : return DataSetUtil . merge2d ( labelsToMerge , labelMasksToMerge ) ; case 3 : return DataSetUtil . mergeTimeSeries ( labelsToMerge , labelMasksToMerge ) ; case 4 : return DataSetUtil . merge4d ( labelsToMerge , labelMasksToMerge ) ; default : throw new ND4JIllegalStateException ( "Cannot merge examples: labels rank must be in range 2 to 4" + " inclusive. First example features shape: " + Arrays . toString ( labelsToMerge [ 0 ] . shape ( ) ) ) ; }


signature:
public class DataSetUtil { /** * Merge the specified 2d arrays and masks . See { @ link # mergeFeatures ( INDArray [ ] , INDArray [ ] ) }
 * and { @ link # mergeLabels ( INDArray [ ] , INDArray [ ] ) }
 * @ param arrays Arrays to merge
 * @ param masks Mask arrays to merge
 * @ return Merged arrays and mask */
public static Pair < INDArray , INDArray > merge2d ( INDArray [ ] arrays , INDArray [ ] masks ) { } }

implementation: long cols = arrays [ 0 ] . columns ( ) ; INDArray [ ] temp = new INDArray [ arrays . length ] ; boolean hasMasks = false ; for ( int i = 0 ; i < arrays . length ; i ++ ) { if ( arrays [ i ] . columns ( ) != cols ) { throw new IllegalStateException ( "Cannot merge 2d arrays with different numbers of columns (firstNCols=" + cols + ", ithNCols=" + arrays [ i ] . columns ( ) + ")" ) ; } temp [ i ] = arrays [ i ] ; if ( masks != null && masks [ i ] != null && masks [ i ] != null ) { hasMasks = true ; } } INDArray out = Nd4j . specialConcat ( 0 , temp ) ; INDArray outMask = null ; if ( hasMasks ) { outMask = DataSetUtil . mergePerOutputMasks2d ( out . shape ( ) , arrays , masks ) ; } return new Pair < > ( out , outMask ) ;


signature:
public class DataSetUtil { /** * Merge the specified 4d arrays and masks . See { @ link # mergeFeatures ( INDArray [ ] , INDArray [ ] ) }
 * and { @ link # mergeLabels ( INDArray [ ] , INDArray [ ] ) }
 * @ param arrays Arrays to merge
 * @ param masks Mask arrays to merge
 * @ return Merged arrays and mask */
public static Pair < INDArray , INDArray > merge4d ( INDArray [ ] arrays , INDArray [ ] masks ) { } }

implementation:
// 4d - > images . In principle : could have 2d mask arrays ( per - example masks )
int nExamples = 0 ; long [ ] shape = arrays [ 0 ] . shape ( ) ; INDArray [ ] temp = new INDArray [ arrays . length ] ; boolean hasMasks = false ; for ( int i = 0 ; i < arrays . length ; i ++ ) { nExamples += arrays [ i ] . size ( 0 ) ; long [ ] thisShape = arrays [ i ] . shape ( ) ; if ( thisShape . length != 4 ) { throw new IllegalStateException ( "Cannot merge 4d arrays with non 4d arrays" ) ; } for ( int j = 1 ; j < 4 ; j ++ ) { if ( thisShape [ j ] != shape [ j ] ) throw new IllegalStateException ( "Cannot merge 4d arrays with different shape (other than # examples): " + " data[0].shape = " + Arrays . toString ( shape ) + ", data[" + i + "].shape = " + Arrays . toString ( thisShape ) ) ; } temp [ i ] = arrays [ i ] ; if ( masks != null && masks [ i ] != null && masks [ i ] != null ) { hasMasks = true ; if ( masks [ i ] . rank ( ) != 2 ) { throw new UnsupportedOperationException ( "Cannot merged 4d arrays with masks that are not rank 2." + " Got mask array with rank: " + masks [ i ] . rank ( ) ) ; } } } INDArray out = Nd4j . specialConcat ( 0 , temp ) ; INDArray outMask = null ; if ( hasMasks ) { outMask = DataSetUtil . mergePerOutputMasks2d ( out . shape ( ) , arrays , masks ) ; } return new Pair < > ( out , outMask ) ;


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

implementation: return new INDArray [ ] { graph . execAndEndResult ( ) } ;


signature:
public class OpExecutionerUtil { /** * Can we do the op ( X = Op ( X ) ) directly on the arrays without breaking X up into 1d tensors first ?
 * In general , this is possible if the elements of X are contiguous in the buffer , OR if every element
 * of X is at position offset + i * elementWiseStride in the buffer */
public static boolean canDoOpDirectly ( INDArray x ) { } }

implementation:
if ( x . elementWiseStride ( ) < 1 ) return false ; if ( x . isVector ( ) ) return true ; // For a single NDArray all we require is that the elements are contiguous in the buffer or every nth element
// Full buffer - > implies all elements are contiguous ( and match )
long l1 = x . lengthLong ( ) ; long dl1 = x . data ( ) . length ( ) ; if ( l1 == dl1 ) return true ; // Strides are same as a zero offset NDArray - > all elements are contiguous ( even if not offset 0)
long [ ] shape1 = x . shape ( ) ; long [ ] stridesAsInit = ( x . ordering ( ) == 'c' ? ArrayUtil . calcStrides ( shape1 ) : ArrayUtil . calcStridesFortran ( shape1 ) ) ; boolean stridesSameAsInit = Arrays . equals ( x . stride ( ) , stridesAsInit ) ; return stridesSameAsInit ;


signature:
public class OpExecutionerUtil { /** * Can we do the transform op ( X = Op ( X , Y ) ) directly on the arrays without breaking them up into 1d tensors first ? */
public static boolean canDoOpDirectly ( INDArray x , INDArray y ) { } }

implementation:
if ( x . isVector ( ) ) return true ; if ( x . ordering ( ) != y . ordering ( ) ) return false ; // other than vectors , elements in f vs . c NDArrays will never line up
if ( x . elementWiseStride ( ) < 1 || y . elementWiseStride ( ) < 1 ) return false ; // Full buffer + matching strides - > implies all elements are contiguous ( and match )
// Need strides to match , otherwise elements in buffer won ' t line up ( i . e . , c vs . f order arrays )
long l1 = x . lengthLong ( ) ; long dl1 = x . data ( ) . length ( ) ; long l2 = y . lengthLong ( ) ; long dl2 = y . data ( ) . length ( ) ; long [ ] strides1 = x . stride ( ) ; long [ ] strides2 = y . stride ( ) ; boolean equalStrides = Arrays . equals ( strides1 , strides2 ) ; if ( l1 == dl1 && l2 == dl2 && equalStrides ) return true ; // Strides match + are same as a zero offset NDArray - > all elements are contiguous ( and match )
if ( equalStrides ) { long [ ] shape1 = x . shape ( ) ; long [ ] stridesAsInit = ( x . ordering ( ) == 'c' ? ArrayUtil . calcStrides ( shape1 ) : ArrayUtil . calcStridesFortran ( shape1 ) ) ; boolean stridesSameAsInit = Arrays . equals ( strides1 , stridesAsInit ) ; return stridesSameAsInit ; } return false ;


signature:
public class OpExecutionerUtil { /** * Tensor1DStats , used to efficiently iterate through tensors on a matrix ( 2d NDArray ) for element - wise ops
 * For example , the offset of each 1d tensor can be calculated using only a single tensorAlongDimension method call ,
 * hence is potentially faster than approaches requiring multiple tensorAlongDimension calls . < br >
 * Note that this can only ( generally ) be used for 2d NDArrays . For certain 3 + d NDArrays , the tensor starts may not
 * be in increasing order */
public static Tensor1DStats get1DTensorStats ( INDArray array , int ... dimension ) { } }

implementation:
long tensorLength = array . size ( dimension [ 0 ] ) ; // As per tensorssAlongDimension :
long numTensors = array . tensorssAlongDimension ( dimension ) ; // First tensor always starts with the first element in the NDArray , regardless of dimension
long firstTensorOffset = array . offset ( ) ; // Next : Need to work out the separation between the start ( first element ) of each 1d tensor
long tensorStartSeparation ; int elementWiseStride ; // Separation in buffer between elements in the tensor
if ( numTensors == 1 ) { tensorStartSeparation = - 1 ; // Not applicable
elementWiseStride = array . elementWiseStride ( ) ; } else { INDArray secondTensor = array . tensorAlongDimension ( 1 , dimension ) ; tensorStartSeparation = secondTensor . offset ( ) - firstTensorOffset ; elementWiseStride = secondTensor . elementWiseStride ( ) ; } return new Tensor1DStats ( firstTensorOffset , tensorStartSeparation , numTensors , tensorLength , elementWiseStride ) ;


signature:
public class DistributedSgDotMessage { /** * This method calculates dot of gives rows */
@ Override public void processMessage ( ) { } }

implementation:
// this only picks up new training round
// log . info ( " sI _ { } Processing DistributedSgDotMessage taskId : { } " , transport . getShardIndex ( ) , getTaskId ( ) ) ;
SkipGramRequestMessage sgrm = new SkipGramRequestMessage ( w1 , w2 , rowsB , codes , negSamples , alpha , 119 ) ; if ( negSamples > 0 ) { // unfortunately we have to get copy of negSamples here
int negatives [ ] = Arrays . copyOfRange ( rowsB , codes . length , rowsB . length ) ; sgrm . setNegatives ( negatives ) ; } sgrm . setTaskId ( this . taskId ) ; sgrm . setOriginatorId ( this . getOriginatorId ( ) ) ; // FIXME : get rid of THAT
SkipGramTrainer sgt = ( SkipGramTrainer ) trainer ; sgt . pickTraining ( sgrm ) ; // TODO : make this thing a single op , even specialOp is ok
// we calculate dot for all involved rows
int resultLength = codes . length + ( negSamples > 0 ? ( negSamples + 1 ) : 0 ) ; INDArray result = Nd4j . createUninitialized ( resultLength , 1 ) ; int e = 0 ; for ( ; e < codes . length ; e ++ ) { double dot = Nd4j . getBlasWrapper ( ) . dot ( storage . getArray ( WordVectorStorage . SYN_0 ) . getRow ( w2 ) , storage . getArray ( WordVectorStorage . SYN_1 ) . getRow ( rowsB [ e ] ) ) ; result . putScalar ( e , dot ) ; } // negSampling round
for ( ; e < resultLength ; e ++ ) { double dot = Nd4j . getBlasWrapper ( ) . dot ( storage . getArray ( WordVectorStorage . SYN_0 ) . getRow ( w2 ) , storage . getArray ( WordVectorStorage . SYN_1_NEGATIVE ) . getRow ( rowsB [ e ] ) ) ; result . putScalar ( e , dot ) ; } if ( voidConfiguration . getExecutionMode ( ) == ExecutionMode . AVERAGING ) { // just local bypass
DotAggregation dot = new DotAggregation ( taskId , ( short ) 1 , shardIndex , result ) ; dot . setTargetId ( ( short ) - 1 ) ; dot . setOriginatorId ( getOriginatorId ( ) ) ; transport . putMessage ( dot ) ; } else if ( voidConfiguration . getExecutionMode ( ) == ExecutionMode . SHARDED ) { // send this message to everyone
DotAggregation dot = new DotAggregation ( taskId , ( short ) voidConfiguration . getNumberOfShards ( ) , shardIndex , result ) ; dot . setTargetId ( ( short ) - 1 ) ; dot . setOriginatorId ( getOriginatorId ( ) ) ; transport . sendMessage ( dot ) ; }


signature:
public class LossFunctions { /** * Mean squared error : L = mean ( ( predicted - label ) ^ 2)
 * @ param outputName Name of the output SDVariable
 * @ param predictions Predictions variable
 * @ param label Label variable
 * @ param weights Weights array . May be null , or any broadcastable shape ( with predictions / label arrays ) .
 * Note that this is also used for masking ( weight of 0 = ' masked out ' )
 * @ param reduction Type of reduction to perform for the loss function
 * @ param dimensions Dimension ( s ) to apply the loss function on
 * @ return LossInfo - bean with variables etc for the loss function */
public static LossInfo mse ( String outputName , SDVariable predictions , SDVariable label , SDVariable weights , Reduction reduction , int ... dimensions ) { } }

implementation: LossInfo . Builder b = validate ( "mse" , predictions , label , reduction ) ; SameDiff sd = predictions . getSameDiff ( ) ; if ( weights == null ) { weights = sd . one ( "mse_loss_weights" , SCALAR ) ; } SDVariable diff = predictions . sub ( label ) ; String name = ( reduction == Reduction . NONE ? outputName : null ) ; SDVariable preReduceLoss = sd . square ( diff ) . mul ( name , weights ) ; return doReduce ( sd , outputName , true , b , reduction , preReduceLoss , label , weights , dimensions ) ;


signature:
public class LossFunctions { /** * Multi - Class Cross Entropy loss function : < br >
 * L = sum _ i actual _ i * log ( predicted _ i )
 * @ param outputName
 * @ param predictions
 * @ param label
 * @ param weights
 * @ param reduction
 * @ param dimensions
 * @ return */
public static LossInfo mcxent ( String outputName , SDVariable predictions , SDVariable label , SDVariable weights , Reduction reduction , int ... dimensions ) { } }

implementation: LossInfo . Builder b = validate ( "mcxent" , predictions , label , reduction ) ; SameDiff sd = predictions . getSameDiff ( ) ; if ( weights == null ) { weights = sd . one ( "mcxent_loss_weights" , SCALAR ) ; } String name = ( reduction == Reduction . NONE ? outputName : null ) ; SDVariable weightedLogProd = sd . log ( predictions ) . mul ( label ) . mul ( name , weights ) ; return doReduce ( sd , outputName , false , b , reduction , weightedLogProd , label , weights , dimensions ) ;


signature:
public class LossFunctions { /** * Determine the number of weight entries that are non - zero , after broadcasting
 * @ param weights
 * @ param labels
 * @ return */
private static SDVariable nonZeroCount ( SDVariable weights , SDVariable labels ) { } }

implementation: SameDiff sd = weights . getSameDiff ( ) ; SDVariable present = sd . neq ( weights , 0.0 ) ; SDVariable presentBroadcast = sd . zerosLike ( labels ) . add ( present ) ; return sd . sum ( presentBroadcast ) ;


signature:
public class LossFunctions { /** * Perform the final reduction on the loss function
 * @ param sd
 * @ param outputName
 * @ param isMean
 * @ param b
 * @ param reduction
 * @ param preReduceLoss
 * @ param label
 * @ param weights
 * @ param dimensions
 * @ return */
private static LossInfo doReduce ( SameDiff sd , String outputName , boolean isMean , LossInfo . Builder b , Reduction reduction , SDVariable preReduceLoss , SDVariable label , SDVariable weights , int [ ] dimensions ) { } }

implementation:
switch ( reduction ) { case NONE : // Return same shape as predictions / labels
b . loss ( preReduceLoss ) ; break ; case SPECIFIED_DIMS : // Reduce along specified dimensions
if ( isMean ) { // Example : MSE + mean along examples
b . loss ( sd . mean ( outputName , preReduceLoss , dimensions ) ) ; } else { // Example : L1 loss ( sum ) + mean along examples
b . loss ( sd . sum ( outputName , preReduceLoss , dimensions ) ) ; } case SUM : if ( isMean ) { // Example : MSE ( mean ) + sum along examples
SDVariable m = sd . mean ( preReduceLoss , dimensions ) ; b . loss ( sd . sum ( outputName , m ) ) ; } else { // Example : L1 loss ( sum ) + sum along examples - > sum along all dimensions
b . loss ( sd . sum ( outputName , preReduceLoss ) ) ; } break ; case MEAN_BY_WEIGHT : SDVariable weightSum = sd . sum ( weights ) ; if ( isMean ) { // Example : MSE ( mean ) + mean by weights over examples
// reduce along dims + reduce along remaining dims = = reduce along * all * dims
SDVariable m2 = sd . mean ( preReduceLoss ) ; b . loss ( m2 . div ( outputName , weightSum ) ) ; } else { // Example : L1 ( sum ) + mean by weights over examples
SDVariable sum = sd . sum ( preReduceLoss , dimensions ) ; b . loss ( sum . div ( outputName , weightSum ) ) ; } break ; case MEAN_BY_COUNT : SDVariable nonZeroWeights = nonZeroCount ( weights , label ) ; SDVariable r ; if ( isMean ) { // Example : MSE ( mean ) + mean by count over examples
r = sd . sum ( preReduceLoss ) ; } else { // Example : L1 ( sum ) + mean by count over examples
SDVariable sum = sd . sum ( preReduceLoss , dimensions ) ; r = sd . mean ( sum ) ; } b . loss ( r . div ( outputName , nonZeroWeights ) ) ; break ; default : throw new RuntimeException ( "Unknown reduction: " + reduction ) ; } return b . build ( ) ;


signature:
public class CaptureTypeImpl { /** * Initialize this CaptureTypeImpl .
 * This is needed for type variable bounds referring to each other : we need the capture of the argument . */
void init ( VarMap varMap ) { } }

implementation:
ArrayList < Type > upperBoundsList = new ArrayList < > ( ) ; upperBoundsList . addAll ( Arrays . asList ( varMap . map ( variable . getBounds ( ) ) ) ) ; List < Type > wildcardUpperBounds = Arrays . asList ( wildcard . getUpperBounds ( ) ) ; if ( wildcardUpperBounds . size ( ) > 0 && wildcardUpperBounds . get ( 0 ) == Object . class ) { // skip the Object bound , we already have a first upper bound from ' variable '
upperBoundsList . addAll ( wildcardUpperBounds . subList ( 1 , wildcardUpperBounds . size ( ) ) ) ; } else { upperBoundsList . addAll ( wildcardUpperBounds ) ; } upperBounds = new Type [ upperBoundsList . size ( ) ] ; upperBoundsList . toArray ( upperBounds ) ;


signature:
public class TypeUtils { /** * Throw an IllegalStateException if the class does not have a no - arg constructor . */
public static < T > Constructor < T > getNoArgConstructor ( Class < T > clazz ) { } }

implementation:
try { Constructor < T > ctor = clazz . getDeclaredConstructor ( new Class [ 0 ] ) ; ctor . setAccessible ( true ) ; return ctor ; } catch ( NoSuchMethodException e ) { // lame there is no way to tell if the class is a nonstatic inner class
if ( clazz . isMemberClass ( ) || clazz . isAnonymousClass ( ) || clazz . isLocalClass ( ) ) throw new IllegalStateException ( clazz . getName ( ) + " must be static and must have a no-arg constructor" , e ) ; else throw new IllegalStateException ( clazz . getName ( ) + " must have a no-arg constructor" , e ) ; }


signature:
public class TypeUtils { /** * Gets a constructor that has the specified types of arguments .
 * Throw an IllegalStateException if the class does not have such a constructor . */
public static MethodHandle getConstructor ( Class < ? > clazz , Class < ? > ... args ) { } }

implementation:
try { // We use unreflect so that we can make the constructor accessible
Constructor < ? > ctor = clazz . getDeclaredConstructor ( args ) ; ctor . setAccessible ( true ) ; return MethodHandles . lookup ( ) . unreflectConstructor ( ctor ) ; } catch ( NoSuchMethodException e ) { throw new IllegalStateException ( clazz . getName ( ) + " has no constructor with args " + Arrays . toString ( args ) , e ) ; } catch ( IllegalAccessException e ) { throw new IllegalStateException ( "Problem getting constructor for " + clazz . getName ( ) + " with args " + Arrays . toString ( args ) , e ) ; }


signature:
public class TypeUtils { /** * Wraps any non - runtime exceptions with a runtime exception */
public static < T > T invoke ( MethodHandle methodHandle , Object ... params ) { } }

implementation: try { return ( T ) methodHandle . invokeWithArguments ( params ) ; } catch ( RuntimeException e ) { throw e ; } catch ( Throwable throwable ) { throw new RuntimeException ( throwable ) ; }


signature:
public class TypeUtils { /** * Checked exceptions are LAME . */
public static < T > T newInstance ( Constructor < T > ctor , Object ... params ) { } }

implementation: try { return ctor . newInstance ( params ) ; } catch ( InstantiationException | IllegalAccessException | InvocationTargetException e ) { throw new RuntimeException ( e ) ; }


signature:
public class TypeUtils { /** * Checked exceptions are LAME . */
public static Object field_get ( Field field , Object obj ) { } }

implementation: try { return field . get ( obj ) ; } catch ( IllegalArgumentException | IllegalAccessException e ) { throw new RuntimeException ( e ) ; }


signature:
public class TypeUtils { /** * Just like Class . isAssignableFrom ( ) , but does the right thing when considering autoboxing . */
public static boolean isAssignableFrom ( Class < ? > to , Class < ? > from ) { } }

implementation: Class < ? > notPrimitiveTo = to . isPrimitive ( ) ? PRIMITIVE_TO_WRAPPER . get ( to ) : to ; Class < ? > notPrimitiveFrom = from . isPrimitive ( ) ? PRIMITIVE_TO_WRAPPER . get ( from ) : from ; return notPrimitiveTo . isAssignableFrom ( notPrimitiveFrom ) ;


signature:
public class TypeUtils { /** * Gets the annotation that has the specified type , or null if there isn ' t one */
@ SuppressWarnings ( "unchecked" ) public static < A extends Annotation > A getAnnotation ( Annotation [ ] annotations , Class < A > annotationType ) { } }

implementation: for ( Annotation anno : annotations ) if ( annotationType . isAssignableFrom ( anno . getClass ( ) ) ) return ( A ) anno ; return null ;


signature:
public class TypeUtils { /** * Get the declared annotation , ignoring any inherited annotations */
public static < A extends Annotation > A getDeclaredAnnotation ( Class < ? > onClass , Class < A > annotationType ) { } }

implementation: return getAnnotation ( onClass . getDeclaredAnnotations ( ) , annotationType ) ;


signature:
public class TypeUtils { /** * Is the declared annotation present , ignoring any inherited annotations */
public static < A extends Annotation > boolean isDeclaredAnnotationPresent ( Class < ? > onClass , Class < A > annotationType ) { } }

implementation: return getDeclaredAnnotation ( onClass , annotationType ) != null ;


signature:
public class ResultProxy { /** * Create a ResultProxy for the given interface . */
@ SuppressWarnings ( "unchecked" ) public static < S > S create ( Class < ? super S > interf , Result < S > result ) { } }

implementation: return ( S ) Proxy . newProxyInstance ( result . getClass ( ) . getClassLoader ( ) , new Class [ ] { interf } , new ResultProxy < > ( result ) ) ;


signature:
public class AsyncTransactionImpl { /** * / * ( non - Javadoc )
 * @ see com . googlecode . objectify . util . cmd . TransactionWrapper # commit ( ) */
@ Override public Response commit ( ) { } }

implementation:
// Complete any enlisted operations so that the session becomes consistent . Note that some of the
// enlisted load operations might result in further enlistment . . . so we have to do this in a loop
// that protects against concurrent modification exceptions
while ( ! enlisted . isEmpty ( ) ) { final List < Result < ? > > last = enlisted ; enlisted = new ArrayList < > ( ) ; for ( final Result < ? > result : last ) result . now ( ) ; } final Response response = transaction . commit ( ) ; afterCommit . run ( ) ; return response ;


signature:
public class EntityMetadata { /** * Converts an entity to an object of the appropriate type for this metadata structure .
 * Does not check that the entity is appropriate ; that should be done when choosing
 * which EntityMetadata to call . */
public P load ( final BaseEntity < ? > ent , final LoadContext ctx ) { } }

implementation:
try { // The context needs to know the root entity for any given point
ctx . setCurrentRoot ( Key . create ( ( com . google . cloud . datastore . Key ) ent . getKey ( ) ) ) ; final EntityValue entityValue = makeLoadEntityValue ( ent ) ; return translator . load ( entityValue , ctx , Path . root ( ) ) ; } catch ( LoadException ex ) { throw ex ; } catch ( Exception ex ) { throw new LoadException ( ent , ex . getMessage ( ) , ex ) ; }


signature:
public class EntityMetadata { /** * The problem is ProjectionEntity ; there ' s no way to create an EntityValue with a ProjectionEntity
 * so we can ' t use the standard translation system for { @ code Value < Entity > } . Instead of making the
 * translation API really complicated , just convert it to a FullEntity . */
private EntityValue makeLoadEntityValue ( final BaseEntity < ? > ent ) { } }

implementation:
if ( ent instanceof FullEntity < ? > ) { return EntityValue . of ( ( FullEntity < ? > ) ent ) ; } else { // Sadly there ' s no more graceful way of doing this
final Builder < ? > builder = FullEntity . newBuilder ( ent . getKey ( ) ) ; for ( final String name : ent . getNames ( ) ) { final Value < ? > value = ent . getValue ( name ) ; builder . set ( name , value ) ; } return EntityValue . of ( builder . build ( ) ) ; }


signature:
public class EntityMetadata { /** * Converts an object to a datastore Entity with the appropriate Key type . */
public FullEntity < ? > save ( final P pojo , final SaveContext ctx ) { } }

implementation: try { return translator . save ( pojo , false , ctx , Path . root ( ) ) . get ( ) ; } catch ( SaveException ex ) { throw ex ; } catch ( Exception ex ) { throw new SaveException ( pojo , ex ) ; }


signature:
public class QueryImpl { /** * / * ( non - Javadoc )
 * @ see com . googlecode . objectify . cmd . Query # filter ( java . lang . String , java . lang . Object ) */
@ Override public QueryImpl < T > filter ( final String condition , final Object value ) { } }

implementation: final QueryImpl < T > q = createQuery ( ) ; q . addFilter ( condition , value ) ; return q ;


signature:
public class QueryImpl { /** * Modifies the instance */
void addFilter ( final String condition , final Object value ) { } }

implementation:
final String [ ] parts = condition . trim ( ) . split ( " " ) ; if ( parts . length < 1 || parts . length > 2 ) throw new IllegalArgumentException ( "'" + condition + "' is not a legal filter condition" ) ; final String prop = parts [ 0 ] . trim ( ) ; final FilterOperator op = ( parts . length == 2 ) ? this . translate ( parts [ 1 ] ) : FilterOperator . EQUAL ; // If we have a class restriction , check to see if the property is the @ Parent or @ Id . We used to try to convert
// filtering on the id field to a _ _ key _ _ query , but that tended to confuse users about the real capabilities
// of GAE and Objectify . So let ' s force users to use filterKey ( ) instead .
if ( this . classRestriction != null ) { final KeyMetadata < ? > meta = loader . ofy . factory ( ) . keys ( ) . getMetadataSafe ( this . classRestriction ) ; if ( prop . equals ( meta . getParentFieldName ( ) ) ) { throw new IllegalArgumentException ( "@Parent fields cannot be filtered on. Perhaps you wish to use filterKey() or ancestor() instead?" ) ; } else if ( prop . equals ( meta . getIdFieldName ( ) ) ) { throw new IllegalArgumentException ( "@Id fields cannot be filtered on. Perhaps you wish to use filterKey() instead?" ) ; } } // Convert to something filterable , possibly extracting / converting keys
final Value < ? > translated = loader . getObjectifyImpl ( ) . makeFilterable ( value ) ; addFilter ( op . of ( prop , translated ) ) ;


signature:
public class QueryImpl { /** * Converts the textual operator ( " > " , " < = " , etc ) into a FilterOperator .
 * Forgiving about the syntax ; ! = and < > are NOT _ EQUAL , = and = = are EQUAL . */
protected FilterOperator translate ( String operator ) { } }

implementation:
operator = operator . trim ( ) ; if ( operator . equals ( "=" ) || operator . equals ( "==" ) ) return FilterOperator . EQUAL ; else if ( operator . equals ( ">" ) ) return FilterOperator . GREATER_THAN ; else if ( operator . equals ( ">=" ) ) return FilterOperator . GREATER_THAN_OR_EQUAL ; else if ( operator . equals ( "<" ) ) return FilterOperator . LESS_THAN ; else if ( operator . equals ( "<=" ) ) return FilterOperator . LESS_THAN_OR_EQUAL ; else if ( operator . equals ( "!=" ) || operator . equals ( "<>" ) ) // return FilterOperator . NOT _ EQUAL ;
throw new UnsupportedOperationException ( "The Cloud Datastore SDK does not currently support 'NOT EQUAL' filters" ) ; else if ( operator . toLowerCase ( ) . equals ( "in" ) ) // return FilterOperator . IN ;
throw new UnsupportedOperationException ( "The Cloud Datastore SDK does not currently support 'IN' filters" ) ; else throw new IllegalArgumentException ( "Unknown operator '" + operator + "'" ) ;


signature:
public class QueryImpl { /** * Modifies the instance */
void addOrder ( String condition ) { } }

implementation:
condition = condition . trim ( ) ; boolean descending = false ; if ( condition . startsWith ( "-" ) ) { descending = true ; condition = condition . substring ( 1 ) . trim ( ) ; } // Prevent ordering by @ Id or @ Parent fields , which are really part of the key
if ( this . classRestriction != null ) { final KeyMetadata < ? > meta = loader . ofy . factory ( ) . keys ( ) . getMetadataSafe ( this . classRestriction ) ; if ( condition . equals ( meta . getParentFieldName ( ) ) ) throw new IllegalArgumentException ( "You cannot order by @Parent field. Perhaps you wish to order by __key__ instead?" ) ; if ( condition . equals ( meta . getIdFieldName ( ) ) ) { throw new IllegalArgumentException ( "You cannot order by @Id field. Perhaps you wish to order by __key__ instead?" ) ; } } this . actual = actual . orderBy ( descending ? OrderBy . desc ( condition ) : OrderBy . asc ( condition ) ) ;


signature:
public class QueryImpl { /** * Modifies the instance */
void setAncestor ( final Object keyOrEntity ) { } }

implementation: final com . google . cloud . datastore . Key key = loader . ofy . factory ( ) . keys ( ) . anythingToRawKey ( keyOrEntity ) ; this . actual = this . actual . andFilter ( PropertyFilter . hasAncestor ( key ) ) ;


signature:
public class QueryImpl { /** * Modifies the instance */
void setLimit ( final int value ) { } }

implementation: this . actual = this . actual . limit ( value ) ; if ( this . chunk == null ) this . chunk = value ;


signature:
public class QueryImpl { /** * Modifies the instance */
void addProjection ( final String ... fields ) { } }

implementation: if ( this . hybrid != null && this . hybrid ) throw new IllegalStateException ( "You cannot ask for both hybrid and projections in the same query. That makes no sense!" ) ; for ( final String field : fields ) { this . actual = this . actual . project ( field ) ; }


signature:
public class QueryImpl { /** * / * ( non - Javadoc )
 * @ see com . googlecode . objectify . cmd . Query # first ( ) */
@ Override public LoadResult < T > first ( ) { } }

implementation:
// By the way , this is the same thing that PreparedQuery . asSingleEntity ( ) does internally
final Iterator < T > it = this . limit ( 1 ) . iterator ( ) ; return new LoadResult < > ( null , new IteratorFirstResult < > ( it ) ) ;


signature:
public class QueryImpl { /** * / * ( non - Javadoc )
 * @ see com . google . cloud . datastore . QueryResultIterable # iterator ( ) */
@ Override public QueryResults < T > iterator ( ) { } }

implementation: if ( ! actual . getProjection ( ) . isEmpty ( ) ) return loader . createQueryEngine ( ) . queryProjection ( this . actual . newProjectionQuery ( ) ) ; else if ( shouldHybridize ( ) ) return loader . createQueryEngine ( ) . queryHybrid ( this . actual . newKeyQuery ( ) , chunk == null ? Integer . MAX_VALUE : chunk ) ; else return loader . createQueryEngine ( ) . queryNormal ( this . actual . newEntityQuery ( ) , chunk == null ? Integer . MAX_VALUE : chunk ) ;


signature:
public class QueryImpl { /** * / * ( non - Javadoc )
 * @ see com . googlecode . objectify . cmd . Query # list ( ) */
@ Override public List < T > list ( ) { } }

implementation: return ResultProxy . create ( List . class , new MakeListResult < > ( this . chunk ( Integer . MAX_VALUE ) . iterator ( ) ) ) ;


signature:
public class QueryImpl { /** * Get an iterator over the keys . Not part of the public api , but used by QueryKeysImpl . Assumes
 * that setKeysOnly ( ) has already been set . */
QueryResults < Key < T > > keysIterator ( ) { } }

implementation: final QueryEngine queryEngine = loader . createQueryEngine ( ) ; final KeyQuery query = this . actual . newKeyQuery ( ) ; return queryEngine . queryKeysOnly ( query ) ;


signature:
public class Queries { /** * The Builder api is programmer - hostile */
public static void addOrderBy ( final StructuredQuery . Builder < ? > builder , final List < OrderBy > orderBy ) { } }

implementation: if ( ! orderBy . isEmpty ( ) ) { builder . addOrderBy ( orderBy . get ( 0 ) , orderBy . subList ( 1 , orderBy . size ( ) ) . toArray ( new OrderBy [ orderBy . size ( ) - 1 ] ) ) ; }


signature:
public class Queries { /** * The Builder api is programmer - hostile */
public static void addProjection ( final ProjectionEntityQuery . Builder builder , final List < String > projection ) { } }

implementation: if ( ! projection . isEmpty ( ) ) { builder . addProjection ( projection . get ( 0 ) , projection . subList ( 1 , projection . size ( ) ) . toArray ( new String [ projection . size ( ) - 1 ] ) ) ; }


signature:
public class Queries { /** * The Builder api is programmer - hostile */
public static void addDistinctOn ( final ProjectionEntityQuery . Builder builder , final List < String > distinctOn ) { } }

implementation: if ( ! distinctOn . isEmpty ( ) ) { builder . addDistinctOn ( distinctOn . get ( 0 ) , distinctOn . subList ( 1 , distinctOn . size ( ) ) . toArray ( new String [ distinctOn . size ( ) - 1 ] ) ) ; }


signature:
public class MemcacheServiceRetryProxy { /** * Create the proxy that does retries . Adds a strict error handler to the service . */
public static MemcacheService createProxy ( final MemcacheService raw , final int retryCount ) { } }

implementation: return ( MemcacheService ) java . lang . reflect . Proxy . newProxyInstance ( raw . getClass ( ) . getClassLoader ( ) , raw . getClass ( ) . getInterfaces ( ) , new MemcacheServiceRetryProxy ( raw , retryCount ) ) ;


signature:
public class MemcacheServiceRetryProxy { /** * / * ( non - Javadoc )
 * @ see java . lang . reflect . InvocationHandler # invoke ( java . lang . Object , java . lang . reflect . Method , java . lang . Object [ ] ) */
@ Override public Object invoke ( Object proxy , Method meth , Object [ ] args ) throws Throwable { } }

implementation:
for ( int i = 0 ; i < this . tries ; i ++ ) { try { return meth . invoke ( this . raw , args ) ; } catch ( InvocationTargetException ex ) { if ( i == ( this . tries - 1 ) ) log . error ( "Memcache operation failed, giving up" , ex ) ; else log . warn ( "Error performing memcache operation, retrying: " + meth , ex ) ; } } // Will reach this point when we have exhausted our retries .
return null ;