Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion thinc/backends/numpy_ops.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ class NumpyOps(Ops):
assert O != 0

cdef np.ndarray maxes
cdef np.ndarray which = self.alloc(shape=(B, O), dtype="i", zeros=False)
# Needs to be zero-initialized as we start by assuming that the first element is the max value.
cdef np.ndarray which = self.alloc(shape=(B, O), dtype="i", zeros=True)
if reals2d_ft is float2d_t:
maxes = self.alloc(shape=(B, O), dtype="float32", zeros=False)
cpu_reduce_max(<float*>maxes.data, <int*>which.data, &X[0, 0], &lengths[0], B, T, O)
Expand Down
6 changes: 6 additions & 0 deletions thinc/tests/backends/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,9 @@ def test_reduce_max_sm(ops, dtype):
lengths = ops.xp.array([2, 2, 2], dtype="i")
maxes, which = ops.reduce_max(X, lengths)
assert maxes.dtype == dtype
assert ops.xp.all(which >= 0)
assert ops.xp.all(which < X.shape[0])

start = 0
for i, length in enumerate(lengths):
truth = X[start : start + length].max(axis=0)
Expand All @@ -781,6 +784,9 @@ def test_reduce_max(ops, dtype):
# m[1, 3] = 3
maxes, which = ops.reduce_max(m, lengths)
assert maxes.dtype == dtype
assert ops.xp.all(which >= 0)
assert ops.xp.all(which < m.shape[0])

start = 0
for i, length in enumerate(lengths):
truth = m[start : start + length].max(axis=0)
Expand Down