Coverage for mlprodict/onnxrt/ops_cpu/op_compress.py: 83%

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

23 statements  

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

2# pylint: disable=E0203,E1101,C0111 

3""" 

4@file 

5@brief Runtime operator. 

6""" 

7import numpy 

8from ..shape_object import ShapeObject 

9from ._op import OpRun, DefaultNone 

10 

11 

12class Compress(OpRun): 

13 

14 atts = {'axis': DefaultNone} 

15 

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

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

18 expected_attributes=Compress.atts, 

19 **options) 

20 

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

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

23 return (numpy.compress(condition, x, axis=self.axis, out=x), ) 

24 return (numpy.compress(condition, x, axis=self.axis), ) 

25 

26 def _infer_shapes(self, x, condition): # pylint: disable=W0221 

27 return (ShapeObject(None, dtype=x.dtype), ) 

28 

29 def _infer_types(self, x, condition): # pylint: disable=W0221 

30 return (x, ) 

31 

32 def to_python(self, inputs): 

33 if self.axis is None: 

34 return "import numpy\nreturn numpy.compress(%s, %s)" % tuple(inputs) 

35 return "import numpy\nreturn numpy.compress(%s, %s, axis=%d)" % ( 

36 tuple(inputs) + (self.axis, )) 

37 

38 def _infer_sizes(self, x, condition): # pylint: disable=W0221 

39 res = self.run(x, condition) 

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