Coverage for mlprodict/onnxrt/validate/_validate_problems_helper.py: 94%

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

33 statements  

1""" 

2@file 

3@brief Validates runtime for many :scikit-learn: operators. 

4The submodule relies on :epkg:`onnxconverter_common`, 

5:epkg:`sklearn-onnx`. 

6""" 

7import numpy 

8 

9 

10text_alpha_num = [ 

11 ('zero', 0), 

12 ('one', 1), 

13 ('two', 2), 

14 ('three', 3), 

15 ('four', 4), 

16 ('five', 5), 

17 ('six', 6), 

18 ('seven', 7), 

19 ('eight', 8), 

20 ('nine', 9), 

21 ('dix', 10), 

22 ('eleven', 11), 

23 ('twelve', 12), 

24 ('thirteen', 13), 

25 ('fourteen', 14), 

26 ('fifteen', 15), 

27 ('sixteen', 16), 

28 ('seventeen', 17), 

29 ('eighteen', 18), 

30 ('nineteen', 19), 

31 ('twenty', 20), 

32 ('twenty one', 21), 

33 ('twenty two', 22), 

34 ('twenty three', 23), 

35 ('twenty four', 24), 

36 ('twenty five', 25), 

37 ('twenty six', 26), 

38 ('twenty seven', 27), 

39 ('twenty eight', 28), 

40 ('twenty nine', 29), 

41] 

42 

43 

44def _guess_noshape(obj, shape): 

45 if isinstance(obj, numpy.ndarray): 

46 if obj.dtype == numpy.float32: 

47 from skl2onnx.common.data_types import ( # delayed 

48 FloatTensorType) 

49 return FloatTensorType(shape) 

50 if obj.dtype == numpy.float64: 

51 from skl2onnx.common.data_types import ( # delayed 

52 DoubleTensorType) 

53 return DoubleTensorType(shape) 

54 raise NotImplementedError( # pragma: no cover 

55 "Unable to process object(1) [{}].".format(obj)) 

56 raise NotImplementedError( # pragma: no cover 

57 "Unable to process object(2) [{}].".format(obj)) 

58 

59 

60def _noshapevar(fct): 

61 

62 def process_itt(itt, Xort): 

63 if isinstance(itt, tuple): 

64 return (process_itt(itt[0], Xort), itt[1]) 

65 

66 # name = "V%s_" % str(id(Xort))[:5] 

67 new_itt = [] 

68 for a, b in itt: 

69 # shape = [name + str(i) for s in b.shape] 

70 shape = [None for s in b.shape] 

71 new_itt.append((a, _guess_noshape(b, shape))) 

72 return new_itt 

73 

74 def new_fct(**kwargs): 

75 X, y, itt, meth, mo, Xort = fct(**kwargs) 

76 new_itt = process_itt(itt, Xort) 

77 return X, y, new_itt, meth, mo, Xort 

78 return new_fct 

79 

80 

81def _1d_problem(fct): 

82 

83 def new_fct(**kwargs): 

84 n_features = kwargs.get('n_features', None) 

85 if n_features not in (None, 1): 

86 raise RuntimeError( # pragma: no cover 

87 "Misconfiguration: the number of features must not be " 

88 "specified for a 1D problem.") 

89 X, y, itt, meth, mo, Xort = fct(**kwargs) 

90 new_itt = itt # process_itt(itt, Xort) 

91 X = X[:, 0] 

92 return X, y, new_itt, meth, mo, Xort 

93 return new_fct