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);
}
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);
}
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);
}
}
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);
}
}
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;
}
Aggregations