2525import io .bioimage .modelrunner .utils .CommonUtils ;
2626
2727import java .io .IOException ;
28+ import java .nio .ByteBuffer ;
2829import java .util .Arrays ;
2930
3031import org .bytedeco .pytorch .Tensor ;
@@ -80,7 +81,8 @@ private static void buildFromTensorByte(Tensor tensor, String memoryName) throws
8081 throw new IllegalArgumentException ("Model output tensor with shape " + Arrays .toString (arrayShape )
8182 + " is too big. Max number of elements per ubyte output tensor supported: " + Integer .MAX_VALUE / 1 );
8283 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new UnsignedByteType (), false , true );
83- tensor .data_ptr_byte ().get (shma .getDataBufferNoHeader ().array ());
84+ ByteBuffer buff = shma .getDataBufferNoHeader ();
85+ buff = tensor .asByteBuffer ();
8486 if (PlatformDetection .isWindows ()) shma .close ();
8587 }
8688
@@ -91,7 +93,8 @@ private static void buildFromTensorInt(Tensor tensor, String memoryName) throws
9193 throw new IllegalArgumentException ("Model output tensor with shape " + Arrays .toString (arrayShape )
9294 + " is too big. Max number of elements per int output tensor supported: " + Integer .MAX_VALUE / 4 );
9395 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new UnsignedByteType (), false , true );
94- tensor .data_ptr_byte ().get (shma .getDataBufferNoHeader ().array ());
96+ ByteBuffer buff = shma .getDataBufferNoHeader ();
97+ buff = tensor .asByteBuffer ();
9598 if (PlatformDetection .isWindows ()) shma .close ();
9699 }
97100
@@ -102,7 +105,8 @@ private static void buildFromTensorFloat(Tensor tensor, String memoryName) throw
102105 throw new IllegalArgumentException ("Model output tensor with shape " + Arrays .toString (arrayShape )
103106 + " is too big. Max number of elements per float output tensor supported: " + Integer .MAX_VALUE / 4 );
104107 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new UnsignedByteType (), false , true );
105- tensor .data_ptr_byte ().get (shma .getDataBufferNoHeader ().array ());
108+ ByteBuffer buff = shma .getDataBufferNoHeader ();
109+ buff = tensor .asByteBuffer ();
106110 if (PlatformDetection .isWindows ()) shma .close ();
107111 }
108112
@@ -113,7 +117,8 @@ private static void buildFromTensorDouble(Tensor tensor, String memoryName) thro
113117 throw new IllegalArgumentException ("Model output tensor with shape " + Arrays .toString (arrayShape )
114118 + " is too big. Max number of elements per double output tensor supported: " + Integer .MAX_VALUE / 8 );
115119 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new UnsignedByteType (), false , true );
116- tensor .data_ptr_byte ().get (shma .getDataBufferNoHeader ().array ());
120+ ByteBuffer buff = shma .getDataBufferNoHeader ();
121+ buff = tensor .asByteBuffer ();
117122 if (PlatformDetection .isWindows ()) shma .close ();
118123 }
119124
@@ -124,7 +129,8 @@ private static void buildFromTensorLong(Tensor tensor, String memoryName) throws
124129 throw new IllegalArgumentException ("Model output tensor with shape " + Arrays .toString (arrayShape )
125130 + " is too big. Max number of elements per long output tensor supported: " + Integer .MAX_VALUE / 8 );
126131 SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new UnsignedByteType (), false , true );
127- tensor .data_ptr_byte ().get (shma .getDataBufferNoHeader ().array ());
132+ ByteBuffer buff = shma .getDataBufferNoHeader ();
133+ buff = tensor .asByteBuffer ();
128134 if (PlatformDetection .isWindows ()) shma .close ();
129135 }
130136}
0 commit comments