Source code for mlprodict.onnxrt.ops_cpu.op_scaler

# -*- encoding: utf-8 -*-
# pylint: disable=E0203,E1101,C0111
"""
Runtime operator.


:githublink:`%|py|7`
"""
from ._op import OpRunUnary


[docs]class Scaler(OpRunUnary): atts = {'offset': None, 'scale': None}
[docs] def __init__(self, onnx_node, desc=None, **options): OpRunUnary.__init__(self, onnx_node, desc=desc, expected_attributes=Scaler.atts, **options)
[docs] def _run(self, x): # pylint: disable=W0221 return self._run_no_checks_(x)
[docs] def _run_no_checks_(self, x): # pylint: disable=W0221 if self.inplaces.get(0, False): return self._run_inplace(x) return ((x - self.offset) * self.scale, )
[docs] def _run_inplace(self, x): x -= self.offset x *= self.scale return (x, )
[docs] def _infer_shapes(self, x): # pylint: disable=W0221 """ Returns the same shape by default. :githublink:`%|py|35` """ return (x, )