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

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

18 statements  

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

2# pylint: disable=E0203,E1101,C0111 

3""" 

4@file 

5@brief Runtime operator. 

6""" 

7import numpy 

8from ._op import OpRunUnaryNum 

9from ._op_numpy_helper import numpy_dot_inplace 

10 

11 

12class LinearRegressor(OpRunUnaryNum): 

13 

14 atts = {'coefficients': None, 'intercepts': None, 

15 'targets': 1, 'post_transform': b'NONE'} 

16 

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

18 OpRunUnaryNum.__init__(self, onnx_node, desc=desc, 

19 expected_attributes=LinearRegressor.atts, 

20 **options) 

21 if not isinstance(self.coefficients, numpy.ndarray): 

22 raise TypeError( # pragma: no cover 

23 "coefficient must be an array not {}.".format( 

24 type(self.coefficients))) 

25 n = self.coefficients.shape[0] // self.targets 

26 self.coefficients = self.coefficients.reshape(self.targets, n).T 

27 

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

29 score = numpy_dot_inplace(self.inplaces, x, self.coefficients) 

30 if self.intercepts is not None: 

31 score += self.intercepts 

32 if self.post_transform == b'NONE': 

33 pass 

34 else: 

35 raise NotImplementedError( # pragma: no cover 

36 "Unknown post_transform: '{}'.".format( 

37 self.post_transform)) 

38 return (score, )