Search in sources :

Example 66 with DoubleBuffer

use of java.nio.DoubleBuffer in project javacv by bytedeco.

the class Frame method createIndexer.

/**
 * Returns an {@link Indexer} for the <i>i</i>th image plane.
 */
public <I extends Indexer> I createIndexer(boolean direct, int i) {
    long[] sizes = { imageHeight, imageWidth, imageChannels };
    long[] strides = { imageStride, imageChannels, 1 };
    Buffer buffer = image[i];
    Object array = buffer.hasArray() ? buffer.array() : null;
    switch(imageDepth) {
        case DEPTH_UBYTE:
            return array != null ? (I) UByteIndexer.create((byte[]) array, sizes, strides).indexable(this) : direct ? (I) UByteIndexer.create((ByteBuffer) buffer, sizes, strides).indexable(this) : (I) UByteIndexer.create(new BytePointer((ByteBuffer) buffer), sizes, strides, false).indexable(this);
        case DEPTH_BYTE:
            return array != null ? (I) ByteIndexer.create((byte[]) array, sizes, strides).indexable(this) : direct ? (I) ByteIndexer.create((ByteBuffer) buffer, sizes, strides).indexable(this) : (I) ByteIndexer.create(new BytePointer((ByteBuffer) buffer), sizes, strides, false).indexable(this);
        case DEPTH_USHORT:
            return array != null ? (I) UShortIndexer.create((short[]) array, sizes, strides).indexable(this) : direct ? (I) UShortIndexer.create((ShortBuffer) buffer, sizes, strides).indexable(this) : (I) UShortIndexer.create(new ShortPointer((ShortBuffer) buffer), sizes, strides, false).indexable(this);
        case DEPTH_SHORT:
            return array != null ? (I) ShortIndexer.create((short[]) array, sizes, strides).indexable(this) : direct ? (I) ShortIndexer.create((ShortBuffer) buffer, sizes, strides).indexable(this) : (I) ShortIndexer.create(new ShortPointer((ShortBuffer) buffer), sizes, strides, false).indexable(this);
        case DEPTH_INT:
            return array != null ? (I) IntIndexer.create((int[]) array, sizes, strides).indexable(this) : direct ? (I) IntIndexer.create((IntBuffer) buffer, sizes, strides).indexable(this) : (I) IntIndexer.create(new IntPointer((IntBuffer) buffer), sizes, strides, false).indexable(this);
        case DEPTH_LONG:
            return array != null ? (I) LongIndexer.create((long[]) array, sizes, strides).indexable(this) : direct ? (I) LongIndexer.create((LongBuffer) buffer, sizes, strides).indexable(this) : (I) LongIndexer.create(new LongPointer((LongBuffer) buffer), sizes, strides, false).indexable(this);
        case DEPTH_FLOAT:
            return array != null ? (I) FloatIndexer.create((float[]) array, sizes, strides).indexable(this) : direct ? (I) FloatIndexer.create((FloatBuffer) buffer, sizes, strides).indexable(this) : (I) FloatIndexer.create(new FloatPointer((FloatBuffer) buffer), sizes, strides, false).indexable(this);
        case DEPTH_DOUBLE:
            return array != null ? (I) DoubleIndexer.create((double[]) array, sizes, strides).indexable(this) : direct ? (I) DoubleIndexer.create((DoubleBuffer) buffer, sizes, strides).indexable(this) : (I) DoubleIndexer.create(new DoublePointer((DoubleBuffer) buffer), sizes, strides, false).indexable(this);
        default:
            assert false;
    }
    return null;
}
Also used : FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer) ByteBuffer(java.nio.ByteBuffer) IntBuffer(java.nio.IntBuffer) Buffer(java.nio.Buffer) DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) BytePointer(org.bytedeco.javacpp.BytePointer) DoublePointer(org.bytedeco.javacpp.DoublePointer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortPointer(org.bytedeco.javacpp.ShortPointer) LongPointer(org.bytedeco.javacpp.LongPointer) FloatPointer(org.bytedeco.javacpp.FloatPointer) IntPointer(org.bytedeco.javacpp.IntPointer) IntBuffer(java.nio.IntBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 67 with DoubleBuffer

use of java.nio.DoubleBuffer in project ffx by mjschnie.

the class DoubleArrayBuf_1 method sendItems.

// Hidden operations.
/**
 * {@inheritDoc}
 *
 * Send as many items as possible from this buffer to the given byte buffer.
 * <P>
 * The <TT>sendItems()</TT> method must not block the calling thread; if it
 * does, all message I/O in MP will be blocked.
 */
protected int sendItems(int i, ByteBuffer buffer) {
    DoubleBuffer doublebuffer = buffer.asDoubleBuffer();
    int n = Math.min(myLength - i, doublebuffer.remaining());
    doublebuffer.put(myArray, myArrayOffset + i, n);
    buffer.position(buffer.position() + 8 * n);
    return n;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer)

Example 68 with DoubleBuffer

use of java.nio.DoubleBuffer in project ffx by mjschnie.

the class DoubleMatrixBuf_1 method receiveItems.

/**
 * {@inheritDoc}
 *
 * Receive as many items as possible from the given byte buffer to this
 * buffer.
 * <P>
 * The <TT>receiveItems()</TT> method must not block the calling thread; if
 * it does, all message I/O in MP will be blocked.
 */
protected int receiveItems(int i, int num, ByteBuffer buffer) {
    DoubleBuffer doublebuffer = buffer.asDoubleBuffer();
    num = Math.min(num, doublebuffer.remaining());
    int n = 0;
    int r = i2r(i);
    int row = r + myLowerRow;
    int c = i2c(i);
    int col = c + myLowerCol;
    int ncols = Math.min(myColCount - c, num);
    while (r < myRowCount && ncols > 0) {
        doublebuffer.get(myMatrix[row], col, ncols);
        num -= ncols;
        n += ncols;
        ++r;
        ++row;
        c = 0;
        col = myLowerCol;
        ncols = Math.min(myColCount, num);
    }
    buffer.position(buffer.position() + 8 * n);
    return n;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer)

Example 69 with DoubleBuffer

use of java.nio.DoubleBuffer in project ffx by mjschnie.

the class DoubleMatrixBuf_1 method sendItems.

// Hidden operations.
/**
 * {@inheritDoc}
 *
 * Send as many items as possible from this buffer to the given byte buffer.
 * <P>
 * The <TT>sendItems()</TT> method must not block the calling thread; if it
 * does, all message I/O in MP will be blocked.
 */
protected int sendItems(int i, ByteBuffer buffer) {
    DoubleBuffer doublebuffer = buffer.asDoubleBuffer();
    int n = 0;
    int r = i2r(i);
    int row = r + myLowerRow;
    int c = i2c(i);
    int col = c + myLowerCol;
    int ncols = Math.min(myColCount - c, doublebuffer.remaining());
    while (r < myRowCount && ncols > 0) {
        doublebuffer.put(myMatrix[row], col, ncols);
        n += ncols;
        ++r;
        ++row;
        c = 0;
        col = myLowerCol;
        ncols = Math.min(myColCount, doublebuffer.remaining());
    }
    buffer.position(buffer.position() + 8 * n);
    return n;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer)

Example 70 with DoubleBuffer

use of java.nio.DoubleBuffer in project ffx by mjschnie.

the class DoubleMatrixReductionBuf_1 method receiveItems.

// Hidden operations.
/**
 * {@inheritDoc}
 *
 * Receive as many items as possible from the given byte buffer to this
 * buffer.
 * <P>
 * The <TT>receiveItems()</TT> method must not block the calling thread; if
 * it does, all message I/O in MP will be blocked.
 */
protected int receiveItems(int i, int num, ByteBuffer buffer) {
    DoubleBuffer doublebuffer = buffer.asDoubleBuffer();
    num = Math.min(num, doublebuffer.remaining());
    int n = 0;
    int r = i2r(i);
    int row = r + myLowerRow;
    int c = i2c(i);
    int col = c + myLowerCol;
    int ncols = Math.min(myColCount - c, num);
    while (r < myRowCount && ncols > 0) {
        double[] myMatrix_row = myMatrix[row];
        for (c = 0; c < ncols; ++c) {
            myMatrix_row[col] = myOp.op(myMatrix_row[col], doublebuffer.get());
            ++col;
        }
        num -= ncols;
        n += ncols;
        ++r;
        ++row;
        col = myLowerCol;
        ncols = Math.min(myColCount, num);
    }
    buffer.position(buffer.position() + 8 * n);
    return n;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer)

Aggregations

DoubleBuffer (java.nio.DoubleBuffer)162 ByteBuffer (java.nio.ByteBuffer)39 FloatBuffer (java.nio.FloatBuffer)26 IntBuffer (java.nio.IntBuffer)25 ShortBuffer (java.nio.ShortBuffer)22 LongBuffer (java.nio.LongBuffer)14 CharBuffer (java.nio.CharBuffer)11 BufferOverflowException (java.nio.BufferOverflowException)8 IOException (java.io.IOException)5 BufferUnderflowException (java.nio.BufferUnderflowException)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ServerDenseDoubleRow (com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)4 Test (org.junit.Test)4 InvalidMarkException (java.nio.InvalidMarkException)3 Random (java.util.Random)3 BytePointer (org.bytedeco.javacpp.BytePointer)3 DoublePointer (org.bytedeco.javacpp.DoublePointer)3 FloatPointer (org.bytedeco.javacpp.FloatPointer)3 IntPointer (org.bytedeco.javacpp.IntPointer)3