Skip to content

Commit

Permalink
fix sparse unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Dupre <[email protected]>
  • Loading branch information
xadupre committed Oct 19, 2023
1 parent ba6accc commit f472c91
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .azure-pipelines/linux-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
strategy:
matrix:

Py311-Onnx150-Rt160-Skl131:
Py311-Onnx150-Rt161-Skl131:
do.bench: '0'
python.version: '3.11' # onnxruntime cannot support python 3.11 yet
numpy.version: '>=1.21.1'
scipy.version: '>=1.7.0'
onnx.version: '-i https://test.pypi.org/simple/ onnx==1.15.0rc1'
onnx.target_opset: ''
onnxrt.version: 'onnxruntime==1.16.0'
onnxrt.version: 'onnxruntime==1.16.1'
sklearn.version: '>=1.3.1'
lgbm.version: ''
onnxcc.version: '>=1.8.1' # git
Expand Down
6 changes: 3 additions & 3 deletions .azure-pipelines/win32-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
vmImage: 'windows-latest'
strategy:
matrix:
Py310-Onnx150-Rt160-Skl131:
Py310-Onnx150-Rt161-Skl131:
python.version: '3.11' # onnxruntime cannot support python 3.11 yet
onnx.version: 'onnx==1.14.1' # '-i https://test.pypi.org/simple/ onnx==1.15.0rc1'
onnx.version: '-i https://test.pypi.org/simple/ onnx==1.15.0rc1'
onnx.target_opset: ''
numpy.version: 'numpy>=1.22.3'
scipy.version: 'scipy'
onnxrt.version: 'onnxruntime==1.16.0'
onnxrt.version: 'onnxruntime==1.16.1'
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
sklearn.version: '>=1.3.1'
Py310-Onnx141-Rt160-Skl131:
Expand Down
2 changes: 1 addition & 1 deletion skl2onnx/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def hash_array(value, length=15):
"Computes a hash identifying the value."
try:
onx = from_array(value)
except AttributeError as e:
except (AttributeError, TypeError) as e:
# sparse matrix for example
if hasattr(value, "tocoo"):
coo = value.tocoo()
Expand Down
9 changes: 5 additions & 4 deletions tests/test_algebra_onnx_operators_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def test_onnx_init_dense(self):
reason="fails with onnxruntime < %s" % THRESHOLD,
)
def test_onnx_init_sparse_coo(self):
row = np.array([0, 0, 1, 3, 1], dtype=np.float32)
col = np.array([0, 2, 1, 3, 1], dtype=np.float32)
row = np.array([0, 0, 1, 3, 2], dtype=np.int64)
col = np.array([0, 2, 1, 3, 1], dtype=np.int64)
data = np.array([1, 1, 1, 1, 1], dtype=np.float32)
# numpy and onnxruntime behave differently when there are duplicated indices.
X = coo_matrix((data, (row, col)), shape=(4, 4))

node = OnnxAdd("X", X, output_names=["Y"], op_version=TARGET_OPSET)
Expand All @@ -70,14 +71,14 @@ def test_onnx_init_sparse_coo(self):
# Sparse tensor is not supported for constant.
return
try:
res = sess.run(None, {"X": X})[0]
res = sess.run(None, {"X": X.todense()})[0]
except RuntimeError as e:
# Sparse tensor is not supported for constant.
warnings.warn(
"Unable to run with %r\n---\n%s\n%s" % ({"X": X}, model_def, e)
)
return
assert_almost_equal(X + X, res)
assert_almost_equal((X + X).todense(), res)


if __name__ == "__main__":
Expand Down

0 comments on commit f472c91

Please sign in to comment.