@@ -110,7 +110,7 @@ public void map()
110
110
max [dimX ] = target .max ( 0 );
111
111
max [dimY ] = target .max ( 1 );
112
112
113
- final IterableInterval < A > ii = Views .iterable ( Views . interval ( source , new FinalInterval ( min , max ) ) );
113
+ final IterableInterval < A > ii = Views .interval ( source , new FinalInterval ( min , max ) );
114
114
115
115
final long portionSize = target .size () / nTasks ;
116
116
@@ -119,92 +119,86 @@ public void map()
119
119
120
120
for ( int t = 0 ; t < nTasks ; ++t )
121
121
{
122
- tasks .add ( new Callable < Void >()
123
- {
124
-
125
- @ Override
126
- public Void call () throws Exception
127
- {
128
- int i = ai .getAndIncrement ();
129
-
130
- final Cursor < B > targetCursor = target .localizingCursor ();
131
-
132
- // we might need either a cursor or a RandomAccess
133
- final RandomAccess < A > sourceRandomAccess = source .randomAccess ();
134
- sourceRandomAccess .setPosition ( position );
135
-
136
- final Cursor < A > sourceCursor = ii .cursor ();
137
-
138
- // jump to correct starting point
139
- targetCursor .jumpFwd ( i * portionSize );
140
- sourceCursor .jumpFwd ( i * portionSize );
141
- long stepsTaken = 0 ;
142
-
143
- if ( target .iterationOrder ().equals ( ii .iterationOrder () )
144
- && !( sourceCursor instanceof RandomAccessibleIntervalCursor ) )
145
- {
146
- // either map a portion or (for the last portion) go
147
- // until the end
148
- while ( ( i != nTasks - 1 && stepsTaken < portionSize )
149
- || ( i == nTasks - 1 && targetCursor .hasNext () ) )
150
- {
151
- stepsTaken ++;
152
- converter .convert ( sourceCursor .next (), targetCursor .next () );
153
- }
154
- }
155
-
156
- else if ( target .iterationOrder () instanceof FlatIterationOrder )
157
- {
158
-
159
- final long cr = -target .dimension ( 0 );
160
- final long width = target .dimension ( 0 );
161
- final long height = target .dimension ( 1 );
162
-
163
- final long initX = ( i * portionSize ) % width ;
164
- final long initY = ( i * portionSize ) / width ;
165
- // either map a portion or (for the last portion) go
166
- // until the end
167
- final long endX = ( i == nTasks - 1 ) ? width : ( initX + ( i + 1 ) * portionSize ) % width ;
168
- final long endY = ( i == nTasks - 1 ) ? height - 1
169
- : ( initX + ( i + 1 ) * portionSize ) / width ;
170
-
171
- sourceRandomAccess .setPosition ( initX , dimX );
172
- sourceRandomAccess .setPosition ( initY , dimY );
173
-
174
- for ( long y = initY ; y <= endY ; ++y )
175
- {
176
- for ( long x = ( y == initY ? initX : 0 ); x < ( y == endY ? endX : width ); ++x )
177
- {
178
- targetCursor .fwd ();
179
- converter .convert ( sourceRandomAccess .get (), targetCursor .get () );
180
- sourceRandomAccess .fwd ( dimX );
181
-
182
- }
183
- sourceRandomAccess .move ( cr , dimX );
184
- sourceRandomAccess .fwd ( dimY );
185
- }
186
- }
187
-
188
- else
189
- {
190
- // either map a portion or (for the last portion) go
191
- // until the end
192
- while ( ( i != nTasks - 1 && stepsTaken < portionSize )
193
- || ( i == nTasks - 1 && targetCursor .hasNext () ) )
194
- {
195
- stepsTaken ++;
196
-
197
- final B b = targetCursor .next ();
198
- sourceRandomAccess .setPosition ( targetCursor .getLongPosition ( 0 ), dimX );
199
- sourceRandomAccess .setPosition ( targetCursor .getLongPosition ( 1 ), dimY );
200
-
201
- converter .convert ( sourceRandomAccess .get (), b );
202
- }
203
- }
204
-
205
- return null ;
206
- }
207
- } );
122
+ tasks .add (() -> {
123
+ int i = ai .getAndIncrement ();
124
+
125
+ final Cursor < B > targetCursor = target .localizingCursor ();
126
+
127
+ // we might need either a cursor or a RandomAccess
128
+ final RandomAccess < A > sourceRandomAccess = source .randomAccess ();
129
+ sourceRandomAccess .setPosition ( position );
130
+
131
+ final Cursor < A > sourceCursor = ii .cursor ();
132
+
133
+ // jump to correct starting point
134
+ targetCursor .jumpFwd ( i * portionSize );
135
+ sourceCursor .jumpFwd ( i * portionSize );
136
+ long stepsTaken = 0 ;
137
+
138
+ if ( target .iterationOrder ().equals ( ii .iterationOrder () )
139
+ && !( sourceCursor instanceof RandomAccessibleIntervalCursor ) )
140
+ {
141
+ // either map a portion or (for the last portion) go
142
+ // until the end
143
+ while ( ( i != nTasks - 1 && stepsTaken < portionSize )
144
+ || ( i == nTasks - 1 && targetCursor .hasNext () ) )
145
+ {
146
+ stepsTaken ++;
147
+ converter .convert ( sourceCursor .next (), targetCursor .next () );
148
+ }
149
+ }
150
+
151
+ else if ( target .iterationOrder () instanceof FlatIterationOrder )
152
+ {
153
+
154
+ final long cr = -target .dimension ( 0 );
155
+ final long width = target .dimension ( 0 );
156
+ final long height = target .dimension ( 1 );
157
+
158
+ final long initX = ( i * portionSize ) % width ;
159
+ final long initY = ( i * portionSize ) / width ;
160
+ // either map a portion or (for the last portion) go
161
+ // until the end
162
+ final long endX = ( i == nTasks - 1 ) ? width : ( initX + ( i + 1 ) * portionSize ) % width ;
163
+ final long endY = ( i == nTasks - 1 ) ? height - 1
164
+ : ( initX + ( i + 1 ) * portionSize ) / width ;
165
+
166
+ sourceRandomAccess .setPosition ( initX , dimX );
167
+ sourceRandomAccess .setPosition ( initY , dimY );
168
+
169
+ for ( long y = initY ; y <= endY ; ++y )
170
+ {
171
+ for ( long x = ( y == initY ? initX : 0 ); x < ( y == endY ? endX : width ); ++x )
172
+ {
173
+ targetCursor .fwd ();
174
+ converter .convert ( sourceRandomAccess .get (), targetCursor .get () );
175
+ sourceRandomAccess .fwd ( dimX );
176
+
177
+ }
178
+ sourceRandomAccess .move ( cr , dimX );
179
+ sourceRandomAccess .fwd ( dimY );
180
+ }
181
+ }
182
+
183
+ else
184
+ {
185
+ // either map a portion or (for the last portion) go
186
+ // until the end
187
+ while ( ( i != nTasks - 1 && stepsTaken < portionSize )
188
+ || ( i == nTasks - 1 && targetCursor .hasNext () ) )
189
+ {
190
+ stepsTaken ++;
191
+
192
+ final B b = targetCursor .next ();
193
+ sourceRandomAccess .setPosition ( targetCursor .getLongPosition ( 0 ), dimX );
194
+ sourceRandomAccess .setPosition ( targetCursor .getLongPosition ( 1 ), dimY );
195
+
196
+ converter .convert ( sourceRandomAccess .get (), b );
197
+ }
198
+ }
199
+
200
+ return null ;
201
+ });
208
202
}
209
203
210
204
try
0 commit comments