org.bytedeco.javacpp.indexer.DoubleIndexer Java Examples

The following examples show how to use org.bytedeco.javacpp.indexer.DoubleIndexer. 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: DoubleDataBufferTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPointerCreation() {
    DoublePointer floatPointer = new DoublePointer(1, 2, 3, 4);
    Indexer indexer = DoubleIndexer.create(floatPointer);
    DataBuffer buffer = Nd4j.createBuffer(floatPointer, DataBuffer.Type.DOUBLE, 4, indexer);
    DataBuffer other = Nd4j.createBuffer(new double[] {1, 2, 3, 4});
    assertArrayEquals(other.asDouble(), buffer.asDouble(), 0.001);
}
 
Example #2
Source File: DefaultDataBufferFactory.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * @param doublePointer
 * @param length
 * @return
 */
@Override
public DataBuffer create(DoublePointer doublePointer, long length) {
    doublePointer.capacity(length);
    doublePointer.limit(length);
    doublePointer.position(0);
    return new DoubleBuffer(doublePointer, DoubleIndexer.create(doublePointer), length);
}
 
Example #3
Source File: DefaultDataBufferFactory.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * @param doublePointer
 * @param length
 * @return
 */
@Override
public DataBuffer create(DoublePointer doublePointer, long length) {
    doublePointer.capacity(length);
    doublePointer.limit(length);
    doublePointer.position(0);
    return new DoubleBuffer(doublePointer, DoubleIndexer.create(doublePointer), length);
}
 
Example #4
Source File: DoubleDataBufferTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPointerCreation() {
    DoublePointer floatPointer = new DoublePointer(1, 2, 3, 4);
    Indexer indexer = DoubleIndexer.create(floatPointer);
    DataBuffer buffer = Nd4j.createBuffer(floatPointer, DataType.DOUBLE, 4, indexer);
    DataBuffer other = Nd4j.createBuffer(new double[] {1, 2, 3, 4});
    assertArrayEquals(other.asDouble(), buffer.asDouble(), 0.001);
}
 
Example #5
Source File: PerspectiveTransformRunner.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
private double[] calculateExtremes(Mat transform, int width, int height) {
    Mat src = new Mat(4, 1, CvType.CV_64FC2);
    DoubleIndexer idx = src.createIndexer();
    // topLeft
    idx.put(0, 0, 0);
    idx.put(0, 1, 0);

    // topRight
    idx.put(1, 0, width);
    idx.put(1, 1, 0);

    // bottomLeft
    idx.put(2, 0, 0);
    idx.put(2, 1, height);

    // bottomRight
    idx.put(3, 0, width);
    idx.put(3, 1, height);


    Mat dst = new Mat();
    opencv_core.perspectiveTransform(src, dst, transform);

    idx = dst.createIndexer();
    double[] xValues = new double[]{
            idx.get(0, 0),
            idx.get(1, 0),
            idx.get(2, 0),
            idx.get(3, 0)
    };
    double[] yValues = new double[]{
            idx.get(0, 1),
            idx.get(1, 1),
            idx.get(2, 1),
            idx.get(3, 1)
    };

    double minX = DoubleStream.of(xValues).min().getAsDouble();
    double maxX = DoubleStream.of(xValues).max().getAsDouble();
    double minY = DoubleStream.of(yValues).min().getAsDouble();
    double maxY = DoubleStream.of(yValues).max().getAsDouble();

    return new double[]{minX, minY, maxX, maxY};
}