Package org.nd4j.linalg.api.buffer
Interface DataBuffer
-
- All Superinterfaces:
AutoCloseable
,Serializable
- All Known Implementing Classes:
BaseDataBuffer
,CompressedDataBuffer
public interface DataBuffer extends Serializable, AutoCloseable
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
DataBuffer.AllocationMode
Mainly used for backward compatability.static class
DataBuffer.TypeEx
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addReferencing(String id)
Add a referencing element to this bufferlong
address()
Returns the address of the pointerorg.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 elementsDataType
dataType()
The data opType of the buffervoid
destroy()
release all resources for this bufferboolean
dirty()
Whether the buffer is dirty: aka has been updatedDataBuffer
dup()
Return a copy of this buffervoid
flush()
Flush the data bufferdouble
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 offsetint
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 offsetlong
getGenerationId()
int
getInt(long ix)
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 offsetlong
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 offsetNumber
getNumber(long i)
Get element i in the buffer as a doubleMemoryWorkspace
getParentWorkspace()
This method returns Workspace this DataBuffer is attached toorg.bytedeco.javacpp.indexer.Indexer
indexer()
Returns the indexer for the 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 Workspace PLEASE NOTE: if this INDArray isn't attached to any Workspace, this method will return trueboolean
isPersist()
Whether the buffer should be persistent.long
length()
Returns the length of the bufferlong
offset()
Returns the offset of the bufferDataBuffer
originalDataBuffer()
Original DataBuffer.long
originalOffset()
Returns the offset of the buffer relative to originalDataBuffervoid
persist()
Mark this buffer as persistentlong
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 existsvoid
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
read(DataInputStream s, DataBuffer.AllocationMode allocationMode, long length, DataType dataType)
void
read(InputStream is, DataBuffer.AllocationMode allocationMode, long length, DataType dataType)
Write this buffer to the input stream.DataBuffer
reallocate(long length)
Reallocate the native memory of the bufferCollection<String>
references()
The referencers pointing to this buffervoid
removeReferencing(String id)
Remove the referenced id if it existsboolean
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)
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()
Un persist the bufferboolean
wasClosed()
This method checks if array or its buffer was closed beforevoid
write(DataOutputStream out)
void
write(OutputStream dos)
Write this buffer to the output stream
-
-
-
Method Detail
-
getGenerationId
long getGenerationId()
-
pointer
org.bytedeco.javacpp.Pointer pointer()
Returns an underlying pointer if one exists- Returns:
-
addressPointer
org.bytedeco.javacpp.Pointer addressPointer()
Returns the address of the pointer wrapped in a Pointer- Returns:
- the address of the pointer wrapped in a Pointer
-
indexer
org.bytedeco.javacpp.indexer.Indexer indexer()
Returns the indexer for the buffer- Returns:
-
address
long address()
Returns the address of the pointer- Returns:
- the address of the pointer
-
platformAddress
long platformAddress()
Returns the address of platform-specific pointer: - for native backend that'll be host pointer - for cuda backend that'll be device pointer- Returns:
-
sameUnderlyingData
boolean sameUnderlyingData(DataBuffer buffer)
Returns true if the underlying data source is the same for both buffers (referential equals)- Parameters:
buffer
- whether the buffer is the same underlying data or not- Returns:
- true if both data buffers have the same underlying data SOURCE
-
read
void read(DataInputStream s, DataBuffer.AllocationMode allocationMode, long length, DataType dataType)
-
write
void write(DataOutputStream out) throws IOException
- Throws:
IOException
-
array
Object array()
Returns the backing array of this buffer (if there is one)- Returns:
- the backing array of this buffer
-
asNioInt
IntBuffer asNioInt()
Returns a view of this as an nio byte buffer- Returns:
- a view of this as an nio int buffer
-
asNioLong
LongBuffer asNioLong()
-
asNioDouble
DoubleBuffer asNioDouble()
Returns a view of this as an nio byte buffer- Returns:
- a view of this as an nio double buffer
-
asNioFloat
FloatBuffer asNioFloat()
Returns a view of this as an nio byte buffer- Returns:
- a view of this as an nio float buffer
-
asNio
ByteBuffer asNio()
Returns a view of this as an nio byte buffer- Returns:
- a view of this as an nio byte buffer
-
dirty
boolean dirty()
Whether the buffer is dirty: aka has been updated- Returns:
- true if the buffer has been updated, false otherwise
-
underlyingDataBuffer
DataBuffer underlyingDataBuffer()
Underlying buffer: This is meant for a data buffer to be a view of another data buffer- Returns:
-
originalDataBuffer
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.
-
copyAtStride
void 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 elements- Parameters:
buf
- the data buffer to copy fromn
- the number of elements to copystride
- the stride to copy atyStride
-offset
-yOffset
-
-
allocationMode
DataBuffer.AllocationMode allocationMode()
Allocation mode for buffers- Returns:
- the allocation mode for the buffer
-
persist
void persist()
Mark this buffer as persistent
-
isPersist
boolean isPersist()
Whether the buffer should be persistent. This is mainly for the aggressive garbage collection strategy.- Returns:
- whether the buffer should be persistent or not (default false)
-
unPersist
void unPersist()
Un persist the buffer
-
getElementSize
int getElementSize()
The number of bytes for each individual element- Returns:
- the number of bytes for each individual element
-
removeReferencing
void removeReferencing(String id)
Remove the referenced id if it exists- Parameters:
id
- the id to remove
-
references
Collection<String> references()
The referencers pointing to this buffer- Returns:
- the references pointing to this buffer
-
addReferencing
void addReferencing(String id)
Add a referencing element to this buffer- Parameters:
id
- the id to reference
-
assign
void assign(long[] indices, float[] data, boolean contiguous, long inc)
Assign the given elements to the given indices- Parameters:
indices
- the indices to assigndata
- the data to assigncontiguous
- whether the indices are contiguous or notinc
- the number to increment by when assigning
-
assign
void assign(long[] indices, double[] data, boolean contiguous, long inc)
Assign the given elements to the given indices- 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
void assign(long[] indices, float[] data, boolean contiguous)
Assign the given elements to the given indices- Parameters:
indices
- the indices to assigndata
- the data to assigncontiguous
- whether the indices are contiguous or not
-
assign
void assign(long[] indices, double[] data, boolean contiguous)
Assign the given elements to the given indices- Parameters:
indices
- the indices to assigndata
- the data to assigncontiguous
- whether the data is contiguous or not
-
getDoublesAt
double[] getDoublesAt(long offset, int length)
Get the doubles at a particular offset- Parameters:
offset
- the offset to startlength
- the length of the array- Returns:
- the doubles at the specified offset and length
-
getFloatsAt
float[] getFloatsAt(long offset, int length)
Get the doubles at a particular offset- Parameters:
offset
- the offset to startlength
- the length of the array- Returns:
- the doubles at the specified offset and length
-
getIntsAt
int[] getIntsAt(long offset, int length)
Get the ints at a particular offset- Parameters:
offset
- the offset to startlength
- the length of the array- Returns:
- the doubles at the specified offset and length
-
getLongsAt
long[] getLongsAt(long offset, int length)
Get the longs at a particular offset- Parameters:
offset
- the offset to startlength
- the length of the array- Returns:
- the doubles at the specified offset and length
-
getDoublesAt
double[] getDoublesAt(long offset, long inc, int length)
Get the doubles at a particular offset- Parameters:
offset
- the offset to startinc
- the increment to uselength
- the length of the array- Returns:
- the doubles at the specified offset and length
-
getFloatsAt
float[] getFloatsAt(long offset, long inc, int length)
Get the doubles at a particular offset- 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
int[] getIntsAt(long offset, long inc, int length)
Get the ints at a particular offset- 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
long[] getLongsAt(long offset, long inc, int length)
Get the long at a particular offset- Parameters:
offset
- the offset to startinc
- the increment to uselength
- the length of the array- Returns:
- the doubles at the specified offset and length
-
assign
void assign(Number value)
Assign the given value to the buffer- Parameters:
value
- the value to assign
-
assign
void assign(Number value, long offset)
Assign the given value to the buffer starting at offset- Parameters:
value
- assign the value to setoffset
- the offset to start at
-
setData
void setData(int[] data)
Set the data for this buffer- Parameters:
data
- the data for this buffer
-
setData
void setData(long[] data)
Set the data for this buffer- Parameters:
data
- the data for this buffer
-
setData
void setData(float[] data)
Set the data for this buffer- Parameters:
data
- the data for this buffer
-
setData
void setData(double[] data)
Set the data for this buffer- Parameters:
data
- the data for this buffer
-
setData
void setData(short[] data)
-
setData
void setData(byte[] data)
-
setData
void setData(boolean[] data)
-
asBytes
byte[] asBytes()
Raw byte array storage- Returns:
- the data represented as a raw byte array
-
dataType
DataType dataType()
The data opType of the buffer- Returns:
- the data opType of the buffer
-
asFloat
float[] asFloat()
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- Returns:
- the buffer as a float
-
asDouble
double[] asDouble()
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- Returns:
- the buffer as a float
-
asInt
int[] asInt()
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- Returns:
- the buffer as a int
-
asLong
long[] asLong()
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- Returns:
- the buffer as a long
-
getDouble
double getDouble(long i)
Get element i in the buffer as a double- Parameters:
i
- the element to getFloat- Returns:
- the element at this index
-
getLong
long getLong(long i)
Get element i in the buffer as long value- Parameters:
i
-- Returns:
-
getFloat
float getFloat(long i)
Get element i in the buffer as a double- Parameters:
i
- the element to getFloat- Returns:
- the element at this index
-
getNumber
Number getNumber(long i)
Get element i in the buffer as a double- Parameters:
i
- the element to getFloat- Returns:
- the element at this index
-
put
void put(long i, float element)
Assign an element in the buffer to the specified index- Parameters:
i
- the indexelement
- the element to assign
-
put
void put(long i, double element)
Assign an element in the buffer to the specified index- Parameters:
i
- the indexelement
- the element to assign
-
put
void put(long i, int element)
Assign an element in the buffer to the specified index- Parameters:
i
- the indexelement
- the element to assign
-
put
void put(long i, long element)
-
put
void put(long i, boolean element)
-
length
long length()
Returns the length of the buffer- Returns:
- the length of the buffer
-
underlyingLength
long underlyingLength()
Returns the length of the buffer- Returns:
- the length of the buffer
-
offset
long offset()
Returns the offset of the buffer- Returns:
- the offset of the buffer
-
originalOffset
long originalOffset()
Returns the offset of the buffer relative to originalDataBuffer- Returns:
-
getInt
int getInt(long ix)
Get the int at the specified index- Parameters:
ix
- the int at the specified index- Returns:
- the int at the specified index
-
dup
DataBuffer dup()
Return a copy of this buffer- Returns:
- a copy of this buffer
-
flush
void flush()
Flush the data buffer
-
assign
void assign(DataBuffer data)
Assign the contents of this buffer to this buffer- Parameters:
data
- the data to assign
-
assign
void assign(long[] offsets, long[] strides, long n, DataBuffer... buffers)
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- Parameters:
offsets
- the offsets to usestrides
- the strides to usen
- the number of elements to operate onbuffers
- the buffers to assign data from
-
assign
void assign(DataBuffer... buffers)
Assign the given data buffers to this buffer- Parameters:
buffers
- the buffers to assign
-
assign
void assign(long[] offsets, long[] strides, DataBuffer... buffers)
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- Parameters:
offsets
- the offsets to usestrides
- the strides to usebuffers
- the buffers to assign data from
-
destroy
void destroy()
release all resources for this buffer
-
write
void write(OutputStream dos)
Write this buffer to the output stream- Parameters:
dos
- the output stream to write
-
read
void read(InputStream is, DataBuffer.AllocationMode allocationMode, long length, DataType dataType)
Write this buffer to the input stream.- Parameters:
is
- the inpus tream to write to
-
isConstant
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.- Returns:
-
setConstant
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- Parameters:
reallyConstant
-
-
isAttached
boolean isAttached()
This method returns True, if this DataBuffer is attached to some workspace. False otherwise- Returns:
-
isInScope
boolean isInScope()
This method checks, if given attached INDArray is still in scope of its parent Workspace PLEASE NOTE: if this INDArray isn't attached to any Workspace, this method will return true- Returns:
-
getParentWorkspace
MemoryWorkspace getParentWorkspace()
This method returns Workspace this DataBuffer is attached to- Returns:
-
reallocate
DataBuffer reallocate(long length)
Reallocate the native memory of the buffer- Parameters:
length
- the new length of the buffer- Returns:
- this databuffer
-
capacity
long capacity()
- Returns:
- the capacity of the databuffer
-
closeable
boolean closeable()
This method checks, if this DataBuffer instalce can use close() method- Returns:
- true if DataBuffer can be released, false otherwise
-
close
void close()
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
-
wasClosed
boolean wasClosed()
This method checks if array or its buffer was closed before- Returns:
- true if was closed, false otherwise
-
-