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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

11 statements  

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): # pylint: disable=W0221 

22 return (numpy.where(x > 0, x * self.gamma, 

23 numpy.exp(x) * self.alpha - self.alpha), ) 

24 

25 def to_python(self, inputs): 

26 return ( 

27 "import numpy", 

28 ("return numpy.where({0} > 0, {0} * {1}, " 

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

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