@@ -98,13 +98,8 @@ private static void buildFromTensorUByte(Tensor<TUint8> tensor, String memoryNam
98
98
throw new IllegalArgumentException ("Model output tensor with shape " + Arrays .toString (arrayShape )
99
99
+ " is too big. Max number of elements per ubyte output tensor supported: " + Integer .MAX_VALUE / 1 );
100
100
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new UnsignedByteType (), false , true );
101
- ByteBuffer buff = shma .getDataBuffer ();
102
- int totalSize = 1 ;
103
- for (long i : arrayShape ) {totalSize *= i ;}
104
- byte [] flatArr = new byte [buff .capacity ()];
105
- buff .get (flatArr );
106
- tensor .rawData ().read (flatArr , flatArr .length - totalSize , totalSize );
107
- shma .setBuffer (ByteBuffer .wrap (flatArr ));
101
+ ByteBuffer buff1 = shma .getDataBufferNoHeader ();
102
+ tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
108
103
if (PlatformDetection .isWindows ()) shma .close ();
109
104
}
110
105
@@ -116,13 +111,8 @@ private static void buildFromTensorInt(Tensor<TInt32> tensor, String memoryName)
116
111
+ " is too big. Max number of elements per int output tensor supported: " + Integer .MAX_VALUE / 4 );
117
112
118
113
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new IntType (), false , true );
119
- ByteBuffer buff = shma .getDataBuffer ();
120
- int totalSize = 4 ;
121
- for (long i : arrayShape ) {totalSize *= i ;}
122
- byte [] flatArr = new byte [buff .capacity ()];
123
- buff .get (flatArr );
124
- tensor .rawData ().read (flatArr , flatArr .length - totalSize , totalSize );
125
- shma .setBuffer (ByteBuffer .wrap (flatArr ));
114
+ ByteBuffer buff1 = shma .getDataBufferNoHeader ();
115
+ tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
126
116
if (PlatformDetection .isWindows ()) shma .close ();
127
117
}
128
118
@@ -134,13 +124,8 @@ private static void buildFromTensorFloat(Tensor<TFloat32> tensor, String memoryN
134
124
+ " is too big. Max number of elements per float output tensor supported: " + Integer .MAX_VALUE / 4 );
135
125
136
126
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new FloatType (), false , true );
137
- ByteBuffer buff = shma .getDataBuffer ();
138
- int totalSize = 4 ;
139
- for (long i : arrayShape ) {totalSize *= i ;}
140
- byte [] flatArr = new byte [buff .capacity ()];
141
- buff .get (flatArr );
142
- tensor .rawData ().read (flatArr , flatArr .length - totalSize , totalSize );
143
- shma .setBuffer (ByteBuffer .wrap (flatArr ));
127
+ ByteBuffer buff1 = shma .getDataBufferNoHeader ();
128
+ tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
144
129
if (PlatformDetection .isWindows ()) shma .close ();
145
130
}
146
131
@@ -152,13 +137,8 @@ private static void buildFromTensorDouble(Tensor<TFloat64> tensor, String memory
152
137
+ " is too big. Max number of elements per double output tensor supported: " + Integer .MAX_VALUE / 8 );
153
138
154
139
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new DoubleType (), false , true );
155
- ByteBuffer buff = shma .getDataBuffer ();
156
- int totalSize = 8 ;
157
- for (long i : arrayShape ) {totalSize *= i ;}
158
- byte [] flatArr = new byte [buff .capacity ()];
159
- buff .get (flatArr );
160
- tensor .rawData ().read (flatArr , flatArr .length - totalSize , totalSize );
161
- shma .setBuffer (ByteBuffer .wrap (flatArr ));
140
+ ByteBuffer buff1 = shma .getDataBufferNoHeader ();
141
+ tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
162
142
if (PlatformDetection .isWindows ()) shma .close ();
163
143
}
164
144
@@ -171,13 +151,8 @@ private static void buildFromTensorLong(Tensor<TInt64> tensor, String memoryName
171
151
172
152
173
153
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new LongType (), false , true );
174
- ByteBuffer buff = shma .getDataBuffer ();
175
- int totalSize = 8 ;
176
- for (long i : arrayShape ) {totalSize *= i ;}
177
- byte [] flatArr = new byte [buff .capacity ()];
178
- buff .get (flatArr );
179
- tensor .rawData ().read (flatArr , flatArr .length - totalSize , totalSize );
180
- shma .setBuffer (ByteBuffer .wrap (flatArr ));
154
+ ByteBuffer buff1 = shma .getDataBufferNoHeader ();
155
+ tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
181
156
if (PlatformDetection .isWindows ()) shma .close ();
182
157
}
183
158
}
0 commit comments