Skip to content

Commit e53e757

Browse files
authored
fix: scalar failed in ND fill (#453)
This should both fix the linked issue, as well avoid an extra copy when the dtype is non-matching and the array is non-contigious. Pybind11 makes a copy if either of those are not true; but we were making a copy here but keeping the dtype, possibly making two copies. Closes #452.
1 parent 504beba commit e53e757

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/boost_histogram/_internal/hist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _fill_cast(value, inner=False):
4242
elif not inner and isinstance(value, (tuple, list)):
4343
return tuple(_fill_cast(a, inner=True) for a in value)
4444
elif hasattr(value, "__iter__") or hasattr(value, "__array__"):
45-
return np.ascontiguousarray(value)
45+
return np.asarray(value)
4646
else:
4747
return value
4848

tests/test_histogram.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ def test_fill_2d(flow):
283283
for j in range(-flow, h.axes[1].size + flow):
284284
assert get(h, i, j) == m[i][j]
285285

286+
h.fill(1, [1, 2])
287+
h.fill(np.float64(1), [1, 2])
288+
286289

287290
def test_add_2d(flow):
288291
h0 = bh.Histogram(

0 commit comments

Comments
 (0)