Coverage for mlprodict/onnxrt/ops_cpu/op_qlinear_conv.py: 96%
24 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_qlinear_conv_ import QLinearConvInt8, QLinearConvUInt8 # pylint: disable=E0611,E0401
12class QLinearConv(OpRun):
14 atts = {'auto_pad': 'NOTSET',
15 'group': 1,
16 'dilations': [],
17 'kernel_shape': [],
18 'pads': [],
19 'strides': []}
21 def __init__(self, onnx_node, desc=None, **options):
22 OpRun.__init__(self, onnx_node, desc=desc,
23 expected_attributes=QLinearConv.atts,
24 **options)
25 self._init()
26 self._cstu8 = numpy.array([], dtype=numpy.uint8)
27 self._csti8 = numpy.array([], dtype=numpy.int8)
29 def _init(self):
30 self.rtu8_ = QLinearConvUInt8()
31 self.rti8_ = QLinearConvInt8()
32 for rt in [self.rtu8_, self.rti8_]:
33 rt.init(self.auto_pad,
34 numpy.array(self.dilations, dtype=numpy.int64),
35 self.group,
36 numpy.array(self.kernel_shape, dtype=numpy.int64),
37 numpy.array(self.pads, dtype=numpy.int64),
38 numpy.array(self.strides, dtype=numpy.int64))
40 def _run(self, X, x_scale, x_zero_point, w, w_scale, w_zero_point, # pylint: disable=W0221
41 y_scale, y_zero_point, B=None, attributes=None, verbose=0, fLOG=None):
42 if X is None:
43 raise ValueError( # pragma: no cover
44 "X cannot be None for operator %r, ONNX=%r" % (
45 type(self), self.onnx_node))
46 if X.dtype == numpy.uint8:
47 if B is None:
48 b = self._cstu8
49 else:
50 b = B
51 return (self.rtu8_.compute(
52 X, x_scale, x_zero_point, w, w_scale, w_zero_point, # pylint: disable=W0221
53 y_scale, y_zero_point, b), )
54 return (self.rti8_.compute(
55 X, x_scale, x_zero_point, w, w_scale, w_zero_point, # pylint: disable=W0221
56 y_scale, y_zero_point, B or self._csti8), )