Package org.nd4j.linalg.api.buffer
Class BaseDataBuffer
- java.lang.Object
-
- org.nd4j.linalg.api.buffer.BaseDataBuffer
-
- All Implemented Interfaces:
Serializable,AutoCloseable,DataBuffer
- Direct Known Subclasses:
CompressedDataBuffer
public abstract class BaseDataBuffer extends Object implements DataBuffer
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.nd4j.linalg.api.buffer.DataBuffer
DataBuffer.AllocationMode, DataBuffer.TypeEx
-
-
Field Summary
Fields Modifier and Type Field Description protected DataBuffer.AllocationModeallocationModeprotected booleanattachedprotected booleanconstantprotected byteelementSizeprotected org.bytedeco.javacpp.indexer.Indexerindexerprotected longlengthprotected longoffsetprotected DataBufferoriginalBufferprotected longoriginalOffsetprotected MemoryWorkspaceparentWorkspaceprotected org.bytedeco.javacpp.Pointerpointerprotected AtomicBooleanreferencedprotected booleanreleasedstatic StringTO_STRING_MAX_ELEMENTSDeprecated.protected DataTypetypeprotected longunderlyingLengthprotected longworkspaceGenerationIdprotected DataBufferwrappedDataBuffer
-
Constructor Summary
Constructors Modifier Constructor Description BaseDataBuffer()BaseDataBuffer(org.bytedeco.javacpp.Pointer pointer, org.bytedeco.javacpp.indexer.Indexer indexer, long length)Meant for creating another view of a bufferprotectedBaseDataBuffer(DataBuffer underlyingBuffer, long length, long offset)Meant for creating another view of a buffer
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddReferencing(String id)Deprecated.longaddress()Returns the address of the pointerabstract org.bytedeco.javacpp.PointeraddressPointer()Returns the address of the pointer wrapped in a PointerDataBuffer.AllocationModeallocationMode()Allocation mode for buffersObjectarray()Returns the backing array of this buffer (if there is one)byte[]asBytes()Raw byte array storagedouble[]asDouble()Return the buffer as a double array Relative to the datatype, this will either be a copy or a reference.float[]asFloat()Return the buffer as a float array Relative to the datatype, this will either be a copy or a reference.int[]asInt()Return the buffer as an int array Relative to the datatype, this will either be a copy or a reference.long[]asLong()Return the buffer as an long array Relative to the datatype, this will either be a copy or a reference.ByteBufferasNio()Returns a view of this as an nio byte bufferDoubleBufferasNioDouble()Returns a view of this as an nio byte bufferFloatBufferasNioFloat()Returns a view of this as an nio byte bufferIntBufferasNioInt()Returns a view of this as an nio byte bufferLongBufferasNioLong()voidassign(long[] indices, double[] data, boolean contiguous)Assign the given elements to the given indicesvoidassign(long[] indices, double[] data, boolean contiguous, long inc)Assign the given elements to the given indicesvoidassign(long[] indices, float[] data, boolean contiguous)Assign the given elements to the given indicesvoidassign(long[] indices, float[] data, boolean contiguous, long inc)Assign the given elements to the given indicesvoidassign(long[] offsets, long[] strides, long n, DataBuffer... buffers)Assign the given buffers to this buffer based on the given offsets and strides.voidassign(long[] offsets, long[] strides, DataBuffer... buffers)Assign the given buffers to this buffer based on the given offsets and strides.voidassign(Number value)Assign the given value to the buffervoidassign(Number value, long offset)Assign the given value to the buffer starting at offsetvoidassign(DataBuffer data)Assign the contents of this buffer to this buffervoidassign(DataBuffer... buffers)Assign the given data buffers to this bufferlongcapacity()voidclose()This method releases exclusive off-heap resources uses by this DataBuffer instance.booleancloseable()This method checks, if this DataBuffer instalce can use close() methodvoidcopyAtStride(DataBuffer buf, long n, long stride, long yStride, long offset, long yOffset)Copies from the given buffer at the specified stride for up to n elementsabstract DataBuffercreate(double[] data)Create the data buffer with respect to the given byte bufferabstract DataBuffercreate(float[] data)Create the data buffer with respect to the given byte bufferabstract DataBuffercreate(int[] data)Create the data buffer with respect to the given byte bufferprotected abstract DataBuffercreate(long length)Create with lengthDataTypedataType()The data opType of the buffervoiddestroy()release all resources for this bufferbooleandirty()Deprecated.protected voiddoReadObject(ObjectInputStream s)DataBufferdup()Return a copy of this bufferbooleanequals(Object o)protected voidfillPointerWithZero()voidflush()Flush the data bufferstatic shortfromFloat(float v)doublegetDouble(long i)Get element i in the buffer as a doubledouble[]getDoublesAt(long offset, int length)Get the doubles at a particular offsetdouble[]getDoublesAt(long offset, long inc, int length)Get the doubles at a particular offsetprotected abstract doublegetDoubleUnsynced(long index)intgetElementSize()The number of bytes for each individual elementfloatgetFloat(long i)Get element i in the buffer as a doublefloat[]getFloatsAt(long offset, int length)Get the doubles at a particular offsetfloat[]getFloatsAt(long offset, long inc, int length)Get the doubles at a particular offsetprotected abstract floatgetFloatUnsynced(long index)longgetGenerationId()intgetInt(long i)Get the int at the specified indexint[]getIntsAt(long offset, int length)Get the ints at a particular offsetint[]getIntsAt(long offset, long inc, int length)Get the ints at a particular offsetprotected abstract intgetIntUnsynced(long index)longgetLong(long i)Get element i in the buffer as long valuelong[]getLongsAt(long offset, int length)Get the longs at a particular offsetlong[]getLongsAt(long offset, long inc, int length)Get the long at a particular offsetprotected abstract longgetLongUnsynced(long index)NumbergetNumber(long i)Get element i in the buffer as a doubleMemoryWorkspacegetParentWorkspace()This method returns Workspace this DataBuffer is attached toprotected shortgetShort(long i)Special method forinthashCode()org.bytedeco.javacpp.indexer.Indexerindexer()Returns the indexer for the bufferprotected abstract voidinitTypeAndSize()Initialize the opType of this bufferbooleanisAttached()This method returns True, if this DataBuffer is attached to some workspace.booleanisConstant()This method returns whether this DataBuffer is constant, or not.booleanisInScope()This method checks, if given attached INDArray is still in scope of its parent WorkspacebooleanisPersist()Deprecated.longlength()Returns the length of the bufferprotected voidmarkReleased()longoffset()Returns the offset of the bufferDataBufferoriginalDataBuffer()Original DataBuffer.longoriginalOffset()Returns the offset of the buffer relative to originalDataBuffervoidpersist()Deprecated.protected voidpickReferent(BaseDataBuffer referent)longplatformAddress()Returns the address of platform-specific pointer: - for native backend that'll be host pointer - for cuda backend that'll be device pointerorg.bytedeco.javacpp.Pointerpointer()Returns an underlying pointer if one existsabstract voidpointerIndexerByCurrentType(DataType currentType)voidput(long i, boolean element)voidput(long i, double element)Assign an element in the buffer to the specified indexvoidput(long i, float element)Assign an element in the buffer to the specified indexvoidput(long i, int element)Assign an element in the buffer to the specified indexvoidput(long i, long element)voidputByDestinationType(long i, Number element, DataType globalType)voidread(DataInputStream s, @NonNull DataBuffer.AllocationMode allocMode, long len, @NonNull DataType dtype)voidread(InputStream is, DataBuffer.AllocationMode allocationMode, long length, DataType dataType)Write this buffer to the input stream.protected voidreadContent(DataInputStream s, DataType sourceType, DataType thisType)static Triple<DataBuffer.AllocationMode,Long,DataType>readHeader(@NonNull InputStream is)abstract DataBufferreallocate(long length)Reallocate the native memory of the bufferCollection<String>references()Deprecated.protected voidrelease()voidremoveReferencing(String id)Deprecated.booleansameUnderlyingData(DataBuffer buffer)Returns true if the underlying data source is the same for both buffers (referential equals)voidsetConstant(boolean reallyConstant)This method allows you to mark databuffer as constant.voidsetData(boolean[] data)voidsetData(byte[] data)voidsetData(double[] data)Set the data for this buffervoidsetData(float[] data)Set the data for this buffervoidsetData(int[] data)Set the data for this buffervoidsetData(long[] data)Set the data for this buffervoidsetData(short[] data)protected voidsetIndexer(org.bytedeco.javacpp.indexer.Indexer indexer)protected voidsetNioBuffer()abstract voidsyncToPrimary()This method synchronizes host memoryabstract voidsyncToSpecial()This method synchronizes device memoryfloattoFloat(int hbits)StringtoString()DataBufferunderlyingDataBuffer()Underlying buffer: This is meant for a data buffer to be a view of another data bufferlongunderlyingLength()Returns the length of the buffervoidunPersist()Deprecated.booleanwasClosed()This method checks if array or its buffer was closed beforeprotected ByteBufferwrappedBuffer()voidwrite(DataOutputStream out)voidwrite(OutputStream dos)Write this buffer to the output stream
-
-
-
Field Detail
-
TO_STRING_MAX_ELEMENTS
public static String TO_STRING_MAX_ELEMENTS
Deprecated.
-
type
protected DataType type
-
length
protected long length
-
underlyingLength
protected long underlyingLength
-
offset
protected long offset
-
elementSize
protected byte elementSize
-
wrappedDataBuffer
protected transient DataBuffer wrappedDataBuffer
-
workspaceGenerationId
protected transient long workspaceGenerationId
-
allocationMode
protected DataBuffer.AllocationMode allocationMode
-
indexer
protected transient org.bytedeco.javacpp.indexer.Indexer indexer
-
pointer
protected transient org.bytedeco.javacpp.Pointer pointer
-
attached
protected transient boolean attached
-
parentWorkspace
protected transient MemoryWorkspace parentWorkspace
-
originalBuffer
protected transient DataBuffer originalBuffer
-
originalOffset
protected transient long originalOffset
-
constant
protected transient boolean constant
-
released
protected transient boolean released
-
referenced
protected transient AtomicBoolean referenced
-
-
Constructor Detail
-
BaseDataBuffer
public BaseDataBuffer()
-
BaseDataBuffer
public BaseDataBuffer(org.bytedeco.javacpp.Pointer pointer, org.bytedeco.javacpp.indexer.Indexer indexer, long length)Meant for creating another view of a buffer- Parameters:
pointer- the underlying buffer to create a view fromindexer- the indexer for the pointerlength- the length of the view
-
BaseDataBuffer
protected BaseDataBuffer(DataBuffer underlyingBuffer, long length, long offset)
Meant for creating another view of a buffer- Parameters:
underlyingBuffer- the underlying buffer to create a view fromlength- the length of the viewoffset- the offset for the view
-
-
Method Detail
-
initTypeAndSize
protected abstract void initTypeAndSize()
Initialize the opType of this buffer
-
getElementSize
public int getElementSize()
Description copied from interface:DataBufferThe number of bytes for each individual element- Specified by:
getElementSizein interfaceDataBuffer- Returns:
- the number of bytes for each individual element
-
getGenerationId
public long getGenerationId()
- Specified by:
getGenerationIdin interfaceDataBuffer
-
setIndexer
protected void setIndexer(org.bytedeco.javacpp.indexer.Indexer indexer)
-
pickReferent
protected void pickReferent(BaseDataBuffer referent)
-
originalDataBuffer
public DataBuffer originalDataBuffer()
Original DataBuffer. In case if we have a view derived from another view, derived from some other view, original DataBuffer will point to the originating DataBuffer, where all views come from.- Specified by:
originalDataBufferin interfaceDataBuffer
-
setNioBuffer
protected void setNioBuffer()
-
indexer
public org.bytedeco.javacpp.indexer.Indexer indexer()
Returns the indexer for the buffer- Specified by:
indexerin interfaceDataBuffer- Returns:
-
pointer
public org.bytedeco.javacpp.Pointer pointer()
Description copied from interface:DataBufferReturns an underlying pointer if one exists- Specified by:
pointerin interfaceDataBuffer- Returns:
-
underlyingDataBuffer
public DataBuffer underlyingDataBuffer()
Description copied from interface:DataBufferUnderlying buffer: This is meant for a data buffer to be a view of another data buffer- Specified by:
underlyingDataBufferin interfaceDataBuffer- Returns:
-
offset
public long offset()
Description copied from interface:DataBufferReturns the offset of the buffer- Specified by:
offsetin interfaceDataBuffer- Returns:
- the offset of the buffer
-
allocationMode
public DataBuffer.AllocationMode allocationMode()
Description copied from interface:DataBufferAllocation mode for buffers- Specified by:
allocationModein interfaceDataBuffer- Returns:
- the allocation mode for the buffer
-
persist
@Deprecated public void persist()
Deprecated.Description copied from interface:DataBufferMark this buffer as persistent- Specified by:
persistin interfaceDataBuffer
-
isPersist
@Deprecated public boolean isPersist()
Deprecated.Description copied from interface:DataBufferWhether the buffer should be persistent. This is mainly for the aggressive garbage collection strategy.- Specified by:
isPersistin interfaceDataBuffer- Returns:
- whether the buffer should be persistent or not (default false)
-
unPersist
@Deprecated public void unPersist()
Deprecated.Description copied from interface:DataBufferUn persist the buffer- Specified by:
unPersistin interfaceDataBuffer
-
fillPointerWithZero
protected void fillPointerWithZero()
-
copyAtStride
public void copyAtStride(DataBuffer buf, long n, long stride, long yStride, long offset, long yOffset)
Description copied from interface:DataBufferCopies from the given buffer at the specified stride for up to n elements- Specified by:
copyAtStridein interfaceDataBuffer- Parameters:
buf- the data buffer to copy fromn- the number of elements to copystride- the stride to copy at
-
removeReferencing
@Deprecated public void removeReferencing(String id)
Deprecated.Description copied from interface:DataBufferRemove the referenced id if it exists- Specified by:
removeReferencingin interfaceDataBuffer- Parameters:
id- the id to remove
-
references
@Deprecated public Collection<String> references()
Deprecated.Description copied from interface:DataBufferThe referencers pointing to this buffer- Specified by:
referencesin interfaceDataBuffer- Returns:
- the references pointing to this buffer
-
addressPointer
public abstract org.bytedeco.javacpp.Pointer addressPointer()
Description copied from interface:DataBufferReturns the address of the pointer wrapped in a Pointer- Specified by:
addressPointerin interfaceDataBuffer- Returns:
- the address of the pointer wrapped in a Pointer
-
address
public long address()
Description copied from interface:DataBufferReturns the address of the pointer- Specified by:
addressin interfaceDataBuffer- Returns:
- the address of the pointer
-
addReferencing
@Deprecated public void addReferencing(String id)
Deprecated.Description copied from interface:DataBufferAdd a referencing element to this buffer- Specified by:
addReferencingin interfaceDataBuffer- Parameters:
id- the id to reference
-
assign
public void assign(long[] indices, float[] data, boolean contiguous, long inc)Description copied from interface:DataBufferAssign the given elements to the given indices- Specified by:
assignin interfaceDataBuffer- Parameters:
indices- the indices to assigndata- the data to assigncontiguous- whether the indices are contiguous or notinc- the number to increment by when assigning
-
setData
public void setData(int[] data)
Description copied from interface:DataBufferSet the data for this buffer- Specified by:
setDatain interfaceDataBuffer- Parameters:
data- the data for this buffer
-
setData
public void setData(float[] data)
Description copied from interface:DataBufferSet the data for this buffer- Specified by:
setDatain interfaceDataBuffer- Parameters:
data- the data for this buffer
-
setData
public void setData(double[] data)
Description copied from interface:DataBufferSet the data for this buffer- Specified by:
setDatain interfaceDataBuffer- Parameters:
data- the data for this buffer
-
setData
public void setData(long[] data)
Description copied from interface:DataBufferSet the data for this buffer- Specified by:
setDatain interfaceDataBuffer- Parameters:
data- the data for this buffer
-
setData
public void setData(byte[] data)
- Specified by:
setDatain interfaceDataBuffer
-
setData
public void setData(short[] data)
- Specified by:
setDatain interfaceDataBuffer
-
setData
public void setData(boolean[] data)
- Specified by:
setDatain interfaceDataBuffer
-
assign
public void assign(long[] indices, double[] data, boolean contiguous, long inc)Description copied from interface:DataBufferAssign the given elements to the given indices- Specified by:
assignin interfaceDataBuffer- Parameters:
indices- the indices to assigndata- the data to assigncontiguous- whether the data is contiguous or notinc- the number to increment by when assigning
-
assign
public void assign(DataBuffer data)
Description copied from interface:DataBufferAssign the contents of this buffer to this buffer- Specified by:
assignin interfaceDataBuffer- Parameters:
data- the data to assign
-
assign
public void assign(long[] indices, float[] data, boolean contiguous)Description copied from interface:DataBufferAssign the given elements to the given indices- Specified by:
assignin interfaceDataBuffer- Parameters:
indices- the indices to assigndata- the data to assigncontiguous- whether the indices are contiguous or not
-
assign
public void assign(long[] indices, double[] data, boolean contiguous)Description copied from interface:DataBufferAssign the given elements to the given indices- Specified by:
assignin interfaceDataBuffer- Parameters:
indices- the indices to assigndata- the data to assigncontiguous- whether the data is contiguous or not
-
underlyingLength
public long underlyingLength()
Description copied from interface:DataBufferReturns the length of the buffer- Specified by:
underlyingLengthin interfaceDataBuffer- Returns:
- the length of the buffer
-
length
public long length()
Description copied from interface:DataBufferReturns the length of the buffer- Specified by:
lengthin interfaceDataBuffer- Returns:
- the length of the buffer
-
assign
public void assign(Number value)
Description copied from interface:DataBufferAssign the given value to the buffer- Specified by:
assignin interfaceDataBuffer- Parameters:
value- the value to assign
-
getDoublesAt
public double[] getDoublesAt(long offset, long inc, int length)Description copied from interface:DataBufferGet the doubles at a particular offset- Specified by:
getDoublesAtin interfaceDataBuffer- Parameters:
offset- the offset to startinc- the increment to uselength- the length of the array- Returns:
- the doubles at the specified offset and length
-
getDoublesAt
public double[] getDoublesAt(long offset, int length)Description copied from interface:DataBufferGet the doubles at a particular offset- Specified by:
getDoublesAtin interfaceDataBuffer- Parameters:
offset- the offset to startlength- the length of the array- Returns:
- the doubles at the specified offset and length
-
getFloatsAt
public float[] getFloatsAt(long offset, int length)Description copied from interface:DataBufferGet the doubles at a particular offset- Specified by:
getFloatsAtin interfaceDataBuffer- Parameters:
offset- the offset to startlength- the length of the array- Returns:
- the doubles at the specified offset and length
-
getFloatsAt
public float[] getFloatsAt(long offset, long inc, int length)Description copied from interface:DataBufferGet the doubles at a particular offset- Specified by:
getFloatsAtin interfaceDataBuffer- Parameters:
offset- the offset to startinc- the increment to uselength- the length of the array- Returns:
- the doubles at the specified offset and length
-
getLongsAt
public long[] getLongsAt(long offset, int length)Description copied from interface:DataBufferGet the longs at a particular offset- Specified by:
getLongsAtin interfaceDataBuffer- Parameters:
offset- the offset to startlength- the length of the array- Returns:
- the doubles at the specified offset and length
-
getLongsAt
public long[] getLongsAt(long offset, long inc, int length)Description copied from interface:DataBufferGet the long at a particular offset- Specified by:
getLongsAtin interfaceDataBuffer- Parameters:
offset- the offset to startinc- the increment to uselength- the length of the array- Returns:
- the doubles at the specified offset and length
-
getIntsAt
public int[] getIntsAt(long offset, int length)Description copied from interface:DataBufferGet the ints at a particular offset- Specified by:
getIntsAtin interfaceDataBuffer- Parameters:
offset- the offset to startlength- the length of the array- Returns:
- the doubles at the specified offset and length
-
getIntsAt
public int[] getIntsAt(long offset, long inc, int length)Description copied from interface:DataBufferGet the ints at a particular offset- Specified by:
getIntsAtin interfaceDataBuffer- Parameters:
offset- the offset to startinc- the increment to uselength- the length of the array- Returns:
- the doubles at the specified offset and length
-
dup
public DataBuffer dup()
Description copied from interface:DataBufferReturn a copy of this buffer- Specified by:
dupin interfaceDataBuffer- Returns:
- a copy of this buffer
-
create
protected abstract DataBuffer create(long length)
Create with length- Parameters:
length- a databuffer of the same opType as this with the given length- Returns:
- a data buffer with the same length and datatype as this one
-
create
public abstract DataBuffer create(double[] data)
Create the data buffer with respect to the given byte buffer- Parameters:
data- the buffer to create- Returns:
- the data buffer based on the given buffer
-
create
public abstract DataBuffer create(float[] data)
Create the data buffer with respect to the given byte buffer- Parameters:
data- the buffer to create- Returns:
- the data buffer based on the given buffer
-
create
public abstract DataBuffer create(int[] data)
Create the data buffer with respect to the given byte buffer- Parameters:
data- the buffer to create- Returns:
- the data buffer based on the given buffer
-
assign
public void assign(long[] offsets, long[] strides, DataBuffer... buffers)Description copied from interface:DataBufferAssign the given buffers to this buffer based on the given offsets and strides. Note that the offsets and strides must be of equal length to the number of buffers- Specified by:
assignin interfaceDataBuffer- Parameters:
offsets- the offsets to usestrides- the strides to usebuffers- the buffers to assign data from
-
asBytes
public byte[] asBytes()
Description copied from interface:DataBufferRaw byte array storage- Specified by:
asBytesin interfaceDataBuffer- Returns:
- the data represented as a raw byte array
-
asFloat
public float[] asFloat()
Description copied from interface:DataBufferReturn the buffer as a float array Relative to the datatype, this will either be a copy or a reference. The reference is preferred for faster access of data and no copying- Specified by:
asFloatin interfaceDataBuffer- Returns:
- the buffer as a float
-
asDouble
public double[] asDouble()
Description copied from interface:DataBufferReturn the buffer as a double array Relative to the datatype, this will either be a copy or a reference. The reference is preferred for faster access of data and no copying- Specified by:
asDoublein interfaceDataBuffer- Returns:
- the buffer as a float
-
asInt
public int[] asInt()
Description copied from interface:DataBufferReturn the buffer as an int array Relative to the datatype, this will either be a copy or a reference. The reference is preferred for faster access of data and no copying- Specified by:
asIntin interfaceDataBuffer- Returns:
- the buffer as a int
-
asLong
public long[] asLong()
Description copied from interface:DataBufferReturn the buffer as an long array Relative to the datatype, this will either be a copy or a reference. The reference is preferred for faster access of data and no copying- Specified by:
asLongin interfaceDataBuffer- Returns:
- the buffer as a long
-
getDouble
public double getDouble(long i)
Description copied from interface:DataBufferGet element i in the buffer as a double- Specified by:
getDoublein interfaceDataBuffer- Parameters:
i- the element to getFloat- Returns:
- the element at this index
-
getLong
public long getLong(long i)
Description copied from interface:DataBufferGet element i in the buffer as long value- Specified by:
getLongin interfaceDataBuffer- Returns:
-
getShort
protected short getShort(long i)
Special method for- Parameters:
i-- Returns:
-
fromFloat
public static short fromFloat(float v)
- Parameters:
v-- Returns:
-
getFloat
public float getFloat(long i)
Description copied from interface:DataBufferGet element i in the buffer as a double- Specified by:
getFloatin interfaceDataBuffer- Parameters:
i- the element to getFloat- Returns:
- the element at this index
-
getInt
public int getInt(long i)
Description copied from interface:DataBufferGet the int at the specified index- Specified by:
getIntin interfaceDataBuffer- Parameters:
i- the int at the specified index- Returns:
- the int at the specified index
-
getNumber
public Number getNumber(long i)
Description copied from interface:DataBufferGet element i in the buffer as a double- Specified by:
getNumberin interfaceDataBuffer- Parameters:
i- the element to getFloat- Returns:
- the element at this index
-
pointerIndexerByCurrentType
public abstract void pointerIndexerByCurrentType(DataType currentType)
-
put
public void put(long i, float element)Description copied from interface:DataBufferAssign an element in the buffer to the specified index- Specified by:
putin interfaceDataBuffer- Parameters:
i- the indexelement- the element to assign
-
put
public void put(long i, double element)Description copied from interface:DataBufferAssign an element in the buffer to the specified index- Specified by:
putin interfaceDataBuffer- Parameters:
i- the indexelement- the element to assign
-
put
public void put(long i, int element)Description copied from interface:DataBufferAssign an element in the buffer to the specified index- Specified by:
putin interfaceDataBuffer- Parameters:
i- the indexelement- the element to assign
-
put
public void put(long i, boolean element)- Specified by:
putin interfaceDataBuffer
-
put
public void put(long i, long element)- Specified by:
putin interfaceDataBuffer
-
dirty
@Deprecated public boolean dirty()
Deprecated.Description copied from interface:DataBufferWhether the buffer is dirty: aka has been updated- Specified by:
dirtyin interfaceDataBuffer- Returns:
- true if the buffer has been updated, false otherwise
-
sameUnderlyingData
public boolean sameUnderlyingData(DataBuffer buffer)
Description copied from interface:DataBufferReturns true if the underlying data source is the same for both buffers (referential equals)- Specified by:
sameUnderlyingDatain interfaceDataBuffer- Parameters:
buffer- whether the buffer is the same underlying data or not- Returns:
- true if both data buffers have the same underlying data SOURCE
-
wrappedBuffer
protected ByteBuffer wrappedBuffer()
-
asNioInt
public IntBuffer asNioInt()
Description copied from interface:DataBufferReturns a view of this as an nio byte buffer- Specified by:
asNioIntin interfaceDataBuffer- Returns:
- a view of this as an nio int buffer
-
asNioLong
public LongBuffer asNioLong()
- Specified by:
asNioLongin interfaceDataBuffer
-
asNioDouble
public DoubleBuffer asNioDouble()
Description copied from interface:DataBufferReturns a view of this as an nio byte buffer- Specified by:
asNioDoublein interfaceDataBuffer- Returns:
- a view of this as an nio double buffer
-
asNioFloat
public FloatBuffer asNioFloat()
Description copied from interface:DataBufferReturns a view of this as an nio byte buffer- Specified by:
asNioFloatin interfaceDataBuffer- Returns:
- a view of this as an nio float buffer
-
asNio
public ByteBuffer asNio()
Description copied from interface:DataBufferReturns a view of this as an nio byte buffer- Specified by:
asNioin interfaceDataBuffer- Returns:
- a view of this as an nio byte buffer
-
assign
public void assign(Number value, long offset)
Description copied from interface:DataBufferAssign the given value to the buffer starting at offset- Specified by:
assignin interfaceDataBuffer- Parameters:
value- assign the value to setoffset- the offset to start at
-
write
public void write(OutputStream dos)
Description copied from interface:DataBufferWrite this buffer to the output stream- Specified by:
writein interfaceDataBuffer- Parameters:
dos- the output stream to write
-
read
public void read(InputStream is, DataBuffer.AllocationMode allocationMode, long length, DataType dataType)
Description copied from interface:DataBufferWrite this buffer to the input stream.- Specified by:
readin interfaceDataBuffer- Parameters:
is- the inpus tream to write to
-
flush
public void flush()
Description copied from interface:DataBufferFlush the data buffer- Specified by:
flushin interfaceDataBuffer
-
assign
public void assign(long[] offsets, long[] strides, long n, DataBuffer... buffers)Description copied from interface:DataBufferAssign the given buffers to this buffer based on the given offsets and strides. Note that the offsets and strides must be of equal length to the number of buffers- Specified by:
assignin interfaceDataBuffer- Parameters:
offsets- the offsets to usestrides- the strides to usen- the number of elements to operate onbuffers- the buffers to assign data from
-
assign
public void assign(DataBuffer... buffers)
Description copied from interface:DataBufferAssign the given data buffers to this buffer- Specified by:
assignin interfaceDataBuffer- Parameters:
buffers- the buffers to assign
-
destroy
public void destroy()
Description copied from interface:DataBufferrelease all resources for this buffer- Specified by:
destroyin interfaceDataBuffer
-
dataType
public DataType dataType()
The data opType of the buffer- Specified by:
dataTypein interfaceDataBuffer- Returns:
- the data opType of the buffer
-
doReadObject
protected void doReadObject(ObjectInputStream s)
-
readHeader
public static Triple<DataBuffer.AllocationMode,Long,DataType> readHeader(@NonNull @NonNull InputStream is)
-
read
public void read(DataInputStream s, @NonNull @NonNull DataBuffer.AllocationMode allocMode, long len, @NonNull @NonNull DataType dtype)
- Specified by:
readin interfaceDataBuffer
-
readContent
protected void readContent(DataInputStream s, DataType sourceType, DataType thisType)
-
getDoubleUnsynced
protected abstract double getDoubleUnsynced(long index)
-
getFloatUnsynced
protected abstract float getFloatUnsynced(long index)
-
getLongUnsynced
protected abstract long getLongUnsynced(long index)
-
getIntUnsynced
protected abstract int getIntUnsynced(long index)
-
write
public void write(DataOutputStream out) throws IOException
- Specified by:
writein interfaceDataBuffer- Throws:
IOException
-
toFloat
public float toFloat(int hbits)
-
array
public Object array()
Description copied from interface:DataBufferReturns the backing array of this buffer (if there is one)- Specified by:
arrayin interfaceDataBuffer- Returns:
- the backing array of this buffer
-
originalOffset
public long originalOffset()
Returns the offset of the buffer relative to originalDataBuffer- Specified by:
originalOffsetin interfaceDataBuffer- Returns:
-
isConstant
public boolean isConstant()
This method returns whether this DataBuffer is constant, or not. Constant buffer means that it modified only during creation time, and then it stays the same for all lifecycle. I.e. used in shape info databuffers.- Specified by:
isConstantin interfaceDataBuffer- Returns:
-
setConstant
public void setConstant(boolean reallyConstant)
This method allows you to mark databuffer as constant. PLEASE NOTE: DO NOT USE THIS METHOD, UNLESS YOU'RE 100% SURE WHAT YOU DO- Specified by:
setConstantin interfaceDataBuffer- Parameters:
reallyConstant-
-
isAttached
public boolean isAttached()
This method returns True, if this DataBuffer is attached to some workspace. False otherwise- Specified by:
isAttachedin interfaceDataBuffer- Returns:
-
isInScope
public boolean isInScope()
This method checks, if given attached INDArray is still in scope of its parent WorkspacePLEASE NOTE: if this INDArray isn't attached to any Workspace, this method will return true
- Specified by:
isInScopein interfaceDataBuffer- Returns:
-
getParentWorkspace
public MemoryWorkspace getParentWorkspace()
Description copied from interface:DataBufferThis method returns Workspace this DataBuffer is attached to- Specified by:
getParentWorkspacein interfaceDataBuffer- Returns:
-
reallocate
public abstract DataBuffer reallocate(long length)
Description copied from interface:DataBufferReallocate the native memory of the buffer- Specified by:
reallocatein interfaceDataBuffer- Parameters:
length- the new length of the buffer- Returns:
- this databuffer
-
capacity
public long capacity()
- Specified by:
capacityin interfaceDataBuffer- Returns:
- the capacity of the buffer
-
closeable
public boolean closeable()
Description copied from interface:DataBufferThis method checks, if this DataBuffer instalce can use close() method- Specified by:
closeablein interfaceDataBuffer- Returns:
- true if DataBuffer can be released, false otherwise
-
markReleased
protected void markReleased()
-
close
public void close()
Description copied from interface:DataBufferThis method releases exclusive off-heap resources uses by this DataBuffer instance. If DataBuffer relies on shared resources, exception will be thrown instead PLEASE NOTE: This method is NOT safe by any means- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDataBuffer
-
release
protected void release()
-
platformAddress
public long platformAddress()
Description copied from interface:DataBufferReturns the address of platform-specific pointer: - for native backend that'll be host pointer - for cuda backend that'll be device pointer- Specified by:
platformAddressin interfaceDataBuffer- Returns:
-
wasClosed
public boolean wasClosed()
Description copied from interface:DataBufferThis method checks if array or its buffer was closed before- Specified by:
wasClosedin interfaceDataBuffer- Returns:
- true if was closed, false otherwise
-
syncToPrimary
public abstract void syncToPrimary()
This method synchronizes host memory
-
syncToSpecial
public abstract void syncToSpecial()
This method synchronizes device memory
-
-