Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy_ops gemm output semantics when BLIS is used #521

Merged
merged 1 commit into from
Aug 16, 2021
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
2 changes: 1 addition & 1 deletion thinc/backends/numpy_ops.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class NumpyOps(Ops):
y = self.as_contig(y)
if out is not None:
out = self.as_contig(out)
return blis.py.gemm(x, y, out=out, trans1=trans1, trans2=trans2)
return blis.py.gemm(x, y, out=out, trans1=trans1, trans2=trans2, beta=0.)
svlandeg marked this conversation as resolved.
Show resolved Hide resolved

def relu(self, np.ndarray X, inplace=False):
cdef np.ndarray out = X if inplace else X.copy()
Expand Down
8 changes: 8 additions & 0 deletions thinc/tests/backends/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ def test_gemm_computes_correctly(cpu_ops):
cpu_ops.gemm(X, W, trans1=True, out=Y)


@pytest.mark.parametrize("cpu_ops", [*CPU_OPS, BLIS_OPS])
def test_gemm_out_used(cpu_ops):
a = b = numpy.zeros((2, 2), dtype="f")
c = numpy.ones((2, 2), dtype="f")
cpu_ops.gemm(a, b, out=c)
assert numpy.array_equal(c, numpy.zeros((2, 2)))


@pytest.mark.parametrize("cpu_ops", CPU_OPS)
@settings(max_examples=MAX_EXAMPLES, deadline=None)
@given(X=strategies.arrays_BI())
Expand Down