Skip to content

Commit 58bd149

Browse files
committed
just copy it
1 parent b006f0b commit 58bd149

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/io/bioimage/modelrunner/pytorch/javacpp/shm/ShmBuilder.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,15 @@ private static void buildFromTensorFloat(Tensor tensor, String memoryName) throw
111111
throw new IllegalArgumentException("Model output tensor with shape " + Arrays.toString(arrayShape)
112112
+ " is too big. Max number of elements per float output tensor supported: " + Integer.MAX_VALUE / 4);
113113
SharedMemoryArray shma = SharedMemoryArray.readOrCreate(memoryName, arrayShape, new FloatType(), false, true);
114-
/*long flatSize = 1;
114+
long flatSize = 1;
115115
for (long l : arrayShape) {flatSize *= l;}
116-
ByteBuffer byteBuffer = ByteBuffer.allocate((int) (flatSize * Float.BYTES));
117-
tensor.data_ptr_float().get(byteBuffer.asFloatBuffer().array());
116+
float[] flat = new float[(int) flatSize];
117+
ByteBuffer byteBuffer = ByteBuffer.allocateDirect((int) (flatSize * Float.BYTES));
118+
FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
119+
tensor.data_ptr_float().get(flat);
120+
floatBuffer.put(flatSize);
121+
byteBuffer.rewind();
118122
shma.getDataBufferNoHeader().put(byteBuffer);
119-
*/
120-
RandomAccessibleInterval<?> rai = shma.getSharedRAI();
121-
rai = ImgLib2Builder.build(tensor);
122123
if (PlatformDetection.isWindows()) shma.close();
123124
}
124125

0 commit comments

Comments
 (0)