Unsupported left operand type for multiplication
tle4336 opened this issue · 2 comments
Bug Report
Is the issue related to model conversion?
No
Describe the bug
Unsupported operand type when running python run mypy
for a working @script()
and function within it. Specifically, the following is the script that got the error such as Unsupported left operand type for * ("BFLOAT16") [operator]
. I raised this question in the repo of mypy
, but they blame it is the issue with onnx
(python/mypy#18200)
import numpy as np
import onnx
import onnxruntime
import pandas as pd
from onnxscript import FLOAT
from onnxscript import opset20 as op
x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13], dtype=np.float32)
y = np.array(x[len(x) - 3: len(x)], dtype=np.float32)
z = np.array(x[len(x)-8: len(x)-3], dtype=np.float32)
x_coef = np.array([1.1, 1.5, 1.7, 1.9, 1.2, 3.1, 4.5, 5.2, 8.5, 9.0, 11.0]
y_coef = np.array([8.5, 9.0, 11.0])
z_coef = np.array([5,7,9,9,10,11])
t1 = len(x)
t2 = len(y)
t3 = len(z)
const_term = 2.37698
h1 = 1.5689
h2 = 1.799
@script()
def conv(a1: FLOAT, a2: FLOAT, a3: FLOAT, a4: FLOAT, a5: FLOAT) -> FLOAT:
const = op.Constant(value_float=const_term)
coeff1 = op.Constant(value_float=h1)
coeff2 = op.Constant(value_float=h2)
s = coeff1 * a1 + coeff2 * a2 - const
for inx in range(t1):
if a3 == x[inx]:
s = s + x_coef[inx]
for inx2 in range(t2):
if a4 == y[inx2]:
s = s + y_coef[inx2]
for inx3 in range(t3):
if a5 == z[inx3]:
s = s + z_coef[inx3]
return op.Exp(s)
Actual Error:
error: Unsupported left operand type for * ("BFLOAT16") [operator]
error: Unsupported left operand type for * ("BOOL") [operator]
error: Unsupported left operand type for * ("COMPLEX128") [operator]
error: Unsupported left operand type for * ("COMPLEX64") [operator]
error: Unsupported left operand type for * ("DOUBLE") [operator]
error: Unsupported left operand type for * ("FLOAT") [operator]
error: Unsupported left operand type for * ("FLOAT16") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FN") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FNUZ") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2FNUZ") [operator]
error: Unsupported left operand type for * ("INT16") [operator]
error: Unsupported left operand type for * ("INT32") [operator]
error: Unsupported left operand type for * ("INT64") [operator]
error: Unsupported left operand type for * ("INT8") [operator]
error: Unsupported left operand type for * ("STRING") [operator]
error: Unsupported left operand type for * ("UINT16") [operator]
error: Unsupported left operand type for * ("UINT32") [operator]
error: Unsupported left operand type for * ("UINT64") [operator]
error: Unsupported left operand type for * ("UINT8") [operator]
note: Left operand is of type "BFLOAT16 | BOOL | COMPLEX128 | COMPLEX64 | DOUBLE | <15 more items>"
error: Unsupported left operand type for * ("BFLOAT16") [operator]
error: Unsupported left operand type for * ("BOOL") [operator]
error: Unsupported left operand type for * ("COMPLEX128") [operator]
error: Unsupported left operand type for * ("COMPLEX64") [operator]
error: Unsupported left operand type for * ("DOUBLE") [operator]
error: Unsupported left operand type for * ("FLOAT") [operator]
error: Unsupported left operand type for * ("FLOAT16") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FN") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FNUZ") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2FNUZ") [operator]
error: Unsupported left operand type for * ("INT16") [operator]
error: Unsupported left operand type for * ("INT32") [operator]
error: Unsupported left operand type for * ("INT64") [operator]
error: Unsupported left operand type for * ("INT8") [operator]
error: Unsupported left operand type for * ("STRING") [operator]
error: Unsupported left operand type for * ("UINT16") [operator]
error: Unsupported left operand type for * ("UINT32") [operator]
error: Unsupported left operand type for * ("UINT64") [operator]
error: Unsupported left operand type for * ("UINT8") [operator]
note: Left operand is of type "BFLOAT16 | BOOL | COMPLEX128 | COMPLEX64 | DOUBLE | <15 more items>"
error: Returning Any from function declared to return "FLOAT" [no-any-return] --- Puzzled by this!!
### System information
- OS Platform and Distribution (e.g. Linux Ubuntu 20.04): Mac OS Somona 14.7.1
- ONNX version (e.g. 1.13):
1.16.0
- Python version:
3.11.9
- GCC/Compiler version (if compiling from source): unsure
- CMake version: unsure
- Protobuf version:
5.28.3
- Visual Studio version (if applicable):--> I used Pycharm IDE version 2024.3 (Community Edition)
Reproduction instructions
import numpy as np
import onnx
import onnxruntime
import pandas as pd
from onnxscript import FLOAT
from onnxscript import opset20 as op
x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13], dtype=np.float32)
y = np.array(x[len(x) - 3: len(x)], dtype=np.float32)
z = np.array(x[len(x)-8: len(x)-3], dtype=np.float32)
x_coef = np.array([1.1, 1.5, 1.7, 1.9, 1.2, 3.1, 4.5, 5.2, 8.5, 9.0, 11.0]
y_coef = np.array([8.5, 9.0, 11.0])
z_coef = np.array([5,7,9,9,10,11])
t1 = len(x)
t2 = len(y)
t3 = len(z)
const_term = 2.37698
h1 = 1.5689
h2 = 1.799
@script()
def conv(a1: FLOAT, a2: FLOAT, a3: FLOAT, a4: FLOAT, a5: FLOAT) -> FLOAT:
const = op.Constant(value_float=const_term)
# Define constants
coeff1 = op.Constant(value_float=h1)
coeff2 = op.Constant(value_float=h2)
s = coeff1 * a1 + coeff2 * a2 - const
for inx in range(t1):
if a4 == x[inx]:
s = s + x_coef[inx]
for inx2 in range(t2):
if a5 == y[inx2]:
s = s + y_coef[inx2]
for inx3 in range(t3):
if a6 == z[inx3]:
s = s + z_coef[inx3]
return op.Exp(s)
Actual Error:
error: Unsupported left operand type for * ("BFLOAT16") [operator]
error: Unsupported left operand type for * ("BOOL") [operator]
error: Unsupported left operand type for * ("COMPLEX128") [operator]
error: Unsupported left operand type for * ("COMPLEX64") [operator]
error: Unsupported left operand type for * ("DOUBLE") [operator]
error: Unsupported left operand type for * ("FLOAT") [operator]
error: Unsupported left operand type for * ("FLOAT16") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FN") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FNUZ") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2FNUZ") [operator]
error: Unsupported left operand type for * ("INT16") [operator]
error: Unsupported left operand type for * ("INT32") [operator]
error: Unsupported left operand type for * ("INT64") [operator]
error: Unsupported left operand type for * ("INT8") [operator]
error: Unsupported left operand type for * ("STRING") [operator]
error: Unsupported left operand type for * ("UINT16") [operator]
error: Unsupported left operand type for * ("UINT32") [operator]
error: Unsupported left operand type for * ("UINT64") [operator]
error: Unsupported left operand type for * ("UINT8") [operator]
note: Left operand is of type "BFLOAT16 | BOOL | COMPLEX128 | COMPLEX64 | DOUBLE | <15 more items>"
error: Unsupported left operand type for * ("BFLOAT16") [operator]
error: Unsupported left operand type for * ("BOOL") [operator]
error: Unsupported left operand type for * ("COMPLEX128") [operator]
error: Unsupported left operand type for * ("COMPLEX64") [operator]
error: Unsupported left operand type for * ("DOUBLE") [operator]
error: Unsupported left operand type for * ("FLOAT") [operator]
error: Unsupported left operand type for * ("FLOAT16") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FN") [operator]
error: Unsupported left operand type for * ("FLOAT8E4M3FNUZ") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2") [operator]
error: Unsupported left operand type for * ("FLOAT8E5M2FNUZ") [operator]
error: Unsupported left operand type for * ("INT16") [operator]
error: Unsupported left operand type for * ("INT32") [operator]
error: Unsupported left operand type for * ("INT64") [operator]
error: Unsupported left operand type for * ("INT8") [operator]
error: Unsupported left operand type for * ("STRING") [operator]
error: Unsupported left operand type for * ("UINT16") [operator]
error: Unsupported left operand type for * ("UINT32") [operator]
error: Unsupported left operand type for * ("UINT64") [operator]
error: Unsupported left operand type for * ("UINT8") [operator]
note: Left operand is of type "BFLOAT16 | BOOL | COMPLEX128 | COMPLEX64 | DOUBLE | <15 more items>"
error: Returning Any from function declared to return "FLOAT" [no-any-return] --- Puzzled by this!!
Expected behavior
No error occurs when running python run mypy
.
Notes
mypy version is: 1.13.0
@JukkaL @msullivan @hauntsaninja @gvanrossum Could either of you please help look into this weird behavior?
Please don’t call out individual developers; it is considered rude.
@gvanrossum My apologies. Didn't think it would come across that way.