@@ -182,25 +182,27 @@ static Constant<T> DoReduction(const Constant<ARRAY> &array,
182
182
ConstantSubscript &maskDimAt{maskAt[*dim - 1 ]};
183
183
ConstantSubscript maskDimLbound{maskDimAt};
184
184
for (auto n{GetSize (resultShape)}; n-- > 0 ;
185
- IncrementSubscripts (at, array.shape ()),
186
- IncrementSubscripts (maskAt, mask.shape ())) {
187
- dimAt = dimLbound;
188
- maskDimAt = maskDimLbound;
185
+ array.IncrementSubscripts (at), mask.IncrementSubscripts (maskAt)) {
189
186
elements.push_back (identity);
190
- bool firstUnmasked{true };
191
- for (ConstantSubscript j{0 }; j < dimExtent; ++j, ++dimAt, ++maskDimAt) {
192
- if (mask.At (maskAt).IsTrue ()) {
193
- accumulator (elements.back (), at, firstUnmasked);
194
- firstUnmasked = false ;
187
+ if (dimExtent > 0 ) {
188
+ dimAt = dimLbound;
189
+ maskDimAt = maskDimLbound;
190
+ bool firstUnmasked{true };
191
+ for (ConstantSubscript j{0 }; j < dimExtent; ++j, ++dimAt, ++maskDimAt) {
192
+ if (mask.At (maskAt).IsTrue ()) {
193
+ accumulator (elements.back (), at, firstUnmasked);
194
+ firstUnmasked = false ;
195
+ }
195
196
}
197
+ --dimAt, --maskDimAt;
196
198
}
197
199
accumulator.Done (elements.back ());
198
200
}
199
201
} else { // no DIM=, result is scalar
200
202
elements.push_back (identity);
201
203
bool firstUnmasked{true };
202
- for (auto n{array.size ()}; n-- > 0 ; IncrementSubscripts (at, array. shape ()),
203
- IncrementSubscripts (maskAt , mask.shape () )) {
204
+ for (auto n{array.size ()}; n-- > 0 ;
205
+ array. IncrementSubscripts (at) , mask.IncrementSubscripts (maskAt )) {
204
206
if (mask.At (maskAt).IsTrue ()) {
205
207
accumulator (elements.back (), at, firstUnmasked);
206
208
firstUnmasked = false ;
0 commit comments