Package java.nio

Examples of java.nio.DoubleBuffer


    }
    public void testDoubleBufferGet() {
        final double MAGIC = 1234.5678;
        Memory m = new Memory(8);
        ByteBuffer buf = m.getByteBuffer(0, m.size()).order(ByteOrder.nativeOrder());
        DoubleBuffer db = buf.asDoubleBuffer();
        m.setDouble(0, MAGIC);
        assertEquals("Double not read from memory", MAGIC,
                db.get(0));
    }
View Full Code Here


                         i < 512 ? 0 : MAGIC, array[i]);
        }
    }
    public void testWrappedDoubleArrayArguent() {
        double[] array = new double[1024];
        DoubleBuffer buf  = DoubleBuffer.wrap(array, 512, 512).slice();
        final double MAGIC = -118.625;
        lib.fillDoubleBuffer(buf, 512, MAGIC);
        for (int i=0;i < array.length;i++) {
            assertEquals("Bad value at index " + i,
                         i < 512 ? 0 : MAGIC, array[i]);
View Full Code Here

     * @param size
     *            required number of double to store.
     * @return the new DoubleBuffer
     */
    public static DoubleBuffer createDoubleBufferOnHeap(final int size) {
        final DoubleBuffer buf = ByteBuffer.allocate(8 * size).order(ByteOrder.nativeOrder()).asDoubleBuffer();
        buf.clear();
        return buf;
    }
View Full Code Here

     * @param size
     *            required number of double to store.
     * @return the new DoubleBuffer
     */
    public static DoubleBuffer createDoubleBuffer(final int size) {
        final DoubleBuffer buf = ByteBuffer.allocateDirect(8 * size).order(ByteOrder.nativeOrder()).asDoubleBuffer();
        buf.clear();
        if (Constants.trackDirectMemory) {
            trackingHash.put(buf, ref);
        }
        return buf;
    }
View Full Code Here

        if (buf == null) {
            return null;
        }
        buf.rewind();

        final DoubleBuffer copy;
        if (buf.isDirect()) {
            copy = createDoubleBuffer(buf.limit());
        } else {
            copy = createDoubleBufferOnHeap(buf.limit());
        }
        copy.put(buf);

        return copy;
    }
View Full Code Here

    assertEquals(a, Arrayz.parse(s));
  }

  private void testBufferRoundTrip(INDArray a) {
    int len = (int) a.elementCount();
    DoubleBuffer buf = DoubleBuffer.allocate(len);
    assertEquals(len, buf.remaining());
    a.toDoubleBuffer(buf);
    assertEquals(0, buf.remaining());
    buf.flip();
    AVector vv = Vectorz.create(buf);
    assertEquals(a.asVector(), vv);
    assertEquals(a, vv.reshape(a.getShape()));
  }
View Full Code Here

        array.addDouble(4);
        MutableDoubleArray backedByArray = MutableDoubleArray.copyOf(array);
        Arrays.reverse(backedByArray);
        array.setAll(backedByArray);
        assertArrayEquals(new double[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray(), 0);
        DoubleBuffer buffer = ByteBuffer.allocateDirect(Double.SIZE / Byte.SIZE * 8).asDoubleBuffer();
        MutableDoubleArray notBackedByArray = Arrays.newMutableArray(buffer);
        notBackedByArray.setAll(backedByArray);
        array.setAll(notBackedByArray);
        assertArrayEquals(new double[]{4, 3, 3, 2, 1, 2, 1, 1}, array.toArray(), 0);
        UnboundedDoubleArray bigger = UnboundedDoubleArray.copyOf(array);
View Full Code Here

        assertArrayEquals(new double[]{1, 1, 2, 1, 2, 3, 3, 4}, array.toArray(), 0);
    }

    @Test
    public void testAddAllNoBackingArray0() throws Exception {
        DoubleBuffer buffer = ByteBuffer.allocateDirect(Double.SIZE / Byte.SIZE * 10).asDoubleBuffer();
        buffer.position(1).limit(9);
        BoundedDoubleArray notBackedByArray = BoundedDoubleArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(DoubleArray.unsafeValueOf());
        assertEquals(8, notBackedByArray.length());
        assertArrayEquals(new double[]{1, 1, 2, 1, 2, 3, 3, 4}, notBackedByArray.toArray(), 0);
View Full Code Here

        assertArrayEquals(new double[]{1, 1, 2, 1, 2, 3, 3, 4}, notBackedByArray.toArray(), 0);
    }

    @Test
    public void testAddAllNoBackingArray1() throws Exception {
        DoubleBuffer buffer = ByteBuffer.allocateDirect(Double.SIZE / Byte.SIZE * 11).asDoubleBuffer();
        buffer.position(1).limit(9);
        BoundedDoubleArray notBackedByArray = BoundedDoubleArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(DoubleArray.unsafeValueOf(5));
        assertEquals(9, notBackedByArray.length());
        assertArrayEquals(new double[]{1, 1, 2, 1, 2, 3, 3, 4, 5}, notBackedByArray.toArray(), 0);
View Full Code Here

        assertArrayEquals(new double[]{1, 1, 2, 1, 2, 3, 3, 4, 5}, notBackedByArray.toArray(), 0);
    }

    @Test
    public void testAddAllNoBackingArray2() throws Exception {
        DoubleBuffer buffer = ByteBuffer.allocateDirect(Double.SIZE / Byte.SIZE * 11).asDoubleBuffer();
        buffer.position(1).limit(9);
        BoundedDoubleArray notBackedByArray = BoundedDoubleArray.valueOf(buffer);
        notBackedByArray.setAll(array);
        notBackedByArray.addAll(DoubleArray.unsafeValueOf(5, 5));
        assertEquals(10, notBackedByArray.length());
        assertArrayEquals(new double[]{1, 1, 2, 1, 2, 3, 3, 4, 5, 5}, notBackedByArray.toArray(), 0);
View Full Code Here

TOP

Related Classes of java.nio.DoubleBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.