Coverage for mlprodict/onnxrt/ops_cpu/op_det.py: 100%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- encoding: utf-8 -*-
2# pylint: disable=E0203,E1101,C0111
3"""
4@file
5@brief Runtime operator.
6"""
7import numpy
8from ..shape_object import ShapeObject
9from ._op import OpRun
12class Det(OpRun):
14 def __init__(self, onnx_node, desc=None, **options):
15 OpRun.__init__(self, onnx_node, desc=desc,
16 **options)
18 def _run(self, x): # pylint: disable=W0221
19 res = numpy.linalg.det(x)
20 if not isinstance(res, numpy.ndarray):
21 res = numpy.array([res])
22 return (res, )
24 def _infer_shapes(self, x): # pylint: disable=W0221
25 return (ShapeObject(None, dtype=x.dtype,
26 name=self.__class__.__name__), )
28 def _infer_types(self, x): # pylint: disable=W0221
29 return (x, )
31 def _infer_sizes(self, *args, **kwargs):
32 res = self.run(*args, **kwargs)
33 return (dict(temp=0), ) + res
35 def to_python(self, inputs):
36 return ('from numpy.linalg import det as npy_det',
37 "\n".join([
38 "res = npy_det({})".format(inputs[0]),
39 "if not isinstance(res, ndarray):",
40 " res = numpy.array([res])",
41 "return res"]))