@@ -97,7 +97,10 @@ private static TUint8 buildUByte(SharedMemoryArray tensor)
97
97
if (!tensor .isNumpyFormat ())
98
98
throw new IllegalArgumentException ("Shared memory arrays must be saved in numpy format." );
99
99
ByteBuffer buff = tensor .getDataBufferNoHeader ();
100
- ByteDataBuffer dataBuffer = RawDataBufferFactory .create (buff .array (), false );
100
+ byte [] flat = new byte [buff .capacity ()];
101
+ buff .get (flat );
102
+ buff .rewind ();
103
+ ByteDataBuffer dataBuffer = RawDataBufferFactory .create (flat , false );
101
104
TUint8 ndarray = Tensor .of (TUint8 .class , Shape .of (ogShape ), dataBuffer );
102
105
return ndarray ;
103
106
}
@@ -112,7 +115,10 @@ private static TInt32 buildInt(SharedMemoryArray tensor)
112
115
if (!tensor .isNumpyFormat ())
113
116
throw new IllegalArgumentException ("Shared memory arrays must be saved in numpy format." );
114
117
ByteBuffer buff = tensor .getDataBufferNoHeader ();
115
- IntDataBuffer dataBuffer = RawDataBufferFactory .create (buff .asIntBuffer ().array (), false );
118
+ int [] flat = new int [buff .capacity () / 4 ];
119
+ buff .asIntBuffer ().get (flat );
120
+ buff .rewind ();
121
+ IntDataBuffer dataBuffer = RawDataBufferFactory .create (flat , false );
116
122
TInt32 ndarray = TInt32 .tensorOf (Shape .of (ogShape ),
117
123
dataBuffer );
118
124
return ndarray ;
@@ -128,7 +134,10 @@ private static TInt64 buildLong(SharedMemoryArray tensor)
128
134
if (!tensor .isNumpyFormat ())
129
135
throw new IllegalArgumentException ("Shared memory arrays must be saved in numpy format." );
130
136
ByteBuffer buff = tensor .getDataBufferNoHeader ();
131
- LongDataBuffer dataBuffer = RawDataBufferFactory .create (buff .asLongBuffer ().array (), false );
137
+ long [] flat = new long [buff .capacity () / 8 ];
138
+ buff .asLongBuffer ().get (flat );
139
+ buff .rewind ();
140
+ LongDataBuffer dataBuffer = RawDataBufferFactory .create (flat , false );
132
141
TInt64 ndarray = TInt64 .tensorOf (Shape .of (ogShape ),
133
142
dataBuffer );
134
143
return ndarray ;
@@ -144,7 +153,10 @@ private static TFloat32 buildFloat(SharedMemoryArray tensor)
144
153
if (!tensor .isNumpyFormat ())
145
154
throw new IllegalArgumentException ("Shared memory arrays must be saved in numpy format." );
146
155
ByteBuffer buff = tensor .getDataBufferNoHeader ();
147
- FloatDataBuffer dataBuffer = RawDataBufferFactory .create (buff .asFloatBuffer ().array (), false );
156
+ float [] flat = new float [buff .capacity () / 4 ];
157
+ buff .asFloatBuffer ().get (flat );
158
+ buff .rewind ();
159
+ FloatDataBuffer dataBuffer = RawDataBufferFactory .create (flat , false );
148
160
TFloat32 ndarray = TFloat32 .tensorOf (Shape .of (ogShape ), dataBuffer );
149
161
return ndarray ;
150
162
}
@@ -159,7 +171,10 @@ private static TFloat64 buildDouble(SharedMemoryArray tensor)
159
171
if (!tensor .isNumpyFormat ())
160
172
throw new IllegalArgumentException ("Shared memory arrays must be saved in numpy format." );
161
173
ByteBuffer buff = tensor .getDataBufferNoHeader ();
162
- DoubleDataBuffer dataBuffer = RawDataBufferFactory .create (buff .asDoubleBuffer ().array (), false );
174
+ double [] flat = new double [buff .capacity () / 8 ];
175
+ buff .asDoubleBuffer ().get (flat );
176
+ buff .rewind ();
177
+ DoubleDataBuffer dataBuffer = RawDataBufferFactory .create (flat , false );
163
178
TFloat64 ndarray = TFloat64 .tensorOf (Shape .of (ogShape ), dataBuffer );
164
179
return ndarray ;
165
180
}
0 commit comments