public abstract class BaseDataBuffer extends Object implements DataBuffer
DataBuffer.AllocationMode, DataBuffer.TypeEx
Modifier and Type | Field and 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 |
Modifier | Constructor and Description |
---|---|
|
BaseDataBuffer() |
protected |
BaseDataBuffer(DataBuffer underlyingBuffer,
long length,
long offset)
Meant for creating another view of a buffer
|
|
BaseDataBuffer(org.bytedeco.javacpp.Pointer pointer,
org.bytedeco.javacpp.indexer.Indexer indexer,
long length)
Meant for creating another view of a buffer
|
Modifier and Type | Method and Description |
---|---|
void |
addReferencing(String id)
Deprecated.
|
long |
address()
Returns the address of the pointer
|
abstract org.bytedeco.javacpp.Pointer |
addressPointer()
Returns the address of the pointer wrapped in a Pointer
|
DataBuffer.AllocationMode |
allocationMode()
Allocation mode for buffers
|
Object |
array()
Returns the backing array
of this buffer (if there is one)
|
byte[] |
asBytes()
Raw byte array storage
|
double[] |
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 buffer
|
DoubleBuffer |
asNioDouble()
Returns a view of this as an
nio byte buffer
|
FloatBuffer |
asNioFloat()
Returns a view of this as an
nio byte buffer
|
IntBuffer |
asNioInt()
Returns a view of this as an
nio byte buffer
|
LongBuffer |
asNioLong() |
void |
assign(DataBuffer... buffers)
Assign the given data buffers to this buffer
|
void |
assign(DataBuffer data)
Assign the contents of this buffer
to this buffer
|
void |
assign(long[] indices,
double[] data,
boolean contiguous)
Assign the given elements to the given indices
|
void |
assign(long[] indices,
double[] data,
boolean contiguous,
long inc)
Assign the given elements to the given indices
|
void |
assign(long[] indices,
float[] data,
boolean contiguous)
Assign the given elements to the given indices
|
void |
assign(long[] indices,
float[] data,
boolean contiguous,
long inc)
Assign the given elements to the given indices
|
void |
assign(long[] offsets,
long[] strides,
DataBuffer... buffers)
Assign the given buffers to this buffer
based on the given offsets and strides.
|
void |
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(Number value)
Assign the given value to the buffer
|
void |
assign(Number value,
long offset)
Assign the given value to the buffer
starting at offset
|
long |
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() method
|
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
|
abstract DataBuffer |
create(double[] data)
Create the data buffer
with respect to the given byte buffer
|
abstract DataBuffer |
create(float[] data)
Create the data buffer
with respect to the given byte buffer
|
abstract DataBuffer |
create(int[] data)
Create the data buffer
with respect to the given byte buffer
|
protected abstract DataBuffer |
create(long length)
Create with length
|
DataType |
dataType()
The data opType of the buffer
|
void |
destroy()
release all resources for this buffer
|
boolean |
dirty()
Deprecated.
|
protected void |
doReadObject(ObjectInputStream s) |
DataBuffer |
dup()
Return a copy of this buffer
|
boolean |
equals(Object o) |
protected void |
fillPointerWithZero() |
void |
flush()
Flush the data buffer
|
static short |
fromFloat(float v) |
double |
getDouble(long i)
Get element i in the buffer as a double
|
double[] |
getDoublesAt(long offset,
int length)
Get the doubles at a particular offset
|
double[] |
getDoublesAt(long offset,
long inc,
int length)
Get the doubles at a particular offset
|
protected abstract double |
getDoubleUnsynced(long index) |
int |
getElementSize()
The number of bytes for each individual element
|
float |
getFloat(long i)
Get element i in the buffer as a double
|
float[] |
getFloatsAt(long offset,
int length)
Get the doubles at a particular offset
|
float[] |
getFloatsAt(long offset,
long inc,
int length)
Get the doubles at a particular offset
|
protected abstract float |
getFloatUnsynced(long index) |
long |
getGenerationId() |
int |
getInt(long i)
Get the int at the specified index
|
int[] |
getIntsAt(long offset,
int length)
Get the ints at a particular offset
|
int[] |
getIntsAt(long offset,
long inc,
int length)
Get the ints at a particular offset
|
protected abstract int |
getIntUnsynced(long index) |
long |
getLong(long i)
Get element i in the buffer as long value
|
long[] |
getLongsAt(long offset,
int length)
Get the longs at a particular offset
|
long[] |
getLongsAt(long offset,
long inc,
int length)
Get the long at a particular offset
|
protected abstract long |
getLongUnsynced(long index) |
Number |
getNumber(long i)
Get element i in the buffer as a double
|
MemoryWorkspace |
getParentWorkspace()
This method returns Workspace this DataBuffer is attached to
|
protected short |
getShort(long i)
Special method for
|
int |
hashCode() |
org.bytedeco.javacpp.indexer.Indexer |
indexer()
Returns the indexer for the buffer
|
protected abstract void |
initTypeAndSize()
Initialize the opType of this buffer
|
boolean |
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
|
boolean |
isPersist()
Deprecated.
|
long |
length()
Returns the length of the buffer
|
protected void |
markReleased() |
long |
offset()
Returns the offset of the buffer
|
DataBuffer |
originalDataBuffer()
Original DataBuffer.
|
long |
originalOffset()
Returns the offset of the buffer relative to originalDataBuffer
|
void |
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 pointer
|
org.bytedeco.javacpp.Pointer |
pointer()
Returns an underlying pointer if one exists
|
abstract 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 index
|
void |
put(long i,
float element)
Assign an element in the buffer to the specified index
|
void |
put(long i,
int element)
Assign an element in the buffer to the specified index
|
void |
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 buffer
|
Collection<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 buffer
|
void |
setData(float[] data)
Set the data for this buffer
|
void |
setData(int[] data)
Set the data for this buffer
|
void |
setData(long[] data)
Set the data for this buffer
|
void |
setData(short[] data) |
protected void |
setIndexer(org.bytedeco.javacpp.indexer.Indexer indexer) |
protected void |
setNioBuffer() |
abstract void |
syncToPrimary()
This method synchronizes host memory
|
abstract void |
syncToSpecial()
This method synchronizes device memory
|
float |
toFloat(int hbits) |
String |
toString() |
DataBuffer |
underlyingDataBuffer()
Underlying buffer:
This is meant for a data buffer
to be a view of another data buffer
|
long |
underlyingLength()
Returns the length of the buffer
|
void |
unPersist()
Deprecated.
|
boolean |
wasClosed()
This method checks if array or its buffer was closed before
|
protected ByteBuffer |
wrappedBuffer() |
void |
write(DataOutputStream out) |
void |
write(OutputStream dos)
Write this buffer to the output stream
|
public static String TO_STRING_MAX_ELEMENTS
ND4JSystemProperties.DATABUFFER_TO_STRING_MAX_ELEMENTS
protected DataType type
protected long length
protected long underlyingLength
protected long offset
protected byte elementSize
protected transient DataBuffer wrappedDataBuffer
protected transient long workspaceGenerationId
protected DataBuffer.AllocationMode allocationMode
protected transient org.bytedeco.javacpp.indexer.Indexer indexer
protected transient org.bytedeco.javacpp.Pointer pointer
protected transient boolean attached
protected transient MemoryWorkspace parentWorkspace
protected transient DataBuffer originalBuffer
protected transient long originalOffset
protected transient boolean constant
protected transient boolean released
protected transient AtomicBoolean referenced
public BaseDataBuffer()
public BaseDataBuffer(org.bytedeco.javacpp.Pointer pointer, org.bytedeco.javacpp.indexer.Indexer indexer, long length)
pointer
- the underlying buffer to create a view fromindexer
- the indexer for the pointerlength
- the length of the viewprotected BaseDataBuffer(DataBuffer underlyingBuffer, long length, long offset)
underlyingBuffer
- the underlying buffer to create a view fromlength
- the length of the viewoffset
- the offset for the viewprotected abstract void initTypeAndSize()
public int getElementSize()
DataBuffer
getElementSize
in interface DataBuffer
public long getGenerationId()
getGenerationId
in interface DataBuffer
protected void setIndexer(org.bytedeco.javacpp.indexer.Indexer indexer)
protected void pickReferent(BaseDataBuffer referent)
public DataBuffer originalDataBuffer()
originalDataBuffer
in interface DataBuffer
protected void setNioBuffer()
public org.bytedeco.javacpp.indexer.Indexer indexer()
indexer
in interface DataBuffer
public org.bytedeco.javacpp.Pointer pointer()
DataBuffer
pointer
in interface DataBuffer
public DataBuffer underlyingDataBuffer()
DataBuffer
underlyingDataBuffer
in interface DataBuffer
public long offset()
DataBuffer
offset
in interface DataBuffer
public DataBuffer.AllocationMode allocationMode()
DataBuffer
allocationMode
in interface DataBuffer
@Deprecated public void persist()
DataBuffer
persist
in interface DataBuffer
@Deprecated public boolean isPersist()
DataBuffer
isPersist
in interface DataBuffer
@Deprecated public void unPersist()
DataBuffer
unPersist
in interface DataBuffer
protected void fillPointerWithZero()
public void copyAtStride(DataBuffer buf, long n, long stride, long yStride, long offset, long yOffset)
DataBuffer
copyAtStride
in interface DataBuffer
buf
- the data buffer to copy fromn
- the number of elements to copystride
- the stride to copy at@Deprecated public void removeReferencing(String id)
DataBuffer
removeReferencing
in interface DataBuffer
id
- the id to remove@Deprecated public Collection<String> references()
DataBuffer
references
in interface DataBuffer
public abstract org.bytedeco.javacpp.Pointer addressPointer()
DataBuffer
addressPointer
in interface DataBuffer
public long address()
DataBuffer
address
in interface DataBuffer
@Deprecated public void addReferencing(String id)
DataBuffer
addReferencing
in interface DataBuffer
id
- the id to referencepublic void assign(long[] indices, float[] data, boolean contiguous, long inc)
DataBuffer
assign
in interface DataBuffer
indices
- the indices to assigndata
- the data to assigncontiguous
- whether the indices are contiguous or notinc
- the number to increment by when assigningpublic void setData(int[] data)
DataBuffer
setData
in interface DataBuffer
data
- the data for this bufferpublic void setData(float[] data)
DataBuffer
setData
in interface DataBuffer
data
- the data for this bufferpublic void setData(double[] data)
DataBuffer
setData
in interface DataBuffer
data
- the data for this bufferpublic void setData(long[] data)
DataBuffer
setData
in interface DataBuffer
data
- the data for this bufferpublic void setData(byte[] data)
setData
in interface DataBuffer
public void setData(short[] data)
setData
in interface DataBuffer
public void setData(boolean[] data)
setData
in interface DataBuffer
public void assign(long[] indices, double[] data, boolean contiguous, long inc)
DataBuffer
assign
in interface DataBuffer
indices
- the indices to assigndata
- the data to assigncontiguous
- whether the data is contiguous or notinc
- the number to increment by when assigningpublic void assign(DataBuffer data)
DataBuffer
assign
in interface DataBuffer
data
- the data to assignpublic void assign(long[] indices, float[] data, boolean contiguous)
DataBuffer
assign
in interface DataBuffer
indices
- the indices to assigndata
- the data to assigncontiguous
- whether the indices are contiguous or notpublic void assign(long[] indices, double[] data, boolean contiguous)
DataBuffer
assign
in interface DataBuffer
indices
- the indices to assigndata
- the data to assigncontiguous
- whether the data is contiguous or notpublic long underlyingLength()
DataBuffer
underlyingLength
in interface DataBuffer
public long length()
DataBuffer
length
in interface DataBuffer
public void assign(Number value)
DataBuffer
assign
in interface DataBuffer
value
- the value to assignpublic double[] getDoublesAt(long offset, long inc, int length)
DataBuffer
getDoublesAt
in interface DataBuffer
offset
- the offset to startinc
- the increment to uselength
- the length of the arraypublic double[] getDoublesAt(long offset, int length)
DataBuffer
getDoublesAt
in interface DataBuffer
offset
- the offset to startlength
- the length of the arraypublic float[] getFloatsAt(long offset, int length)
DataBuffer
getFloatsAt
in interface DataBuffer
offset
- the offset to startlength
- the length of the arraypublic float[] getFloatsAt(long offset, long inc, int length)
DataBuffer
getFloatsAt
in interface DataBuffer
offset
- the offset to startinc
- the increment to uselength
- the length of the arraypublic long[] getLongsAt(long offset, int length)
DataBuffer
getLongsAt
in interface DataBuffer
offset
- the offset to startlength
- the length of the arraypublic long[] getLongsAt(long offset, long inc, int length)
DataBuffer
getLongsAt
in interface DataBuffer
offset
- the offset to startinc
- the increment to uselength
- the length of the arraypublic int[] getIntsAt(long offset, int length)
DataBuffer
getIntsAt
in interface DataBuffer
offset
- the offset to startlength
- the length of the arraypublic int[] getIntsAt(long offset, long inc, int length)
DataBuffer
getIntsAt
in interface DataBuffer
offset
- the offset to startinc
- the increment to uselength
- the length of the arraypublic DataBuffer dup()
DataBuffer
dup
in interface DataBuffer
protected abstract DataBuffer create(long length)
length
- a databuffer of the same opType as
this with the given lengthpublic abstract DataBuffer create(double[] data)
data
- the buffer to createpublic abstract DataBuffer create(float[] data)
data
- the buffer to createpublic abstract DataBuffer create(int[] data)
data
- the buffer to createpublic void assign(long[] offsets, long[] strides, DataBuffer... buffers)
DataBuffer
assign
in interface DataBuffer
offsets
- the offsets to usestrides
- the strides to usebuffers
- the buffers to assign data frompublic byte[] asBytes()
DataBuffer
asBytes
in interface DataBuffer
public float[] asFloat()
DataBuffer
asFloat
in interface DataBuffer
public double[] asDouble()
DataBuffer
asDouble
in interface DataBuffer
public int[] asInt()
DataBuffer
asInt
in interface DataBuffer
public long[] asLong()
DataBuffer
asLong
in interface DataBuffer
public double getDouble(long i)
DataBuffer
getDouble
in interface DataBuffer
i
- the element to getFloatpublic long getLong(long i)
DataBuffer
getLong
in interface DataBuffer
protected short getShort(long i)
i
- public static short fromFloat(float v)
v
- public float getFloat(long i)
DataBuffer
getFloat
in interface DataBuffer
i
- the element to getFloatpublic int getInt(long i)
DataBuffer
getInt
in interface DataBuffer
i
- the int at the specified indexpublic Number getNumber(long i)
DataBuffer
getNumber
in interface DataBuffer
i
- the element to getFloatpublic abstract void pointerIndexerByCurrentType(DataType currentType)
public void put(long i, float element)
DataBuffer
put
in interface DataBuffer
i
- the indexelement
- the element to assignpublic void put(long i, double element)
DataBuffer
put
in interface DataBuffer
i
- the indexelement
- the element to assignpublic void put(long i, int element)
DataBuffer
put
in interface DataBuffer
i
- the indexelement
- the element to assignpublic void put(long i, boolean element)
put
in interface DataBuffer
public void put(long i, long element)
put
in interface DataBuffer
@Deprecated public boolean dirty()
DataBuffer
dirty
in interface DataBuffer
public boolean sameUnderlyingData(DataBuffer buffer)
DataBuffer
sameUnderlyingData
in interface DataBuffer
buffer
- whether the buffer is the same underlying data or notprotected ByteBuffer wrappedBuffer()
public IntBuffer asNioInt()
DataBuffer
asNioInt
in interface DataBuffer
public LongBuffer asNioLong()
asNioLong
in interface DataBuffer
public DoubleBuffer asNioDouble()
DataBuffer
asNioDouble
in interface DataBuffer
public FloatBuffer asNioFloat()
DataBuffer
asNioFloat
in interface DataBuffer
public ByteBuffer asNio()
DataBuffer
asNio
in interface DataBuffer
public void assign(Number value, long offset)
DataBuffer
assign
in interface DataBuffer
value
- assign the value to setoffset
- the offset to start atpublic void write(OutputStream dos)
DataBuffer
write
in interface DataBuffer
dos
- the output stream to writepublic void read(InputStream is, DataBuffer.AllocationMode allocationMode, long length, DataType dataType)
DataBuffer
read
in interface DataBuffer
is
- the inpus tream to write topublic void flush()
DataBuffer
flush
in interface DataBuffer
public void assign(long[] offsets, long[] strides, long n, DataBuffer... buffers)
DataBuffer
assign
in interface DataBuffer
offsets
- the offsets to usestrides
- the strides to usen
- the number of elements to operate onbuffers
- the buffers to assign data frompublic void assign(DataBuffer... buffers)
DataBuffer
assign
in interface DataBuffer
buffers
- the buffers to assignpublic void destroy()
DataBuffer
destroy
in interface DataBuffer
public DataType dataType()
dataType
in interface DataBuffer
protected void doReadObject(ObjectInputStream s)
public static Triple<DataBuffer.AllocationMode,Long,DataType> readHeader(@NonNull @NonNull InputStream is)
public void read(DataInputStream s, @NonNull @NonNull DataBuffer.AllocationMode allocMode, long len, @NonNull @NonNull DataType dtype)
read
in interface DataBuffer
protected void readContent(DataInputStream s, DataType sourceType, DataType thisType)
protected abstract double getDoubleUnsynced(long index)
protected abstract float getFloatUnsynced(long index)
protected abstract long getLongUnsynced(long index)
protected abstract int getIntUnsynced(long index)
public void write(DataOutputStream out) throws IOException
write
in interface DataBuffer
IOException
public float toFloat(int hbits)
public Object array()
DataBuffer
array
in interface DataBuffer
public long originalOffset()
originalOffset
in interface DataBuffer
public boolean isConstant()
isConstant
in interface DataBuffer
public void setConstant(boolean reallyConstant)
setConstant
in interface DataBuffer
reallyConstant
- public boolean isAttached()
isAttached
in interface DataBuffer
public boolean isInScope()
PLEASE NOTE: if this INDArray isn't attached to any Workspace, this method will return true
isInScope
in interface DataBuffer
public MemoryWorkspace getParentWorkspace()
DataBuffer
getParentWorkspace
in interface DataBuffer
public abstract DataBuffer reallocate(long length)
DataBuffer
reallocate
in interface DataBuffer
length
- the new length of the bufferpublic long capacity()
capacity
in interface DataBuffer
public boolean closeable()
DataBuffer
closeable
in interface DataBuffer
protected void markReleased()
public void close()
DataBuffer
close
in interface AutoCloseable
close
in interface DataBuffer
protected void release()
public long platformAddress()
DataBuffer
platformAddress
in interface DataBuffer
public boolean wasClosed()
DataBuffer
wasClosed
in interface DataBuffer
public abstract void syncToPrimary()
public abstract void syncToSpecial()
Copyright © 2020. All rights reserved.