diff --git a/src/main/java/io/bioimage/modelrunner/tensor/Utils.java b/src/main/java/io/bioimage/modelrunner/tensor/Utils.java index 683c9fac..05d5849d 100644 --- a/src/main/java/io/bioimage/modelrunner/tensor/Utils.java +++ b/src/main/java/io/bioimage/modelrunner/tensor/Utils.java @@ -80,27 +80,17 @@ RandomAccessibleInterval transpose(RandomAccessibleInterval rai){ */ public static & RealType> RandomAccessibleInterval rearangeAxes(RandomAccessibleInterval 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 checker = new ArrayList(); - 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( 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); } } diff --git a/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayLinux.java b/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayLinux.java index cacac1b8..16bde69d 100644 --- a/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayLinux.java +++ b/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayLinux.java @@ -486,8 +486,8 @@ private void buildInt8(RandomAccessibleInterval tensor, boolean isFort Cursor 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()); } } @@ -522,8 +522,8 @@ private void buildInt16(RandomAccessibleInterval tensor, boolean isFo Cursor 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 ++; } } @@ -541,8 +541,8 @@ private void buildUint16(RandomAccessibleInterval tensor, boo Cursor 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 ++; } } @@ -617,8 +617,8 @@ private void buildFloat32(RandomAccessibleInterval tensor, boolean is Cursor 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 ++; } } @@ -636,8 +636,8 @@ private void buildFloat64(RandomAccessibleInterval tensor, boolean i Cursor 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 ++; } } diff --git a/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayMacOS.java b/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayMacOS.java index 2dae1117..96ac6089 100644 --- a/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayMacOS.java +++ b/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayMacOS.java @@ -441,8 +441,8 @@ private void buildInt8(RandomAccessibleInterval tensor, boolean isFort Cursor 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()); } } @@ -477,8 +477,8 @@ private void buildInt16(RandomAccessibleInterval tensor, boolean isFo Cursor 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 ++; } } @@ -496,8 +496,8 @@ private void buildUint16(RandomAccessibleInterval tensor, boo Cursor 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 ++; } } @@ -515,8 +515,8 @@ private void buildInt32(RandomAccessibleInterval tensor, boolean isFort Cursor 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 ++; } } @@ -534,8 +534,8 @@ private void buildUint32(RandomAccessibleInterval tensor, boole Cursor 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 ++; } } @@ -553,8 +553,8 @@ private void buildInt64(RandomAccessibleInterval tensor, boolean isFor Cursor 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 ++; } } @@ -572,8 +572,8 @@ private void buildFloat32(RandomAccessibleInterval tensor, boolean is Cursor 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 ++; } } @@ -591,8 +591,8 @@ private void buildFloat64(RandomAccessibleInterval tensor, boolean i Cursor 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 ++; } } diff --git a/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayWin.java b/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayWin.java index 69aef967..0bea9ce5 100644 --- a/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayWin.java +++ b/src/main/java/io/bioimage/modelrunner/tensor/shm/SharedMemoryArrayWin.java @@ -527,8 +527,8 @@ private void buildInt8(RandomAccessibleInterval tensor, boolean isFort Cursor 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()); } } @@ -563,8 +563,8 @@ private void buildInt16(RandomAccessibleInterval tensor, boolean isFo Cursor 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 ++; } } @@ -582,8 +582,8 @@ private void buildUint16(RandomAccessibleInterval tensor, boo Cursor 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 ++; } } @@ -601,8 +601,8 @@ private void buildInt32(RandomAccessibleInterval tensor, boolean isFort Cursor 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 ++; } } @@ -620,8 +620,8 @@ private void buildUint32(RandomAccessibleInterval tensor, boole Cursor 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 ++; } } @@ -639,8 +639,8 @@ private void buildInt64(RandomAccessibleInterval tensor, boolean isFor Cursor 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 ++; } } @@ -658,8 +658,8 @@ private void buildFloat32(RandomAccessibleInterval tensor, boolean is Cursor 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 ++; } } @@ -677,8 +677,8 @@ private void buildFloat64(RandomAccessibleInterval tensor, boolean i Cursor 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 ++; } }