Coverage for mlprodict/npy/numpy_onnx_pyrt.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
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
1"""
2@file
3@brief :epkg:`numpy` functions implemented with :epkg:`onnx`
4and compiled with this python runtime.
6.. versionadded:: 0.6
7"""
8import numpy
9from .onnx_numpy_annotation import (
10 NDArrayType,
11 NDArrayTypeSameShape,
12 NDArraySameType,
13 NDArraySameTypeSameShape)
14from .numpy_onnx_impl import (
15 abs as nx_abs,
16 acos as nx_acos,
17 acosh as nx_acosh,
18 amin as nx_min,
19 amax as nx_max,
20 arange as nx_arange,
21 argmax as nx_argmax,
22 argmin as nx_argmin,
23 asin as nx_asin,
24 asinh as nx_asinh,
25 atan as nx_atan,
26 atanh as nx_atanh,
27 ceil as nx_ceil,
28 clip as nx_clip,
29 compress as nx_compress,
30 cos as nx_cos,
31 cosh as nx_cosh,
32 cumsum as nx_cumsum,
33 concat as nx_concat,
34 det as nx_det,
35 dot as nx_dot,
36 einsum as nx_einsum,
37 erf as nx_erf,
38 exp as nx_exp,
39 expit as nx_expit,
40 expand_dims as nx_expand_dims,
41 floor as nx_floor,
42 hstack as nx_hstack,
43 isnan as nx_isnan,
44 log as nx_log,
45 log1p as nx_log1p,
46 matmul as nx_matmul,
47 mean as nx_mean,
48 pad as nx_pad,
49 prod as nx_prod,
50 reciprocal as nx_reciprocal,
51 relu as nx_relu,
52 round as nx_round,
53 sigmoid as nx_sigmoid,
54 sign as nx_sign,
55 sin as nx_sin,
56 sinh as nx_sinh,
57 sqrt as nx_sqrt,
58 squeeze as nx_squeeze,
59 sum as nx_sum,
60 tan as nx_tan,
61 tanh as nx_tanh,
62 topk as nx_topk,
63 transpose as nx_transpose,
64 unsqueeze as nx_unsqueeze,
65 vstack as nx_vstack,
66 where as nx_where,
67)
68from .onnx_numpy_wrapper import onnxnumpy_np
71@onnxnumpy_np(signature=NDArraySameTypeSameShape("all"))
72def abs(x):
73 "abs"
74 return nx_abs(x)
77@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
78def acos(x):
79 "acos"
80 return nx_acos(x)
83@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
84def acosh(x):
85 "acosh"
86 return nx_acosh(x)
89@onnxnumpy_np(signature=NDArrayType((numpy.int64, numpy.int64)))
90def arange(start, stop, step=1):
91 "arange, *start*, *stop* must be specified."
92 return nx_arange(start, stop, step=step)
95@onnxnumpy_np(signature=NDArraySameType("all"))
96def amax(x, axis=None, keepdims=0):
97 "amax"
98 return nx_max(x, axis=axis, keepdims=keepdims)
101@onnxnumpy_np(signature=NDArraySameType("all"))
102def amin(x, axis=None, keepdims=0):
103 "amin"
104 return nx_min(x, axis=axis, keepdims=keepdims)
107@onnxnumpy_np(signature=NDArrayType("all_int"))
108def argmax(x, axis=0, keepdims=0):
109 "argmax"
110 return nx_argmax(x, axis=axis, keepdims=keepdims)
113@onnxnumpy_np(signature=NDArrayType("all_int"))
114def argmin(x, axis=0, keepdims=0):
115 "argmin"
116 return nx_argmin(x, axis=axis, keepdims=keepdims)
119@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
120def asin(x):
121 "asin"
122 return nx_asin(x)
125@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
126def asinh(x):
127 "asinh"
128 return nx_asinh(x)
131@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
132def atan(x):
133 "atan"
134 return nx_atan(x)
137@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
138def atanh(x):
139 "atanh"
140 return nx_atanh(x)
143@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
144def ceil(x):
145 "ceil"
146 return nx_ceil(x)
149@onnxnumpy_np(
150 signature=NDArrayType(("all", "all", "all"), n_optional=2))
151def clip(x, a_min=None, a_max=None):
152 "clip"
153 return nx_clip(x, a_min, a_max)
156@onnxnumpy_np(signature=NDArrayType(("bool", "T:all"), dtypes_out=('T',)))
157def compress(condition, x, axis=None):
158 "compress"
159 return nx_compress(condition, x, axis=axis)
162@onnxnumpy_np(signature=NDArrayType("all", nvars=True))
163def concat(*x, axis=0):
164 "concat"
165 return nx_concat(*x, axis=axis)
168@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
169def cos(x):
170 "cos"
171 return nx_cos(x)
174@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
175def cosh(x):
176 "cosh"
177 return nx_cosh(x)
180@onnxnumpy_np(signature=NDArrayType(("all", "ints")))
181def cumsum(x, axis):
182 "cumsum"
183 return nx_cumsum(x, axis)
186@onnxnumpy_np(signature=NDArrayType("all"))
187def det(x):
188 "det"
189 return nx_det(x)
192@onnxnumpy_np(signature=NDArrayType(("T:all", "T")))
193def dot(a, b):
194 "dot"
195 return nx_dot(a, b)
198@onnxnumpy_np(signature=NDArrayType("all", nvars=True))
199def einsum(*x, equation=None):
200 "einsum"
201 return nx_einsum(*x, equation=equation)
204@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
205def erf(x):
206 "erf"
207 return nx_erf(x)
210@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
211def exp(x):
212 "exp"
213 return nx_exp(x)
216@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
217def expit(x):
218 "expit"
219 return nx_expit(x)
222@onnxnumpy_np(signature=NDArrayType("floats"))
223def expand_dims(x, axis=0):
224 "expand_dims"
225 return nx_expand_dims(x, axis)
228@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
229def floor(x):
230 "floor"
231 return nx_floor(x)
234@onnxnumpy_np(signature=NDArrayType("all", nvars=True))
235def hstack(*x):
236 "hstack"
237 return nx_hstack(*x)
240@onnxnumpy_np(signature=NDArrayTypeSameShape("all_bool"))
241def isnan(x):
242 "isnan"
243 return nx_isnan(x)
246@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
247def log(x):
248 "log"
249 return nx_log(x)
252@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
253def log1p(x):
254 "log1p"
255 return nx_log1p(x)
258@onnxnumpy_np(signature=NDArrayType(("T:all", "T")))
259def matmul(a, b):
260 "matmul"
261 return nx_matmul(a, b)
264@onnxnumpy_np(signature=NDArrayType(("T:all", numpy.int64, 'T'), n_optional=1))
265def pad(x, pads, constant_value=None, mode='constant'):
266 "pad"
267 return nx_pad(x, pads, mode=mode, constant_value=constant_value)
270@onnxnumpy_np(signature=NDArraySameType("all"))
271def prod(x, axis=None, keepdims=0):
272 "prod"
273 return nx_prod(x, axis=axis, keepdims=keepdims)
276@onnxnumpy_np(signature=NDArraySameType("all"))
277def mean(x, axis=None, keepdims=0):
278 "mean"
279 return nx_mean(x, axis=axis, keepdims=keepdims)
282@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
283def reciprocal(x):
284 "reciprocal"
285 return nx_reciprocal(x)
288@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
289def relu(x):
290 "relu"
291 return nx_relu(x)
294@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
295def round(x):
296 "round"
297 return nx_round(x)
300@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
301def sigmoid(x):
302 "expit"
303 return nx_sigmoid(x)
306@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
307def sign(x):
308 "sign"
309 return nx_sign(x)
312@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
313def sin(x):
314 "sin"
315 return nx_sin(x)
318@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
319def sinh(x):
320 "sinh"
321 return nx_sinh(x)
324@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
325def sqrt(x):
326 "sqrt"
327 return nx_sqrt(x)
330@onnxnumpy_np(signature=NDArrayType(("all", numpy.int64), n_optional=1))
331def squeeze(x, axis=None):
332 "squeeze"
333 return nx_squeeze(x, axis)
336@onnxnumpy_np(signature=NDArraySameType("all"))
337def sum(x, axis=None, keepdims=0):
338 "sum"
339 return nx_sum(x, axis=axis, keepdims=keepdims)
342@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
343def tan(x):
344 "tan"
345 return nx_tan(x)
348@onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"))
349def tanh(x):
350 "tanh"
351 return nx_tanh(x)
354@onnxnumpy_np(signature=NDArrayType(("T:all", "ints"), ("T", (numpy.int64,))))
355def topk(x, k, axis=-1, largest=1, sorted=1):
356 "topk"
357 return nx_topk(x, k, axis=axis, largest=largest, sorted=sorted)
360@onnxnumpy_np(signature=NDArraySameType("all"))
361def transpose(x, perm=(1, 0)):
362 "transpose"
363 return nx_transpose(x, perm=perm)
366@onnxnumpy_np(signature=NDArrayType(("all", numpy.int64)))
367def unsqueeze(x, axes):
368 "unsqueeze"
369 return nx_unsqueeze(x, axes)
372@onnxnumpy_np(signature=NDArrayType("all", nvars=True))
373def vstack(*x):
374 "vstack"
375 return nx_vstack(*x)
378@onnxnumpy_np(signature=NDArrayType(("bool", "T:all", "T"), ("T", )))
379def where(cond, x, y):
380 "where"
381 return nx_where(cond, x, y)