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.AllocationMode
allocationMode
protected boolean
attached
protected boolean
constant
protected byte
elementSize
protected org.bytedeco.javacpp.indexer.Indexer
indexer
protected long
length
protected long
offset
protected DataBuffer
originalBuffer
protected long
originalOffset
protected MemoryWorkspace
parentWorkspace
protected org.bytedeco.javacpp.Pointer
pointer
protected AtomicBoolean
referenced
protected boolean
released
static String
TO_STRING_MAX_ELEMENTS
Deprecated.protected DataType
type
protected long
underlyingLength
protected long
workspaceGenerationId
protected DataBuffer
wrappedDataBuffer
-
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 bufferprotected
BaseDataBuffer(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 void
addReferencing(String id)
Deprecated.long
address()
Returns the address of the pointerabstract org.bytedeco.javacpp.Pointer
addressPointer()
Returns the address of the pointer wrapped in a PointerDataBuffer.AllocationMode
allocationMode()
Allocation mode for buffersObject
array()
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.ByteBuffer
asNio()
Returns a view of this as an nio byte bufferDoubleBuffer
asNioDouble()
Returns a view of this as an nio byte bufferFloatBuffer
asNioFloat()
Returns a view of this as an nio byte bufferIntBuffer
asNioInt()
Returns a view of this as an nio byte bufferLongBuffer
asNioLong()
void
assign(long[] indices, double[] data, boolean contiguous)
Assign the given elements to the given indicesvoid
assign(long[] indices, double[] data, boolean contiguous, long inc)
Assign the given elements to the given indicesvoid
assign(long[] indices, float[] data, boolean contiguous)
Assign the given elements to the given indicesvoid
assign(long[] indices, float[] data, boolean contiguous, long inc)
Assign the given elements to the given indicesvoid
assign(long[] offsets, long[] strides, long n, DataBuffer... buffers)
Assign the given buffers to this buffer based on the given offsets and strides.void
assign(long[] offsets, long[] strides, DataBuffer... buffers)
Assign the given buffers to this buffer based on the given offsets and strides.void
assign(Number value)
Assign the given value to the buffervoid
assign(Number value, long offset)
Assign the given value to the buffer starting at offsetvoid
assign(DataBuffer data)
Assign the contents of this buffer to this buffervoid
assign(DataBuffer... buffers)
Assign the given data buffers to this bufferlong
capacity()
void
close()
This method releases exclusive off-heap resources uses by this DataBuffer instance.boolean
closeable()
This method checks, if this DataBuffer instalce can use close() methodvoid
copyAtStride(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 DataBuffer
create(double[] data)
Create the data buffer with respect to the given byte bufferabstract DataBuffer
create(float[] data)
Create the data buffer with respect to the given byte bufferabstract DataBuffer
create(int[] data)
Create the data buffer with respect to the given byte bufferprotected abstract DataBuffer
create(long length)
Create with lengthDataType
dataType()
The data opType of the buffervoid
destroy()
release all resources for this bufferboolean
dirty()
Deprecated.protected void
doReadObject(ObjectInputStream s)
DataBuffer
dup()
Return a copy of this bufferboolean
equals(Object o)
protected void
fillPointerWithZero()
void
flush()
Flush the data bufferstatic short
fromFloat(float v)
double
getDouble(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 double
getDoubleUnsynced(long index)
int
getElementSize()
The number of bytes for each individual elementfloat
getFloat(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 float
getFloatUnsynced(long index)
long
getGenerationId()
int
getInt(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 int
getIntUnsynced(long index)
long
getLong(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 long
getLongUnsynced(long index)
Number
getNumber(long i)
Get element i in the buffer as a doubleMemoryWorkspace
getParentWorkspace()
This method returns Workspace this DataBuffer is attached toprotected short
getShort(long i)
Special method forint
hashCode()
org.bytedeco.javacpp.indexer.Indexer
indexer()
Returns the indexer for the bufferprotected abstract void
initTypeAndSize()
Initialize the opType of this bufferboolean
isAttached()
This method returns True, if this DataBuffer is attached to some workspace.boolean
isConstant()
This method returns whether this DataBuffer is constant, or not.boolean
isInScope()
This method checks, if given attached INDArray is still in scope of its parent Workspaceboolean
isPersist()
Deprecated.long
length()
Returns the length of the bufferprotected void
markReleased()
long
offset()
Returns the offset of the bufferDataBuffer
originalDataBuffer()
Original DataBuffer.long
originalOffset()
Returns the offset of the buffer relative to originalDataBuffervoid
persist()
Deprecated.protected void
pickReferent(BaseDataBuffer referent)
long
platformAddress()
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.Pointer
pointer()
Returns an underlying pointer if one existsabstract void
pointerIndexerByCurrentType(DataType currentType)
void
put(long i, boolean element)
void
put(long i, double element)
Assign an element in the buffer to the specified indexvoid
put(long i, float element)
Assign an element in the buffer to the specified indexvoid
put(long i, int element)
Assign an element in the buffer to the specified indexvoid
put(long i, long element)
void
putByDestinationType(long i, Number element, DataType globalType)
void
read(DataInputStream s, @NonNull DataBuffer.AllocationMode allocMode, long len, @NonNull DataType dtype)
void
read(InputStream is, DataBuffer.AllocationMode allocationMode, long length, DataType dataType)
Write this buffer to the input stream.protected void
readContent(DataInputStream s, DataType sourceType, DataType thisType)
static Triple<DataBuffer.AllocationMode,Long,DataType>
readHeader(@NonNull InputStream is)
abstract DataBuffer
reallocate(long length)
Reallocate the native memory of the bufferCollection<String>
references()
Deprecated.protected void
release()
void
removeReferencing(String id)
Deprecated.boolean
sameUnderlyingData(DataBuffer buffer)
Returns true if the underlying data source is the same for both buffers (referential equals)void
setConstant(boolean reallyConstant)
This method allows you to mark databuffer as constant.void
setData(boolean[] data)
void
setData(byte[] data)
void
setData(double[] data)
Set the data for this buffervoid
setData(float[] data)
Set the data for this buffervoid
setData(int[] data)
Set the data for this buffervoid
setData(long[] data)
Set the data for this buffervoid
setData(short[] data)
protected void
setIndexer(org.bytedeco.javacpp.indexer.Indexer indexer)
protected void
setNioBuffer()
abstract void
syncToPrimary()
This method synchronizes host memoryabstract void
syncToSpecial()
This method synchronizes device memoryfloat
toFloat(int hbits)
String
toString()
DataBuffer
underlyingDataBuffer()
Underlying buffer: This is meant for a data buffer to be a view of another data bufferlong
underlyingLength()
Returns the length of the buffervoid
unPersist()
Deprecated.boolean
wasClosed()
This method checks if array or its buffer was closed beforeprotected ByteBuffer
wrappedBuffer()
void
write(DataOutputStream out)
void
write(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:DataBuffer
The number of bytes for each individual element- Specified by:
getElementSize
in interfaceDataBuffer
- Returns:
- the number of bytes for each individual element
-
getGenerationId
public long getGenerationId()
- Specified by:
getGenerationId
in 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:
originalDataBuffer
in interfaceDataBuffer
-
setNioBuffer
protected void setNioBuffer()
-
indexer
public org.bytedeco.javacpp.indexer.Indexer indexer()
Returns the indexer for the buffer- Specified by:
indexer
in interfaceDataBuffer
- Returns:
-
pointer
public org.bytedeco.javacpp.Pointer pointer()
Description copied from interface:DataBuffer
Returns an underlying pointer if one exists- Specified by:
pointer
in interfaceDataBuffer
- Returns:
-
underlyingDataBuffer
public DataBuffer underlyingDataBuffer()
Description copied from interface:DataBuffer
Underlying buffer: This is meant for a data buffer to be a view of another data buffer- Specified by:
underlyingDataBuffer
in interfaceDataBuffer
- Returns:
-
offset
public long offset()
Description copied from interface:DataBuffer
Returns the offset of the buffer- Specified by:
offset
in interfaceDataBuffer
- Returns:
- the offset of the buffer
-
allocationMode
public DataBuffer.AllocationMode allocationMode()
Description copied from interface:DataBuffer
Allocation mode for buffers- Specified by:
allocationMode
in interfaceDataBuffer
- Returns:
- the allocation mode for the buffer
-
persist
@Deprecated public void persist()
Deprecated.Description copied from interface:DataBuffer
Mark this buffer as persistent- Specified by:
persist
in interfaceDataBuffer
-
isPersist
@Deprecated public boolean isPersist()
Deprecated.Description copied from interface:DataBuffer
Whether the buffer should be persistent. This is mainly for the aggressive garbage collection strategy.- Specified by:
isPersist
in interfaceDataBuffer
- Returns:
- whether the buffer should be persistent or not (default false)
-
unPersist
@Deprecated public void unPersist()
Deprecated.Description copied from interface:DataBuffer
Un persist the buffer- Specified by:
unPersist
in 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:DataBuffer
Copies from the given buffer at the specified stride for up to n elements- Specified by:
copyAtStride
in 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:DataBuffer
Remove the referenced id if it exists- Specified by:
removeReferencing
in interfaceDataBuffer
- Parameters:
id
- the id to remove
-
references
@Deprecated public Collection<String> references()
Deprecated.Description copied from interface:DataBuffer
The referencers pointing to this buffer- Specified by:
references
in interfaceDataBuffer
- Returns:
- the references pointing to this buffer
-
addressPointer
public abstract org.bytedeco.javacpp.Pointer addressPointer()
Description copied from interface:DataBuffer
Returns the address of the pointer wrapped in a Pointer- Specified by:
addressPointer
in interfaceDataBuffer
- Returns:
- the address of the pointer wrapped in a Pointer
-
address
public long address()
Description copied from interface:DataBuffer
Returns the address of the pointer- Specified by:
address
in interfaceDataBuffer
- Returns:
- the address of the pointer
-
addReferencing
@Deprecated public void addReferencing(String id)
Deprecated.Description copied from interface:DataBuffer
Add a referencing element to this buffer- Specified by:
addReferencing
in interfaceDataBuffer
- Parameters:
id
- the id to reference
-
assign
public void assign(long[] indices, float[] data, boolean contiguous, long inc)
Description copied from interface:DataBuffer
Assign the given elements to the given indices- Specified by:
assign
in 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:DataBuffer
Set the data for this buffer- Specified by:
setData
in interfaceDataBuffer
- Parameters:
data
- the data for this buffer
-
setData
public void setData(float[] data)
Description copied from interface:DataBuffer
Set the data for this buffer- Specified by:
setData
in interfaceDataBuffer
- Parameters:
data
- the data for this buffer
-
setData
public void setData(double[] data)
Description copied from interface:DataBuffer
Set the data for this buffer- Specified by:
setData
in interfaceDataBuffer
- Parameters:
data
- the data for this buffer
-
setData
public void setData(long[] data)
Description copied from interface:DataBuffer
Set the data for this buffer- Specified by:
setData
in interfaceDataBuffer
- Parameters:
data
- the data for this buffer
-
setData
public void setData(byte[] data)
- Specified by:
setData
in interfaceDataBuffer
-
setData
public void setData(short[] data)
- Specified by:
setData
in interfaceDataBuffer
-
setData
public void setData(boolean[] data)
- Specified by:
setData
in interfaceDataBuffer
-
assign
public void assign(long[] indices, double[] data, boolean contiguous, long inc)
Description copied from interface:DataBuffer
Assign the given elements to the given indices- Specified by:
assign
in 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:DataBuffer
Assign the contents of this buffer to this buffer- Specified by:
assign
in interfaceDataBuffer
- Parameters:
data
- the data to assign
-
assign
public void assign(long[] indices, float[] data, boolean contiguous)
Description copied from interface:DataBuffer
Assign the given elements to the given indices- Specified by:
assign
in 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:DataBuffer
Assign the given elements to the given indices- Specified by:
assign
in 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:DataBuffer
Returns the length of the buffer- Specified by:
underlyingLength
in interfaceDataBuffer
- Returns:
- the length of the buffer
-
length
public long length()
Description copied from interface:DataBuffer
Returns the length of the buffer- Specified by:
length
in interfaceDataBuffer
- Returns:
- the length of the buffer
-
assign
public void assign(Number value)
Description copied from interface:DataBuffer
Assign the given value to the buffer- Specified by:
assign
in interfaceDataBuffer
- Parameters:
value
- the value to assign
-
getDoublesAt
public double[] getDoublesAt(long offset, long inc, int length)
Description copied from interface:DataBuffer
Get the doubles at a particular offset- Specified by:
getDoublesAt
in 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:DataBuffer
Get the doubles at a particular offset- Specified by:
getDoublesAt
in 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:DataBuffer
Get the doubles at a particular offset- Specified by:
getFloatsAt
in 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:DataBuffer
Get the doubles at a particular offset- Specified by:
getFloatsAt
in 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:DataBuffer
Get the longs at a particular offset- Specified by:
getLongsAt
in 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:DataBuffer
Get the long at a particular offset- Specified by:
getLongsAt
in 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:DataBuffer
Get the ints at a particular offset- Specified by:
getIntsAt
in 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:DataBuffer
Get the ints at a particular offset- Specified by:
getIntsAt
in 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:DataBuffer
Return a copy of this buffer- Specified by:
dup
in 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:DataBuffer
Assign 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:
assign
in 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:DataBuffer
Raw byte array storage- Specified by:
asBytes
in interfaceDataBuffer
- Returns:
- the data represented as a raw byte array
-
asFloat
public float[] asFloat()
Description copied from interface:DataBuffer
Return 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:
asFloat
in interfaceDataBuffer
- Returns:
- the buffer as a float
-
asDouble
public double[] asDouble()
Description copied from interface:DataBuffer
Return 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:
asDouble
in interfaceDataBuffer
- Returns:
- the buffer as a float
-
asInt
public int[] asInt()
Description copied from interface:DataBuffer
Return 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:
asInt
in interfaceDataBuffer
- Returns:
- the buffer as a int
-
asLong
public long[] asLong()
Description copied from interface:DataBuffer
Return 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:
asLong
in interfaceDataBuffer
- Returns:
- the buffer as a long
-
getDouble
public double getDouble(long i)
Description copied from interface:DataBuffer
Get element i in the buffer as a double- Specified by:
getDouble
in interfaceDataBuffer
- Parameters:
i
- the element to getFloat- Returns:
- the element at this index
-
getLong
public long getLong(long i)
Description copied from interface:DataBuffer
Get element i in the buffer as long value- Specified by:
getLong
in 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:DataBuffer
Get element i in the buffer as a double- Specified by:
getFloat
in interfaceDataBuffer
- Parameters:
i
- the element to getFloat- Returns:
- the element at this index
-
getInt
public int getInt(long i)
Description copied from interface:DataBuffer
Get the int at the specified index- Specified by:
getInt
in 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:DataBuffer
Get element i in the buffer as a double- Specified by:
getNumber
in 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:DataBuffer
Assign an element in the buffer to the specified index- Specified by:
put
in interfaceDataBuffer
- Parameters:
i
- the indexelement
- the element to assign
-
put
public void put(long i, double element)
Description copied from interface:DataBuffer
Assign an element in the buffer to the specified index- Specified by:
put
in interfaceDataBuffer
- Parameters:
i
- the indexelement
- the element to assign
-
put
public void put(long i, int element)
Description copied from interface:DataBuffer
Assign an element in the buffer to the specified index- Specified by:
put
in interfaceDataBuffer
- Parameters:
i
- the indexelement
- the element to assign
-
put
public void put(long i, boolean element)
- Specified by:
put
in interfaceDataBuffer
-
put
public void put(long i, long element)
- Specified by:
put
in interfaceDataBuffer
-
dirty
@Deprecated public boolean dirty()
Deprecated.Description copied from interface:DataBuffer
Whether the buffer is dirty: aka has been updated- Specified by:
dirty
in interfaceDataBuffer
- Returns:
- true if the buffer has been updated, false otherwise
-
sameUnderlyingData
public boolean sameUnderlyingData(DataBuffer buffer)
Description copied from interface:DataBuffer
Returns true if the underlying data source is the same for both buffers (referential equals)- Specified by:
sameUnderlyingData
in 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:DataBuffer
Returns a view of this as an nio byte buffer- Specified by:
asNioInt
in interfaceDataBuffer
- Returns:
- a view of this as an nio int buffer
-
asNioLong
public LongBuffer asNioLong()
- Specified by:
asNioLong
in interfaceDataBuffer
-
asNioDouble
public DoubleBuffer asNioDouble()
Description copied from interface:DataBuffer
Returns a view of this as an nio byte buffer- Specified by:
asNioDouble
in interfaceDataBuffer
- Returns:
- a view of this as an nio double buffer
-
asNioFloat
public FloatBuffer asNioFloat()
Description copied from interface:DataBuffer
Returns a view of this as an nio byte buffer- Specified by:
asNioFloat
in interfaceDataBuffer
- Returns:
- a view of this as an nio float buffer
-
asNio
public ByteBuffer asNio()
Description copied from interface:DataBuffer
Returns a view of this as an nio byte buffer- Specified by:
asNio
in interfaceDataBuffer
- Returns:
- a view of this as an nio byte buffer
-
assign
public void assign(Number value, long offset)
Description copied from interface:DataBuffer
Assign the given value to the buffer starting at offset- Specified by:
assign
in interfaceDataBuffer
- Parameters:
value
- assign the value to setoffset
- the offset to start at
-
write
public void write(OutputStream dos)
Description copied from interface:DataBuffer
Write this buffer to the output stream- Specified by:
write
in 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:DataBuffer
Write this buffer to the input stream.- Specified by:
read
in interfaceDataBuffer
- Parameters:
is
- the inpus tream to write to
-
flush
public void flush()
Description copied from interface:DataBuffer
Flush the data buffer- Specified by:
flush
in interfaceDataBuffer
-
assign
public void assign(long[] offsets, long[] strides, long n, DataBuffer... buffers)
Description copied from interface:DataBuffer
Assign 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:
assign
in 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:DataBuffer
Assign the given data buffers to this buffer- Specified by:
assign
in interfaceDataBuffer
- Parameters:
buffers
- the buffers to assign
-
destroy
public void destroy()
Description copied from interface:DataBuffer
release all resources for this buffer- Specified by:
destroy
in interfaceDataBuffer
-
dataType
public DataType dataType()
The data opType of the buffer- Specified by:
dataType
in 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:
read
in 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:
write
in interfaceDataBuffer
- Throws:
IOException
-
toFloat
public float toFloat(int hbits)
-
array
public Object array()
Description copied from interface:DataBuffer
Returns the backing array of this buffer (if there is one)- Specified by:
array
in interfaceDataBuffer
- Returns:
- the backing array of this buffer
-
originalOffset
public long originalOffset()
Returns the offset of the buffer relative to originalDataBuffer- Specified by:
originalOffset
in 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:
isConstant
in 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:
setConstant
in interfaceDataBuffer
- Parameters:
reallyConstant
-
-
isAttached
public boolean isAttached()
This method returns True, if this DataBuffer is attached to some workspace. False otherwise- Specified by:
isAttached
in 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:
isInScope
in interfaceDataBuffer
- Returns:
-
getParentWorkspace
public MemoryWorkspace getParentWorkspace()
Description copied from interface:DataBuffer
This method returns Workspace this DataBuffer is attached to- Specified by:
getParentWorkspace
in interfaceDataBuffer
- Returns:
-
reallocate
public abstract DataBuffer reallocate(long length)
Description copied from interface:DataBuffer
Reallocate the native memory of the buffer- Specified by:
reallocate
in interfaceDataBuffer
- Parameters:
length
- the new length of the buffer- Returns:
- this databuffer
-
capacity
public long capacity()
- Specified by:
capacity
in interfaceDataBuffer
- Returns:
- the capacity of the buffer
-
closeable
public boolean closeable()
Description copied from interface:DataBuffer
This method checks, if this DataBuffer instalce can use close() method- Specified by:
closeable
in interfaceDataBuffer
- Returns:
- true if DataBuffer can be released, false otherwise
-
markReleased
protected void markReleased()
-
close
public void close()
Description copied from interface:DataBuffer
This 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDataBuffer
-
release
protected void release()
-
platformAddress
public long platformAddress()
Description copied from interface:DataBuffer
Returns the address of platform-specific pointer: - for native backend that'll be host pointer - for cuda backend that'll be device pointer- Specified by:
platformAddress
in interfaceDataBuffer
- Returns:
-
wasClosed
public boolean wasClosed()
Description copied from interface:DataBuffer
This method checks if array or its buffer was closed before- Specified by:
wasClosed
in 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
-
-