Skip to content

Commit

Permalink
Zero dim fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adityagoel4512 committed Jan 26, 2025
1 parent a73f1b3 commit bc6141e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
# to the main branch and tags.
push:
branches:
- "main"
- "*"
tags:
- "*"

Expand Down
20 changes: 19 additions & 1 deletion ndonnx/_opset_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,25 @@ def clip(input: _CoreArray, min: _CoreArray, max: _CoreArray) -> _CoreArray:

@eager_propagate
def matmul(a: _CoreArray, b: _CoreArray) -> _CoreArray:
return _CoreArray(op.matmul(a.var, b.var))
# TODO(adityagoel4512): this requires an upstream patch in onnxruntime
# onnxruntime goes into UB with zero size inputs
(out,) = op.if_(
op.equal(op.size(a.var), op.const(0, dtype=np.int64)),
then_branch=lambda: [
op.const(
np.zeros(
(),
dtype=np.result_type(
a.var.unwrap_tensor().dtype, b.var.unwrap_tensor().dtype
),
)
),
],
else_branch=lambda: [
op.matmul(a.var, b.var),
],
)
return _CoreArray(out)


@eager_propagate
Expand Down
1 change: 0 additions & 1 deletion xfails.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ array_api_tests/test_has_names.py::test_has_names[linalg-diagonal]
array_api_tests/test_has_names.py::test_has_names[linalg-eigh]
array_api_tests/test_has_names.py::test_has_names[linalg-eigvalsh]
array_api_tests/test_has_names.py::test_has_names[linalg-inv]
array_api_tests/test_has_names.py::test_has_names[linalg-matmul]
array_api_tests/test_has_names.py::test_has_names[linalg-matrix_norm]
array_api_tests/test_has_names.py::test_has_names[linalg-matrix_power]
array_api_tests/test_has_names.py::test_has_names[linalg-matrix_rank]
Expand Down

0 comments on commit bc6141e

Please sign in to comment.