Coverage for mlprodict/onnxrt/ops_cpu/op_conv.py: 95%
22 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-04 02:28 +0100
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-04 02:28 +0100
1# -*- encoding: utf-8 -*-
2# pylint: disable=E0203,E1101,C0111
3"""
4@file
5@brief Runtime operator.
6"""
7import numpy
8from ._op import OpRun
9from .op_conv_ import ConvFloat, ConvDouble # pylint: disable=E0611,E0401
12class Conv(OpRun):
14 atts = {'auto_pad': 'NOTSET', 'group': 1,
15 'dilations': [1, 1],
16 'kernel_shape': [],
17 'pads': [],
18 'strides': [1, 1]}
20 def __init__(self, onnx_node, desc=None, **options):
21 OpRun.__init__(self, onnx_node, desc=desc,
22 expected_attributes=Conv.atts,
23 **options)
24 self._init()
26 def _init(self):
27 self.rt32_ = ConvFloat()
28 self.rt64_ = ConvDouble()
29 for rt in [self.rt32_, self.rt64_]:
30 rt.init(self.auto_pad,
31 numpy.array(self.dilations, dtype=numpy.int64),
32 self.group,
33 numpy.array(self.kernel_shape, dtype=numpy.int64),
34 numpy.array(self.pads, dtype=numpy.int64),
35 numpy.array(self.strides, dtype=numpy.int64))
37 def _run(self, X, W, B=None, attributes=None, verbose=0, fLOG=None): # pylint: disable=W0221
38 if X is None:
39 raise ValueError( # pragma: no cover
40 "X cannot be None for operator %r, ONNX=%r" % (
41 type(self), self.onnx_node))
42 if min(X.shape) == 0:
43 raise RuntimeError( # pragma: no cover
44 f"Unable to run operator Conv on an empty matrix. X.shape={X.shape!r}.")
45 if min(W.shape) == 0:
46 raise RuntimeError( # pragma: no cover
47 f"Unable to run operator Conv on an empty matrix. W.shape={W.shape!r}.")
48 if B is not None and min(B.shape) == 0:
49 raise RuntimeError( # pragma: no cover
50 f"Unable to run operator Conv on an empty matrix. B.shape={B.shape!r}.")
51 if X.dtype == numpy.float32:
52 return (self.rt32_.compute(X, W, B), )
53 return (self.rt64_.compute(X, W, B), )