nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/blas/BlasBufferUtil.java
public static void setData(float[] data, INDArray toSet) {
        if (toSet.data().dataType() != DataBuffer.Type.FLOAT) {
            throw new IllegalArgumentException("Unable to set double data for opType " + toSet.data().dataType());
        }

        if (toSet.data().allocationMode() == DataBuffer.AllocationMode.HEAP) {
            Object array = toSet.data().array();
            //data is assumed to have already been updated
            if (array == data)
                return;
            else {
                //copy the data over directly to the underlying array
                float[] d = (float[]) array;

                if (toSet.offset() == 0 && toSet.length() == data.length)
                    System.arraycopy(data, 0, d, 0, d.length);
                else {
                    int count = 0;
                    //need to do strided access with offset
                    for (int i = 0; i < data.length; i++) {
                        // FIXME: LONG
                        int dIndex = (int) toSet.offset() + (i * toSet.majorStride());
                        d[dIndex] = data[count++];
                    }
                }
            }
        } else {
            //assumes the underlying data is in the right order
            DataBuffer underlyingData = toSet.data();
            if (data.length == toSet.length() && toSet.offset() == 0) {
                for (int i = 0; i < toSet.length(); i++) {
                    underlyingData.put(i, data[i]);
                }
            } else {
                int count = 0;
                //need to do strided access with offset
                for (int i = 0; i < data.length; i++) {
                    // FIXME: LONG
                    int dIndex = (int) toSet.offset() + (i * toSet.majorStride());
                    underlyingData.put(dIndex, data[count++]);
                }
            }
        }

    }
public static void setData(float[] data, INDArray toSet) {
        if (toSet.data().dataType() != DataBuffer.Type.FLOAT) {
            throw new IllegalArgumentException("Unable to set double data for opType " + toSet.data().dataType());
        }

        if (toSet.data().allocationMode() == DataBuffer.AllocationMode.HEAP) {
            Object array = toSet.data().array();
            //data is assumed to have already been updated
            if (array == data)
                return;
            else {
                //copy the data over directly to the underlying array
                float[] d = (float[]) array;

                if (toSet.offset() == 0 && toSet.length() == data.length)
                    System.arraycopy(data, 0, d, 0, d.length);
                else {
                    int count = 0;
                    //need to do strided access with offset
                    for (int i = 0; i < data.length; i++) {
                        // FIXME: LONG
                        int dIndex = (int) toSet.offset() + (i * toSet.majorStride());
                        d[dIndex] = data[count++];
                    }
                }
            }
        } else {
            //assumes the underlying data is in the right order
            DataBuffer underlyingData = toSet.data();
            if (data.length == toSet.length() && toSet.offset() == 0) {
                for (int i = 0; i < toSet.length(); i++) {
                    underlyingData.put(i, data[i]);
                }
            } else {
                int count = 0;
                //need to do strided access with offset
                for (int i = 0; i < data.length; i++) {
                    // FIXME: LONG
                    int dIndex = (int) toSet.offset() + (i * toSet.majorStride());
                    underlyingData.put(dIndex, data[count++]);
                }
            }
        }

    }
public static void setData ( float [ ] data , INDArray toSet ) { if ( toSet . data ( ) . dataType ( ) != DataBuffer . Type . FLOAT ) { throw new IllegalArgumentException ( "Unable to set double data for opType " + toSet . data ( ) . dataType ( ) ) ; } if ( toSet . data ( ) . allocationMode ( ) == DataBuffer . AllocationMode . HEAP ) { Object array = toSet . data ( ) . array ( ) ; //data is assumed to have already been updated if ( array == data ) return ; else { //copy the data over directly to the underlying array float [ ] d = ( float [ ] ) array ; if ( toSet . offset ( ) == 0 && toSet . length ( ) == data . length ) System . arraycopy ( data , 0 , d , 0 , d . length ) ; else { int count = 0 ; //need to do strided access with offset for ( int i = 0 ; i < data . length ; i ++ ) { // FIXME: LONG int dIndex = ( int ) toSet . offset ( ) + ( i * toSet . majorStride ( ) ) ; d [ dIndex ] = data [ count ++ ] ; } } } } else { //assumes the underlying data is in the right order DataBuffer underlyingData = toSet . data ( ) ; if ( data . length == toSet . length ( ) && toSet . offset ( ) == 0 ) { for ( int i = 0 ; i < toSet . length ( ) ; i ++ ) { underlyingData . put ( i , data [ i ] ) ; } } else { int count = 0 ; //need to do strided access with offset for ( int i = 0 ; i < data . length ; i ++ ) { // FIXME: LONG int dIndex = ( int ) toSet . offset ( ) + ( i * toSet . majorStride ( ) ) ; underlyingData . put ( dIndex , data [ count ++ ] ) ; } } } }
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.


@param data the data to set
@param toSet the array to set the data to
Set the data for the underlying array . If the underlying buffer s array is equivalent to this array it returns ( avoiding an unneccessary copy )