Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
better handling of float 8 in onnx_simple_text_plot
  • Loading branch information
xadupre committed Jun 30, 2023
commit efd36edd41b490407f992dd874b55e0d7dcc9bc6
17 changes: 15 additions & 2 deletions onnx_array_api/plotting/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,25 @@ def _get_type(obj0):
return tensor_dtype_to_np_dtype(TensorProto.DOUBLE)
if obj.data_type == TensorProto.INT64 and hasattr(obj, "int64_data"):
return tensor_dtype_to_np_dtype(TensorProto.INT64)
if obj.data_type == TensorProto.INT32 and hasattr(obj, "int32_data"):
if obj.data_type in (
TensorProto.INT8,
TensorProto.UINT8,
TensorProto.UINT16,
TensorProto.INT16,
TensorProto.INT32,
TensorProto.FLOAT8E4M3FN,
TensorProto.FLOAT8E4M3FNUZ,
TensorProto.FLOAT8E5M2,
TensorProto.FLOAT8E5M2FNUZ,
) and hasattr(obj, "int32_data"):
return tensor_dtype_to_np_dtype(TensorProto.INT32)
if hasattr(obj, "raw_data") and len(obj.raw_data) > 0:
arr = to_array(obj)
return arr.dtype
raise RuntimeError(f"Unable to guess type from {obj0!r}.")
raise RuntimeError(
f"Unable to guess type from obj.data_type={obj.data_type} "
f"and obj={obj0!r} - {TensorProto.__dict__}."
)
if hasattr(obj, "type"):
obj = obj.type
if hasattr(obj, "tensor_type"):
Expand Down
6 changes: 5 additions & 1 deletion onnx_array_api/plotting/text_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

import numpy
from onnx import AttributeProto
from onnx.numpy_helper import to_array

try:
from onnx.reference.op_run import to_array_extended as to_array
except ImportError:
from onnx.numpy_helper import to_array

from ._helper import _get_shape, _get_type, attributes_as_dict

Expand Down