Class BlasBufferUtil


  • public class BlasBufferUtil
    extends Object
    Blas buffer util for interopping with the underlying buffers and the given ndarrays
    Author:
    Adam Gibson
    • Constructor Detail

      • BlasBufferUtil

        public BlasBufferUtil()
    • Method Detail

      • getBlasOffset

        public static long getBlasOffset​(INDArray arr)
        Get blas stride for the given array
        Parameters:
        arr - the array
        Returns:
        the blas stride
      • getBlasStride

        public static int getBlasStride​(INDArray arr)
        Get blas stride for the given array
        Parameters:
        arr - the array
        Returns:
        the blas stride
      • getFloatData

        public static float[] getFloatData​(INDArray buf)
        Returns the float data for this ndarray. If possible (the offset is 0 representing the whole buffer) it will return a direct reference to the underlying array
        Parameters:
        buf - the ndarray to get the data for
        Returns:
        the float data for this ndarray
      • getDoubleData

        public static double[] getDoubleData​(INDArray buf)
        Returns the double data for this ndarray. If possible (the offset is 0 representing the whole buffer) it will return a direct reference to the underlying array
        Parameters:
        buf - the ndarray to get the data for
        Returns:
        the double data for this ndarray
      • getCharForTranspose

        public static char getCharForTranspose​(INDArray arr)
        Returns the proper character for how to interpret a buffer (fortran being N C being T)
        Parameters:
        arr - the array to get the transpose for
        Returns:
        the character for transpose of a particular array
      • getStrideForOrdering

        public static int getStrideForOrdering​(INDArray arr)
        Return the proper stride through a vector relative to the ordering of the array This is for incX/incY parameters in BLAS.
        Parameters:
        arr - the array to get the stride for
        Returns:
        the stride wrt the ordering for the given array
      • getDimension

        public static long getDimension​(INDArray arr,
                                        boolean defaultRows)
        Get the dimension associated with the given ordering. When working with blas routines, they typically assume c ordering, instead you can invert the rows/columns which enable you to do no copy blas operations.
        Parameters:
        arr -
        defaultRows -
        Returns:
      • getLd

        public static int getLd​(INDArray arr)
        Get the leading dimension for a blas invocation. The lead dimension is usually arr.size(0) (this is only for fortran ordering though). It can be size(1) (assuming matrix) for C ordering though.
        Parameters:
        arr - the array to
        Returns:
        the leading dimension wrt the ordering of the array
      • getFloatData

        public static float[] getFloatData​(DataBuffer buf)
        Returns the float data for this buffer. If possible (the offset is 0 representing the whole buffer) it will return a direct reference to the underlying array
        Parameters:
        buf - the ndarray to get the data for
        Returns:
        the double data for this ndarray
      • getDoubleData

        public static double[] getDoubleData​(DataBuffer buf)
        Returns the double data for this buffer. If possible (the offset is 0 representing the whole buffer) it will return a direct reference to the underlying array
        Parameters:
        buf - the ndarray to get the data for
        Returns:
        the double data for this buffer
      • setData

        public static void setData​(float[] data,
                                   INDArray toSet)
        Set the data for the underlying array. If the underlying buffer's array is equivalent to this array it returns (avoiding an unneccessary copy) If the underlying storage mechanism isn't heap (no arrays) it just copied the data over (strided access with offsets where neccessary) This is meant to be used with blas operations where the underlying blas implementation takes an array but the data buffer being used might not be an array. This is also for situations where there is strided access and it's not optimal to want to use the whole data buffer but just the subset of the buffer needed for calculations.
        Parameters:
        data - the data to set
        toSet - the array to set the data to
      • setData

        public static void setData​(double[] data,
                                   INDArray toSet)
        Set the data for the underlying array. If the underlying buffer's array is equivalent to this array it returns (avoiding an unneccessary copy) If the underlying storage mechanism isn't heap (no arrays) it just copied the data over (strided access with offsets where neccessary) This is meant to be used with blas operations where the underlying blas implementation takes an array but the data buffer being used might not be an array. This is also for situations where there is strided access and it's not optimal to want to use the whole data buffer but just the subset of the buffer needed for calculations.
        Parameters:
        data - the data to set
        toSet - the array to set the data to