java.nio.DoubleBuffer#allocate ( )源码实例Demo

下面列出了java.nio.DoubleBuffer#allocate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MikuMikuStudio   文件: BufferUtils.java
/**
 * Creates a new DoubleBuffer with the same contents as the given
 * DoubleBuffer. The new DoubleBuffer is seperate from the old one and
 * changes are not reflected across. If you want to reflect changes,
 * consider using Buffer.duplicate().
 *
 * @param buf
 *            the DoubleBuffer to copy
 * @return the copy
 */
public static DoubleBuffer clone(DoubleBuffer buf) {
    if (buf == null) {
        return null;
    }
    buf.rewind();

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

    return copy;
}
 
源代码2 项目: Robot-Overlord-App   文件: Spidee.java
void Draw_Body(GL2 gl2) {
	gl2.glPushMatrix();

	DoubleBuffer m=DoubleBuffer.allocate(16);

	m.put( 0,-body.left.x);
	m.put( 1,-body.left.y);
	m.put( 2,-body.left.z);
	m.put( 4,body.forward.x);
	m.put( 5,body.forward.y);
	m.put( 6,body.forward.z);
	m.put( 8,body.up.x);
	m.put( 9,body.up.y);
	m.put(10,body.up.z);
	m.put(15,1);

	matBody.render(gl2);
    gl2.glTranslated(body.pos.x + 7.5f * body.up.x,
                 body.pos.y + 7.5f * body.up.y,
                 body.pos.z + 7.5f * body.up.z );
    gl2.glMultMatrixd(m);
    gl2.glRotatef(180,0,1,0);
    modelBody.render(gl2);

    gl2.glPopMatrix();
}
 
源代码3 项目: Ultraino   文件: BufferUtils.java
/**
 * Creates a new DoubleBuffer with the same contents as the given
 * DoubleBuffer. The new DoubleBuffer is separate from the old one and
 * changes are not reflected across. If you want to reflect changes,
 * consider using Buffer.duplicate().
 *
 * @param buf
 *            the DoubleBuffer to copy
 * @return the copy
 */
public static DoubleBuffer clone(DoubleBuffer buf) {
    if (buf == null) {
        return null;
    }
    buf.rewind();

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

    return copy;
}
 
源代码4 项目: jmonkeyengine   文件: BufferUtils.java
/**
 * Creates a new DoubleBuffer with the same contents as the given
 * DoubleBuffer. The new DoubleBuffer is separate from the old one and
 * changes are not reflected across. If you want to reflect changes,
 * consider using Buffer.duplicate().
 *
 * @param buf
 *            the DoubleBuffer to copy
 * @return the copy
 */
public static DoubleBuffer clone(DoubleBuffer buf) {
    if (buf == null) {
        return null;
    }
    buf.rewind();

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

    return copy;
}
 
源代码5 项目: djl   文件: NDManager.java
/**
 * Creates and initializes a 2D {@link NDArray}.
 *
 * @param data the float array that needs to be set
 * @return a new instance of {@link NDArray}
 */
default NDArray create(double[][] data) {
    DoubleBuffer buffer = DoubleBuffer.allocate(data.length * data[0].length);
    for (double[] d : data) {
        buffer.put(d);
    }
    buffer.rewind();
    return create(buffer, new Shape(data.length, data[0].length));
}
 
源代码6 项目: powsybl-core   文件: DoubleDataChunkTest.java
@Test
public void baseTest() throws IOException {
    UncompressedDoubleDataChunk chunk = new UncompressedDoubleDataChunk(1, new double[] {1d, 2d, 3d});
    assertEquals(1, chunk.getOffset());
    assertEquals(3, chunk.getLength());
    assertArrayEquals(new double[]{1d, 2d, 3d}, chunk.getValues(), 0d);
    assertEquals(24, chunk.getEstimatedSize());
    assertFalse(chunk.isCompressed());
    assertEquals(1d, chunk.getCompressionFactor(), 0d);
    DoubleBuffer buffer = DoubleBuffer.allocate(4);
    for (int i = 0; i < 4; i++) {
        buffer.put(i, Double.NaN);
    }
    chunk.fillBuffer(buffer, 0);
    assertArrayEquals(new double[] {Double.NaN, 1d, 2d, 3d}, buffer.array(), 0d);
    String jsonRef = String.join(System.lineSeparator(),
            "{",
            "  \"offset\" : 1,",
            "  \"values\" : [ 1.0, 2.0, 3.0 ]",
            "}");
    assertEquals(jsonRef, JsonUtil.toJson(chunk::writeJson));
    RegularTimeSeriesIndex index = RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T00:45:00Z"),
                                                                 Duration.ofMinutes(15));
    assertEquals(ImmutableList.of(new DoublePoint(1, Instant.parse("2015-01-01T00:15:00Z").toEpochMilli(), 1d),
                                  new DoublePoint(2, Instant.parse("2015-01-01T00:30:00Z").toEpochMilli(), 2d),
                                  new DoublePoint(3, Instant.parse("2015-01-01T00:45:00Z").toEpochMilli(), 3d)),
            chunk.stream(index).collect(Collectors.toList()));
}
 
源代码7 项目: jpmml-tensorflow   文件: TensorUtil.java
static
public double[] toDoubleArray(Tensor tensor){
	DoubleBuffer doubleBuffer = DoubleBuffer.allocate(tensor.numElements());

	tensor.writeTo(doubleBuffer);

	return doubleBuffer.array();
}
 
源代码8 项目: vespa   文件: TestableModel.java
private org.tensorflow.Tensor<?> tensorFlowDoubleInputArgument(int d0Size, int d1Size) {
    DoubleBuffer fb1 = DoubleBuffer.allocate(d0Size * d1Size);
    int i = 0;
    for (int d0 = 0; d0 < d0Size; d0++)
        for (int d1 = 0; d1 < d1Size; ++d1)
            fb1.put(i++, (float)(d1 * 1.0 / d1Size));
    return org.tensorflow.Tensor.create(new long[]{ d0Size, d1Size }, fb1);
}
 
源代码9 项目: java   文件: DoubleNioDataBufferTest.java
@Override
protected DoubleDataBuffer allocate(long size) {
  return new DoubleNioDataBuffer(DoubleBuffer.allocate((int)size));
}
 
源代码10 项目: zoltar   文件: JTensor.java
/**
 * Create a new {@link JTensor} instance by extracting data from the underlying {@link Tensor} and
 * closing it afterwards.
 */
public static JTensor create(final Tensor<?> tensor) {
  final JTensor jt;
  try {
    switch (tensor.dataType()) {
      case STRING:
        if (tensor.numDimensions() == 0) {
          final String value = new String(tensor.bytesValue(), UTF_8);
          jt =
              new AutoValue_JTensor(
                  tensor.dataType(), tensor.numDimensions(), tensor.shape(), value);
        } else {
          final int[] dimensions = toIntExact(tensor.shape());
          final Object byteArray =
              tensor.copyTo(Array.newInstance(byte[].class, toIntExact(tensor.shape())));
          jt =
              new AutoValue_JTensor(
                  tensor.dataType(),
                  tensor.numDimensions(),
                  tensor.shape(),
                  toStringArray(byteArray, tensor.numElements(), dimensions));
        }
        break;
      case INT32:
        final IntBuffer intBuf = IntBuffer.allocate(tensor.numElements());
        tensor.writeTo(intBuf);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), intBuf.array());
        break;
      case INT64:
        final LongBuffer longBuf = LongBuffer.allocate(tensor.numElements());
        tensor.writeTo(longBuf);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), longBuf.array());
        break;
      case FLOAT:
        final FloatBuffer floatBuf = FloatBuffer.allocate(tensor.numElements());
        tensor.writeTo(floatBuf);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), floatBuf.array());
        break;
      case DOUBLE:
        final DoubleBuffer doubleBuf = DoubleBuffer.allocate(tensor.numElements());
        tensor.writeTo(doubleBuf);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), doubleBuf.array());
        break;
      case BOOL:
        final boolean[] array = new boolean[tensor.numElements()];
        tensor.copyTo(array);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), array);
        break;
      default:
        throw new IllegalStateException("Unsupported data type " + tensor.dataType());
    }
  } finally {
    tensor.close();
  }

  return jt;
}
 
源代码11 项目: powsybl-core   文件: CalculatedTimeSeries.java
@Override
public double[] toArray() {
    DoubleBuffer buffer = DoubleBuffer.allocate(metadata.getIndex().getPointCount());
    fillBuffer(buffer, 0);
    return buffer.array();
}
 
源代码12 项目: powsybl-core   文件: DoubleDataChunkTest.java
@Test
public void compressTest() throws IOException {
    UncompressedDoubleDataChunk chunk = new UncompressedDoubleDataChunk(1, new double[] {1d, 2d, 2d, 2d, 2d, 3d});
    DoubleDataChunk maybeCompressedChunk = chunk.tryToCompress();
    assertTrue(maybeCompressedChunk instanceof CompressedDoubleDataChunk);
    CompressedDoubleDataChunk compressedChunk = (CompressedDoubleDataChunk) maybeCompressedChunk;
    assertEquals(1, compressedChunk.getOffset());
    assertEquals(6, compressedChunk.getLength());
    assertTrue(compressedChunk.isCompressed());
    assertEquals(36, compressedChunk.getEstimatedSize());
    assertEquals(36d / 48, compressedChunk.getCompressionFactor(), 0d);
    assertArrayEquals(new double[] {1d, 2d, 3d}, compressedChunk.getStepValues(), 0d);
    assertArrayEquals(new int[] {1, 4, 1}, compressedChunk.getStepLengths());
    DoubleBuffer buffer = DoubleBuffer.allocate(7);
    for (int i = 0; i < 7; i++) {
        buffer.put(i, Double.NaN);
    }
    compressedChunk.fillBuffer(buffer, 0);
    assertArrayEquals(new double[] {Double.NaN, 1d, 2d, 2d, 2d, 2d, 3d}, buffer.array(), 0d);

    // json test
    String jsonRef = String.join(System.lineSeparator(),
            "{",
            "  \"offset\" : 1,",
            "  \"uncompressedLength\" : 6,",
            "  \"stepValues\" : [ 1.0, 2.0, 3.0 ],",
            "  \"stepLengths\" : [ 1, 4, 1 ]",
            "}");
    assertEquals(jsonRef, JsonUtil.toJson(compressedChunk::writeJson));

    // test json with object mapper
    ObjectMapper objectMapper = JsonUtil.createObjectMapper()
            .registerModule(new TimeSeriesJsonModule());

    List<DoubleDataChunk> chunks = objectMapper.readValue(objectMapper.writeValueAsString(Arrays.asList(chunk, compressedChunk)),
                                                           TypeFactory.defaultInstance().constructCollectionType(List.class, DoubleDataChunk.class));
    assertEquals(2, chunks.size());
    assertEquals(chunk, chunks.get(0));
    assertEquals(compressedChunk, chunks.get(1));

    // check base class (DataChunk) deserializer
    assertTrue(objectMapper.readValue(objectMapper.writeValueAsString(chunk), DataChunk.class) instanceof DoubleDataChunk);

    // stream test
    RegularTimeSeriesIndex index = RegularTimeSeriesIndex.create(Interval.parse("2015-01-01T00:00:00Z/2015-01-01T01:30:00Z"),
                                                                 Duration.ofMinutes(15));
    assertEquals(ImmutableList.of(new DoublePoint(1, Instant.parse("2015-01-01T00:15:00Z").toEpochMilli(), 1d),
                                  new DoublePoint(2, Instant.parse("2015-01-01T00:30:00Z").toEpochMilli(), 2d),
                                  new DoublePoint(6, Instant.parse("2015-01-01T01:30:00Z").toEpochMilli(), 3d)),
                 compressedChunk.stream(index).collect(Collectors.toList()));
}
 
源代码13 项目: OSPREY3   文件: BufferTools.java
@Override
public DoubleBuffer makeDouble(int size) {
	return DoubleBuffer.allocate(size);
}
 
源代码14 项目: datacollector   文件: DoubleTensorTypeSupport.java
@Override
public DoubleBuffer allocateBuffer(long[] shape) {
  return DoubleBuffer.allocate(calculateCapacityForShape(shape));
}
 
源代码15 项目: TencentKona-8   文件: BufferArray.java
/**
 * Constructor
 * @param size initial size
 */
public BufferArray(final int size) {
    buf = DoubleBuffer.allocate(size);
}
 
源代码16 项目: jdk8u60   文件: BufferArray.java
/**
 * Constructor
 * @param size initial size
 */
public BufferArray(final int size) {
    buf = DoubleBuffer.allocate(size);
}
 
源代码17 项目: openjdk-jdk8u   文件: BufferArray.java
/**
 * Constructor
 * @param size initial size
 */
public BufferArray(final int size) {
    buf = DoubleBuffer.allocate(size);
}
 
源代码18 项目: openjdk-jdk9   文件: BufferArray.java
/**
 * Constructor
 * @param size initial size
 */
public BufferArray(final int size) {
    buf = DoubleBuffer.allocate(size);
}
 
源代码19 项目: hottub   文件: BufferArray.java
/**
 * Constructor
 * @param size initial size
 */
public BufferArray(final int size) {
    buf = DoubleBuffer.allocate(size);
}
 
源代码20 项目: jdk8u_nashorn   文件: BufferArray.java
/**
 * Constructor
 * @param size initial size
 */
public BufferArray(final int size) {
    buf = DoubleBuffer.allocate(size);
}