Java Code Examples for org.nd4j.linalg.api.buffer.DataBuffer#getDouble()

The following examples show how to use org.nd4j.linalg.api.buffer.DataBuffer#getDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataBufferStruct.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public static int createDataBufferStruct(FlatBufferBuilder bufferBuilder,DataBuffer create) {
    bufferBuilder.prep(create.getElementSize(), (int) create.length() * create.getElementSize());
    for(int i = (int) (create.length() - 1); i >= 0; i--) {
        switch(create.dataType()) {
            case DOUBLE:
                double putDouble = create.getDouble(i);
                bufferBuilder.putDouble(putDouble);
                break;
            case FLOAT:
                float putFloat = create.getFloat(i);
                bufferBuilder.putFloat(putFloat);
                break;
            case INT:
                int putInt = create.getInt(i);
                bufferBuilder.putInt(putInt);
                break;
            case LONG:
                long putLong = create.getLong(i);
                bufferBuilder.putLong(putLong);
        }
    }

    return bufferBuilder.offset();

}
 
Example 2
Source File: DataBufferStruct.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * Create a data buffer struct within
 * the passed in {@link FlatBufferBuilder}
 * @param bufferBuilder the existing flatbuffer
 *                      to use to serialize the {@link DataBuffer}
 * @param create the databuffer to serialize
 * @return an int representing the offset of the buffer
 */
public static int createDataBufferStruct(FlatBufferBuilder bufferBuilder,DataBuffer create) {
    bufferBuilder.prep(create.getElementSize(), (int) create.length() * create.getElementSize());
    for(int i = (int) (create.length() - 1); i >= 0; i--) {
        switch(create.dataType()) {
            case DOUBLE:
                double putDouble = create.getDouble(i);
                bufferBuilder.putDouble(putDouble);
                break;
            case FLOAT:
                float putFloat = create.getFloat(i);
                bufferBuilder.putFloat(putFloat);
                break;
            case INT:
                int putInt = create.getInt(i);
                bufferBuilder.putInt(putInt);
                break;
            case LONG:
                long putLong = create.getLong(i);
                bufferBuilder.putLong(putLong);
        }
    }

    return bufferBuilder.offset();

}
 
Example 3
Source File: BlasBufferUtil.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 * @param buf the ndarray to get the data for
 * @return the double data for this buffer
 */
public static double[] getDoubleData(DataBuffer buf) {
    if (buf.allocationMode() == DataBuffer.AllocationMode.HEAP)
        return buf.asDouble();
    else {
        double[] ret = new double[(int) buf.length()];
        for (int i = 0; i < buf.length(); i++)
            ret[i] = buf.getDouble(i);
        return ret;

    }
}
 
Example 4
Source File: BlasBufferUtil.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 * @param buf the ndarray to get the data for
 * @return the double data for this buffer
 */
public static double[] getDoubleData(DataBuffer buf) {
    if (buf.allocationMode() == DataBuffer.AllocationMode.HEAP)
        return buf.asDouble();
    else {
        double[] ret = new double[(int) buf.length()];
        for (int i = 0; i < buf.length(); i++)
            ret[i] = buf.getDouble(i);
        return ret;

    }
}