Skip to content

Commit 48c2175

Browse files
committed
SparseShape: support empty tiles
1 parent 9432123 commit 48c2175

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/TiledArray/sparse_shape.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,26 @@ class SparseShape {
163163
math::inplace_vector_op(
164164
[threshold, real_max, &zero_tile_count](value_type& norm,
165165
const value_type size) {
166-
if (ScaleBy_ == ScaleBy::Volume)
166+
if (size == value_type(0)) {
167+
// zero-size tiles always have zero norm
168+
norm = value_type(0);
169+
if (Screen) ++zero_tile_count;
170+
} else if (ScaleBy_ == ScaleBy::Volume) {
167171
norm *= size;
168-
else
172+
if (!std::isfinite(norm)) {
173+
norm = real_max;
174+
} else if (Screen && norm < threshold) {
175+
norm = value_type(0);
176+
++zero_tile_count;
177+
}
178+
} else {
169179
norm /= size;
170-
if (!std::isfinite(norm)) {
171-
norm = real_max;
172-
} else if (Screen && norm < threshold) {
173-
norm = value_type(0);
174-
++zero_tile_count;
180+
if (!std::isfinite(norm)) {
181+
norm = real_max;
182+
} else if (Screen && norm < threshold) {
183+
norm = value_type(0);
184+
++zero_tile_count;
185+
}
175186
}
176187
},
177188
size_vectors[0].size(), tile_norms.data(), size_vectors[0].data());
@@ -187,7 +198,7 @@ class SparseShape {
187198
/// for scaling by inverse volume
188199
auto inv_vec_op = [](const vector_type& size_vector) {
189200
return vector_type(size_vector, [](const value_type size) {
190-
return value_type(1) / size;
201+
return size > value_type(0) ? value_type(1) / size : value_type(0);
191202
});
192203
};
193204

0 commit comments

Comments
 (0)