@Override
    public void setOutstream(OutputStream outstream) {
        if ( buffout == null )
        {
            // try reuse
            buffout = (FSTOutputStream) conf.getCachedObject(FSTOutputStream.class);
            if ( buffout == null ) // if fail, alloc
                buffout = new FSTOutputStream(1000, outstream);
            else
                buffout.reset(); // reset resued fstoutput
        }
        if ( outstream == null )
            buffout.setOutstream(buffout);
        else
            buffout.setOutstream(outstream);
    }

@
Override
public
void
setOutstream
(
OutputStream
outstream
)
{
if
(
buffout
==
)
{
// try reuse
buffout
=
(
FSTOutputStream
)
conf
.
getCachedObject
(
FSTOutputStream
.
class
)
;
if
(
buffout
==
)
// if fail, alloc
buffout
=
new
FSTOutputStream
(
1000
,
outstream
)
;
else
buffout
.
reset
(
)
;
// reset resued fstoutput
}
if
(
outstream
==
)
buffout
.
setOutstream
(
buffout
)
;
else
buffout
.
setOutstream
(
outstream
)
;
}

if output stream is null, just encode into a byte array
@param outstream

if output stream is null just encode into a byte array


public static FSTConfiguration createJsonConfiguration(boolean prettyPrint, boolean shareReferences ) {
        if ( shareReferences && prettyPrint ) {
            throw new RuntimeException("unsupported flag combination");
        }
        return createJsonConfiguration(prettyPrint,shareReferences,null);
    }

public
static
FSTConfiguration
createJsonConfiguration
(
boolean
prettyPrint
,
boolean
shareReferences
)
{
if
(
shareReferences
&&
prettyPrint
)
{
throw
new
RuntimeException
(
"unsupported flag combination"
)
;
}
return
createJsonConfiguration
(
prettyPrint
,
shareReferences
,
)
;
}

create a json conf with given attributes. Note that shared refs = true for jason might be not as stable as for binary encodings
as fst relies on stream positions to identify objects within a given input, so any inbetween formatting will break proper reference
resolution.

WARNING: use of sharedrefs = true is Deprecated as its flakey

@param prettyPrint
@param shareReferences
@return

create a json conf with given attributes . Note that shared refs = true for jason might be not as stable as for binary encodings as fst relies on stream positions to identify objects within a given input so any inbetween formatting will break proper reference resolution .


public static FSTConfiguration createStructConfiguration() {
        FSTConfiguration conf = new FSTConfiguration(null);
        conf.setStructMode(true);
        return conf;
    }

public static FSTConfiguration createStructConfiguration ( ) { FSTConfiguration conf = new FSTConfiguration ( null ) ; conf . setStructMode ( true ) ; return conf ; }

special configuration used internally for struct emulation
@return


public int calcObjectSizeBytesNotAUtility( Object obj ) throws IOException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
        FSTObjectOutput ou = new FSTObjectOutput(bout,this);
        ou.writeObject(obj, obj.getClass());
        ou.close();
        return bout.toByteArray().length;
    }

public int calcObjectSizeBytesNotAUtility ( Object obj ) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream ( 10000 ) ; FSTObjectOutput ou = new FSTObjectOutput ( bout , this ) ; ou . writeObject ( obj , obj . getClass ( ) ) ; ou . close ( ) ; return bout . toByteArray ( ) . length ; }

for optimization purposes, do not use to benchmark processing time or in a regular program as
this methods creates a temporary binaryoutputstream and serializes the object in order to measure the
size.

for optimization purposes do not use to benchmark processing time or in a regular program as this methods creates a temporary binaryoutputstream and serializes the object in order to measure the size .


public void clearCaches() {
        try {
            FSTInputStream.cachedBuffer.set(null);
            while (!cacheLock.compareAndSet(false, true)) {
                // empty
            }
            cachedObjects.clear();
        } finally {
            cacheLock.set( false );
        }
    }

public
void
clearCaches
(
)
{
try
{
FSTInputStream
.
cachedBuffer
.
set
(
)
;
while
(
!
cacheLock
.
compareAndSet
(
false
,
true
)
)
{
// empty
}
cachedObjects
.
clear
(
)
;
}
finally
{
cacheLock
.
set
(
false
)
;
}
}

clear cached softref s and ThreadLocal .


public FSTObjectInput getObjectInput( InputStream in ) {
        FSTObjectInput fstObjectInput = getIn();
        try {
            fstObjectInput.resetForReuse(in);
            return fstObjectInput;
        } catch (IOException e) {
            FSTUtil.<RuntimeException>rethrow(e);
        }
        return null;
    }

public FSTObjectInput getObjectInput ( InputStream in ) { FSTObjectInput fstObjectInput = getIn ( ) ; try { fstObjectInput . resetForReuse ( in ) ; return fstObjectInput ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }

utility for thread safety and reuse. Do not close the resulting stream. However you should close
the given InputStream 'in'
@param in
@return

utility for thread safety and reuse . Do not close the resulting stream . However you should close the given InputStream in


public FSTObjectInput getObjectInput( byte arr[], int len ) {
        FSTObjectInput fstObjectInput = getIn();
        try {
            fstObjectInput.resetForReuseUseArray(arr,len);
            return fstObjectInput;
        } catch (IOException e) {
            FSTUtil.<RuntimeException>rethrow(e);
        }
        return null;
    }

public FSTObjectInput getObjectInput ( byte arr [ ] , int len ) { FSTObjectInput fstObjectInput = getIn ( ) ; try { fstObjectInput . resetForReuseUseArray ( arr , len ) ; return fstObjectInput ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }

take the given array as input. the array is NOT copied.

WARNING: the input streams takes over ownership and might overwrite content
of this array in subsequent IO operations.

@param arr
@param len
@return

take the given array as input . the array is NOT copied .


public FSTObjectInput getObjectInputCopyFrom( byte arr[],int off, int len ) {
        FSTObjectInput fstObjectInput = getIn();
        try {
            fstObjectInput.resetForReuseCopyArray(arr, off, len);
            return fstObjectInput;
        } catch (IOException e) {
            FSTUtil.<RuntimeException>rethrow(e);
        }
        return null;
    }

public FSTObjectInput getObjectInputCopyFrom ( byte arr [ ] , int off , int len ) { FSTObjectInput fstObjectInput = getIn ( ) ; try { fstObjectInput . resetForReuseCopyArray ( arr , off , len ) ; return fstObjectInput ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }

take the given array and copy it to input. the array IS copied
@param arr
@param len
@return

take the given array and copy it to input . the array IS copied


public FSTObjectOutput getObjectOutput(OutputStream out) {
        FSTObjectOutput fstObjectOutput = getOut();
        fstObjectOutput.resetForReUse(out);
        return fstObjectOutput;
    }

public FSTObjectOutput getObjectOutput ( OutputStream out ) { FSTObjectOutput fstObjectOutput = getOut ( ) ; fstObjectOutput . resetForReUse ( out ) ; return fstObjectOutput ; }

utility for thread safety and reuse. Do not close the resulting stream. However you should close
the given OutputStream 'out'
@param out - can be null (temp bytearrays stream is created then)
@return

utility for thread safety and reuse . Do not close the resulting stream . However you should close the given OutputStream out


public FSTConfiguration registerCrossPlatformClassMapping( String[][] keysAndVals ) {
        for (int i = 0; i < keysAndVals.length; i++) {
            String[] keysAndVal = keysAndVals[i];
            registerCrossPlatformClassMapping(keysAndVal[0], keysAndVal[1]);
        }
        return this;
    }

public FSTConfiguration registerCrossPlatformClassMapping ( String [ ] [ ] keysAndVals ) { for ( int i = 0 ; i < keysAndVals . length ; i ++ ) { String [ ] keysAndVal = keysAndVals [ i ] ; registerCrossPlatformClassMapping ( keysAndVal [ 0 ] , keysAndVal [ 1 ] ) ; } return this ; }

init right after creation of configuration, not during operation as it is not threadsafe regarding mutation
currently only for minbin serialization

@param keysAndVals { { "symbolicName", "fullQualifiedClazzName" }, .. }

init right after creation of configuration not during operation as it is not threadsafe regarding mutation currently only for minbin serialization


public String getCPNameForClass( Class cl ) {
        String res = minbinNamesReverse.get(cl.getName());
        if (res == null) {
            if (cl.isAnonymousClass()) {
                return getCPNameForClass(cl.getSuperclass());
            }
            return cl.getName();
        }
        return res;
    }

public String getCPNameForClass ( Class cl ) { String res = minbinNamesReverse . get ( cl . getName ( ) ) ; if ( res == null ) { if ( cl . isAnonymousClass ( ) ) { return getCPNameForClass ( cl . getSuperclass ( ) ) ; } return cl . getName ( ) ; } return res ; }

get cross platform symbolic class identifier
@param cl
@return


public void writeInt(byte type, long data) {
        if (!MinBin.isPrimitive(type) || MinBin.isArray(type))
            throw new RuntimeException("illegal type code");
        writeOut(type);
        writeRawInt(type, data);
    }

public
void
writeInt
(
byte
type
,
long
data
)
{
if
(
!
MinBin
.
isPrimitive
(
type
)
||
MinBin
.
isArray
(
type
)
)
throw
new
RuntimeException
(
"illegal type code"
)
;
writeOut
(
type
)
;
writeRawInt
(
type
,
data
)
;
}

write an int type with header
@param type
@param data


protected void writeRawInt(byte type, long data) {
        int numBytes = MinBin.extractNumBytes(type);
        for (int i = 0; i < numBytes; i++) {
            writeOut((byte) (data & 0xff));
            data = data >>> 8;
        }
    }

protected void writeRawInt ( byte type , long data ) { int numBytes = MinBin . extractNumBytes ( type ) ; for ( int i = 0 ; i < numBytes ; i ++ ) { writeOut ( ( byte ) ( data & 0xff ) ) ; data = data >>> 8 ; } }

encode int without header tag
@param data


public void writeIntPacked(long data) {
        if (data <= Byte.MAX_VALUE && data >= Byte.MIN_VALUE)            writeInt(MinBin.INT_8,  data);
        else if (data <= Short.MAX_VALUE && data >= Short.MIN_VALUE)     writeInt(MinBin.INT_16, data);
        else if (data <= Integer.MAX_VALUE && data >= Integer.MIN_VALUE) writeInt(MinBin.INT_32, data);
        else if (data <= Long.MAX_VALUE && data >= Long.MIN_VALUE)       writeInt(MinBin.INT_64, data);
    }

public void writeIntPacked ( long data ) { if ( data <= Byte . MAX_VALUE && data >= Byte . MIN_VALUE ) writeInt ( MinBin . INT_8 , data ) ; else if ( data <= Short . MAX_VALUE && data >= Short . MIN_VALUE ) writeInt ( MinBin . INT_16 , data ) ; else if ( data <= Integer . MAX_VALUE && data >= Integer . MIN_VALUE ) writeInt ( MinBin . INT_32 , data ) ; else if ( data <= Long . MAX_VALUE && data >= Long . MIN_VALUE ) writeInt ( MinBin . INT_64 , data ) ; }

encode int using only as much bytes as needed to represent it
@param data


public void writeArray(Object primitiveArray, int start, int len) {
        byte type = MinBin.ARRAY_MASK;
        Class<?> componentType = primitiveArray.getClass().getComponentType();
        if (componentType == boolean.class)    type |= MinBin.INT_8;
        else if (componentType == byte.class)  type |= MinBin.INT_8;
        else if (componentType == short.class) type |= MinBin.INT_16;
        else if (componentType == char.class)  type |= MinBin.INT_16 | MinBin.UNSIGN_MASK;
        else if (componentType == int.class)   type |= MinBin.INT_32;
        else if (componentType == long.class)  type |= MinBin.INT_64;
        else throw new RuntimeException("unsupported type " + componentType.getName());
        writeOut(type);
        writeIntPacked(len);
        switch (type) {
            case MinBin.INT_8|MinBin.ARRAY_MASK: {
                if ( componentType == boolean.class ) {
                    boolean[] arr = (boolean[]) primitiveArray;
                    for (int i = start; i < start + len; i++) {
                        writeRawInt(type, arr[i] ? 1 : 0);
                    }
                } else {
                    byte[] arr = (byte[]) primitiveArray;
                    for (int i = start; i < start + len; i++) {
                        writeRawInt(type, arr[i]);
                    }
                }
            }
            break;
            case MinBin.CHAR|MinBin.ARRAY_MASK: {
                char[] charArr = (char[]) primitiveArray;
                for (int i = start; i < start + len; i++) {
                    writeRawInt(type, charArr[i]);
                }
            }
            break;
            case MinBin.INT_32|MinBin.ARRAY_MASK: {
                int[] arr = (int[]) primitiveArray;
                for (int i = start; i < start + len; i++) {
                    writeRawInt(type, arr[i]);
                }
            }
            break;
            case MinBin.INT_64|MinBin.ARRAY_MASK: {
                long[] arr = (long[]) primitiveArray;
                for (int i = start; i < start + len; i++) {
                    writeRawInt(type, arr[i]);
                }
            }
            break;
            default: {
                for (int i = start; i < start + len; i++) {
                    if (componentType == boolean.class)
                        writeRawInt(type, Array.getBoolean(primitiveArray, i) ? 1 : 0);
                    else
                        writeRawInt(type, Array.getLong(primitiveArray, i));
                }
            }
        }
    }

public
void
writeArray
(
Object
primitiveArray
,
int
start
,
int
len
)
{
byte
type
=
MinBin
.
ARRAY_MASK
;
Class
<
>
componentType
=
primitiveArray
.
getClass
(
)
.
getComponentType
(
)
;
if
(
componentType
==
boolean
.
class
)
type
|=
MinBin
.
INT_8
;
else
if
(
componentType
==
byte
.
class
)
type
|=
MinBin
.
INT_8
;
else
if
(
componentType
==
short
.
class
)
type
|=
MinBin
.
INT_16
;
else
if
(
componentType
==
char
.
class
)
type
|=
MinBin
.
INT_16
|
MinBin
.
UNSIGN_MASK
;
else
if
(
componentType
==
int
.
class
)
type
|=
MinBin
.
INT_32
;
else
if
(
componentType
==
long
.
class
)
type
|=
MinBin
.
INT_64
;
else
throw
new
RuntimeException
(
"unsupported type "
+
componentType
.
getName
(
)
)
;
writeOut
(
type
)
;
writeIntPacked
(
len
)
;
switch
(
type
)
{
case
MinBin
.
INT_8
|
MinBin
.
ARRAY_MASK
:
{
if
(
componentType
==
boolean
.
class
)
{
boolean
[
]
arr
=
(
boolean
[
]
)
primitiveArray
;
for
(
int
i
=
start
;
i
<
start
+
len
;
i
++
)
{
writeRawInt
(
type
,
arr
[
i
]
1
:
0
)
;
}
}
else
{
byte
[
]
arr
=
(
byte
[
]
)
primitiveArray
;
for
(
int
i
=
start
;
i
<
start
+
len
;
i
++
)
{
writeRawInt
(
type
,
arr
[
i
]
)
;
}
}
}
break
;
case
MinBin
.
CHAR
|
MinBin
.
ARRAY_MASK
:
{
char
[
]
charArr
=
(
char
[
]
)
primitiveArray
;
for
(
int
i
=
start
;
i
<
start
+
len
;
i
++
)
{
writeRawInt
(
type
,
charArr
[
i
]
)
;
}
}
break
;
case
MinBin
.
INT_32
|
MinBin
.
ARRAY_MASK
:
{
int
[
]
arr
=
(
int
[
]
)
primitiveArray
;
for
(
int
i
=
start
;
i
<
start
+
len
;
i
++
)
{
writeRawInt
(
type
,
arr
[
i
]
)
;
}
}
break
;
case
MinBin
.
INT_64
|
MinBin
.
ARRAY_MASK
:
{
long
[
]
arr
=
(
long
[
]
)
primitiveArray
;
for
(
int
i
=
start
;
i
<
start
+
len
;
i
++
)
{
writeRawInt
(
type
,
arr
[
i
]
)
;
}
}
break
;
default
:
{
for
(
int
i
=
start
;
i
<
start
+
len
;
i
++
)
{
if
(
componentType
==
boolean
.
class
)
writeRawInt
(
type
,
Array
.
getBoolean
(
primitiveArray
,
i
)
1
:
0
)
;
else
writeRawInt
(
type
,
Array
.
getLong
(
primitiveArray
,
i
)
)
;
}
}
}
}

write primitive array + header. no floating point or object array allowed. Just int based types
@param primitiveArray
@param start
@param len

write primitive array + header . no floating point or object array allowed . Just int based types


public void writeRaw(byte[] bufferedName, int i, int length) {
        if (pos+length >= bytez.length - 1) {
            resize();
        }
        System.arraycopy(bufferedName,i,bytez,pos,length);
        pos += length;
    }

public void writeRaw ( byte [ ] bufferedName , int i , int length ) { if ( pos + length >= bytez . length - 1 ) { resize ( ) ; } System . arraycopy ( bufferedName , i , bytez , pos , length ) ; pos += length ; }

allow write through to underlying byte for performance reasons
@param bufferedName
@param i
@param length


protected FSTClazzInfo.FSTFieldInfo getCachedFI( Class... possibles ) {
        if ( refs == null ) {
            refs = refsLocal.get();
        }
        if ( curDepth >= refs.length ) {
            return new FSTClazzInfo.FSTFieldInfo(possibles, null, true);
        } else {
            FSTClazzInfo.FSTFieldInfo inf = refs[curDepth];
            if ( inf == null ) {
                inf = new FSTClazzInfo.FSTFieldInfo(possibles, null, true);
                refs[curDepth] = inf;
                return inf;
            }
            inf.setPossibleClasses(possibles);
            return inf;
        }
    }

protected FSTClazzInfo . FSTFieldInfo getCachedFI ( Class ... possibles ) { if ( refs == null ) { refs = refsLocal . get ( ) ; } if ( curDepth >= refs . length ) { return new FSTClazzInfo . FSTFieldInfo ( possibles , null , true ) ; } else { FSTClazzInfo . FSTFieldInfo inf = refs [ curDepth ] ; if ( inf == null ) { inf = new FSTClazzInfo . FSTFieldInfo ( possibles , null , true ) ; refs [ curDepth ] = inf ; return inf ; } inf . setPossibleClasses ( possibles ) ; return inf ; } }


protected void objectWillBeWritten( Object obj, int streamPosition ) {
        if (listener != null) {
            listener.objectWillBeWritten(obj, streamPosition);
        }
    }

protected void objectWillBeWritten ( Object obj , int streamPosition ) { if ( listener != null ) { listener . objectWillBeWritten ( obj , streamPosition ) ; } }

hook for debugging profiling. register a FSTSerialisationListener to use
@param obj
@param streamPosition

hook for debugging profiling . register a FSTSerialisationListener to use


protected void objectHasBeenWritten( Object obj, int oldStreamPosition, int streamPosition ) {
        if (listener != null) {
            listener.objectHasBeenWritten(obj, oldStreamPosition, streamPosition);
        }
    }

protected void objectHasBeenWritten ( Object obj , int oldStreamPosition , int streamPosition ) { if ( listener != null ) { listener . objectHasBeenWritten ( obj , oldStreamPosition , streamPosition ) ; } }

hook for debugging profiling. empty impl, you need to subclass to make use of this hook
@param obj
@param oldStreamPosition
@param streamPosition

hook for debugging profiling . empty impl you need to subclass to make use of this hook


protected FSTClazzInfo getFstClazzInfo(FSTClazzInfo.FSTFieldInfo referencee, Class clazz) {
        FSTClazzInfo serializationInfo = null;
        FSTClazzInfo lastInfo = referencee.lastInfo;
        if ( lastInfo != null && lastInfo.getClazz() == clazz && lastInfo.conf == conf ) {
            serializationInfo = lastInfo;
        } else {
            serializationInfo = getClassInfoRegistry().getCLInfo(clazz, conf);
            referencee.lastInfo = serializationInfo;
        }
        return serializationInfo;
    }

protected FSTClazzInfo getFstClazzInfo ( FSTClazzInfo . FSTFieldInfo referencee , Class clazz ) { FSTClazzInfo serializationInfo = null ; FSTClazzInfo lastInfo = referencee . lastInfo ; if ( lastInfo != null && lastInfo . getClazz ( ) == clazz && lastInfo . conf == conf ) { serializationInfo = lastInfo ; } else { serializationInfo = getClassInfoRegistry ( ) . getCLInfo ( clazz , conf ) ; referencee . lastInfo = serializationInfo ; } return serializationInfo ; }

if class is same as last referenced, returned cached clzinfo, else do a lookup

if class is same as last referenced returned cached clzinfo else do a lookup


protected void writeArray(FSTClazzInfo.FSTFieldInfo referencee, Object array) throws IOException {
        if ( array == null ) {
            getCodec().writeClass(Object.class);
            getCodec().writeFInt(-1);
            return;
        }
        final int len = Array.getLength(array);
        Class<?> componentType = array.getClass().getComponentType();
        getCodec().writeClass(array.getClass());
        getCodec().writeFInt(len);
        if ( ! componentType.isArray() ) {
            if (getCodec().isPrimitiveArray(array, componentType)) {
                getCodec().writePrimitiveArray(array, 0, len);
            } else { // objects
                Object arr[] = (Object[])array;
                Class lastClz = null;
                FSTClazzInfo lastInfo = null;
                for ( int i = 0; i < len; i++ )
                {
                    Object toWrite = arr[i];
                    if ( toWrite != null ) {
                        lastInfo = writeObjectWithContext(referencee, toWrite, lastClz == toWrite.getClass() ? lastInfo : null);
                        lastClz = toWrite.getClass();
                    } else
                        writeObjectWithContext(referencee, toWrite, null);
                }
            }
        } else { // multidim array. FIXME shared refs to subarrays are not tested !!!
            Object[] arr = (Object[])array;
            FSTClazzInfo.FSTFieldInfo ref1 = new FSTClazzInfo.FSTFieldInfo(referencee.getPossibleClasses(), null, conf.getCLInfoRegistry().isIgnoreAnnotations());
            for ( int i = 0; i < len; i++ ) {
                Object subArr = arr[i];
                boolean needsWrite = true;
                if ( getCodec().isTagMultiDimSubArrays() ) {
                    if ( subArr == null ) {
                        needsWrite = !getCodec().writeTag(NULL, null, 0, null, this);
                    } else {
                        needsWrite = !getCodec().writeTag(ARRAY, subArr, 0, subArr, this);
                    }
                }
                if ( needsWrite ) {
                    writeArray(ref1, subArr);
                    getCodec().writeArrayEnd();
                }
            }
        }
    }


public void setString(String s) {
        if ( s == null ) {
            setLen(0);
            return;
        }
        if ( s.length() > charsLen() ) {
            throw new RuntimeException("String length exceeds buffer size. String len "+s.length()+" charsLen:"+charsLen());
        }
        for (int i=0; i < s.length(); i++) {
            chars(i,s.charAt(i));
        }
        len = s.length();
    }

modify content of this StructString. The length of the new String must not exceed
the length of internal char array
@param s

modify content of this StructString . The length of the new String must not exceed the length of internal char array


@Override
    public void writePrimitiveArray(Object array, int start, int length) throws IOException {
        out.writeArray(array, start, length);
    }

@ Override public void writePrimitiveArray ( Object array , int start , int length ) throws IOException { out . writeArray ( array , start , length ) ; }

does not write class tag and length

@param array
@param start
@param length @throws java.io.IOException


public FSTStructChange finishChangeTracking() {
        tracker.snapshotChanges((int) getOffset(), getBase());
        FSTStructChange res = tracker;
        tracker = null;
        return res;
    }

public FSTStructChange finishChangeTracking ( ) { tracker . snapshotChanges ( ( int ) getOffset ( ) , getBase ( ) ) ; FSTStructChange res = tracker ; tracker = null ; return res ; }

works only if change tracking is enabled


public void snapshotChanges(int originBase, Bytez origin) {
        int sumLen = 0;
        for (int i = 0; i < curIndex; i++) {
            sumLen += changeLength[i];
        }
        snapshot = new byte[sumLen];
        int targetIdx = 0;
        for (int i = 0; i < curIndex; i++) {
            int changeOffset = changeOffsets[i];
            int len = changeLength[i];
            for ( int ii = 0; ii < len; ii++) {
                snapshot[targetIdx++] = origin.get(changeOffset+ii);
            }
        }
        rebase(originBase);
    }

public void snapshotChanges ( int originBase , Bytez origin ) { int sumLen = 0 ; for ( int i = 0 ; i < curIndex ; i ++ ) { sumLen += changeLength [ i ] ; } snapshot = new byte [ sumLen ] ; int targetIdx = 0 ; for ( int i = 0 ; i < curIndex ; i ++ ) { int changeOffset = changeOffsets [ i ] ; int len = changeLength [ i ] ; for ( int ii = 0 ; ii < len ; ii ++ ) { snapshot [ targetIdx ++ ] = origin . get ( changeOffset + ii ) ; } } rebase ( originBase ) ; }

collects all changes and rebases.
@param originBase
@param origin


public int registerObjectForWrite(Object o, int streamPosition, FSTClazzInfo clzInfo, int reUseType[]) {
        if (disabled) {
            return Integer.MIN_VALUE;
        }
//        System.out.println("REGISTER AT WRITE:"+streamPosition+" "+o.getClass().getSimpleName());
//        final Class clazz = o.getClass();
        if ( clzInfo == null ) { // array oder enum oder primitive
            // unused ?
//            clzInfo = reg.getCLInfo(clazz);
        } else if ( clzInfo.isFlat() ) {
            return Integer.MIN_VALUE;
        }
        int handle = objects.putOrGet(o,streamPosition);
        if ( handle >= 0 ) {
//            if ( idToObject.get(handle) == null ) { // (*) (can get improved)
//                idToObject.add(handle, o);
//            }
            reUseType[0] = 0;
            return handle;
        }
        return Integer.MIN_VALUE;
    }

//        final Class clazz = o.getClass();

//            clzInfo = reg.getCLInfo(clazz);

//                idToObject.add(handle, o);

add an object to the register, return handle if already present. Called during write only

@param o
@param streamPosition
@return 0 if added, handle if already present

add an object to the register return handle if already present . Called during write only


@Override
    public int toByteArray( Object o, byte arr[], int startIndex, int availableSize ) {
        out.resetForReUse();
        writeTarget.setBase(arr, startIndex, availableSize);
        try {
            out.writeObject(o);
        } catch (IOException e) {
            FSTUtil.<RuntimeException>rethrow(e);
        }
        int written = out.getWritten();
        return written;
    }

@ Override public int toByteArray ( Object o , byte arr [ ] , int startIndex , int availableSize ) { out . resetForReUse ( ) ; writeTarget . setBase ( arr , startIndex , availableSize ) ; try { out . writeObject ( o ) ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } int written = out . getWritten ( ) ; return written ; }

throws FSTBufferTooSmallExcpetion in case object does not fit into given range
Zero Copy method

@param o
@param availableSize
@throws java.io.IOException
@return number of bytes written to the memory region


@Override
    public Object toObject( byte arr[], int startIndex, int availableSize) {
        try {
            in.resetForReuse(null);
            readTarget.setBase(arr,startIndex,availableSize);
            Object o = in.readObject();
            return o;
        } catch (Exception e) {
            FSTUtil.<RuntimeException>rethrow(e);
        }
        return null;
    }

@ Override public Object toObject ( byte arr [ ] , int startIndex , int availableSize ) { try { in . resetForReuse ( null ) ; readTarget . setBase ( arr , startIndex , availableSize ) ; Object o = in . readObject ( ) ; return o ; } catch ( Exception e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }

throws FSTBufferTooSmallExcpetion in case object does not fit into given range

@param arr
@param startIndex
@param availableSize
@return
@throws Exception


public byte[] readByteArray(int len) {
        if ( available() < len ) {
            throw new RuntimeException("not enough data available, check available() > len before calling");
        }
        byte b[] = new byte[len];
        int count = 0;
        while ( pollIndex != addIndex && count < len ) {
            b[count++] = storage.get(pollIndex++);
            if ( pollIndex >= storage.length() ) {
                pollIndex = 0;
            }
        }
        return b;
    }

convenience method to read len byte array. Throws an excpetion if not enough data is present

@param len
@return

convenience method to read len byte array . Throws an excpetion if not enough data is present


public int readInt() {
        if ( available() < 4 ) {
            throw new RuntimeException("not enough data available, check available() > 4 before calling");
        }
        int ch1 = poll();
        int ch2 = poll();
        int ch3 = poll();
        int ch4 = poll();
        return (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0);
    }

read an int. throws an exception if not enough data is present
@return

read an int . throws an exception if not enough data is present


public void back( int len ) {
        if ( pollIndex >= len )
            pollIndex -= len;
        else
            pollIndex = pollIndex + capacity() - len;

    }

public void back ( int len ) { if ( pollIndex >= len ) pollIndex -= len ; else pollIndex = pollIndex + capacity ( ) - len ; }


public void setThreadPoolEnabled(boolean value) {
        if (value && (threadPool == null)) {
            threadPool = Executors.newCachedThreadPool();
        }
        threadPoolEnabled = value;
    }

public void setThreadPoolEnabled ( boolean value ) { if ( value && ( threadPool == null ) ) { threadPool = Executors . newCachedThreadPool ( ) ; } threadPoolEnabled = value ; }

Set thread pool enabled.
This thread pool is not for the service threads, it is for the user service method.
If your service method takes a long time, or will be blocked, please set this property to be true.
@param value is thread pool enabled

Set thread pool enabled . This thread pool is not for the service threads it is for the user service method . If your service method takes a long time or will be blocked please set this property to be true .


public static void startEmbeddedCassandra(File file, String tmpDir, long timeout) throws IOException, ConfigurationException {
        if (cassandraDaemon != null) {
            /* nothing to do Cassandra is already started */
            return;
        }

        checkConfigNameForRestart(file.getAbsolutePath());

        log.debug("Starting cassandra...");
        log.debug("Initialization needed");

        System.setProperty("cassandra.config", "file:" + file.getAbsolutePath());
        System.setProperty("cassandra-foreground", "true");
        System.setProperty("cassandra.native.epoll.enabled", "false"); // JNA doesnt cope with relocated netty
        System.setProperty("cassandra.unsafesystem", "true"); // disable fsync for a massive speedup on old platters

        // If there is no log4j config set already, set the default config
        if (System.getProperty("log4j.configuration") == null) {
            copy(DEFAULT_LOG4J_CONFIG_FILE, tmpDir);
            System.setProperty("log4j.configuration", "file:" + tmpDir + DEFAULT_LOG4J_CONFIG_FILE);
        }

        DatabaseDescriptor.daemonInitialization();

        cleanupAndLeaveDirs();
        final CountDownLatch startupLatch = new CountDownLatch(1);
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.execute(() -> {
            cassandraDaemon = new CassandraDaemon();
            cassandraDaemon.activate();
            startupLatch.countDown();
        });
        try {
            if (!startupLatch.await(timeout, MILLISECONDS)) {
                log.error("Cassandra daemon did not start after " + timeout + " ms. Consider increasing the timeout");
                throw new AssertionError("Cassandra daemon did not start within timeout");
            }
            Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                if (session != null) session.close();
                if (cluster != null) cluster.close();
            }));
        } catch (InterruptedException e) {
            log.error("Interrupted waiting for Cassandra daemon to start:", e);
            throw new AssertionError(e);
        } finally {
            executor.shutdown();
        }
    }

Set embedded cassandra up and spawn it in a new thread.

@throws TTransportException
@throws IOException
@throws ConfigurationException

Set embedded cassandra up and spawn it in a new thread .


public static void cleanDataEmbeddedCassandra(String keyspace, String... excludedTables) {
            if (session != null) {
                cleanDataWithNativeDriver(keyspace, excludedTables);
            }
    }

public static void cleanDataEmbeddedCassandra ( String keyspace , String ... excludedTables ) { if ( session != null ) { cleanDataWithNativeDriver ( keyspace , excludedTables ) ; } }

truncate data in keyspace, except specified tables

truncate data in keyspace except specified tables


private static Path copy(String resource, String directory) throws IOException {
        mkdir(directory);
        String fileName = resource.substring(resource.lastIndexOf("/") + 1);
        InputStream from = EmbeddedCassandraServerHelper.class.getResourceAsStream(resource);
        Path copyName = Paths.get(directory, fileName);
        Files.copy(from, copyName);
        return copyName;
    }

private static Path copy ( String resource , String directory ) throws IOException { mkdir ( directory ) ; String fileName = resource . substring ( resource . lastIndexOf ( "/" ) + 1 ) ; InputStream from = EmbeddedCassandraServerHelper . class . getResourceAsStream ( resource ) ; Path copyName = Paths . get ( directory , fileName ) ; Files . copy ( from , copyName ) ; return copyName ; }

Copies a resource from within the jar to a directory.

@param resource
@param directory
@throws IOException

Copies a resource from within the jar to a directory .


public static void printThreadInfo(PrintWriter stream, String title) {
        final int STACK_DEPTH = 20;
        boolean contention = threadBean.isThreadContentionMonitoringEnabled();
        long[] threadIds = threadBean.getAllThreadIds();
        stream.println("Process Thread Dump: " + title);
        stream.println(threadIds.length + " active threads");
        for (long tid : threadIds) {
            ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH);
            if (info == null) {
                stream.println("  Inactive");
                continue;
            }
            stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":");
            Thread.State state = info.getThreadState();
            stream.println("  State: " + state);
            stream.println("  Blocked count: " + info.getBlockedCount());
            stream.println("  Waited count: " + info.getWaitedCount());
            if (contention) {
                stream.println("  Blocked time: " + info.getBlockedTime());
                stream.println("  Waited time: " + info.getWaitedTime());
            }
            if (state == Thread.State.WAITING) {
                stream.println("  Waiting on " + info.getLockName());
            } else if (state == Thread.State.BLOCKED) {
                stream.println("  Blocked on " + info.getLockName());
                stream.println("  Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName()));
            }
            stream.println("  Stack:");
            for (StackTraceElement frame : info.getStackTrace()) {
                stream.println("    " + frame.toString());
            }
        }
        stream.flush();
    }

public
static
void
printThreadInfo
(
PrintWriter
stream
,
String
title
)
{
final
int
STACK_DEPTH
=
20
;
boolean
contention
=
threadBean
.
isThreadContentionMonitoringEnabled
(
)
;
long
[
]
threadIds
=
threadBean
.
getAllThreadIds
(
)
;
stream
.
println
(
"Process Thread Dump: "
+
title
)
;
stream
.
println
(
threadIds
.
length
+
" active threads"
)
;
for
(
long
tid
:
threadIds
)
{
ThreadInfo
info
=
threadBean
.
getThreadInfo
(
tid
,
STACK_DEPTH
)
;
if
(
info
==
)
{
stream
.
println
(
"  Inactive"
)
;
continue
;
}
stream
.
println
(
"Thread "
+
getTaskName
(
info
.
getThreadId
(
)
,
info
.
getThreadName
(
)
)
+
":"
)
;
Thread
.
State
state
=
info
.
getThreadState
(
)
;
stream
.
println
(
"  State: "
+
state
)
;
stream
.
println
(
"  Blocked count: "
+
info
.
getBlockedCount
(
)
)
;
stream
.
println
(
"  Waited count: "
+
info
.
getWaitedCount
(
)
)
;
if
(
contention
)
{
stream
.
println
(
"  Blocked time: "
+
info
.
getBlockedTime
(
)
)
;
stream
.
println
(
"  Waited time: "
+
info
.
getWaitedTime
(
)
)
;
}
if
(
state
==
Thread
.
State
.
WAITING
)
{
stream
.
println
(
"  Waiting on "
+
info
.
getLockName
(
)
)
;
}
else
if
(
state
==
Thread
.
State
.
BLOCKED
)
{
stream
.
println
(
"  Blocked on "
+
info
.
getLockName
(
)
)
;
stream
.
println
(
"  Blocked by "
+
getTaskName
(
info
.
getLockOwnerId
(
)
,
info
.
getLockOwnerName
(
)
)
)
;
}
stream
.
println
(
"  Stack:"
)
;
for
(
StackTraceElement
frame
:
info
.
getStackTrace
(
)
)
{
stream
.
println
(
"    "
+
frame
.
toString
(
)
)
;
}
}
stream
.
flush
(
)
;
}

Print all of the thread's information and stack traces.

@param stream the stream to
@param title a string title for the stack trace

Print all of the thread s information and stack traces .


public static boolean remotePortTaken(String node, int port, int timeout) {
        Socket s = null;
        try {
            s = new Socket();
            s.setReuseAddress(true);
            SocketAddress sa = new InetSocketAddress(node, port);
            s.connect(sa, timeout * 1000);
        } catch (IOException e) {
            if (e.getMessage().equals("Connection refused")) {
                return false;
            }
            if (e instanceof SocketTimeoutException || e instanceof UnknownHostException) {
                throw e;
            }
        } finally {
            if (s != null) {
                if (s.isConnected()) {
                    return true;
                } else {
                }
                try {
                    s.close();
                } catch (IOException e) {
                }
            }

            return false;
        }

    }

public
static
boolean
remotePortTaken
(
String
node
,
int
port
,
int
timeout
)
{
Socket
s
=
;
try
{
s
=
new
Socket
(
)
;
s
.
setReuseAddress
(
true
)
;
SocketAddress
sa
=
new
InetSocketAddress
(
node
,
port
)
;
s
.
connect
(
sa
,
timeout
*
1000
)
;
}
catch
(
IOException
e
)
{
if
(
e
.
getMessage
(
)
.
equals
(
"Connection refused"
)
)
{
return
false
;
}
if
(
e
instanceof
SocketTimeoutException
||
e
instanceof
UnknownHostException
)
{
throw
e
;
}
}
finally
{
if
(
s
!=
)
{
if
(
s
.
isConnected
(
)
)
{
return
true
;
}
else
{
}
try
{
s
.
close
(
)
;
}
catch
(
IOException
e
)
{
}
}
return
false
;
}
}

Check if a remote port is taken
@param node the host to check
@param port the port to check
@param timeout the timeout for the connection
@return true if the port is taken false otherwise


public static SubscriberState empty() {
        return SubscriberState.builder().serverState("empty").streamId(-1)
                        .parameterUpdaterStatus(Collections.emptyMap()).totalUpdates(-1).isMaster(false).build();
    }

public static SubscriberState empty ( ) { return SubscriberState . builder ( ) . serverState ( "empty" ) . streamId ( - 1 ) . parameterUpdaterStatus ( Collections . emptyMap ( ) ) . totalUpdates ( - 1 ) . isMaster ( false ) . build ( ) ; }

Returns an empty subscriber state
with -1 as total updates, master as false
and server state as empty
@return an empty subscriber state

Returns an empty subscriber state with - 1 as total updates master as false and server state as empty


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

            return descriptorMap;
        }
    }

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

Get the onnx op descriptors by name
@return the onnx op descriptors by name
@throws Exception


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

        return ret;
    }

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

Calculate the output shape for this op

@return


public static boolean or(IComplexNDArray n, Condition cond) {
        boolean ret = false;
        IComplexNDArray linear = n.linearView();
        for (int i = 0; i < linear.length(); i++) {
            ret = ret || cond.apply(linear.getComplex(i));
        }

        return ret;
    }

public static boolean or ( IComplexNDArray n , Condition cond ) { boolean ret = false ; IComplexNDArray linear = n . linearView ( ) ; for ( int i = 0 ; i < linear . length ( ) ; i ++ ) { ret = ret || cond . apply ( linear . getComplex ( i ) ) ; } return ret ; }

Or over the whole ndarray given some condition

@param n
@param cond
@return


public static boolean and(final INDArray n, final Condition cond) {
        if (cond instanceof BaseCondition) {
            long val = (long) Nd4j.getExecutioner().exec(new MatchCondition(n, cond), Integer.MAX_VALUE).getDouble(0);

            if (val == n.lengthLong())
                return true;
            else
                return false;

        } else {
            boolean ret = true;
            final AtomicBoolean a = new AtomicBoolean(ret);
            Shape.iterate(n, new CoordinateFunction() {
                @Override
                public void process(long[]... coord) {
                    if (a.get())
                        a.compareAndSet(true, a.get() && cond.apply(n.getDouble(coord[0])));
                }
            });

            return a.get();
        }
    }

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

And over the whole ndarray given some condition

@param n    the ndarray to test
@param cond the condition to test against
@return true if all of the elements meet the specified
condition false otherwise


public static boolean[] and(final INDArray n, final Condition condition, int... dimension) {
        if (!(condition instanceof BaseCondition))
            throw new UnsupportedOperationException("Only static Conditions are supported");

        MatchCondition op = new MatchCondition(n, condition);
        INDArray arr = Nd4j.getExecutioner().exec(op, dimension);
        boolean[] result = new boolean[(int) arr.length()];

        long tadLength = Shape.getTADLength(n.shape(), dimension);

        for (int i = 0; i < arr.length(); i++) {
            if (arr.getDouble(i) == tadLength)
                result[i] = true;
            else
                result[i] = false;
        }

        return result;
    }

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

And over the whole ndarray given some condition, with respect to dimensions

@param n    the ndarray to test
@param condition the condition to test against
@return true if all of the elements meet the specified
condition false otherwise

And over the whole ndarray given some condition with respect to dimensions


public static boolean[] or(final INDArray n, final Condition condition, int... dimension) {
        if (!(condition instanceof BaseCondition))
            throw new UnsupportedOperationException("Only static Conditions are supported");

        MatchCondition op = new MatchCondition(n, condition);
        INDArray arr = Nd4j.getExecutioner().exec(op, dimension);

        // FIXME: int cast

        boolean[] result = new boolean[(int) arr.length()];

        for (int i = 0; i < arr.length(); i++) {
            if (arr.getDouble(i) > 0)
                result[i] = true;
            else
                result[i] = false;
        }

        return result;
    }

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

Or over the whole ndarray given some condition, with respect to dimensions

@param n    the ndarray to test
@param condition the condition to test against
@return true if all of the elements meet the specified
condition false otherwise

Or over the whole ndarray given some condition with respect to dimensions


public static void applyWhere(final INDArray to, final Condition condition, final Number number) {
        if (condition instanceof BaseCondition) {
            // for all static conditions we go native

            Nd4j.getExecutioner().exec(new CompareAndSet(to, number.doubleValue(), condition));

        } else {
            final double value = number.doubleValue();

            final Function<Number, Number> dynamic = new Function<Number, Number>() {
                @Override
                public Number apply(Number number) {
                    return value;
                }
            };

            Shape.iterate(to, new CoordinateFunction() {
                @Override
                public void process(long[]... coord) {
                    if (condition.apply(to.getDouble(coord[0])))
                        to.putScalar(coord[0], dynamic.apply(to.getDouble(coord[0])).doubleValue());

                }
            });
        }
    }

This method sets provided number to all elements which match specified condition

@param to
@param condition
@param number


public static INDArray firstIndex(INDArray array, Condition condition) {
        if (!(condition instanceof BaseCondition))
            throw new UnsupportedOperationException("Only static Conditions are supported");

        FirstIndex idx = new FirstIndex(array, condition);
        Nd4j.getExecutioner().exec(idx);
        return Nd4j.scalar((double) idx.getFinalResult());
    }

public
static
INDArray
firstIndex
(
INDArray
array
,
Condition
condition
)
{
if
(
!
(
condition
instanceof
BaseCondition
)
)
throw
new
UnsupportedOperationException
(
"Only static Conditions are supported"
)
;
FirstIndex
idx
=
new
FirstIndex
(
array
,
condition
)
;
Nd4j
.
getExecutioner
(
)
.
exec
(
idx
)
;
return
Nd4j
.
scalar
(
(
double
)
idx
.
getFinalResult
(
)
)
;
}

This method returns first index matching given condition

PLEASE NOTE: This method will return -1 value if condition wasn't met

@param array
@param condition
@return


public int asFlatProperties(FlatBufferBuilder bufferBuilder) {
        int iname = bufferBuilder.createString(name);
        int ii = FlatProperties.createIVector(bufferBuilder, Ints.toArray(i));
        int il = FlatProperties.createLVector(bufferBuilder, Longs.toArray(l));
        int id = FlatProperties.createDVector(bufferBuilder, Doubles.toArray(d));

        int arrays[] = new int[a.size()];
        int cnt = 0;
        for (val array: a) {
            int off = array.toFlatArray(bufferBuilder);
            arrays[cnt++] = off;
        }

        int ia = FlatProperties.createAVector(bufferBuilder, arrays);

        return FlatProperties.createFlatProperties(bufferBuilder, iname, ii, il, id, ia);
    }

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

This method converts this FunctionProperties instance to FlatBuffers representation
@param bufferBuilder
@return


public static FunctionProperties fromFlatProperties(FlatProperties properties) {
        val props = new FunctionProperties();

        for (int e = 0; e < properties.iLength(); e++)
            props.getI().add(properties.i(e));

        for (int e = 0; e < properties.lLength(); e++)
            props.getL().add(properties.l(e));

        for (int e = 0; e < properties.dLength(); e++)
            props.getD().add(properties.d(e));

        for (int e = 0; e < properties.iLength(); e++)
            props.getA().add(Nd4j.createFromFlatArray(properties.a(e)));

        return props;
    }

public static FunctionProperties fromFlatProperties ( FlatProperties properties ) { val props = new FunctionProperties ( ) ; for ( int e = 0 ; e < properties . iLength ( ) ; e ++ ) props . getI ( ) . ( properties . i ( ) ) ; for ( int e = 0 ; e < properties . lLength ( ) ; e ++ ) props . getL ( ) . ( properties . l ( ) ) ; for ( int e = 0 ; e < properties . dLength ( ) ; e ++ ) props . getD ( ) . ( properties . ( e ) ) ; for ( int e = 0 ; e < properties . iLength ( ) ; e ++ ) props . getA ( ) . ( Nd4j . createFromFlatArray ( properties . ( ) ) ) ; return props ; }

This method creates new FunctionProperties instance from FlatBuffers representation
@param properties
@return


public static int asFlatProperties(FlatBufferBuilder bufferBuilder, Collection<FunctionProperties> properties) {
        int props[] = new int[properties.size()];

        int cnt = 0;
        for (val p: properties)
            props[cnt++] = p.asFlatProperties(bufferBuilder);

        return FlatNode.createPropertiesVector(bufferBuilder, props);
    }

public static int asFlatProperties ( FlatBufferBuilder bufferBuilder , Collection < FunctionProperties > properties ) { int props [ ] = new int [ properties . size ( ) ] ; int cnt = 0 ; for ( val p : properties ) props [ cnt ++ ] = p . asFlatProperties ( bufferBuilder ) ; return FlatNode . createPropertiesVector ( bufferBuilder , props ) ; }

This method converts multiple FunctionProperties to FlatBuffers representation

@param bufferBuilder
@param properties
@return


public void set(Throwable t) {
        try {
            lock.writeLock().lock();

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

public void set ( Throwable t ) { try { lock . writeLock ( ) . lock ( ) ; this . t = t ; } finally { lock . writeLock ( ) . unlock ( ) ; } }

This method updates state with given Throwable
@param t


public void setIfFirst(Throwable t) {
        try {
            lock.writeLock().lock();

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

public void setIfFirst ( Throwable t ) { try { lock . writeLock ( ) . lock ( ) ; if ( this . t == null ) this . t = t ; } finally { lock . writeLock ( ) . unlock ( ) ; } }

This method updates state only if it wasn't set before

@param t

This method updates state only if it wasn t set before


public static List<Double> mergeCoords(List<Double> x, List<Double> y) {
        if (x.size() != y.size())
            throw new IllegalArgumentException(
                            "Sample sizes must be the same for each data applyTransformToDestination.");

        List<Double> ret = new ArrayList<Double>();

        for (int i = 0; i < x.size(); i++) {
            ret.add(x.get(i));
            ret.add(y.get(i));
        }
        return ret;
    }

This will merge the coordinates of the given coordinate system.

@param x the x coordinates
@param y the y coordinates
@return a vector such that each (x,y) pair is at ret[i],ret[i+1]

This will merge the coordinates of the given coordinate system .


public static List<List<Double>> partitionVariable(List<Double> arr, int chunk) {
        int count = 0;
        List<List<Double>> ret = new ArrayList<List<Double>>();

        while (count < arr.size()) {

            List<Double> sublist = arr.subList(count, count + chunk);
            count += chunk;
            ret.add(sublist);

        }
        //All data sets must be same size
        for (List<Double> lists : ret) {
            if (lists.size() < chunk)
                ret.remove(lists);
        }
        return ret;
    }

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

This will partition the given whole variable data applyTransformToDestination in to the specified chunk number.

@param arr   the data applyTransformToDestination to pass in
@param chunk the number to separate by
@return a partition data applyTransformToDestination relative to the passed in chunk number

This will partition the given whole variable data applyTransformToDestination in to the specified chunk number .


public DataBuffer.Type nd4jTypeFromOnnxType(OnnxProto3.TensorProto.DataType dataType) {
        switch (dataType) {
            case DOUBLE: return DataBuffer.Type.DOUBLE;
            case FLOAT: return DataBuffer.Type.FLOAT;
            case FLOAT16: return DataBuffer.Type.HALF;
            case INT32:
            case INT64: return DataBuffer.Type.INT;
            default: return DataBuffer.Type.UNKNOWN;
        }
    }

public DataBuffer . Type nd4jTypeFromOnnxType ( OnnxProto3 . TensorProto . DataType dataType ) { switch ( dataType ) { case DOUBLE : return DataBuffer . Type . DOUBLE ; case FLOAT : return DataBuffer . Type . FLOAT ; case FLOAT16 : return DataBuffer . Type . HALF ; case INT32 : case INT64 : return DataBuffer . Type . INT ; default : return DataBuffer . Type . UNKNOWN ; } }

Convert an onnx type to the proper nd4j type
@param dataType the data type to convert
@return the nd4j type for the onnx type


public void shutdown() {
        /**
         * Probably we don't need this method in practice
         */
        if (initLocker.get() && shutdownLocker.compareAndSet(false, true)) {
            // do shutdown
            log.info("Shutting down transport...");

            // we just sending out ShutdownRequestMessage
            //transport.sendMessage(new ShutdownRequestMessage());
            transport.shutdown();

            executor.shutdown();

        }
    }

This method initiates shutdown sequence for this instance.

PLEASE NOTE: This method is blocking for first caller only

This method initiates shutdown sequence for this instance .


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

        return arch.get(deviceId);
    }

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

Get the current device architecture
@return the major/minor version of
the current device


public static INDArray col2im(INDArray col, int sy, int sx, int ph, int pw, int h, int w) {
        if (col.rank() != 6)
            throw new IllegalArgumentException("col2im input array must be rank 6");

        INDArray output = Nd4j.create(new long[]{col.size(0), col.size(1), h, w});

        Col2Im col2Im = Col2Im.builder()
                .inputArrays(new  INDArray[]{col})
                .outputs(new INDArray[]{output})
                .conv2DConfig(Conv2DConfig.builder()
                        .sy(sy)
                        .sx(sx)
                        .dw(1)
                        .dh(1)
                        .kh(h)
                        .kw(w)
                        .ph(ph)
                        .pw(pw)
                        .build())
                .build();

        Nd4j.getExecutioner().exec(col2Im);
        return col2Im.outputArguments()[0];
    }

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

Rearrange matrix
columns into blocks

@param col the column
transposed image to convert
@param sy stride y
@param sx stride x
@param ph padding height
@param pw padding width
@param h height
@param w width
@return


public static INDArray pooling2D(INDArray img, int kh, int kw, int sy, int sx, int ph, int pw,
                                     int dh, int dw, boolean isSameMode, Pooling2D.Pooling2DType type, Pooling2D.Divisor divisor,
                                     double extra, int virtualHeight, int virtualWidth, INDArray out) {
        Pooling2D pooling = Pooling2D.builder()
                .arrayInputs(new INDArray[]{img})
                .arrayOutputs(new INDArray[] {out})
                .config(Pooling2DConfig.builder()
                        .dh(dh)
                        .dw(dw)
                        .extra(extra)
                        .kh(kh)
                        .kw(kw)
                        .ph(ph)
                        .pw(pw)
                        .isSameMode(isSameMode)
                        .sx(sx)
                        .sy(sy)
                        .virtualHeight(virtualHeight)
                        .virtualWidth(virtualWidth)
                        .type(type)
                        .divisor(divisor)
                        .build())
                .build();
        Nd4j.getExecutioner().exec(pooling);
        return out;
    }

public static INDArray pooling2D ( INDArray img , int kh , int kw , int sy , int sx , int ph , int pw , int dh , int dw , boolean isSameMode , Pooling2D . Pooling2DType type , Pooling2D . Divisor divisor , double extra , int virtualHeight , int virtualWidth , INDArray out ) { Pooling2D pooling = Pooling2D . builder ( ) . arrayInputs ( new INDArray [ ] { img } ) . arrayOutputs ( new INDArray [ ] { out } ) . config ( Pooling2DConfig . builder ( ) . dh ( dh ) . dw ( dw ) . extra ( extra ) . kh ( kh ) . kw ( kw ) . ph ( ph ) . pw ( pw ) . isSameMode ( isSameMode ) . sx ( sx ) . sy ( sy ) . virtualHeight ( virtualHeight ) . virtualWidth ( virtualWidth ) . type ( type ) . divisor ( divisor ) . build ( ) ) . build ( ) ; Nd4j . getExecutioner ( ) . exec ( pooling ) ; return out ; }

Pooling 2d implementation
@param img
@param kh
@param kw
@param sy
@param sx
@param ph
@param pw
@param dh
@param dw
@param isSameMode
@param type
@param extra optional argument. I.e. used in pnorm pooling.
@param virtualHeight
@param virtualWidth
@param out
@return


public static CompressionDescriptor fromByteBuffer(ByteBuffer byteBuffer) {
        CompressionDescriptor compressionDescriptor = new CompressionDescriptor();
        //compression opType
        int compressionTypeOrdinal = byteBuffer.getInt();
        CompressionType compressionType = CompressionType.values()[compressionTypeOrdinal];
        compressionDescriptor.setCompressionType(compressionType);

        //compression algo
        int compressionAlgoOrdinal = byteBuffer.getInt();
        CompressionAlgorithm compressionAlgorithm = CompressionAlgorithm.values()[compressionAlgoOrdinal];
        compressionDescriptor.setCompressionAlgorithm(compressionAlgorithm.name());
        //from here everything is longs
        compressionDescriptor.setOriginalLength(byteBuffer.getLong());
        compressionDescriptor.setCompressedLength(byteBuffer.getLong());
        compressionDescriptor.setNumberOfElements(byteBuffer.getLong());
        compressionDescriptor.setOriginalElementSize(byteBuffer.getLong());
        return compressionDescriptor;
    }

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

Instantiate a compression descriptor from
the given bytebuffer
@param byteBuffer the bytebuffer to instantiate
the descriptor from
@return the instantiated descriptor based on the given
bytebuffer


public static <U extends Aggregate> List<Batch<U>> getBatches(List<U> list, int partitionSize) {
        List<List<U>> partitions = Lists.partition(list, partitionSize);
        List<Batch<U>> split = new ArrayList<>();

        for (List<U> partition : partitions) {
            split.add(new Batch<U>(partition));
        }

        return split;
    }

public static < U extends Aggregate > List < Batch < U > > getBatches ( List < U > list , int partitionSize ) { List < List < U >> partitions = Lists . partition ( list , partitionSize ) ; List < Batch < U > > split = new ArrayList <> ( ) ; for ( List < U > partition : partitions ) { split . add ( new Batch < U > ( partition ) ) ; } return split ; }

Helper method to create batch from list of aggregates, for cases when list of aggregates is higher then batchLimit

@param list
@param <U>
@return

Helper method to create batch from list of aggregates for cases when list of aggregates is higher then batchLimit


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

    }

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

input arrays must have same number of dimensions


@Override
    public void setDType(DataBuffer.Type dtype) {
        assert dtype == DataBuffer.Type.DOUBLE || dtype == DataBuffer.Type.FLOAT
                        || dtype == DataBuffer.Type.INT : "Invalid opType passed, must be float or double";
        // this.dtype = dtype;
    }


@Override
    public INDArray linspace(int lower, int upper, int num) {
        double[] data = new double[num];
        for (int i = 0; i < num; i++) {
            double t = (double) i / (num - 1);
            data[i] = lower * (1 - t) + t * upper;

        }

        //edge case for scalars
        INDArray ret = Nd4j.create(data.length);
        if (ret.isScalar())
            return ret;

        for (int i = 0; i < ret.length(); i++)
            ret.putScalar(i, data[i]);
        return ret;
    }

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

Generate a linearly spaced vector

@param lower upper bound
@param upper lower bound
@param num   the step size
@return the linearly spaced vector


@Override
    public INDArray toFlattened(Collection<INDArray> matrices) {
        int length = 0;
        for (INDArray m : matrices)
            length += m.length();
        INDArray ret = Nd4j.create(1, length);
        int linearIndex = 0;
        for (INDArray d : matrices) {
            ret.put(new INDArrayIndex[] {NDArrayIndex.interval(linearIndex, linearIndex + d.length())}, d);
            linearIndex += d.length();
        }

        return ret;

    }

@ Override public INDArray toFlattened ( Collection < INDArray > matrices ) { int length = 0 ; for ( INDArray m : matrices ) length += m . length ( ) ; INDArray ret = Nd4j . create ( 1 , length ) ; int linearIndex = 0 ; for ( INDArray d : matrices ) { ret . put ( new INDArrayIndex [ ] { NDArrayIndex . interval ( linearIndex , linearIndex + d . length ( ) ) } , d ) ; linearIndex += d . length ( ) ; } return ret ; }

Returns a vector with all of the elements in every nd array
equal to the sum of the lengths of the ndarrays

@param matrices the ndarrays to getFloat a flattened representation of
@return the flattened ndarray


@Override
    public INDArray bilinearProducts(INDArray curr, INDArray in) {
        assert curr.shape().length == 3;
        if (in.columns() != 1) {
            throw new AssertionError("Expected a column vector");
        }
        if (in.rows() != curr.size(curr.shape().length - 1)) {
            throw new AssertionError("Number of rows in the input does not match number of columns in tensor");
        }

        if (curr.size(curr.shape().length - 2) != curr.size(curr.shape().length - 1)) {
            throw new AssertionError("Can only perform this operation on a SimpleTensor with square slices");
        }

        INDArray ret = Nd4j.create(curr.slices(), 1);
        INDArray inT = in.transpose();
        for (int i = 0; i < curr.slices(); i++) {
            INDArray slice = curr.slice(i);
            INDArray inTTimesSlice = inT.mmul(slice);
            ret.putScalar(i, Nd4j.getBlasWrapper().dot(inTTimesSlice, in));
        }
        return ret;
    }

Returns a column vector where each entry is the nth bilinear
product of the nth slices of the two tensors.

Returns a column vector where each entry is the nth bilinear product of the nth slices of the two tensors .


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

Creates an ndarray with the specified data

@param data the number of columns in the row vector
@return ndarray


@Override
    public IComplexNDArray complexValueOf(int num, double value) {
        IComplexNDArray ones = complexOnes(num);
        ones.assign(Nd4j.createDouble(value, 0.0));
        return ones;
    }

@ Override public IComplexNDArray complexValueOf ( int num , double value ) { IComplexNDArray ones = complexOnes ( num ) ; ones . assign ( Nd4j . createDouble ( value , 0.0 ) ) ; return ones ; }

Creates an 1 x num ndarray with the specified value

@param num   the number of columns
@param value the value to assign
@return a complex ndarray of the specified size
and value


@Override
    public IComplexNDArray complexValueOf(int[] shape, double value) {
        IComplexNDArray ones = complexOnes(shape);
        ones.assign(Nd4j.scalar(value));
        return ones;
    }

@ Override public IComplexNDArray complexValueOf ( int [ ] shape , double value ) { IComplexNDArray ones = complexOnes ( shape ) ; ones . assign ( Nd4j . scalar ( value ) ) ; return ones ; }

Creates an shape ndarray with the specified value

@param shape the shape of the ndarray
@param value the value to assign
@return a complex ndarray of the specified size
and value


@Override
    public boolean shouldReplicate() {
        long now = System.currentTimeMillis();
        long diff = Math.abs(now - lastSynced);
        return diff > syncTime;
    }

@ Override public boolean shouldReplicate ( ) { long now = System . currentTimeMillis ( ) ; long diff = Math . abs ( now - lastSynced ) ; return diff > syncTime ; }

Returns true if
the updater has accumulated enough ndarrays to
replicate to the workers

@return true if replication should happen,false otherwise


@Override
    public IComplexNumber subi(IComplexNumber c, IComplexNumber result) {
        return result.set(realComponent().doubleValue() - c.realComponent().doubleValue(),
                        imaginaryComponent().doubleValue() - c.imaginaryComponent().doubleValue());
    }

@ Override public IComplexNumber subi ( IComplexNumber c , IComplexNumber result ) { return result . set ( realComponent ( ) . doubleValue ( ) - c . realComponent ( ) . doubleValue ( ) , imaginaryComponent ( ) . doubleValue ( ) - c . imaginaryComponent ( ) . doubleValue ( ) ) ; }

Subtract two complex numbers, in-place

@param c
@param result


public static IComplexNumber atan(IComplexNumber num) {
        Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).atan();
        return Nd4j.createDouble(c.getReal(), c.getImaginary());
    }

public static IComplexNumber atan ( IComplexNumber num ) { Complex c = new Complex ( num . realComponent ( ) . doubleValue ( ) , num . imaginaryComponent ( ) . doubleValue ( ) ) . atan ( ) ; return Nd4j . createDouble ( c . getReal ( ) , c . getImaginary ( ) ) ; }

Return the  sin value of the given complex number

@param num the number to getScalar the absolute value for
@return the absolute value of this complex number


public static IComplexNumber ceil(IComplexNumber num) {
        Complex c = new Complex(FastMath.ceil(num.realComponent().doubleValue()),
                        FastMath.ceil(num.imaginaryComponent().doubleValue()));
        return Nd4j.createDouble(c.getReal(), c.getImaginary());
    }

public static IComplexNumber ceil ( IComplexNumber num ) { Complex c = new Complex ( FastMath . ceil ( num . realComponent ( ) . doubleValue ( ) ) , FastMath . ceil ( num . imaginaryComponent ( ) . doubleValue ( ) ) ) ; return Nd4j . createDouble ( c . getReal ( ) , c . getImaginary ( ) ) ; }

Return the  ceiling value of the given complex number

@param num the number to getScalar the absolute value for
@return the absolute value of this complex number


public static IComplexNumber neg(IComplexNumber num) {
        Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).negate();
        return Nd4j.createDouble(c.getReal(), c.getImaginary());
    }

public static IComplexNumber neg ( IComplexNumber num ) { Complex c = new Complex ( num . realComponent ( ) . doubleValue ( ) , num . imaginaryComponent ( ) . doubleValue ( ) ) . negate ( ) ; return Nd4j . createDouble ( c . getReal ( ) , c . getImaginary ( ) ) ; }

Return the  log value of the given complex number

@param num the number to getScalar the absolute value for
@return the absolute value of this complex number


public static IComplexNumber abs(IComplexNumber num) {
        double c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).abs();
        return Nd4j.createDouble(c, 0);
    }

public static IComplexNumber abs ( IComplexNumber num ) { double c = new Complex ( num . realComponent ( ) . doubleValue ( ) , num . imaginaryComponent ( ) . doubleValue ( ) ) . abs ( ) ; return Nd4j . createDouble ( c , 0 ) ; }

Return the absolute value of the given complex number

@param num the number to getScalar the absolute value for
@return the absolute value of this complex number


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

    }

public static IComplexNumber pow ( IComplexNumber num , IComplexNumber power ) { Complex c = new Complex ( num . realComponent ( ) . doubleValue ( ) , num . imaginaryComponent ( ) . doubleValue ( ) ) . pow ( new Complex ( power . realComponent ( ) . doubleValue ( ) , power . imaginaryComponent ( ) . doubleValue ( ) ) ) ; if ( c . isNaN ( ) ) c = new Complex ( Nd4j . EPS_THRESHOLD , 0.0 ) ; return Nd4j . createDouble ( c . getReal ( ) , c . getImaginary ( ) ) ; }

Raise a complex number to a power

@param num   the number to raise
@param power the power to raise to
@return the number raised to a power


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

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


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

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

Binarizes the dataset such that any number greater than cutoff is 1 otherwise zero

@param cutoff the cutoff point


@Override
    public DataSet sample(int numSamples, org.nd4j.linalg.api.rng.Random rng, boolean withReplacement) {
        INDArray examples = Nd4j.create(numSamples, getFeatures().columns());
        INDArray outcomes = Nd4j.create(numSamples, numOutcomes());
        Set<Integer> added = new HashSet<>();
        for (int i = 0; i < numSamples; i++) {
            int picked = rng.nextInt(numExamples());
            if (!withReplacement)
                while (added.contains(picked))
                    picked = rng.nextInt(numExamples());

            examples.putRow(i, get(picked).getFeatures());
            outcomes.putRow(i, get(picked).getLabels());

        }
        return new DataSet(examples, outcomes);

    }

@ Override public DataSet sample ( int numSamples , org . nd4j . linalg . api . rng . Random rng , boolean withReplacement ) { INDArray examples = Nd4j . create ( numSamples , getFeatures ( ) . columns ( ) ) ; INDArray outcomes = Nd4j . create ( numSamples , numOutcomes ( ) ) ; Set < Integer > added = new HashSet <> ( ) ; for ( int i = 0 ; i < numSamples ; i ++ ) { int picked = rng . nextInt ( numExamples ( ) ) ; if ( ! withReplacement ) while ( added . contains ( picked ) ) picked = rng . nextInt ( numExamples ( ) ) ; examples . putRow ( i , get ( picked ) . getFeatures ( ) ) ; outcomes . putRow ( i , get ( picked ) . getLabels ( ) ) ; } return new DataSet ( examples , outcomes ) ; }

Sample a dataset

@param numSamples      the number of samples to getFromOrigin
@param rng             the rng to use
@param withReplacement whether to allow duplicates (only tracked by example row number)
@return the sample dataset


@Override
    public long getMemoryFootprint() {
        long reqMem = features.lengthLong() * Nd4j.sizeOfDataType();
        reqMem += labels == null ? 0 : labels.lengthLong() * Nd4j.sizeOfDataType();
        reqMem += featuresMask == null ? 0 : featuresMask.lengthLong() * Nd4j.sizeOfDataType();
        reqMem += labelsMask == null ? 0 : labelsMask.lengthLong() * Nd4j.sizeOfDataType();

        return reqMem;
    }

@ Override public long getMemoryFootprint ( ) { long reqMem = features . lengthLong ( ) * Nd4j . sizeOfDataType ( ) ; reqMem += labels == null ? 0 : labels . lengthLong ( ) * Nd4j . sizeOfDataType ( ) ; reqMem += featuresMask == null ? 0 : featuresMask . lengthLong ( ) * Nd4j . sizeOfDataType ( ) ; reqMem += labelsMask == null ? 0 : labelsMask . lengthLong ( ) * Nd4j . sizeOfDataType ( ) ; return reqMem ; }

This method returns memory used by this DataSet

@return


public static String stringifyException(Throwable e) {
        StringWriter stm = new StringWriter();
        PrintWriter wrt = new PrintWriter(stm);
        e.printStackTrace(wrt);
        wrt.close();
        return stm.toString();
    }

public static String stringifyException ( Throwable e ) { StringWriter stm = new StringWriter ( ) ; PrintWriter wrt = new PrintWriter ( stm ) ; e . printStackTrace ( wrt ) ; wrt . close ( ) ; return stm . toString ( ) ; }

Make a string representation of the exception.
@param e The exception to stringify
@return A string with exception name and call stack.

Make a string representation of the exception .


public static String simpleHostname(String fullHostname) {
        if (InetAddresses.isInetAddress(fullHostname)) {
            return fullHostname;
        }
        int offset = fullHostname.indexOf('.');
        if (offset != -1) {
            return fullHostname.substring(0, offset);
        }
        return fullHostname;
    }

public static String simpleHostname ( String fullHostname ) { if ( InetAddresses . isInetAddress ( fullHostname ) ) { return fullHostname ; } int offset = fullHostname . indexOf ( ' ' ) ; if ( offset != - 1 ) { return fullHostname . substring ( 0 , offset ) ; } return fullHostname ; }

Given a full hostname, return the word upto the first dot.
@param fullHostname the full hostname
@return the hostname to the first dot

Given a full hostname return the word upto the first dot .


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

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

Given an array of strings, return a comma-separated list of its elements.
@param strs Array of strings
@return Empty string if strs.length is 0, comma separated list of strings
otherwise

Given an array of strings return a comma - separated list of its elements .


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

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

Given an array of bytes it will convert the bytes to a hex string
representation of the bytes
@param bytes
@param start start index, inclusively
@param end end index, exclusively
@return hex string representation of the byte array


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

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

Returns an arraylist of strings.
@param str the string values
@param delim delimiter to separate the values
@return the arraylist of the separated string values


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

Split a string using the given separator
@param str a string that may have escaped separator
@param escapeChar a char that be used to escape the separator
@param separator a separator char
@return an array of strings


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

Split a string using the given separator, with no escaping performed.
@param str a string to be split. Note that this may not be null.
@param separator a separator char
@return an array of strings

Split a string using the given separator with no escaping performed .


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

public
static
int
findNext
(
String
str
,
char
separator
,
char
escapeChar
,
int
start
,
StringBuilder
split
)
{
int
numPreEscapes
=
0
;
for
(
int
i
=
start
;
i
<
str
.
length
(
)
;
i
++
)
{
char
curChar
=
str
.
charAt
(
i
)
;
if
(
numPreEscapes
==
0
&&
curChar
==
separator
)
{
// separator
return
i
;
}
else
{
split
.
append
(
curChar
)
;
numPreEscapes
=
(
curChar
==
escapeChar
)
(
++
numPreEscapes
)
%
2
:
0
;
}
}
return
1
;
}

Finds the first occurrence of the separator character ignoring the escaped
separators starting from the index. Note the substring between the index
and the position of the separator is passed.
@param str the source string
@param separator the character to find
@param escapeChar character used to escape
@param start from where to search
@param split used to pass back the extracted string

Finds the first occurrence of the separator character ignoring the escaped separators starting from the index . Note the substring between the index and the position of the separator is passed .


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

        return sb.toString();
    }

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

Escapes HTML Special characters present in the string.
@param string
@return HTML Escaped String representation

Escapes HTML Special characters present in the string .


public static String join(CharSequence separator, Iterable<?> strings) {
        Iterator<?> i = strings.iterator();
        if (!i.hasNext()) {
            return "";
        }
        StringBuilder sb = new StringBuilder(i.next().toString());
        while (i.hasNext()) {
            sb.append(separator);
            sb.append(i.next().toString());
        }
        return sb.toString();
    }

public static String join ( CharSequence separator , Iterable < ? > strings ) { Iterator < ? > i = strings . iterator ( ) ; if ( ! i . hasNext ( ) ) { return "" ; } StringBuilder sb = new StringBuilder ( i . next ( ) . toString ( ) ) ; while ( i . hasNext ( ) ) { sb . append ( separator ) ; sb . append ( i . next ( ) . toString ( ) ) ; } return sb . toString ( ) ; }

Concatenates strings, using a separator.

@param separator Separator to join with.
@param strings Strings to join.

Concatenates strings using a separator .


public static String camelize(String s) {
        StringBuilder sb = new StringBuilder();
        String[] words = split(StringUtils.toLowerCase(s), ESCAPE_CHAR,  '_');

        for (String word : words)
            sb.append(org.apache.commons.lang3.StringUtils.capitalize(word));

        return sb.toString();
    }

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

Convert SOME_STUFF to SomeStuff

@param s input string
@return camelized string


public static String replaceTokens(String template, Pattern pattern,
                                       Map<String, String> replacements) {
        StringBuffer sb = new StringBuffer();
        Matcher matcher = pattern.matcher(template);
        while (matcher.find()) {
            String replacement = replacements.get(matcher.group(1));
            if (replacement == null) {
                replacement = "";
            }
            matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
        }
        matcher.appendTail(sb);
        return sb.toString();
    }

public static String replaceTokens ( String template , Pattern pattern , Map < String , String > replacements ) { StringBuffer sb = new StringBuffer ( ) ; Matcher matcher = pattern . matcher ( template ) ; while ( matcher . find ( ) ) { String replacement = replacements . get ( matcher . group ( 1 ) ) ; if ( replacement == null ) { replacement = "" ; } matcher . appendReplacement ( sb , Matcher . quoteReplacement ( replacement ) ) ; } matcher . appendTail ( sb ) ; return sb . toString ( ) ; }

Matches a template string against a pattern, replaces matched tokens with
the supplied replacements, and returns the result.  The regular expression
must use a capturing group.  The value of the first capturing group is used
to look up the replacement.  If no replacement is found for the token, then
it is replaced with the empty string.

For example, assume template is "%foo%_%bar%_%baz%", pattern is "%(.*?)%",
and replacements contains 2 entries, mapping "foo" to "zoo" and "baz" to
"zaz".  The result returned would be "zoo__zaz".

@param template String template to receive replacements
@param pattern Pattern to match for identifying tokens, must use a capturing
group
@param replacements Map<String, String> mapping tokens identified by the
capturing group to their replacement values
@return String template with replacements

Matches a template string against a pattern replaces matched tokens with the supplied replacements and returns the result . The regular expression must use a capturing group . The value of the first capturing group is used to look up the replacement . If no replacement is found for the token then it is replaced with the empty string .


public static String getStackTrace(Thread t) {
        final StackTraceElement[] stackTrace = t.getStackTrace();
        StringBuilder str = new StringBuilder();
        for (StackTraceElement e : stackTrace) {
            str.append(e.toString() + "\n");
        }
        return str.toString();
    }

public static String getStackTrace ( Thread t ) { final StackTraceElement [ ] stackTrace = t . getStackTrace ( ) ; StringBuilder str = new StringBuilder ( ) ; for ( StackTraceElement e : stackTrace ) { str . append ( e . toString ( ) + "\n" ) ; } return str . toString ( ) ; }


public static INDArray invert(INDArray arr, boolean inPlace) {
        if (!arr.isSquare()) {
            throw new IllegalArgumentException("invalid array: must be square matrix");
        }

        //FIX ME: Please
       /* int[] IPIV = new int[arr.length() + 1];
        int LWORK = arr.length() * arr.length();
        INDArray WORK = Nd4j.create(new double[LWORK]);
        INDArray inverse = inPlace ? arr : arr.dup();
        Nd4j.getBlasWrapper().lapack().getrf(arr);
        Nd4j.getBlasWrapper().lapack().getri(arr.size(0),inverse,arr.size(0),IPIV,WORK,LWORK,0);*/

        RealMatrix rm = CheckUtil.convertToApacheMatrix(arr);
        RealMatrix rmInverse = new LUDecomposition(rm).getSolver().getInverse();

        INDArray inverse = CheckUtil.convertFromApacheMatrix(rmInverse);
        if (inPlace)
            arr.assign(inverse);
        return inverse;

    }

Inverts a matrix
@param arr the array to invert
@param inPlace Whether to store the result in {@code arr}
@return the inverted matrix


public BigInteger at(int n) {
        while (a.size() <= n) {
            final int lastn = a.size() - 1;
            final BigInteger nextn = BigInteger.valueOf(lastn + 1);
            a.add(a.get(lastn).multiply(nextn));
        }
        return a.get(n);
    }

public BigInteger at ( int n ) { while ( a . size ( ) <= n ) { final int lastn = a . size ( ) - 1 ; final BigInteger nextn = BigInteger . valueOf ( lastn + 1 ) ; a . add ( a . get ( lastn ) . multiply ( nextn ) ) ; } return a . get ( n ) ; }

Compute the factorial of the non-negative integer.

@param n the argument to the factorial, non-negative.
@return the factorial of n.

Compute the factorial of the non - negative integer .


public boolean isActualOnHostSide() {
        //log.info("isActuialOnHostSide() -> Host side: [{}], Device side: [{}]", accessHostRead.get(), accessDeviceRead.get());
        boolean result = accessHostWrite.get() >= accessDeviceWrite.get()
                        || accessHostRead.get() >= accessDeviceWrite.get();
        //log.info("isActuialOnHostSide() -> {}, shape: {}", result, shape);
        return result;
    }

This method returns, if host side has actual copy of data

@return true, if data is actual, false otherwise

This method returns if host side has actual copy of data


public boolean isActualOnDeviceSide() {
        //log.info("isActuialOnDeviceSide() -> Host side: [{}], Device side: [{}]", accessHostWrite.get(), accessDeviceWrite.get());
        boolean result = accessDeviceWrite.get() >= accessHostWrite.get()
                        || accessDeviceRead.get() >= accessHostWrite.get(); //accessHostWrite.get() <= getDeviceAccessTime();
        //        log.info("isActuialOnDeviceSide() -> {} ({}), Shape: {}", result, objectId, shape);
        return result;
    }

This method returns, if device side has actual copy of data

@return

This method returns if device side has actual copy of data


@Override
    public Pair<DataBuffer, long[]> createShapeInformation(int[] shape) {
        char order = Nd4j.order();

        return createShapeInformation(shape, order);
    }

@ Override public Pair < DataBuffer , long [ ] > createShapeInformation ( int [ ] shape ) { char order = Nd4j . order ( ) ; return createShapeInformation ( shape , order ) ; }

This method creates shapeInformation buffer, based on shape being passed in

@param shape
@return

This method creates shapeInformation buffer based on shape being passed in