Skip to content

Commit

Permalink
revert error
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 18, 2024
1 parent 847bde2 commit 510d93c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 43 deletions.
34 changes: 12 additions & 22 deletions src/main/java/io/bioimage/modelrunner/tensor/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,17 @@ RandomAccessibleInterval<T> transpose(RandomAccessibleInterval<T> rai){
*/
public static <T extends NumericType<T> & RealType<T>>
RandomAccessibleInterval<T> rearangeAxes(RandomAccessibleInterval<T> rai, int[] orderChange){
if (rai.dimensionsAsLongArray().length != orderChange.length)
throw new IllegalArgumentException("The parameter 'orderChange' should have the same dimensions as the array provided witht he first parameter 'rai'.");
List<Integer> checker = new ArrayList<Integer>();
for (int i : orderChange) {
if (!checker.contains(i))
checker.add(i);
}
if (checker.size() != orderChange.length)
throw new IllegalArgumentException("The 'orderChange' parameter should not contain repeated"
+ " numbers and should go from 0 to rai.dimensionsAsLongArray().length - 1");
long[] max = rai.maxAsPoint().positionAsLongArray();
long[] min = rai.minAsPoint().positionAsLongArray();
long[] tensorShape = rai.dimensionsAsLongArray();
MixedTransform t = new MixedTransform( tensorShape.length, tensorShape.length );
t.setComponentMapping(orderChange);
long[] minMax = new long[tensorShape.length * 2];
for (int i = 0; i < tensorShape.length; i ++) {
minMax[i] = min[orderChange[i]];
minMax[i + tensorShape.length] = max[orderChange[i]];
}
return Views.interval(new MixedTransformView<T>( rai, t ),
Intervals.createMinMax(minMax));
final int n = rai.numDimensions();
final long[] min = new long[n];
final long[] max = new long[n];
final int[] invOrderChange = new int[n];
for (int i = 0; i < n; i++) {
min[i] = rai.min(orderChange[i]);
max[i] = rai.max(orderChange[i]);
invOrderChange[orderChange[i]] = i;
}
MixedTransform t = new MixedTransform(n, n);
t.setComponentMapping(invOrderChange);
return Views.interval(new MixedTransformView<>(rai, t), min, max);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ private void buildInt8(RandomAccessibleInterval<ByteType> tensor, boolean isFort
Cursor<ByteType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setByte(offset + (i ++), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setByte(offset + (i ++), cursor.get().get());
}
}

Expand Down Expand Up @@ -522,8 +522,8 @@ private void buildInt16(RandomAccessibleInterval<ShortType> tensor, boolean isFo
Cursor<ShortType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setShort(offset + (i * Short.BYTES), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setShort(offset + (i * Short.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -541,8 +541,8 @@ private void buildUint16(RandomAccessibleInterval<UnsignedShortType> tensor, boo
Cursor<UnsignedShortType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setShort(offset + (i * Short.BYTES), cursor.get().getShort());
cursor.fwd();
this.pSharedMemory.setShort(offset + (i * Short.BYTES), cursor.get().getShort());
i ++;
}
}
Expand Down Expand Up @@ -617,8 +617,8 @@ private void buildFloat32(RandomAccessibleInterval<FloatType> tensor, boolean is
Cursor<FloatType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setFloat(offset + (i * Float.BYTES), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setFloat(offset + (i * Float.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -636,8 +636,8 @@ private void buildFloat64(RandomAccessibleInterval<DoubleType> tensor, boolean i
Cursor<DoubleType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setDouble(offset + (i * Double.BYTES), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setDouble(offset + (i * Double.BYTES), cursor.get().get());
i ++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ private void buildInt8(RandomAccessibleInterval<ByteType> tensor, boolean isFort
Cursor<ByteType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setByte(offset + (i ++), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setByte(offset + (i ++), cursor.get().get());
}
}

Expand Down Expand Up @@ -477,8 +477,8 @@ private void buildInt16(RandomAccessibleInterval<ShortType> tensor, boolean isFo
Cursor<ShortType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setShort(offset + (i * Short.BYTES), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setShort(offset + (i * Short.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -496,8 +496,8 @@ private void buildUint16(RandomAccessibleInterval<UnsignedShortType> tensor, boo
Cursor<UnsignedShortType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setShort(offset + (i * Short.BYTES), cursor.get().getShort());
cursor.fwd();
this.pSharedMemory.setShort(offset + (i * Short.BYTES), cursor.get().getShort());
i ++;
}
}
Expand All @@ -515,8 +515,8 @@ private void buildInt32(RandomAccessibleInterval<IntType> tensor, boolean isFort
Cursor<IntType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setInt(offset + (i * Integer.BYTES), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setInt(offset + (i * Integer.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -534,8 +534,8 @@ private void buildUint32(RandomAccessibleInterval<UnsignedIntType> tensor, boole
Cursor<UnsignedIntType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setInt(offset + (i * Integer.BYTES), cursor.get().getInt());
cursor.fwd();
this.pSharedMemory.setInt(offset + (i * Integer.BYTES), cursor.get().getInt());
i ++;
}
}
Expand All @@ -553,8 +553,8 @@ private void buildInt64(RandomAccessibleInterval<LongType> tensor, boolean isFor
Cursor<LongType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setLong(offset + (i * Long.BYTES), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setLong(offset + (i * Long.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -572,8 +572,8 @@ private void buildFloat32(RandomAccessibleInterval<FloatType> tensor, boolean is
Cursor<FloatType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setFloat(offset + (i * Float.BYTES), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setFloat(offset + (i * Float.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -591,8 +591,8 @@ private void buildFloat64(RandomAccessibleInterval<DoubleType> tensor, boolean i
Cursor<DoubleType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.pSharedMemory.setDouble(offset + (i * Double.BYTES), cursor.get().get());
cursor.fwd();
this.pSharedMemory.setDouble(offset + (i * Double.BYTES), cursor.get().get());
i ++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ private void buildInt8(RandomAccessibleInterval<ByteType> tensor, boolean isFort
Cursor<ByteType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.mappedPointer.setByte(offset + (i ++), cursor.get().get());
cursor.fwd();
this.mappedPointer.setByte(offset + (i ++), cursor.get().get());
}
}

Expand Down Expand Up @@ -563,8 +563,8 @@ private void buildInt16(RandomAccessibleInterval<ShortType> tensor, boolean isFo
Cursor<ShortType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.mappedPointer.setShort(offset + (i * Short.BYTES), cursor.get().get());
cursor.fwd();
this.mappedPointer.setShort(offset + (i * Short.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -582,8 +582,8 @@ private void buildUint16(RandomAccessibleInterval<UnsignedShortType> tensor, boo
Cursor<UnsignedShortType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.mappedPointer.setShort(offset + (i * Short.BYTES), cursor.get().getShort());
cursor.fwd();
this.mappedPointer.setShort(offset + (i * Short.BYTES), cursor.get().getShort());
i ++;
}
}
Expand All @@ -601,8 +601,8 @@ private void buildInt32(RandomAccessibleInterval<IntType> tensor, boolean isFort
Cursor<IntType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.mappedPointer.setInt(offset + (i * Integer.BYTES), cursor.get().get());
cursor.fwd();
this.mappedPointer.setInt(offset + (i * Integer.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -620,8 +620,8 @@ private void buildUint32(RandomAccessibleInterval<UnsignedIntType> tensor, boole
Cursor<UnsignedIntType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.mappedPointer.setInt(offset + (i * Integer.BYTES), cursor.get().getInt());
cursor.fwd();
this.mappedPointer.setInt(offset + (i * Integer.BYTES), cursor.get().getInt());
i ++;
}
}
Expand All @@ -639,8 +639,8 @@ private void buildInt64(RandomAccessibleInterval<LongType> tensor, boolean isFor
Cursor<LongType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.mappedPointer.setLong(offset + (i * Long.BYTES), cursor.get().get());
cursor.fwd();
this.mappedPointer.setLong(offset + (i * Long.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -658,8 +658,8 @@ private void buildFloat32(RandomAccessibleInterval<FloatType> tensor, boolean is
Cursor<FloatType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.mappedPointer.setFloat(offset + (i * Float.BYTES), cursor.get().get());
cursor.fwd();
this.mappedPointer.setFloat(offset + (i * Float.BYTES), cursor.get().get());
i ++;
}
}
Expand All @@ -677,8 +677,8 @@ private void buildFloat64(RandomAccessibleInterval<DoubleType> tensor, boolean i
Cursor<DoubleType> cursor = Views.flatIterable(tensor).cursor();
long i = 0;
while (cursor.hasNext()) {
this.mappedPointer.setDouble(offset + (i * Double.BYTES), cursor.get().get());
cursor.fwd();
this.mappedPointer.setDouble(offset + (i * Double.BYTES), cursor.get().get());
i ++;
}
}
Expand Down

0 comments on commit 510d93c

Please sign in to comment.