Search in sources :

Example 41 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project nd4j by deeplearning4j.

the class CompressionTests method testBitmapEncoding3.

@Test
public void testBitmapEncoding3() throws Exception {
    INDArray initial = Nd4j.create(new double[] { 0.0, -6e-4, 1e-3, -1e-3, 0.0, 0.0 });
    INDArray exp_0 = Nd4j.create(new double[] { 0.0, -1e-4, 0.0, 0.0, 0.0, 0.0 });
    INDArray exp_1 = Nd4j.create(new double[] { 0.0, -5e-4, 1e-3, -1e-3, 0.0, 0.0 });
    DataBuffer ib = Nd4j.getDataBufferFactory().createInt(5);
    INDArray enc = Nd4j.createArrayFromShapeBuffer(ib, initial.shapeInfoDataBuffer());
    long elements = Nd4j.getExecutioner().bitmapEncode(initial, enc, 1e-3);
    log.info("Encoded: {}", Arrays.toString(enc.data().asInt()));
    assertArrayEquals(new int[] { 6, 6, 981668463, 1, 655372 }, enc.data().asInt());
    assertEquals(3, elements);
    assertEquals(exp_0, initial);
    INDArray target = Nd4j.create(6);
    Nd4j.getExecutioner().bitmapDecode(enc, target);
    log.info("Target: {}", Arrays.toString(target.data().asFloat()));
    assertEquals(exp_1, target);
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 42 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project nd4j by deeplearning4j.

the class CompressionTests method testFP16Compression2.

@Test
public void testFP16Compression2() {
    DataBuffer buffer = Nd4j.createBuffer(new float[] { 1f, 2f, 3f, 4f, 5f });
    DataBuffer exp = Nd4j.createBuffer(new float[] { 1f, 2f, 3f, 4f, 5f });
    BasicNDArrayCompressor.getInstance().setDefaultCompression("FLOAT16");
    DataBuffer compr = BasicNDArrayCompressor.getInstance().compress(buffer);
    assertEquals(DataBuffer.Type.COMPRESSED, compr.dataType());
    DataBuffer decomp = BasicNDArrayCompressor.getInstance().decompress(compr);
    assertEquals(1.0f, decomp.getFloat(0), 0.01f);
    assertEquals(2.0f, decomp.getFloat(1), 0.01f);
    assertEquals(3.0f, decomp.getFloat(2), 0.01f);
    assertEquals(4.0f, decomp.getFloat(3), 0.01f);
    assertEquals(5.0f, decomp.getFloat(4), 0.01f);
}
Also used : DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 43 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project nd4j by deeplearning4j.

the class LapackTest method testCholeskyL.

@Test
public void testCholeskyL() {
    INDArray A = Nd4j.create(new double[] { 2, -1, 1, -1, 2, -1, 1, -1, 2 });
    A = A.reshape('c', 3, 3);
    INDArray O = Nd4j.create(A.shape());
    Nd4j.copy(A, O);
    Nd4j.getBlasWrapper().lapack().potrf(A, true);
    A.mmuli(A.transpose());
    O.subi(A);
    DataBuffer db = O.data();
    for (int i = 0; i < db.length(); i++) {
        assertEquals(0, db.getFloat(i), 1e-5);
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 44 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project nd4j by deeplearning4j.

the class LapackTest method testQRRect.

@Test
public void testQRRect() {
    INDArray A = Nd4j.create(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
    A = A.reshape('f', 4, 3);
    INDArray O = Nd4j.create(A.shape());
    Nd4j.copy(A, O);
    INDArray R = Nd4j.create(A.columns(), A.columns());
    Nd4j.getBlasWrapper().lapack().geqrf(A, R);
    A.mmuli(R);
    O.subi(A);
    DataBuffer db = O.data();
    for (int i = 0; i < db.length(); i++) {
        assertEquals(0, db.getFloat(i), 1e-5);
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 45 with DataBuffer

use of org.nd4j.linalg.api.buffer.DataBuffer in project nd4j by deeplearning4j.

the class Float16 method decompress.

@Override
public DataBuffer decompress(DataBuffer buffer) {
    val type = getGlobalTypeEx();
    DataBuffer result = Nd4j.getNDArrayFactory().convertDataEx(DataBuffer.TypeEx.FLOAT16, buffer, type);
    return result;
}
Also used : lombok.val(lombok.val) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer) CompressedDataBuffer(org.nd4j.linalg.compression.CompressedDataBuffer)

Aggregations

DataBuffer (org.nd4j.linalg.api.buffer.DataBuffer)186 INDArray (org.nd4j.linalg.api.ndarray.INDArray)79 Test (org.junit.Test)47 CompressedDataBuffer (org.nd4j.linalg.compression.CompressedDataBuffer)44 CudaContext (org.nd4j.linalg.jcublas.context.CudaContext)39 CudaPointer (org.nd4j.jita.allocator.pointers.CudaPointer)30 AllocationPoint (org.nd4j.jita.allocator.impl.AllocationPoint)25 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)23 BaseDataBuffer (org.nd4j.linalg.api.buffer.BaseDataBuffer)19 Pointer (org.bytedeco.javacpp.Pointer)18 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)16 CudaDoubleDataBuffer (org.nd4j.linalg.jcublas.buffer.CudaDoubleDataBuffer)16 IntPointer (org.bytedeco.javacpp.IntPointer)13 PagedPointer (org.nd4j.linalg.api.memory.pointers.PagedPointer)13 CudaIntDataBuffer (org.nd4j.linalg.jcublas.buffer.CudaIntDataBuffer)13 DoublePointer (org.bytedeco.javacpp.DoublePointer)12 FloatPointer (org.bytedeco.javacpp.FloatPointer)12 GridExecutioner (org.nd4j.linalg.api.ops.executioner.GridExecutioner)12 LongPointerWrapper (org.nd4j.nativeblas.LongPointerWrapper)11 CUstream_st (org.bytedeco.javacpp.cuda.CUstream_st)10