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

28 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 

10from .op_murmurhash3_ import ( # pylint: disable=E0611 

11 MurmurHash3_x86_32, MurmurHash3_x86_32_positive) 

12 

13 

14class MurmurHash3(OpRun): 

15 

16 atts = {'positive': 1, 'seed': 0} 

17 

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

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

20 expected_attributes=MurmurHash3.atts, 

21 **options) 

22 

23 def _find_custom_operator_schema(self, op_name): 

24 if op_name == "MurmurHash3": 

25 return MurmurHash3Schema() 

26 raise RuntimeError( # pragma: no cover 

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

28 

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

30 if self.positive: 

31 res = numpy.empty(x.shape, dtype=numpy.uint32).flatten() 

32 xf = x.flatten() 

33 for i in range(len(xf)): # pylint: disable=C0200 

34 res[i] = MurmurHash3_x86_32_positive(xf[i], self.seed) 

35 return (res.reshape(x.shape), ) 

36 

37 res = numpy.empty(x.shape, dtype=numpy.int32).flatten() 

38 xf = x.flatten() 

39 for i in range(len(xf)): # pylint: disable=C0200 

40 res[i] = MurmurHash3_x86_32(xf[i], self.seed) 

41 return (res.reshape(x.shape), ) 

42 

43 

44class MurmurHash3Schema(OperatorSchema): 

45 """ 

46 Defines a schema for operators added in this package 

47 such as @see cl MurmurHash3. 

48 """ 

49 

50 def __init__(self): 

51 OperatorSchema.__init__(self, 'MurmurHash3') 

52 self.attributes = MurmurHash3.atts