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

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

源代码1 项目: 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;
}
 
源代码2 项目: aion-germany   文件: 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;
}
 
源代码3 项目: 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;
}
 
源代码4 项目: 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;
}
 
源代码5 项目: samantha   文件: TensorFlowModel.java
public Map<String, String> getStringifiedSparseTensor(List<LearningInstance> instances) {
    Map<String, Integer> numFeatures = getNumSparseFeatures(instances);
    Map<String, String> tensorMap = new HashMap<>();
    for (Map.Entry<String, Integer> entry : numFeatures.entrySet()) {
        String name = entry.getKey();
        int numFeature = entry.getValue();
        DoubleBuffer valBuffer = DoubleBuffer.allocate(numFeature);
        IntBuffer idxBuffer = IntBuffer.allocate(numFeature);
        for (LearningInstance instance : instances) {
            TensorFlowInstance tfins = (TensorFlowInstance) instance;
            double[] doubleValues = tfins.getName2Values().get(name);
            int[] intValues = tfins.getName2Indices().get(name);
            for (int i=0; i<doubleValues.length; i++) {
                valBuffer.put(doubleValues[i]);
            }
            for (int i=0; i<intValues.length; i++) {
                idxBuffer.put(intValues[i]);
            }
        }
        tensorMap.put(name + VALUE_APPENDIX, StringUtils.join(valBuffer.array(), ','));
        tensorMap.put(name + INDEX_APPENDIX, StringUtils.join(idxBuffer.array(), ','));
    }
    return tensorMap;
}
 
源代码6 项目: OSPREY3   文件: CCDKernelCuda.java
public void runAsync(DoubleMatrix1D x, ObjectiveFunction.DofBounds dofBounds) {
	
	// make sure the energy function is still valid
	if (ffenergy.getFullSubset().handleChemicalChanges() != ffSequenceNumber) {
		throw new Error("don't re-use kernel instances after chemical changes. This is a bug");
	}
	
	// upload x and bounds
	DoubleBuffer buf = xAndBounds.getHostBuffer();
	buf.clear();
	int numDofs = dofInfos.size();
	for (int d=0; d<numDofs; d++) {
		buf.put(Math.toRadians(x.get(d)));
		buf.put(Math.toRadians(dofBounds.getMin(d)));
		buf.put(Math.toRadians(dofBounds.getMax(d)));
	}
	xAndBounds.uploadAsync();
	
	// run the kernel
	func.runAsync();
}
 
源代码7 项目: BIMserver   文件: GeometryUtils.java
public static byte[] doubleArrayToByteArray(double[] vertices) {
	if (vertices == null) {
		return null;
	}
	ByteBuffer buffer = ByteBuffer.wrap(new byte[vertices.length * 4]);
	buffer.order(ByteOrder.LITTLE_ENDIAN);
	DoubleBuffer asDoubleBuffer = buffer.asDoubleBuffer();
	for (double d : vertices) {
		asDoubleBuffer.put(d);
	}
	return buffer.array();
}
 
源代码8 项目: MeteoInfo   文件: ArrayDate.java
@Override
public ByteBuffer getDataAsByteBuffer() {
    ByteBuffer bb = ByteBuffer.allocate((int) (8 * getSize()));
    DoubleBuffer ib = bb.asDoubleBuffer();
    ib.put((double[]) get1DJavaArray(double.class)); // make sure its in canonical order
    return bb;
}
 
源代码9 项目: BIMserver   文件: BinUtils.java
public static byte[] doubleToByteArray(Double inDouble) {
	byte[] bArray = new byte[8];
	ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
	DoubleBuffer lBuffer = bBuffer.asDoubleBuffer();
	lBuffer.put(inDouble);
	return bArray;
}
 
源代码10 项目: powsybl-core   文件: StoredDoubleTimeSeries.java
@Override
public double[] toArray() {
    DoubleBuffer buffer = DoubleBuffer.allocate(metadata.getIndex().getPointCount());
    for (int i = 0; i < metadata.getIndex().getPointCount(); i++) {
        buffer.put(i, Double.NaN);
    }
    fillBuffer(buffer, 0);
    return buffer.array();
}
 
源代码11 项目: 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()));
}
 
源代码12 项目: BIMserver   文件: StreamingGeometryGenerator.java
void setTransformationMatrix(VirtualObject geometryInfo, double[] transformationMatrix) throws BimserverDatabaseException {
	ByteBuffer byteBuffer = ByteBuffer.allocate(16 * 8);
	byteBuffer.order(ByteOrder.nativeOrder());
	DoubleBuffer asDoubleBuffer = byteBuffer.asDoubleBuffer();
	for (double d : transformationMatrix) {
		asDoubleBuffer.put(d);
	}
	geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_Transformation(), byteBuffer.array());
}
 
源代码13 项目: datacollector   文件: DoubleTensorTypeSupport.java
@Override
public void writeField(DoubleBuffer buffer, Field field) {
  Utils.checkState(
      field.getType() == Field.Type.DOUBLE,
      Utils.format("Not a Double scalar, it is {}", field.getType())
  );
  buffer.put(field.getValueAsDouble());
}
 
源代码14 项目: vespa   文件: TestableTensorFlowModel.java
/** Must be the same as vespaInputArgument() */
private org.tensorflow.Tensor<?> tensorFlowDoubleInputArgument() {
    DoubleBuffer fb = DoubleBuffer.allocate(d0Size * d1Size);
    int i = 0;
    for (int d0 = 0; d0 < d0Size; d0++)
        for (int d1 = 0; d1 < d1Size; ++d1)
            fb.put(i++, (d1 * 1.0 / d1Size));
    return org.tensorflow.Tensor.create(new long[]{ d0Size, d1Size }, fb);
}
 
源代码15 项目: 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);
}
 
源代码16 项目: OSPREY3   文件: ResidueForcefieldEnergyCuda.java
private double getEnergy(CUBuffer<IntBuffer> indices) {
	
	// check broken-ness first. easy peasy
	if (isBroken) {
		return Double.POSITIVE_INFINITY;
	}
	
	// make sure this thread can use the cuda context
	getStream().getContext().attachCurrentThread();
	
	// capture the current molecule state
	DoubleBuffer coordsbuf = coords.getHostBuffer();
	coordsbuf.clear();
	for (Residue res : residues) {
		coordsbuf.put(res.coords);
	}
	coordsbuf.clear();
	coords.uploadAsync();
	
	// launch kernel
	func.setArgs(Pointer.to(
		coords.getDevicePointer(),
		data.getDevicePointer(),
		Pointer.to(new int[] { indices.getHostBuffer().limit() }),
		indices.getDevicePointer(),
		energy.getDevicePointer()
	));
	func.runAsync();
	
	// download the energy
	DoubleBuffer buf = energy.downloadSync();
	buf.rewind();
	return buf.get();
}
 
源代码17 项目: netcdf-java   文件: ArrayDouble.java
public ByteBuffer getDataAsByteBuffer() {
  ByteBuffer bb = ByteBuffer.allocate((int) (8 * getSize()));
  DoubleBuffer ib = bb.asDoubleBuffer();
  ib.put((double[]) get1DJavaArray(DataType.DOUBLE)); // make sure its in canonical order
  return bb;
}
 
源代码18 项目: es6draft   文件: TypedArrayFunctions.java
private static final void put(IntToDoubleFunction src, int srcPos, DoubleBuffer dest, int destPos, int length) {
    for (int n = destPos, k = srcPos; k < srcPos + length;) {
        dest.put(n++, src.applyAsDouble(k++));
    }
}
 
源代码19 项目: MeteoInfo   文件: ArrayDouble.java
public ByteBuffer getDataAsByteBuffer() {
    ByteBuffer bb = ByteBuffer.allocate((int) (8 * getSize()));
    DoubleBuffer ib = bb.asDoubleBuffer();
    ib.put((double[]) get1DJavaArray(double.class)); // make sure its in canonical order
    return bb;
}
 
源代码20 项目: openjdk-jdk9   文件: ByteBufferTest.java
void putDouble(DoubleBuffer v, double x) { putLongX(pos, Double.doubleToRawLongBits(x)); pos += 8; v.put(x); }