本文整理匯總了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);
}