Coverage for mlprodict/onnxrt/ops_cpu/op_debug.py: 85%

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

27 statements  

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

2# pylint: disable=E0203,E1101,C0111 

3""" 

4@file 

5@brief Runtime operator. 

6""" 

7from ._op import OpRun 

8from ._new_ops import OperatorSchema 

9 

10 

11class DEBUG(OpRun): 

12 

13 atts = {} 

14 

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

16 OpRun.__init__(self, onnx_node, desc=desc, 

17 **options) 

18 

19 def _run(self, a, *args): # pylint: disable=W0221 

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

21 return (a, ) 

22 return (a.copy(), ) 

23 

24 def to_python(self, inputs): 

25 return "", "return %s.copy()" % inputs[0] 

26 

27 def _find_custom_operator_schema(self, op_name): 

28 if op_name == "DEBUG": 

29 return DEBUGSchema() 

30 raise RuntimeError( # pragma: no cover 

31 "Unable to find a schema for operator '{}'.".format(op_name)) 

32 

33 def _infer_shapes(self, x, *args): # pylint: disable=E0202,W0221 

34 """ 

35 Returns the same shape by default. 

36 """ 

37 return (x, ) 

38 

39 def _infer_types(self, x, *args): # pylint: disable=E0202,W0221 

40 """ 

41 Returns the same type by default. 

42 """ 

43 return (x, ) 

44 

45 def _infer_sizes(self, *args, **kwargs): 

46 res = self.run(*args, **kwargs) 

47 return (dict(temp=0), ) + res 

48 

49 

50class DEBUGSchema(OperatorSchema): 

51 """ 

52 Defines a schema for operators added in this package 

53 such as @see cl Solve. 

54 """ 

55 

56 def __init__(self): 

57 OperatorSchema.__init__(self, 'DEBUG') 

58 self.attributes = DEBUG.atts