Interface DataBuffer

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void addReferencing​(String id)
      Add a referencing element to this buffer
      long address()
      Returns the address of the pointer
      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​(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, 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 buffer
      void assign​(Number value, long offset)
      Assign the given value to the buffer starting at offset
      void assign​(DataBuffer data)
      Assign the contents of this buffer to this buffer
      void assign​(DataBuffer... buffers)
      Assign the given data buffers to this buffer
      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
      DataType dataType()
      The data opType of the buffer
      void destroy()
      release all resources for this buffer
      boolean dirty()
      Whether the buffer is dirty: aka has been updated
      DataBuffer dup()
      Return a copy of this buffer
      void flush()
      Flush the data buffer
      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
      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
      long getGenerationId()  
      int getInt​(long ix)
      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
      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
      Number getNumber​(long i)
      Get element i in the buffer as a double
      MemoryWorkspace getParentWorkspace()
      This method returns Workspace this DataBuffer is attached to
      org.bytedeco.javacpp.indexer.Indexer indexer()
      Returns the indexer for the 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 PLEASE NOTE: if this INDArray isn't attached to any Workspace, this method will return true
      boolean isPersist()
      Whether the buffer should be persistent.
      long length()
      Returns the length of the buffer
      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()
      Mark this buffer as persistent
      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
      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 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 buffer
      Collection<String> references()
      The referencers pointing to this buffer
      void removeReferencing​(String id)
      Remove the referenced id if it exists
      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)  
      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()
      Un persist the buffer
      boolean wasClosed()
      This method checks if array or its buffer was closed before
      void 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
      • 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
      • 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 from
        n - the number of elements to copy
        stride - the stride to copy at
        yStride -
        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 assign
        data - the data to assign
        contiguous - whether the indices are contiguous or not
        inc - 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 assign
        data - the data to assign
        contiguous - whether the data is contiguous or not
        inc - 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 assign
        data - the data to assign
        contiguous - 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 assign
        data - the data to assign
        contiguous - 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 start
        length - 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 start
        length - 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 start
        length - 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 start
        length - 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 start
        inc - the increment to use
        length - 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 start
        inc - the increment to use
        length - 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 start
        inc - the increment to use
        length - 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 start
        inc - the increment to use
        length - 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 set
        offset - 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 index
        element - the element to assign
      • put

        void put​(long i,
                 double element)
        Assign an element in the buffer to the specified index
        Parameters:
        i - the index
        element - the element to assign
      • put

        void put​(long i,
                 int element)
        Assign an element in the buffer to the specified index
        Parameters:
        i - the index
        element - 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 use
        strides - the strides to use
        n - the number of elements to operate on
        buffers - 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 use
        strides - the strides to use
        buffers - 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
      • 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 interface AutoCloseable
      • wasClosed

        boolean wasClosed()
        This method checks if array or its buffer was closed before
        Returns:
        true if was closed, false otherwise