@@ -98,8 +98,11 @@ 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 buff1 = shma .getDataBufferNoHeader ();
102
- tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
101
+ ByteBuffer buff = shma .getDataBufferNoHeader ();
102
+ byte [] flat = new byte [buff .capacity ()];
103
+ ByteBuffer buff2 = ByteBuffer .wrap (flat );
104
+ tensor .rawData ().read (flat , 0 , buff .capacity ());
105
+ buff = buff2 ;
103
106
if (PlatformDetection .isWindows ()) shma .close ();
104
107
}
105
108
@@ -111,8 +114,11 @@ private static void buildFromTensorInt(Tensor<TInt32> tensor, String memoryName)
111
114
+ " is too big. Max number of elements per int output tensor supported: " + Integer .MAX_VALUE / 4 );
112
115
113
116
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new IntType (), false , true );
114
- ByteBuffer buff1 = shma .getDataBufferNoHeader ();
115
- tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
117
+ ByteBuffer buff = shma .getDataBufferNoHeader ();
118
+ byte [] flat = new byte [buff .capacity ()];
119
+ ByteBuffer buff2 = ByteBuffer .wrap (flat );
120
+ tensor .rawData ().read (flat , 0 , buff .capacity ());
121
+ buff = buff2 ;
116
122
if (PlatformDetection .isWindows ()) shma .close ();
117
123
}
118
124
@@ -124,8 +130,11 @@ private static void buildFromTensorFloat(Tensor<TFloat32> tensor, String memoryN
124
130
+ " is too big. Max number of elements per float output tensor supported: " + Integer .MAX_VALUE / 4 );
125
131
126
132
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new FloatType (), false , true );
127
- ByteBuffer buff1 = shma .getDataBufferNoHeader ();
128
- tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
133
+ ByteBuffer buff = shma .getDataBufferNoHeader ();
134
+ byte [] flat = new byte [buff .capacity ()];
135
+ ByteBuffer buff2 = ByteBuffer .wrap (flat );
136
+ tensor .rawData ().read (flat , 0 , buff .capacity ());
137
+ buff = buff2 ;
129
138
if (PlatformDetection .isWindows ()) shma .close ();
130
139
}
131
140
@@ -137,8 +146,11 @@ private static void buildFromTensorDouble(Tensor<TFloat64> tensor, String memory
137
146
+ " is too big. Max number of elements per double output tensor supported: " + Integer .MAX_VALUE / 8 );
138
147
139
148
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new DoubleType (), false , true );
140
- ByteBuffer buff1 = shma .getDataBufferNoHeader ();
141
- tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
149
+ ByteBuffer buff = shma .getDataBufferNoHeader ();
150
+ byte [] flat = new byte [buff .capacity ()];
151
+ ByteBuffer buff2 = ByteBuffer .wrap (flat );
152
+ tensor .rawData ().read (flat , 0 , buff .capacity ());
153
+ buff = buff2 ;
142
154
if (PlatformDetection .isWindows ()) shma .close ();
143
155
}
144
156
@@ -151,8 +163,11 @@ private static void buildFromTensorLong(Tensor<TInt64> tensor, String memoryName
151
163
152
164
153
165
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new LongType (), false , true );
154
- ByteBuffer buff1 = shma .getDataBufferNoHeader ();
155
- tensor .rawData ().read (buff1 .array (), 0 , buff1 .capacity ());
166
+ ByteBuffer buff = shma .getDataBufferNoHeader ();
167
+ byte [] flat = new byte [buff .capacity ()];
168
+ ByteBuffer buff2 = ByteBuffer .wrap (flat );
169
+ tensor .rawData ().read (flat , 0 , buff .capacity ());
170
+ buff = buff2 ;
156
171
if (PlatformDetection .isWindows ()) shma .close ();
157
172
}
158
173
}
0 commit comments