Coverage for mlprodict/onnxrt/ops_cpu/op_expand.py: 87%

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 ._op import OpRun 

9from ..shape_object import ShapeObject 

10 

11 

12def common_reference_implementation(data, shape): 

13 ones = numpy.ones(shape, dtype=data.dtype) 

14 return data * ones 

15 

16 

17class CommonExpand(OpRun): 

18 

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

20 OpRun.__init__( 

21 self, onnx_node, desc=desc, 

22 expected_attributes=expected_attributes, **options) 

23 

24 def _run(self, data, shape): # pylint: disable=W0221 

25 return (common_reference_implementation(data, shape), ) 

26 

27 def _infer_shapes(self, data, shape): # pylint: disable=W0221 

28 return (ShapeObject(None, dtype=data.dtype), ) 

29 

30 def _infer_types(self, data, shape): # pylint: disable=W0221 

31 return (data, ) 

32 

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

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

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

36 

37 

38class Expand_13(CommonExpand): 

39 

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

41 CommonExpand.__init__( 

42 self, onnx_node, desc=desc, **options) 

43 

44 

45Expand = Expand_13