diff --git a/.azure-pipelines/linux-conda-CI.yml b/.azure-pipelines/linux-conda-CI.yml index f2a4e0498..69b587863 100644 --- a/.azure-pipelines/linux-conda-CI.yml +++ b/.azure-pipelines/linux-conda-CI.yml @@ -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 diff --git a/.azure-pipelines/win32-conda-CI.yml b/.azure-pipelines/win32-conda-CI.yml index 61dbc5a27..d6da599dc 100644 --- a/.azure-pipelines/win32-conda-CI.yml +++ b/.azure-pipelines/win32-conda-CI.yml @@ -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: diff --git a/skl2onnx/common/utils.py b/skl2onnx/common/utils.py index b2a98c11c..3aaf1a4e8 100644 --- a/skl2onnx/common/utils.py +++ b/skl2onnx/common/utils.py @@ -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() diff --git a/tests/test_algebra_onnx_operators_sparse.py b/tests/test_algebra_onnx_operators_sparse.py index d52d50f44..0a9c288c5 100644 --- a/tests/test_algebra_onnx_operators_sparse.py +++ b/tests/test_algebra_onnx_operators_sparse.py @@ -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) @@ -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__":