Coverage for mlprodict/onnxrt/ops_cpu/op_concat.py: 100%
19 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
11class Concat(OpRun):
13 atts = {'axis': 0}
14 python_inputs = ['*inputs']
16 def __init__(self, onnx_node, desc=None, **options):
17 OpRun.__init__(self, onnx_node, desc=desc,
18 expected_attributes=Concat.atts,
19 **options)
21 def _preprocess(self, a):
22 if len(a.shape) == 0:
23 raise RuntimeError( # pragma: no cover
24 f"Concat: one input has an empty shape: {a!r}.")
25 if self.axis >= len(a.shape):
26 new_shape = a.shape + (1, ) * (self.axis + 1 - len(a.shape))
27 return a.reshape(new_shape)
28 return a
30 def _run(self, *args, attributes=None, verbose=0, fLOG=None): # pylint: disable=W0221
31 targs = tuple(self._preprocess(a) for a in args)
32 return (numpy.concatenate(targs, self.axis), )
34 def to_python(self, inputs):
35 return "import numpy", "return numpy.concatenate(inputs, axis=axis)"