Class BaseDataBuffer

    • Field Detail

      • 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
      • indexer

        protected transient org.bytedeco.javacpp.indexer.Indexer indexer
      • pointer

        protected transient org.bytedeco.javacpp.Pointer pointer
      • attached

        protected transient boolean attached
      • originalBuffer

        protected transient DataBuffer originalBuffer
      • originalOffset

        protected transient long originalOffset
      • constant

        protected transient boolean constant
      • released

        protected transient boolean released
    • 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 from
        indexer - the indexer for the pointer
        length - 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 from
        length - the length of the view
        offset - 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 interface DataBuffer
        Returns:
        the number of bytes for each individual element
      • 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 interface DataBuffer
      • setNioBuffer

        protected void setNioBuffer()
      • indexer

        public org.bytedeco.javacpp.indexer.Indexer indexer()
        Returns the indexer for the buffer
        Specified by:
        indexer in interface DataBuffer
        Returns:
      • pointer

        public org.bytedeco.javacpp.Pointer pointer()
        Description copied from interface: DataBuffer
        Returns an underlying pointer if one exists
        Specified by:
        pointer in interface DataBuffer
        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 interface DataBuffer
        Returns:
      • offset

        public long offset()
        Description copied from interface: DataBuffer
        Returns the offset of the buffer
        Specified by:
        offset in interface DataBuffer
        Returns:
        the offset of the buffer
      • 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 interface DataBuffer
        Returns:
        whether the buffer should be persistent or not (default false)
      • 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 interface DataBuffer
        Parameters:
        buf - the data buffer to copy from
        n - the number of elements to copy
        stride - the stride to copy at
      • 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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        Parameters:
        indices - the indices to assign
        data - the data to assign
        contiguous - whether the indices are contiguous or not
        inc - 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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        Parameters:
        data - the data for this buffer
      • setData

        public void setData​(byte[] data)
        Specified by:
        setData in interface DataBuffer
      • setData

        public void setData​(short[] data)
        Specified by:
        setData in interface DataBuffer
      • setData

        public void setData​(boolean[] data)
        Specified by:
        setData in interface DataBuffer
      • 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 interface DataBuffer
        Parameters:
        indices - the indices to assign
        data - the data to assign
        contiguous - whether the data is contiguous or not
        inc - 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 interface DataBuffer
        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 interface DataBuffer
        Parameters:
        indices - the indices to assign
        data - the data to assign
        contiguous - 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 interface DataBuffer
        Parameters:
        indices - the indices to assign
        data - the data to assign
        contiguous - 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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        Parameters:
        offset - the offset to start
        inc - the increment to use
        length - 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 interface DataBuffer
        Parameters:
        offset - the offset to start
        length - 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 interface DataBuffer
        Parameters:
        offset - the offset to start
        length - 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 interface DataBuffer
        Parameters:
        offset - the offset to start
        inc - the increment to use
        length - 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 interface DataBuffer
        Parameters:
        offset - the offset to start
        length - 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 interface DataBuffer
        Parameters:
        offset - the offset to start
        inc - the increment to use
        length - 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 interface DataBuffer
        Parameters:
        offset - the offset to start
        length - 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 interface DataBuffer
        Parameters:
        offset - the offset to start
        inc - the increment to use
        length - 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 interface DataBuffer
        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 interface DataBuffer
        Parameters:
        offsets - the offsets to use
        strides - the strides to use
        buffers - the buffers to assign data from
      • asBytes

        public byte[] asBytes()
        Description copied from interface: DataBuffer
        Raw byte array storage
        Specified by:
        asBytes in interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        Parameters:
        i - the element to getFloat
        Returns:
        the element at this index
      • pointerIndexerByCurrentType

        public abstract void pointerIndexerByCurrentType​(DataType currentType)
      • putByDestinationType

        public void putByDestinationType​(long i,
                                         Number element,
                                         DataType globalType)
      • 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 interface DataBuffer
        Parameters:
        i - the index
        element - 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 interface DataBuffer
        Parameters:
        i - the index
        element - 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 interface DataBuffer
        Parameters:
        i - the index
        element - the element to assign
      • put

        public void put​(long i,
                        boolean element)
        Specified by:
        put in interface DataBuffer
      • put

        public void put​(long i,
                        long element)
        Specified by:
        put in interface DataBuffer
      • dirty

        @Deprecated
        public boolean dirty()
        Deprecated.
        Description copied from interface: DataBuffer
        Whether the buffer is dirty: aka has been updated
        Specified by:
        dirty in interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        Returns:
        a view of this as an nio int buffer
      • asNioDouble

        public DoubleBuffer asNioDouble()
        Description copied from interface: DataBuffer
        Returns a view of this as an nio byte buffer
        Specified by:
        asNioDouble in interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        Parameters:
        value - assign the value to set
        offset - 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 interface DataBuffer
        Parameters:
        dos - the output stream to write
      • flush

        public void flush()
        Description copied from interface: DataBuffer
        Flush the data buffer
        Specified by:
        flush in interface DataBuffer
      • 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 interface DataBuffer
        Parameters:
        offsets - the offsets to use
        strides - the strides to use
        n - the number of elements to operate on
        buffers - 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 interface DataBuffer
        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 interface DataBuffer
      • dataType

        public DataType dataType()
        The data opType of the buffer
        Specified by:
        dataType in interface DataBuffer
        Returns:
        the data opType of the buffer
      • 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)
      • 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 interface DataBuffer
        Returns:
        the backing array of this buffer
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • originalOffset

        public long originalOffset()
        Returns the offset of the buffer relative to originalDataBuffer
        Specified by:
        originalOffset in interface DataBuffer
        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 interface DataBuffer
        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 interface DataBuffer
        Parameters:
        reallyConstant -
      • isAttached

        public boolean isAttached()
        This method returns True, if this DataBuffer is attached to some workspace. False otherwise
        Specified by:
        isAttached in interface DataBuffer
        Returns:
      • isInScope

        public 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

        Specified by:
        isInScope in interface DataBuffer
        Returns:
      • reallocate

        public abstract DataBuffer reallocate​(long length)
        Description copied from interface: DataBuffer
        Reallocate the native memory of the buffer
        Specified by:
        reallocate in interface DataBuffer
        Parameters:
        length - the new length of the buffer
        Returns:
        this databuffer
      • capacity

        public long capacity()
        Specified by:
        capacity in interface DataBuffer
        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 interface DataBuffer
        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 interface AutoCloseable
        Specified by:
        close in interface DataBuffer
      • 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 interface DataBuffer
        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 interface DataBuffer
        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