Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commutative property #283

@ghost

Description

Hello,
I was testing mlprodict, but playing with the first tutorial I ran into a blocking situation for me.

from typing import Any
import numpy as np
import mlprodict.npy.numpy_onnx_impl as npnx
from mlprodict.npy import onnxnumpy_default, NDArray


# The numpy function
def log_1(x):
    return np.log(1 + x)


# The ONNX function
@onnxnumpy_default
def onnx_log_1(x: NDArray[Any, np.float32]) -> NDArray[Any, np.float32]:
    return npnx.log(np.float32(1) + x)


x = np.random.rand(2, 3).astype(np.float32)

print('numpy')
print(log_1(x))

print('onnx')
print(onnx_log_1(x))

It's the tutorial http://www.xavierdupre.fr/app/mlprodict/helpsphinx/tutorial/numpy_api_onnx.html#principle with inverted addends.
Running it I get the following error:

Traceback (most recent call last):
  File "/home/mvm/code/onnx/tutorial.py", line 14, in <module>
    def onnx_log_1(x: NDArray[Any, np.float32]) -> NDArray[Any, np.float32]:
  File "/home/mvm/venvs/onnx/lib/python3.9/site-packages/mlprodict/npy/onnx_numpy_wrapper.py", line 110, in onnxnumpy_default
    return onnxnumpy()(fct)
  File "/home/mvm/venvs/onnx/lib/python3.9/site-packages/mlprodict/npy/onnx_numpy_wrapper.py", line 88, in decorator_fct
    compiled = OnnxNumpyCompiler(
  File "/home/mvm/venvs/onnx/lib/python3.9/site-packages/mlprodict/npy/onnx_numpy_compiler.py", line 140, in __init__
    self.onnx_ = self._to_onnx(
  File "/home/mvm/venvs/onnx/lib/python3.9/site-packages/mlprodict/npy/onnx_numpy_compiler.py", line 333, in _to_onnx
    onx_var = self.fct_(*names_var, **kwargs)
  File "/home/mvm/code/onnx/tutorial.py", line 15, in onnx_log_1
    return npnx.log(np.float32(1) + x)
TypeError: unsupported operand type(s) for +: 'float' and 'OnnxVar'

Am i missing something or is there a problem?

Best regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions