Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -*- encoding: utf-8 -*- 

2# pylint: disable=E0203,E1101,C0111 

3""" 

4@file 

5@brief Runtime operator. 

6""" 

7from ._op import OpRunUnary 

8 

9 

10class Scaler(OpRunUnary): 

11 

12 atts = {'offset': None, 'scale': None} 

13 

14 def __init__(self, onnx_node, desc=None, **options): 

15 OpRunUnary.__init__(self, onnx_node, desc=desc, 

16 expected_attributes=Scaler.atts, 

17 **options) 

18 

19 def _run(self, x): # pylint: disable=W0221 

20 return self._run_no_checks_(x) 

21 

22 def _run_no_checks_(self, x): # pylint: disable=W0221 

23 if self.inplaces.get(0, False): 

24 return self._run_inplace(x) 

25 return ((x - self.offset) * self.scale, ) 

26 

27 def _run_inplace(self, x): 

28 x -= self.offset 

29 x *= self.scale 

30 return (x, )