Skip to content

Commit b740bad

Browse files
committed
Make ConvolverNativeType.process logic the same as for other convolvers
Also brings a slight speed up
1 parent 85d9b2b commit b740bad

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/main/java/net/imglib2/algorithm/convolution/kernel/ConvolverNativeType.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ public final class ConvolverNativeType< T extends NumericType< T > & NativeType<
7272

7373
private final T b2;
7474

75-
private final T tmp;
76-
7775
public ConvolverNativeType( final Kernel1D kernel, final RandomAccess< ? extends T > in, final RandomAccess< ? extends T > out, final int d, final long lineLength )
7876
{
7977
// NB: This constructor is used in ConvolverFactories. It needs to be public and have this exact signature.
@@ -87,11 +85,12 @@ public ConvolverNativeType( final Kernel1D kernel, final RandomAccess< ? extends
8785
linelen = lineLength;
8886

8987
final T type = out.get();
90-
final ArrayImg< T, ? > buf = new ArrayImgFactory<>( type ).create( new long[] { k1k } );
88+
final ArrayImg< T, ? > buf = new ArrayImgFactory<>( type ).create( k1k + 1 );
9189
b1 = buf.randomAccess().get();
9290
b2 = buf.randomAccess().get();
9391

94-
tmp = type.createVariable();
92+
b1.updateIndex( k1k );
93+
b1.setZero();
9594
}
9695

9796
private void prefill()
@@ -116,23 +115,13 @@ private void next()
116115
private void process( final T w )
117116
{
118117
// move buf contents down
119-
for ( int i = 0; i < k1k1; ++i )
118+
for ( int i = 0; i < k1k; ++i )
120119
{
121-
b2.updateIndex( i + 1 );
122120
b1.updateIndex( i );
123-
b1.set( b2 );
124-
}
125-
126-
b1.updateIndex( k1k1 );
127-
b1.setZero();
128-
129-
// loop
130-
for ( int j = 0; j < k1k; ++j )
131-
{
132-
tmp.set( w );
133-
tmp.mul( kernel[ j ] );
134-
b1.updateIndex( j );
135-
b1.add( tmp );
121+
b2.updateIndex( i + 1 );
122+
b1.set( w );
123+
b1.mul( kernel[ i ] );
124+
b1.add( b2 );
136125
}
137126
}
138127

0 commit comments

Comments
 (0)