- Fixes #170, add operator pad
Showing 3 of 4 files from the diff.
Newly tracked file
mlprodict/onnxrt/ops_cpu/op_pad.py
created.
Other files ignored by Codecov
@@ -213,7 +213,8 @@
Loading
213 | 213 | except (TypeError, ValueError) as e: |
|
214 | 214 | raise TypeError( |
|
215 | 215 | "Unable to call infer_shapes with {} arguments for class" |
|
216 | - | " '{}'".format(len(args), self.ops_.__class__.__name__)) from e |
|
216 | + | " '{}' ({})".format(len(args), self.ops_.__class__.__name__, |
|
217 | + | self.ops_.infer_shapes)) from e |
|
217 | 218 | if not isinstance(res, tuple): |
|
218 | 219 | raise RuntimeError( # pragma: no cover |
|
219 | 220 | "Results of an operator should be a tuple for operator '{}'" |
@@ -0,0 +1,46 @@
Loading
1 | + | # -*- encoding: utf-8 -*- |
|
2 | + | # pylint: disable=E0203,E1101,C0111 |
|
3 | + | """ |
|
4 | + | @file |
|
5 | + | @brief Runtime operator. |
|
6 | + | """ |
|
7 | + | import numpy |
|
8 | + | from ._op import OpRun |
|
9 | + | from ..shape_object import ShapeObject |
|
10 | + | ||
11 | + | ||
12 | + | def _pad_impl(data, raw_pads, mode, constant_values=0.0): |
|
13 | + | input_rank = data.ndim |
|
14 | + | if input_rank * 2 != raw_pads.size: |
|
15 | + | raise Exception( |
|
16 | + | 'The number of elements in raw_pads should be 2 * data_rank') |
|
17 | + | ||
18 | + | half = raw_pads.shape[0] // 2 |
|
19 | + | pad_width = tuple((raw_pads[i], raw_pads[i + half]) |
|
20 | + | for i in range(0, half)) |
|
21 | + | ||
22 | + | if mode == 'constant': |
|
23 | + | return numpy.pad(data, pad_width=pad_width, mode=mode, |
|
24 | + | constant_values=constant_values) |
|
25 | + | return numpy.pad(data, pad_width=pad_width, mode=mode) |
|
26 | + | ||
27 | + | ||
28 | + | class Pad(OpRun): |
|
29 | + | ||
30 | + | atts = {'mode': b'constant'} |
|
31 | + | ||
32 | + | def __init__(self, onnx_node, desc=None, **options): |
|
33 | + | OpRun.__init__(self, onnx_node, desc=desc, |
|
34 | + | expected_attributes=Pad.atts, |
|
35 | + | **options) |
|
36 | + | self.mode_ = self.mode.decode('ascii') |
|
37 | + | ||
38 | + | def _run(self, data, pads, constant_value=None): # pylint: disable=W0221 |
|
39 | + | return (_pad_impl(data, pads, mode=self.mode_, |
|
40 | + | constant_values=constant_value), ) |
|
41 | + | ||
42 | + | def _infer_shapes(self, data, pads, constant_value=None): # pylint: disable=E0202,W0221 |
|
43 | + | """ |
|
44 | + | Returns the same shape by default. |
|
45 | + | """ |
|
46 | + | return (ShapeObject(None, data.dtype), ) |
Files | Coverage |
---|---|
mlprodict | 91.53% |
Project Totals (226 files) | 91.53% |
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.