Skip to content

Commit 88667e5

Browse files
committed
correct bug
1 parent 616aa98 commit 88667e5

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

Diff for: src/main/java/io/bioimage/modelrunner/pytorch/shm/TensorBuilder.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private static NDArray buildUByte(SharedMemoryArray tensor, NDManager manager)
9393
if (!tensor.isNumpyFormat())
9494
throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format.");
9595
ByteBuffer buff = tensor.getDataBufferNoHeader();
96-
NDArray ndarray = manager.create(buff.array(), new Shape(ogShape));
96+
NDArray ndarray = manager.create(buff, new Shape(ogShape));
9797
return ndarray;
9898
}
9999

@@ -108,9 +108,7 @@ private static NDArray buildInt(SharedMemoryArray tensor, NDManager manager)
108108
throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format.");
109109
ByteBuffer buff = tensor.getDataBufferNoHeader();
110110
IntBuffer intBuff = buff.asIntBuffer();
111-
int[] intArray = new int[intBuff.capacity()];
112-
intBuff.get(intArray);
113-
NDArray ndarray = manager.create(intBuff.array(), new Shape(ogShape));
111+
NDArray ndarray = manager.create(intBuff, new Shape(ogShape));
114112
return ndarray;
115113
}
116114

@@ -125,9 +123,7 @@ private static NDArray buildLong(SharedMemoryArray tensor, NDManager manager)
125123
throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format.");
126124
ByteBuffer buff = tensor.getDataBufferNoHeader();
127125
LongBuffer longBuff = buff.asLongBuffer();
128-
long[] longArray = new long[longBuff.capacity()];
129-
longBuff.get(longArray);
130-
NDArray ndarray = manager.create(longBuff.array(), new Shape(ogShape));
126+
NDArray ndarray = manager.create(longBuff, new Shape(ogShape));
131127
return ndarray;
132128
}
133129

@@ -142,8 +138,6 @@ private static NDArray buildFloat(SharedMemoryArray tensor, NDManager manager)
142138
throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format.");
143139
ByteBuffer buff = tensor.getDataBufferNoHeader();
144140
FloatBuffer floatBuff = buff.asFloatBuffer();
145-
//float[] floatArray = new float[floatBuff.capacity()];
146-
//floatBuff.get(floatArray);
147141
NDArray ndarray = manager.create(floatBuff, new Shape(ogShape));
148142
return ndarray;
149143
}
@@ -159,9 +153,7 @@ private static NDArray buildDouble(SharedMemoryArray tensor, NDManager manager)
159153
throw new IllegalArgumentException("Shared memory arrays must be saved in numpy format.");
160154
ByteBuffer buff = tensor.getDataBufferNoHeader();
161155
DoubleBuffer doubleBuff = buff.asDoubleBuffer();
162-
double[] doubleArray = new double[doubleBuff.capacity()];
163-
doubleBuff.get(doubleArray);
164-
NDArray ndarray = manager.create(doubleBuff.array(), new Shape(ogShape));
156+
NDArray ndarray = manager.create(doubleBuff, new Shape(ogShape));
165157
return ndarray;
166158
}
167159
}

0 commit comments

Comments
 (0)