Source code for mlprodict.onnxrt.ops_cpu.op_eyelike

# -*- encoding: utf-8 -*-
# pylint: disable=E0203,E1101,C0111
"""
Runtime operator.


:githublink:`%|py|7`
"""
import numpy
from ._op import OpRun
from ._op_helper import proto2dtype, dtype_name
from ..shape_object import ShapeObject


[docs]class EyeLike(OpRun): atts = {'k': 0, 'dtype': 1}
[docs] def __init__(self, onnx_node, desc=None, **options): OpRun.__init__(self, onnx_node, desc=desc, expected_attributes=EyeLike.atts, **options) self.dtype_ = proto2dtype(self.dtype)
[docs] def _run(self, shape, *args): # pylint: disable=W0221 return (numpy.eye(*shape, k=self.k, dtype=self.dtype_), )
[docs] def _infer_shapes(self, shape): # pylint: disable=W0221 return (ShapeObject(None, dtype=self.dtype_), )
[docs] def to_python(self, inputs): return ( "import numpy", "return numpy.eye(*%s, k=%d, dtype=numpy.%s)" % ( inputs[0], self.k, dtype_name(self.dtype_)))