本文整理汇总了Java中java.nio.DoubleBuffer.allocate方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleBuffer.allocate方法的具体用法?Java DoubleBuffer.allocate怎么用?Java DoubleBuffer.allocate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.DoubleBuffer
的用法示例。
在下文中一共展示了DoubleBuffer.allocate方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clone
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
/**
* 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 (isDirect(buf)) {
copy = createDoubleBuffer(buf.limit());
} else {
copy = DoubleBuffer.allocate(buf.limit());
}
copy.put(buf);
return copy;
}
示例2: getWorldCoordinates
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
public static Location getWorldCoordinates(GL gl, GLU glu, Location screen, Location store) {
if (store == null) {
store = new Location(0,0,0);
}
// Modelview matrix
DoubleBuffer mvBuffer = DoubleBuffer.allocate(16);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvBuffer);
// Projection_matrix
DoubleBuffer prBuffer = DoubleBuffer.allocate(16);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, prBuffer);
// Viewport matrix
IntBuffer vpBuffer = IntBuffer.allocate(16); // 4 is necessary
gl.glGetIntegerv(GL.GL_VIEWPORT, vpBuffer);
// 3d coordinates
DoubleBuffer result = DoubleBuffer.allocate(3);
glu.gluUnProject(screen.x,
screen.y,
screen.z,
mvBuffer,
prBuffer,
vpBuffer,
result);
store = new Location(result.get(0), result.get(1), result.get(2));
return store;
}
示例3: getScreenCoordinates
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
public static Location getScreenCoordinates(GL gl, GLU glu, Location worldPosition, Location store) {
if (store == null) {
store = new Location(0,0,0);
}
// Modelview matrix
DoubleBuffer mvBuffer = DoubleBuffer.allocate(16);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvBuffer);
// Projection_matrix
DoubleBuffer prBuffer = DoubleBuffer.allocate(16);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, prBuffer);
// Viewport matrix
IntBuffer vpBuffer = IntBuffer.allocate(16);
gl.glGetIntegerv(GL.GL_VIEWPORT, vpBuffer);
DoubleBuffer result = DoubleBuffer.allocate(3);
glu.gluProject(worldPosition.x,
worldPosition.y,
worldPosition.z,
mvBuffer,
prBuffer,
vpBuffer,
result);
store = new Location(result.get(0), result.get(1), result.get(2));
return store;
}
示例4: toArray
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
@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();
}
示例5: baseTest
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
@Test
public void baseTest() throws IOException {
UncompressedDoubleArrayChunk chunk = new UncompressedDoubleArrayChunk(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()));
}
示例6: asDoubleBuffer
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
public DoubleBuffer asDoubleBuffer()
{
DoubleBuffer buffer = DoubleBuffer.allocate(4*4);
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
buffer.put(data[i][j]);
buffer.flip();
return buffer;
}
示例7: toDoubleArray
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
static
public double[] toDoubleArray(Tensor tensor){
DoubleBuffer doubleBuffer = DoubleBuffer.allocate(tensor.numElements());
tensor.writeTo(doubleBuffer);
return doubleBuffer.array();
}
示例8: compressTest
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
@Test
public void compressTest() throws IOException {
UncompressedDoubleArrayChunk chunk = new UncompressedDoubleArrayChunk(1, new double[] {1d, 2d, 2d, 2d, 2d, 3d});
DoubleArrayChunk maybeCompressedChunk = chunk.tryToCompress();
assertTrue(maybeCompressedChunk instanceof CompressedDoubleArrayChunk);
CompressedDoubleArrayChunk compressedChunk = (CompressedDoubleArrayChunk) 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 = new ObjectMapper()
.registerModule(new TimeSeriesJsonModule());
List<DoubleArrayChunk> chunks = objectMapper.readValue(objectMapper.writeValueAsString(Arrays.asList(chunk, compressedChunk)),
TypeFactory.defaultInstance().constructCollectionType(List.class, DoubleArrayChunk.class));
assertEquals(2, chunks.size());
assertEquals(chunk, chunks.get(0));
assertEquals(compressedChunk, chunks.get(1));
// check base class (ArrayChunk) deserializer
assertTrue(objectMapper.readValue(objectMapper.writeValueAsString(chunk), ArrayChunk.class) instanceof DoubleArrayChunk);
// 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()));
}
示例9: generateDoubleBuffer
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
@Generates private DoubleBuffer generateDoubleBuffer() {
return DoubleBuffer.allocate(generateInt());
}
示例10: testTensorToImgReverse
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
/** Tests the img<Type>(Tensor) functions */
@Test
public void testTensorToImgReverse() {
final long[] shape = new long[] { 20, 10, 3 };
final int[] mapping = new int[] { 2, 1, 0 };
final long[] dims = new long[] { 3, 10, 20 };
final int n = shape.length;
final int size = 600;
// Get some points to mark
List<Point> points = createTestPoints(n);
// Create Tensors of different type and convert them to images
ByteBuffer dataByte = ByteBuffer.allocateDirect(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataByte.put(i, (byte) (int) v));
Tensor tensorByte = Tensor.create(DataType.UINT8, shape, dataByte);
Img<ByteType> imgByte = Tensors.imgByte(tensorByte);
DoubleBuffer dataDouble = DoubleBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataDouble.put(i, v));
Tensor tensorDouble = Tensor.create(shape, dataDouble);
Img<DoubleType> imgDouble = Tensors.imgDouble(tensorDouble);
FloatBuffer dataFloat = FloatBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataFloat.put(i, v));
Tensor tensorFloat = Tensor.create(shape, dataFloat);
Img<FloatType> imgFloat = Tensors.imgFloat(tensorFloat);
IntBuffer dataInt = IntBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataInt.put(i, v));
Tensor tensorInt = Tensor.create(shape, dataInt);
Img<IntType> imgInt = Tensors.imgInt(tensorInt);
LongBuffer dataLong = LongBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataLong.put(i, v));
Tensor tensorLong = Tensor.create(shape, dataLong);
Img<LongType> imgLong = Tensors.imgLong(tensorLong);
// Check all created images
checkImage(imgByte, n, dims, points);
checkImage(imgDouble, n, dims, points);
checkImage(imgFloat, n, dims, points);
checkImage(imgInt, n, dims, points);
checkImage(imgLong, n, dims, points);
}
示例11: testTensorToImgDirect
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
/** Tests the img<Type>Direct(Tensor) functions */
@Test
public void testTensorToImgDirect() {
final long[] shape = new long[] { 20, 10, 3 };
final int[] mapping = new int[] { 0, 1, 2 };
final int n = shape.length;
final int size = 600;
// Get some points to mark
List<Point> points = createTestPoints(n);
// Create Tensors of different type and convert them to images
ByteBuffer dataByte = ByteBuffer.allocateDirect(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataByte.put(i, (byte) (int) v));
Tensor tensorByte = Tensor.create(DataType.UINT8, shape, dataByte);
Img<ByteType> imgByte = Tensors.imgByteDirect(tensorByte);
DoubleBuffer dataDouble = DoubleBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataDouble.put(i, v));
Tensor tensorDouble = Tensor.create(shape, dataDouble);
Img<DoubleType> imgDouble = Tensors.imgDoubleDirect(tensorDouble);
FloatBuffer dataFloat = FloatBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataFloat.put(i, v));
Tensor tensorFloat = Tensor.create(shape, dataFloat);
Img<FloatType> imgFloat = Tensors.imgFloatDirect(tensorFloat);
IntBuffer dataInt = IntBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataInt.put(i, v));
Tensor tensorInt = Tensor.create(shape, dataInt);
Img<IntType> imgInt = Tensors.imgIntDirect(tensorInt);
LongBuffer dataLong = LongBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataLong.put(i, v));
Tensor tensorLong = Tensor.create(shape, dataLong);
Img<LongType> imgLong = Tensors.imgLongDirect(tensorLong);
// Check all created images
checkImage(imgByte, n, shape, points);
checkImage(imgDouble, n, shape, points);
checkImage(imgFloat, n, shape, points);
checkImage(imgInt, n, shape, points);
checkImage(imgLong, n, shape, points);
}
示例12: testTensorToImgMapping
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
/** Tests the img<Type>(Tensor, int[]) functions */
@Test
public void testTensorToImgMapping() {
final long[] shape = new long[] { 3, 5, 2, 4 };
final int[] mapping = new int[] { 1, 3, 0, 2 }; // A strange mapping
final long[] dims = new long[] { 5, 4, 3, 2 };
final int n = shape.length;
final int size = 120;
// Get some points to mark
List<Point> points = createTestPoints(n);
// Create Tensors of different type and convert them to images
ByteBuffer dataByte = ByteBuffer.allocateDirect(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataByte.put(i, (byte) (int) v));
Tensor tensorByte = Tensor.create(DataType.UINT8, shape, dataByte);
Img<ByteType> imgByte = Tensors.imgByte(tensorByte, mapping);
DoubleBuffer dataDouble = DoubleBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataDouble.put(i, v));
Tensor tensorDouble = Tensor.create(shape, dataDouble);
Img<DoubleType> imgDouble = Tensors.imgDouble(tensorDouble, mapping);
FloatBuffer dataFloat = FloatBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataFloat.put(i, v));
Tensor tensorFloat = Tensor.create(shape, dataFloat);
Img<FloatType> imgFloat = Tensors.imgFloat(tensorFloat, mapping);
IntBuffer dataInt = IntBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataInt.put(i, v));
Tensor tensorInt = Tensor.create(shape, dataInt);
Img<IntType> imgInt = Tensors.imgInt(tensorInt, mapping);
LongBuffer dataLong = LongBuffer.allocate(size);
execForPointsWithBufferIndex(shape, mapping, points, (i, v) -> dataLong.put(i, v));
Tensor tensorLong = Tensor.create(shape, dataLong);
Img<LongType> imgLong = Tensors.imgLong(tensorLong, mapping);
// Check all created images
checkImage(imgByte, n, dims, points);
checkImage(imgDouble, n, dims, points);
checkImage(imgFloat, n, dims, points);
checkImage(imgInt, n, dims, points);
checkImage(imgLong, n, dims, points);
}
示例13: BufferArray
import java.nio.DoubleBuffer; //导入方法依赖的package包/类
/**
* Constructor
* @param size initial size
*/
public BufferArray(final int size) {
buf = DoubleBuffer.allocate(size);
}