Coverage for mlprodict/onnxrt/ops_cpu/op_selu.py: 100%

11 statements  

« 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 OpRunUnaryNum 

9 

10 

11class Selu(OpRunUnaryNum): 

12 

13 atts = {'alpha': 1.67326319217681884765625, 

14 'gamma': 1.05070102214813232421875} 

15 

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

17 OpRunUnaryNum.__init__(self, onnx_node, desc=desc, 

18 expected_attributes=Selu.atts, 

19 **options) 

20 

21 def _run(self, x, attributes=None, verbose=0, fLOG=None): # pylint: disable=W0221 

22 return (numpy.where( 

23 x > 0, x, 

24 numpy.exp(x) * self.alpha - self.alpha) * self.gamma, ) 

25 

26 def to_python(self, inputs): 

27 return ( 

28 "import numpy", 

29 ("return numpy.where({0} > 0, {0}, " 

30 "numpy.exp({0}) * {2} - {2}) * {1}").format( 

31 inputs[0], self.gamma, self.alpha))