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

23 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 OpRun 

9from ._new_ops import OperatorSchema 

10 

11 

12class ComplexAbs(OpRun): 

13 

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

15 OpRun.__init__(self, onnx_node, desc=desc, **options) 

16 

17 def _find_custom_operator_schema(self, op_name): 

18 if op_name == "ComplexAbs": 

19 return ComplexAbsSchema() 

20 raise RuntimeError( # pragma: no cover 

21 f"Unable to find a schema for operator '{op_name}'.") 

22 

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

24 y = numpy.absolute(x) 

25 if x.dtype == numpy.complex64: 

26 y = y.astype(numpy.float32) 

27 elif x.dtype == numpy.complex128: 

28 y = y.astype(numpy.float64) 

29 else: 

30 raise TypeError( # pragma: no cover 

31 f"Unexpected input type for x: {x.dtype!r}.") 

32 return (y, ) 

33 

34 def to_python(self, inputs): 

35 return self._to_python_numpy(inputs, 'absolute') 

36 

37 

38class ComplexAbsSchema(OperatorSchema): 

39 """ 

40 Defines a schema for operators added in this package 

41 such as @see cl ComplexAbs. 

42 """ 

43 

44 def __init__(self): 

45 OperatorSchema.__init__(self, 'ComplexAbs') 

46 self.attributes = {}