本文整理汇总了Java中java.nio.LongBuffer.allocate方法的典型用法代码示例。如果您正苦于以下问题:Java LongBuffer.allocate方法的具体用法?Java LongBuffer.allocate怎么用?Java LongBuffer.allocate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.LongBuffer
的用法示例。
在下文中一共展示了LongBuffer.allocate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toLongArray
import java.nio.LongBuffer; //导入方法依赖的package包/类
static
public long[] toLongArray(Tensor tensor){
LongBuffer longBuffer = LongBuffer.allocate(tensor.numElements());
tensor.writeTo(longBuffer);
return longBuffer.array();
}
示例2: getCompressedCounts
import java.nio.LongBuffer; //导入方法依赖的package包/类
@Override
public long[] getCompressedCounts() {
LongBuffer buf = LongBuffer.allocate(200);
Simple64.compress(buf, counts, 0, counts.length);
long[] r = new long[buf.position()];
buf.flip();
buf.get(r);
return r;
}
示例3: getCompressedCounts
import java.nio.LongBuffer; //导入方法依赖的package包/类
@Override
public long[] getCompressedCounts() {
LongBuffer buf = LongBuffer.allocate(counts.length);
Simple64.compress(buf, counts, 0, counts.length);
long[] r = new long[buf.position()];
buf.flip();
buf.get(r);
return r;
}
示例4: generateLongBuffer
import java.nio.LongBuffer; //导入方法依赖的package包/类
@Generates private LongBuffer generateLongBuffer() {
return LongBuffer.allocate(generateInt());
}
示例5: testTensorToImgReverse
import java.nio.LongBuffer; //导入方法依赖的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);
}
示例6: testTensorToImgDirect
import java.nio.LongBuffer; //导入方法依赖的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);
}
示例7: testTensorToImgMapping
import java.nio.LongBuffer; //导入方法依赖的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);
}