Skip to content

Commit 4598798

Browse files
committed
ImgMath: fix critical error in VarargsFunction: when the length of the array
was 2, the first operation was being duplicated. While this wouldn't be an issue in java, it shows in scripting languages that fail to use the 2-arg constructor and instead use the varags one.
1 parent 29089c5 commit 4598798

File tree

15 files changed

+46
-19
lines changed

15 files changed

+46
-19
lines changed

src/main/java/net/imglib2/algorithm/math/Add.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public < O extends RealType< O > > Addition< O > reInit(
2626
final O tmp,
2727
final Map< String, O > bindings,
2828
final Converter< RealType< ? >, O > converter,
29-
Map< Variable< O >, OFunction< O > > imgSources )
29+
final Map< Variable< O >, OFunction< O > > imgSources )
3030
{
31-
return new Addition< O >( tmp.copy(), this.a.reInit( tmp, bindings, converter, imgSources ), this.b.reInit( tmp, bindings, converter, imgSources ) );
31+
return new Addition< O >( tmp.copy(),
32+
this.a.reInit( tmp, bindings, converter, imgSources ),
33+
this.b.reInit( tmp, bindings, converter, imgSources ) );
3234
}
3335
}

src/main/java/net/imglib2/algorithm/math/Compute.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public final void convert( final RealType< ? > input, final O output)
7979
output.setReal( input.getRealDouble() );
8080
}
8181
};
82-
82+
8383
// Recursive copy: initializes interval iterators and sets temporary computation holder
8484
final OFunction< O > f = this.operation.reInit(
8585
target.randomAccess().get().createVariable(),
8686
new HashMap< String, O >(),
8787
converter, null );
8888

8989
// Check compatible iteration order and dimensions
90-
if ( compatible_iteration_order )
90+
if ( this.compatible_iteration_order )
9191
{
9292
// Evaluate function for every pixel
9393
for ( final O output : Views.iterable( target ) )

src/main/java/net/imglib2/algorithm/math/Div.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public < O extends RealType< O > > Division< O > reInit(
2727
final O tmp,
2828
final Map< String, O > bindings,
2929
final Converter< RealType< ? >, O > converter,
30-
Map< Variable< O >, OFunction< O > > imgSources )
30+
final Map< Variable< O >, OFunction< O > > imgSources )
3131
{
32-
return new Division< O >( tmp.copy(), this.a.reInit( tmp, bindings, converter, imgSources ), this.b.reInit( tmp, bindings, converter, imgSources ) );
32+
return new Division< O >( tmp.copy(),
33+
this.a.reInit( tmp, bindings, converter, imgSources ),
34+
this.b.reInit( tmp, bindings, converter, imgSources ) );
3335
}
3436
}

src/main/java/net/imglib2/algorithm/math/Equal.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public < O extends RealType< O > > OFunction< O > reInit(
2323
final Converter< RealType< ? >, O > converter,
2424
final Map< Variable< O >, OFunction< O > > imgSources )
2525
{
26-
return new Equality< O >( tmp.copy(), this.a.reInit( tmp, bindings, converter, imgSources ), this.b.reInit( tmp, bindings, converter, imgSources ) );
26+
return new Equality< O >( tmp.copy(),
27+
this.a.reInit( tmp, bindings, converter, imgSources ),
28+
this.b.reInit( tmp, bindings, converter, imgSources ) );
2729
}
2830
}

src/main/java/net/imglib2/algorithm/math/GreaterThan.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ public < O extends RealType< O > > IsGreaterThan< O > reInit(
2121
final O tmp,
2222
final Map< String, O > bindings,
2323
final Converter< RealType< ? >, O > converter,
24-
Map< Variable< O >, OFunction< O > > imgSources )
24+
final Map< Variable< O >, OFunction< O > > imgSources )
2525
{
26-
return new IsGreaterThan< O >( tmp.copy(), this.a.reInit( tmp, bindings, converter, imgSources ), this.b.reInit( tmp, bindings, converter, imgSources ) );
26+
return new IsGreaterThan< O >( tmp.copy(),
27+
this.a.reInit( tmp, bindings, converter, imgSources ),
28+
this.b.reInit( tmp, bindings, converter, imgSources ) );
2729
}
2830
}

src/main/java/net/imglib2/algorithm/math/ImgSource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public < O extends RealType< O > > OFunction< O > reInit(
2929
final Map< Variable< O >, OFunction< O > > imgSources )
3030
{
3131
// Optimization: if input image type is the same or a subclass of
32-
// the output image type (represented here by tmp), then avoid the converter.
32+
// the output image type (represented here by tmp), then avoid the converter
33+
// but only if the targetImg is different than this.rai: otherwise, an intermediate
34+
// computation result holder must be used (the scrap).
3335
final OFunction< O > s;
3436
if ( tmp.getClass().isAssignableFrom( this.rai.randomAccess().get().getClass() ) )
3537
s = new ImgSourceIterableDirect< O >( ( RandomAccessibleInterval< O > )this.rai );

src/main/java/net/imglib2/algorithm/math/LessThan.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public < O extends RealType< O > > IsLessThan< O > reInit(
2323
final Converter< RealType< ? >, O > converter,
2424
final Map< Variable< O >, OFunction< O > > imgSources )
2525
{
26-
return new IsLessThan< O >( tmp.copy(), this.a.reInit( tmp, bindings, converter, imgSources ), this.b.reInit( tmp, bindings, converter, imgSources ) );
26+
return new IsLessThan< O >( tmp.copy(),
27+
this.a.reInit( tmp, bindings, converter, imgSources ),
28+
this.b.reInit( tmp, bindings, converter, imgSources ) );
2729
}
2830
}

src/main/java/net/imglib2/algorithm/math/Let.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public < O extends RealType< O > > LetBinding< O > reInit(
6868
final O scrap = tmp.copy();
6969
final Map< String, O > rebind = new HashMap<>( bindings );
7070
rebind.put( this.varName, scrap );
71-
return new LetBinding< O >( scrap, this.varName, this.varValue.reInit( tmp, rebind, converter, imgSources ), this.body.reInit( tmp, rebind, converter, imgSources ) );
71+
return new LetBinding< O >( scrap, this.varName,
72+
this.varValue.reInit( tmp, rebind, converter, imgSources ),
73+
this.body.reInit( tmp, rebind, converter, imgSources ) );
7274
}
7375

7476
@Override

src/main/java/net/imglib2/algorithm/math/Max.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public < O extends RealType< O > > Maximum< O > reInit(
2828
final Converter< RealType< ? >, O > converter,
2929
final Map< Variable< O >, OFunction< O > > imgSources )
3030
{
31-
return new Maximum< O >( this.a.reInit( tmp, bindings, converter, imgSources ), this.b.reInit( tmp, bindings, converter, imgSources ) );
31+
return new Maximum< O >(
32+
this.a.reInit( tmp, bindings, converter, imgSources ),
33+
this.b.reInit( tmp, bindings, converter, imgSources ) );
3234
}
3335
}

src/main/java/net/imglib2/algorithm/math/Min.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public < O extends RealType< O > > Minimum< O > reInit(
2828
final Converter< RealType< ? >, O > converter,
2929
final Map< Variable< O >, OFunction< O > > imgSources )
3030
{
31-
return new Minimum< O >( this.a.reInit(tmp, bindings, converter, imgSources), this.b.reInit(tmp, bindings, converter, imgSources) );
31+
return new Minimum< O >(
32+
this.a.reInit( tmp, bindings, converter, imgSources ),
33+
this.b.reInit( tmp, bindings, converter, imgSources ) );
3234
}
3335
}

0 commit comments

Comments
 (0)