pynumerics 2.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pynumerics/__init__.py +73 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.LICENSE.txt +27 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.dll +0 -0
- pynumerics/_bin/Numerics.dll +0 -0
- pynumerics/_bin/pynumerics.runtimeconfig.json +15 -0
- pynumerics/_coverage.py +3825 -0
- pynumerics/_util.py +237 -0
- pynumerics/_version.py +40 -0
- pynumerics/bootstrap.py +593 -0
- pynumerics/callbacks.py +791 -0
- pynumerics/copulas.py +910 -0
- pynumerics/data.py +2233 -0
- pynumerics/differentiation.py +348 -0
- pynumerics/distributions.py +4043 -0
- pynumerics/download.py +623 -0
- pynumerics/enums.py +119 -0
- pynumerics/errors.py +245 -0
- pynumerics/functions.py +1142 -0
- pynumerics/goodness_of_fit.py +699 -0
- pynumerics/graphs.py +556 -0
- pynumerics/hypothesis_tests.py +445 -0
- pynumerics/identity.py +144 -0
- pynumerics/integration.py +677 -0
- pynumerics/linalg.py +1408 -0
- pynumerics/machine_learning.py +1335 -0
- pynumerics/marshal.py +733 -0
- pynumerics/mathematics.py +1053 -0
- pynumerics/mcmc.py +1406 -0
- pynumerics/multivariate.py +1539 -0
- pynumerics/ode.py +156 -0
- pynumerics/optimization.py +1736 -0
- pynumerics/probability.py +966 -0
- pynumerics/py.typed +0 -0
- pynumerics/regional.py +522 -0
- pynumerics/roots.py +274 -0
- pynumerics/runtime.py +384 -0
- pynumerics/sampling.py +1758 -0
- pynumerics/special.py +1079 -0
- pynumerics/statistics.py +1958 -0
- pynumerics/timeseries.py +1326 -0
- pynumerics-2.3.0.dist-info/METADATA +142 -0
- pynumerics-2.3.0.dist-info/RECORD +46 -0
- pynumerics-2.3.0.dist-info/WHEEL +5 -0
- pynumerics-2.3.0.dist-info/licenses/LICENSE +10 -0
- pynumerics-2.3.0.dist-info/top_level.txt +1 -0
pynumerics/special.py
ADDED
|
@@ -0,0 +1,1079 @@
|
|
|
1
|
+
"""Special functions from ``Numerics.Mathematics.SpecialFunctions``.
|
|
2
|
+
|
|
3
|
+
Gamma, beta, error, Bessel and Debye functions, factorials and combinations, and polynomial
|
|
4
|
+
evaluation. Every value is computed by the Numerics routine, and arguments broadcast like NumPy
|
|
5
|
+
ufuncs. A scalar argument calls the scalar member, bound once per process. An array argument of a
|
|
6
|
+
gamma, beta, error, Bessel or Debye function crosses into .NET once, through the ``IList<double>``
|
|
7
|
+
overload of the member (one call per distinct order for the integer-order Bessel functions), and
|
|
8
|
+
every value is the bits of the scalar member.
|
|
9
|
+
|
|
10
|
+
The incomplete gamma functions take ``(a, x)`` in the order of ``scipy.special.gammainc``, and the
|
|
11
|
+
regularized incomplete beta function and its inverse take ``(a, b, x)`` in the order of
|
|
12
|
+
``scipy.special.betainc``.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from collections.abc import Iterator
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
from pynumerics._util import bind, broadcast_loop, cached_overload, loop, namespace, overload
|
|
23
|
+
from pynumerics.errors import translate_public
|
|
24
|
+
from pynumerics.marshal import (
|
|
25
|
+
_flat_doubles,
|
|
26
|
+
_numpy_rectangular,
|
|
27
|
+
to_net_doubles,
|
|
28
|
+
to_net_ints,
|
|
29
|
+
to_numpy_doubles,
|
|
30
|
+
to_numpy_ints,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _special() -> Any:
|
|
35
|
+
"""Return the ``Numerics.Mathematics.SpecialFunctions`` namespace after starting the runtime."""
|
|
36
|
+
return namespace("Numerics.Mathematics.SpecialFunctions")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _member(type_name: str, name: str, arity: int = 1) -> Any:
|
|
40
|
+
"""Return ``<type_name>.<name>`` taking ``arity`` doubles, bound once per process."""
|
|
41
|
+
return cached_overload(f"{type_name}.{name}({arity} double)",
|
|
42
|
+
lambda: bind(getattr(getattr(_special(), type_name), name), arity))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _typed_member(type_name: str, name: str, *types: str) -> Any:
|
|
46
|
+
"""Return the overload of ``<type_name>.<name>`` taking the named ``System`` types, bound once per process."""
|
|
47
|
+
return cached_overload(f"{type_name}.{name}({', '.join(types)})",
|
|
48
|
+
lambda: overload(getattr(getattr(_special(), type_name), name), *types))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _list_member(type_name: str, name: str, *types: str) -> Any:
|
|
52
|
+
"""Return the list overload of ``<type_name>.<name>`` taking ``types``, resolved once per process."""
|
|
53
|
+
return cached_overload(f"{type_name}.{name}({', '.join(types)})",
|
|
54
|
+
lambda: overload(getattr(getattr(_special(), type_name), name), *types))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
_APPLY_MEMBERS: dict[tuple[str, str, int], tuple[Any, Any]] = {}
|
|
58
|
+
"""The (scalar, list) overload pair of each ``_apply`` member, keyed by type, member name and arity."""
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _apply(type_name: str, name: str, *args: Any, order: tuple[int, ...] | None = None) -> Any:
|
|
62
|
+
"""Evaluate the double member ``<type_name>.<name>`` over the broadcast of ``args``.
|
|
63
|
+
|
|
64
|
+
``order`` gives the Numerics parameter order as indices into ``args`` (for example ``(1, 0)``
|
|
65
|
+
when the member takes the arguments in the reverse order). Scalars call the bound scalar member
|
|
66
|
+
and give a Python float. Arrays are broadcast, flattened and passed as one ``System.Double[]``
|
|
67
|
+
per parameter to the ``IList<double>`` overload, so they cross once; the result has the
|
|
68
|
+
broadcast shape and the bits of the scalar member at every element. A single argument needs no
|
|
69
|
+
broadcasting, and each broadcast argument crosses in one strided copy, with no contiguous copy
|
|
70
|
+
first.
|
|
71
|
+
"""
|
|
72
|
+
members = _APPLY_MEMBERS.get((type_name, name, len(args)))
|
|
73
|
+
if members is None:
|
|
74
|
+
members = _APPLY_MEMBERS[(type_name, name, len(args))] = (
|
|
75
|
+
_member(type_name, name, len(args)), _list_member(type_name, name, *(("IList[Double]",) * len(args))))
|
|
76
|
+
scalar, vector = members
|
|
77
|
+
order = order or range(len(args))
|
|
78
|
+
if len(args) == 1:
|
|
79
|
+
arrays = (np.asarray(args[0], dtype=np.float64),)
|
|
80
|
+
else:
|
|
81
|
+
arrays = np.broadcast_arrays(*(np.asarray(a, dtype=np.float64) for a in args))
|
|
82
|
+
if arrays[0].ndim == 0:
|
|
83
|
+
return float(scalar(*(float(arrays[i]) for i in order)))
|
|
84
|
+
result = to_numpy_doubles(vector(*(_flat_doubles(arrays[i]) for i in order)))
|
|
85
|
+
return result if arrays[0].ndim == 1 else result.reshape(arrays[0].shape)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def gamma_function(x: Any) -> Any:
|
|
89
|
+
"""Return the gamma function (``Gamma.Function``).
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
x : float or array_like
|
|
94
|
+
Arguments; large positive arguments give +inf.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
float or numpy.ndarray
|
|
99
|
+
The values, shaped like ``x``.
|
|
100
|
+
|
|
101
|
+
Raises
|
|
102
|
+
------
|
|
103
|
+
ArithmeticError
|
|
104
|
+
At zero and at the negative integers (poles; raised by Numerics).
|
|
105
|
+
"""
|
|
106
|
+
return _apply("Gamma", "Function", x)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def log_gamma(x: Any) -> Any:
|
|
110
|
+
"""Return ln|Gamma(x)| (``Gamma.LogGamma``), the quantity of ``scipy.special.gammaln``.
|
|
111
|
+
|
|
112
|
+
Parameters
|
|
113
|
+
----------
|
|
114
|
+
x : float or array_like
|
|
115
|
+
Arguments.
|
|
116
|
+
|
|
117
|
+
Returns
|
|
118
|
+
-------
|
|
119
|
+
float or numpy.ndarray
|
|
120
|
+
The values, shaped like ``x``.
|
|
121
|
+
"""
|
|
122
|
+
return _apply("Gamma", "LogGamma", x)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def digamma(x: Any) -> Any:
|
|
126
|
+
"""Return the digamma function, the derivative of ln Gamma (``Gamma.Digamma``, algorithm AS 103).
|
|
127
|
+
|
|
128
|
+
Parameters
|
|
129
|
+
----------
|
|
130
|
+
x : float or array_like
|
|
131
|
+
Arguments.
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
float or numpy.ndarray
|
|
136
|
+
The values, shaped like ``x``.
|
|
137
|
+
"""
|
|
138
|
+
return _apply("Gamma", "Digamma", x)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def trigamma(x: Any) -> Any:
|
|
142
|
+
"""Return the trigamma function, the second derivative of ln Gamma (``Gamma.Trigamma``).
|
|
143
|
+
|
|
144
|
+
Parameters
|
|
145
|
+
----------
|
|
146
|
+
x : float or array_like
|
|
147
|
+
Positive arguments.
|
|
148
|
+
|
|
149
|
+
Returns
|
|
150
|
+
-------
|
|
151
|
+
float or numpy.ndarray
|
|
152
|
+
The values, shaped like ``x``.
|
|
153
|
+
"""
|
|
154
|
+
return _apply("Gamma", "Trigamma", x)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def gamma_max() -> float:
|
|
158
|
+
"""Return ``Gamma.GammaMax``, the largest argument for which the gamma function is finite.
|
|
159
|
+
|
|
160
|
+
Returns
|
|
161
|
+
-------
|
|
162
|
+
float
|
|
163
|
+
The constant the loaded assembly uses.
|
|
164
|
+
"""
|
|
165
|
+
return float(_special().Gamma.GammaMax)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def stirling_gamma(x: Any) -> Any:
|
|
169
|
+
"""Return Stirling's approximation of the gamma function (``Gamma.Stirling``).
|
|
170
|
+
|
|
171
|
+
An asymptotic series, accurate for large arguments only.
|
|
172
|
+
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
175
|
+
x : float or array_like
|
|
176
|
+
Arguments.
|
|
177
|
+
|
|
178
|
+
Returns
|
|
179
|
+
-------
|
|
180
|
+
float or numpy.ndarray
|
|
181
|
+
The approximations, shaped like ``x``.
|
|
182
|
+
"""
|
|
183
|
+
return _apply("Gamma", "Stirling", x)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def lanczos_gamma(x: Any) -> Any:
|
|
187
|
+
"""Return the Lanczos approximation of the gamma function (``Gamma.Lanczos``).
|
|
188
|
+
|
|
189
|
+
Parameters
|
|
190
|
+
----------
|
|
191
|
+
x : float or array_like
|
|
192
|
+
Arguments.
|
|
193
|
+
|
|
194
|
+
Returns
|
|
195
|
+
-------
|
|
196
|
+
float or numpy.ndarray
|
|
197
|
+
The approximations, shaped like ``x``.
|
|
198
|
+
"""
|
|
199
|
+
return _apply("Gamma", "Lanczos", x)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def incomplete_gamma(a: Any, x: Any) -> Any:
|
|
203
|
+
"""Return the regularized lower incomplete gamma integral by algorithm AS 239 (``Gamma.Incomplete``).
|
|
204
|
+
|
|
205
|
+
``Gamma.Incomplete(X, alpha)`` is called with ``X = x`` and ``alpha = a``. It keeps the argument
|
|
206
|
+
order and validation of AS 239 and returns the value of :func:`lower_incomplete_gamma`, accurate
|
|
207
|
+
to about 1e-14 relative and nonzero wherever the result is representable.
|
|
208
|
+
|
|
209
|
+
Parameters
|
|
210
|
+
----------
|
|
211
|
+
a : float or array_like
|
|
212
|
+
Positive shape parameters.
|
|
213
|
+
x : float or array_like
|
|
214
|
+
Non-negative upper limits; arrays broadcast with ``a``.
|
|
215
|
+
|
|
216
|
+
Returns
|
|
217
|
+
-------
|
|
218
|
+
float or numpy.ndarray
|
|
219
|
+
P(a, x), in the broadcast shape.
|
|
220
|
+
|
|
221
|
+
Raises
|
|
222
|
+
------
|
|
223
|
+
ValueError
|
|
224
|
+
If ``a <= 0`` or ``x < 0`` (raised by Numerics).
|
|
225
|
+
"""
|
|
226
|
+
return _apply("Gamma", "Incomplete", a, x, order=(1, 0))
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def lower_incomplete_gamma(a: Any, x: Any) -> Any:
|
|
230
|
+
"""Return the regularized lower incomplete gamma function P(a, x) (``Gamma.LowerIncomplete``).
|
|
231
|
+
|
|
232
|
+
The quantity of ``scipy.special.gammainc``; P(a, x) = 0 for x <= 0. Series, continued fraction
|
|
233
|
+
and Temme's uniform expansion, accurate to about 1e-14 relative where P exceeds 1e-30.
|
|
234
|
+
|
|
235
|
+
Parameters
|
|
236
|
+
----------
|
|
237
|
+
a : float or array_like
|
|
238
|
+
Shape parameters.
|
|
239
|
+
x : float or array_like
|
|
240
|
+
Upper limits; arrays broadcast with ``a``.
|
|
241
|
+
|
|
242
|
+
Returns
|
|
243
|
+
-------
|
|
244
|
+
float or numpy.ndarray
|
|
245
|
+
P(a, x), in the broadcast shape.
|
|
246
|
+
"""
|
|
247
|
+
return _apply("Gamma", "LowerIncomplete", a, x)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def upper_incomplete_gamma(a: Any, x: Any) -> Any:
|
|
251
|
+
"""Return the regularized upper incomplete gamma function Q(a, x) (``Gamma.UpperIncomplete``).
|
|
252
|
+
|
|
253
|
+
The quantity of ``scipy.special.gammaincc``; Q(a, x) = 1 for x <= 0. Accurate to about 1e-14
|
|
254
|
+
relative where Q exceeds 1e-30.
|
|
255
|
+
|
|
256
|
+
Parameters
|
|
257
|
+
----------
|
|
258
|
+
a : float or array_like
|
|
259
|
+
Shape parameters.
|
|
260
|
+
x : float or array_like
|
|
261
|
+
Lower limits; arrays broadcast with ``a``.
|
|
262
|
+
|
|
263
|
+
Returns
|
|
264
|
+
-------
|
|
265
|
+
float or numpy.ndarray
|
|
266
|
+
Q(a, x), in the broadcast shape.
|
|
267
|
+
"""
|
|
268
|
+
return _apply("Gamma", "UpperIncomplete", a, x)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def inverse_lower_incomplete_gamma(a: Any, y: Any) -> Any:
|
|
272
|
+
"""Return x with P(a, x) = y (``Gamma.InverseLowerIncomplete``), as ``scipy.special.gammaincinv``.
|
|
273
|
+
|
|
274
|
+
Parameters
|
|
275
|
+
----------
|
|
276
|
+
a : float or array_like
|
|
277
|
+
Positive shape parameters.
|
|
278
|
+
y : float or array_like
|
|
279
|
+
Probabilities in [0, 1]; arrays broadcast with ``a``.
|
|
280
|
+
|
|
281
|
+
Returns
|
|
282
|
+
-------
|
|
283
|
+
float or numpy.ndarray
|
|
284
|
+
The quantiles (0 at y = 0, +inf at y = 1), in the broadcast shape.
|
|
285
|
+
"""
|
|
286
|
+
return _apply("Gamma", "InverseLowerIncomplete", a, y)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def inverse_upper_incomplete_gamma(a: Any, y: Any) -> Any:
|
|
290
|
+
"""Return x with Q(a, x) = y (``Gamma.InverseUpperIncomplete``), as ``scipy.special.gammainccinv``.
|
|
291
|
+
|
|
292
|
+
Parameters
|
|
293
|
+
----------
|
|
294
|
+
a : float or array_like
|
|
295
|
+
Positive shape parameters.
|
|
296
|
+
y : float or array_like
|
|
297
|
+
Probabilities in [0, 1]; arrays broadcast with ``a``.
|
|
298
|
+
|
|
299
|
+
Returns
|
|
300
|
+
-------
|
|
301
|
+
float or numpy.ndarray
|
|
302
|
+
The quantiles, in the broadcast shape.
|
|
303
|
+
"""
|
|
304
|
+
return _apply("Gamma", "InverseUpperIncomplete", a, y)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def beta_function(a: Any, b: Any) -> Any:
|
|
308
|
+
"""Return the beta function B(a, b) = Gamma(a) Gamma(b) / Gamma(a + b) (``Beta.Function``).
|
|
309
|
+
|
|
310
|
+
Parameters
|
|
311
|
+
----------
|
|
312
|
+
a, b : float or array_like
|
|
313
|
+
Positive arguments; arrays broadcast.
|
|
314
|
+
|
|
315
|
+
Returns
|
|
316
|
+
-------
|
|
317
|
+
float or numpy.ndarray
|
|
318
|
+
The values, in the broadcast shape.
|
|
319
|
+
"""
|
|
320
|
+
return _apply("Beta", "Function", a, b)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def log_beta(a: Any, b: Any) -> Any:
|
|
324
|
+
"""Return the natural logarithm of the beta function, ln B(a, b) (``Beta.LogFunction``).
|
|
325
|
+
|
|
326
|
+
The value comes from the routines BETALN, ALGDIV and BCORR of algorithm 708 (DiDonato and
|
|
327
|
+
Morris, 1992), so it keeps its accuracy at large or very unequal shapes, where
|
|
328
|
+
``log_gamma(a) + log_gamma(b) - log_gamma(a + b)`` subtracts large, nearly equal numbers. It
|
|
329
|
+
agrees with ``scipy.special.betaln``, including ln|B(a, b)| for non-positive arguments.
|
|
330
|
+
|
|
331
|
+
Parameters
|
|
332
|
+
----------
|
|
333
|
+
a, b : float or array_like
|
|
334
|
+
Arguments; arrays broadcast.
|
|
335
|
+
|
|
336
|
+
Returns
|
|
337
|
+
-------
|
|
338
|
+
float or numpy.ndarray
|
|
339
|
+
The values, in the broadcast shape.
|
|
340
|
+
"""
|
|
341
|
+
return _apply("Beta", "LogFunction", a, b)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def beta_incomplete(a: Any, b: Any, x: Any) -> Any:
|
|
345
|
+
"""Return the regularized incomplete beta function I_x(a, b) (``Beta.Incomplete``).
|
|
346
|
+
|
|
347
|
+
Parameters
|
|
348
|
+
----------
|
|
349
|
+
a, b : float or array_like
|
|
350
|
+
Positive shape parameters; arrays broadcast.
|
|
351
|
+
x : float or array_like
|
|
352
|
+
Arguments in [0, 1]; arrays broadcast.
|
|
353
|
+
|
|
354
|
+
Returns
|
|
355
|
+
-------
|
|
356
|
+
float or numpy.ndarray
|
|
357
|
+
The values, in the broadcast shape.
|
|
358
|
+
"""
|
|
359
|
+
return _apply("Beta", "Incomplete", a, b, x)
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def beta_incomplete_inverse(a: Any, b: Any, probability: Any) -> Any:
|
|
363
|
+
"""Return the inverse of the regularized incomplete beta function (``Beta.IncompleteInverse``).
|
|
364
|
+
|
|
365
|
+
Parameters
|
|
366
|
+
----------
|
|
367
|
+
a, b : float or array_like
|
|
368
|
+
Positive shape parameters; arrays broadcast.
|
|
369
|
+
probability : float or array_like
|
|
370
|
+
Probabilities in [0, 1]; arrays broadcast.
|
|
371
|
+
|
|
372
|
+
Returns
|
|
373
|
+
-------
|
|
374
|
+
float or numpy.ndarray
|
|
375
|
+
The x with I_x(a, b) equal to each probability, in the broadcast shape.
|
|
376
|
+
"""
|
|
377
|
+
return _apply("Beta", "IncompleteInverse", a, b, probability)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def beta_continued_fraction1(a: Any, b: Any, x: Any) -> Any:
|
|
381
|
+
"""Return continued fraction expansion 1 of the incomplete beta integral (``Beta.Incbcf``).
|
|
382
|
+
|
|
383
|
+
One of the expansions ``beta_incomplete`` combines (Cephes ``incbcf``).
|
|
384
|
+
|
|
385
|
+
Parameters
|
|
386
|
+
----------
|
|
387
|
+
a, b : float or array_like
|
|
388
|
+
Shape parameters.
|
|
389
|
+
x : float or array_like
|
|
390
|
+
Arguments in (0, 1); arrays broadcast.
|
|
391
|
+
|
|
392
|
+
Returns
|
|
393
|
+
-------
|
|
394
|
+
float or numpy.ndarray
|
|
395
|
+
The values, in the broadcast shape.
|
|
396
|
+
"""
|
|
397
|
+
return _apply("Beta", "Incbcf", a, b, x)
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def beta_continued_fraction2(a: Any, b: Any, x: Any) -> Any:
|
|
401
|
+
"""Return continued fraction expansion 2 of the incomplete beta integral (``Beta.Incbd``).
|
|
402
|
+
|
|
403
|
+
One of the expansions ``beta_incomplete`` combines (Cephes ``incbd``).
|
|
404
|
+
|
|
405
|
+
Parameters
|
|
406
|
+
----------
|
|
407
|
+
a, b : float or array_like
|
|
408
|
+
Shape parameters.
|
|
409
|
+
x : float or array_like
|
|
410
|
+
Arguments in (0, 1); arrays broadcast.
|
|
411
|
+
|
|
412
|
+
Returns
|
|
413
|
+
-------
|
|
414
|
+
float or numpy.ndarray
|
|
415
|
+
The values, in the broadcast shape.
|
|
416
|
+
"""
|
|
417
|
+
return _apply("Beta", "Incbd", a, b, x)
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def beta_power_series(a: Any, b: Any, x: Any) -> Any:
|
|
421
|
+
"""Return the power series of the regularized incomplete beta integral (``Beta.PowerSeries``).
|
|
422
|
+
|
|
423
|
+
Accurate when b x is small and x is not close to 1.
|
|
424
|
+
|
|
425
|
+
Parameters
|
|
426
|
+
----------
|
|
427
|
+
a, b : float or array_like
|
|
428
|
+
Shape parameters.
|
|
429
|
+
x : float or array_like
|
|
430
|
+
Arguments in [0, 1); arrays broadcast.
|
|
431
|
+
|
|
432
|
+
Returns
|
|
433
|
+
-------
|
|
434
|
+
float or numpy.ndarray
|
|
435
|
+
The values, in the broadcast shape.
|
|
436
|
+
"""
|
|
437
|
+
return _apply("Beta", "PowerSeries", a, b, x)
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def beta_incomplete_ratio(a: Any, b: Any, x: Any, log_beta: Any) -> Any:
|
|
441
|
+
"""Return the incomplete beta function ratio I_x(a, b) by algorithm AS 63 (``Beta.IncompleteRatio``).
|
|
442
|
+
|
|
443
|
+
``Beta.IncompleteRatio(x, p, q, beta)`` is called with ``p = a``, ``q = b`` and
|
|
444
|
+
``beta = log_beta``.
|
|
445
|
+
|
|
446
|
+
Parameters
|
|
447
|
+
----------
|
|
448
|
+
a, b : float or array_like
|
|
449
|
+
Positive shape parameters.
|
|
450
|
+
x : float or array_like
|
|
451
|
+
Arguments in [0, 1].
|
|
452
|
+
log_beta : float or array_like
|
|
453
|
+
The log beta function ln B(a, b), for example ``scipy.special.betaln(a, b)``; arrays broadcast.
|
|
454
|
+
|
|
455
|
+
Returns
|
|
456
|
+
-------
|
|
457
|
+
float or numpy.ndarray
|
|
458
|
+
I_x(a, b), in the broadcast shape.
|
|
459
|
+
"""
|
|
460
|
+
return _apply("Beta", "IncompleteRatio", a, b, x, log_beta, order=(2, 0, 1, 3))
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def erf(x: Any) -> Any:
|
|
464
|
+
"""Return the error function (``Erf.Function``).
|
|
465
|
+
|
|
466
|
+
Parameters
|
|
467
|
+
----------
|
|
468
|
+
x : float or array_like
|
|
469
|
+
Arguments.
|
|
470
|
+
|
|
471
|
+
Returns
|
|
472
|
+
-------
|
|
473
|
+
float or numpy.ndarray
|
|
474
|
+
The values, shaped like ``x``.
|
|
475
|
+
"""
|
|
476
|
+
return _apply("Erf", "Function", x)
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def erfc(x: Any) -> Any:
|
|
480
|
+
"""Return the complementary error function 1 - erf(x) (``Erf.Erfc``).
|
|
481
|
+
|
|
482
|
+
Evaluated directly, never as 1 - erf(x), from the scaled function exp(x**2) erfc(x) with the factor
|
|
483
|
+
exp(-x**2) formed without rounding x**2; within about 5e-16 relative of mpmath up to x = 26.5, where the
|
|
484
|
+
result becomes subnormal (scipy's erfc errs by up to about 6e-14 there).
|
|
485
|
+
|
|
486
|
+
Parameters
|
|
487
|
+
----------
|
|
488
|
+
x : float or array_like
|
|
489
|
+
Arguments.
|
|
490
|
+
|
|
491
|
+
Returns
|
|
492
|
+
-------
|
|
493
|
+
float or numpy.ndarray
|
|
494
|
+
The values, shaped like ``x``.
|
|
495
|
+
"""
|
|
496
|
+
return _apply("Erf", "Erfc", x)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def inverse_erf(y: Any) -> Any:
|
|
500
|
+
"""Return the inverse error function (``Erf.InverseErf``), as ``scipy.special.erfinv``.
|
|
501
|
+
|
|
502
|
+
Parameters
|
|
503
|
+
----------
|
|
504
|
+
y : float or array_like
|
|
505
|
+
Values in [-1, 1]; y = +-1 gives +-inf.
|
|
506
|
+
|
|
507
|
+
Returns
|
|
508
|
+
-------
|
|
509
|
+
float or numpy.ndarray
|
|
510
|
+
The values, shaped like ``y``.
|
|
511
|
+
|
|
512
|
+
Raises
|
|
513
|
+
------
|
|
514
|
+
ValueError
|
|
515
|
+
If abs(y) > 1 (raised by Numerics).
|
|
516
|
+
"""
|
|
517
|
+
return _apply("Erf", "InverseErf", y)
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def inverse_erfc(y: Any) -> Any:
|
|
521
|
+
"""Return the inverse complementary error function (``Erf.InverseErfc``), as ``scipy.special.erfcinv``.
|
|
522
|
+
|
|
523
|
+
Parameters
|
|
524
|
+
----------
|
|
525
|
+
y : float or array_like
|
|
526
|
+
Values in [0, 2].
|
|
527
|
+
|
|
528
|
+
Returns
|
|
529
|
+
-------
|
|
530
|
+
float or numpy.ndarray
|
|
531
|
+
The values, shaped like ``y``.
|
|
532
|
+
"""
|
|
533
|
+
return _apply("Erf", "InverseErfc", y)
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def _bessel_n(name: str, n: Any, x: Any) -> Any:
|
|
537
|
+
"""Evaluate the integer-order Bessel member ``name`` over the broadcast of ``n`` and ``x``.
|
|
538
|
+
|
|
539
|
+
Scalars call the bound scalar member. Arrays cross once per distinct order into the
|
|
540
|
+
``(int, IList<double>)`` overload, and every value is the scalar member's.
|
|
541
|
+
"""
|
|
542
|
+
scalar = _typed_member("Bessel", name, "Int32", "Double")
|
|
543
|
+
vector = _list_member("Bessel", name, "Int32", "IList[Double]")
|
|
544
|
+
orders, values = np.broadcast_arrays(np.asarray(n, dtype=np.int64), np.asarray(x, dtype=np.float64))
|
|
545
|
+
if values.ndim == 0:
|
|
546
|
+
return float(scalar(int(orders), float(values)))
|
|
547
|
+
out = np.empty(values.shape, dtype=np.float64)
|
|
548
|
+
for order in np.unique(orders):
|
|
549
|
+
mask = orders == order
|
|
550
|
+
out[mask] = to_numpy_doubles(vector(int(order), to_net_doubles(values[mask])))
|
|
551
|
+
return out
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
def bessel_i0(x: Any) -> Any:
|
|
555
|
+
"""Return the modified Bessel function of the first kind of order 0 (``Bessel.I0``).
|
|
556
|
+
|
|
557
|
+
The Cephes Chebyshev expansion of exp(-abs(x)) I0(x) times exp(abs(x)), accurate to about 1e-15 relative.
|
|
558
|
+
|
|
559
|
+
Parameters
|
|
560
|
+
----------
|
|
561
|
+
x : float or array_like
|
|
562
|
+
Arguments.
|
|
563
|
+
|
|
564
|
+
Returns
|
|
565
|
+
-------
|
|
566
|
+
float or numpy.ndarray
|
|
567
|
+
I0(x), shaped like ``x``.
|
|
568
|
+
"""
|
|
569
|
+
return _apply("Bessel", "I0", x)
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
def bessel_i1(x: Any) -> Any:
|
|
573
|
+
"""Return the modified Bessel function of the first kind of order 1 (``Bessel.I1``).
|
|
574
|
+
|
|
575
|
+
The Cephes Chebyshev expansion of exp(-abs(x)) I1(x) times exp(abs(x)), accurate to about 1e-15 relative.
|
|
576
|
+
|
|
577
|
+
Parameters
|
|
578
|
+
----------
|
|
579
|
+
x : float or array_like
|
|
580
|
+
Arguments.
|
|
581
|
+
|
|
582
|
+
Returns
|
|
583
|
+
-------
|
|
584
|
+
float or numpy.ndarray
|
|
585
|
+
I1(x), shaped like ``x``.
|
|
586
|
+
"""
|
|
587
|
+
return _apply("Bessel", "I1", x)
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def bessel_i0e(x: Any) -> Any:
|
|
591
|
+
"""Return the exponentially scaled exp(-abs(x)) I0(x) (``Bessel.I0e``), as ``scipy.special.i0e``.
|
|
592
|
+
|
|
593
|
+
Parameters
|
|
594
|
+
----------
|
|
595
|
+
x : float or array_like
|
|
596
|
+
Arguments.
|
|
597
|
+
|
|
598
|
+
Returns
|
|
599
|
+
-------
|
|
600
|
+
float or numpy.ndarray
|
|
601
|
+
The scaled values, shaped like ``x``.
|
|
602
|
+
"""
|
|
603
|
+
return _apply("Bessel", "I0e", x)
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
def bessel_i1e(x: Any) -> Any:
|
|
607
|
+
"""Return the exponentially scaled exp(-abs(x)) I1(x) (``Bessel.I1e``), as ``scipy.special.i1e``.
|
|
608
|
+
|
|
609
|
+
Parameters
|
|
610
|
+
----------
|
|
611
|
+
x : float or array_like
|
|
612
|
+
Arguments.
|
|
613
|
+
|
|
614
|
+
Returns
|
|
615
|
+
-------
|
|
616
|
+
float or numpy.ndarray
|
|
617
|
+
The scaled values, shaped like ``x``.
|
|
618
|
+
"""
|
|
619
|
+
return _apply("Bessel", "I1e", x)
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
def bessel_in(n: Any, x: Any) -> Any:
|
|
623
|
+
"""Return the modified Bessel function of the first kind of integer order n (``Bessel.In``).
|
|
624
|
+
|
|
625
|
+
Miller's downward recurrence normalized by I0.
|
|
626
|
+
|
|
627
|
+
Parameters
|
|
628
|
+
----------
|
|
629
|
+
n : int or array_like of int
|
|
630
|
+
Orders.
|
|
631
|
+
x : float or array_like
|
|
632
|
+
Arguments; arrays broadcast with ``n``.
|
|
633
|
+
|
|
634
|
+
Returns
|
|
635
|
+
-------
|
|
636
|
+
float or numpy.ndarray
|
|
637
|
+
In(x), in the broadcast shape.
|
|
638
|
+
"""
|
|
639
|
+
return _bessel_n("In", n, x)
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
def bessel_k0(x: Any) -> Any:
|
|
643
|
+
"""Return the modified Bessel function of the second kind of order 0 (``Bessel.K0``).
|
|
644
|
+
|
|
645
|
+
Parameters
|
|
646
|
+
----------
|
|
647
|
+
x : float or array_like
|
|
648
|
+
Positive arguments.
|
|
649
|
+
|
|
650
|
+
Returns
|
|
651
|
+
-------
|
|
652
|
+
float or numpy.ndarray
|
|
653
|
+
K0(x), shaped like ``x``.
|
|
654
|
+
"""
|
|
655
|
+
return _apply("Bessel", "K0", x)
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
def bessel_k1(x: Any) -> Any:
|
|
659
|
+
"""Return the modified Bessel function of the second kind of order 1 (``Bessel.K1``).
|
|
660
|
+
|
|
661
|
+
Parameters
|
|
662
|
+
----------
|
|
663
|
+
x : float or array_like
|
|
664
|
+
Positive arguments.
|
|
665
|
+
|
|
666
|
+
Returns
|
|
667
|
+
-------
|
|
668
|
+
float or numpy.ndarray
|
|
669
|
+
K1(x), shaped like ``x``.
|
|
670
|
+
"""
|
|
671
|
+
return _apply("Bessel", "K1", x)
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
def bessel_kn(n: Any, x: Any) -> Any:
|
|
675
|
+
"""Return the modified Bessel function of the second kind of integer order n (``Bessel.Kn``).
|
|
676
|
+
|
|
677
|
+
Forward recurrence from K0 and K1.
|
|
678
|
+
|
|
679
|
+
Parameters
|
|
680
|
+
----------
|
|
681
|
+
n : int or array_like of int
|
|
682
|
+
Orders.
|
|
683
|
+
x : float or array_like
|
|
684
|
+
Positive arguments; arrays broadcast with ``n``.
|
|
685
|
+
|
|
686
|
+
Returns
|
|
687
|
+
-------
|
|
688
|
+
float or numpy.ndarray
|
|
689
|
+
Kn(x), in the broadcast shape.
|
|
690
|
+
"""
|
|
691
|
+
return _bessel_n("Kn", n, x)
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
def bessel_j0(x: Any) -> Any:
|
|
695
|
+
"""Return the Bessel function of the first kind of order 0 (``Bessel.J0``).
|
|
696
|
+
|
|
697
|
+
Parameters
|
|
698
|
+
----------
|
|
699
|
+
x : float or array_like
|
|
700
|
+
Arguments.
|
|
701
|
+
|
|
702
|
+
Returns
|
|
703
|
+
-------
|
|
704
|
+
float or numpy.ndarray
|
|
705
|
+
J0(x), shaped like ``x``.
|
|
706
|
+
"""
|
|
707
|
+
return _apply("Bessel", "J0", x)
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
def bessel_j1(x: Any) -> Any:
|
|
711
|
+
"""Return the Bessel function of the first kind of order 1 (``Bessel.J1``).
|
|
712
|
+
|
|
713
|
+
Parameters
|
|
714
|
+
----------
|
|
715
|
+
x : float or array_like
|
|
716
|
+
Arguments.
|
|
717
|
+
|
|
718
|
+
Returns
|
|
719
|
+
-------
|
|
720
|
+
float or numpy.ndarray
|
|
721
|
+
J1(x), shaped like ``x``.
|
|
722
|
+
"""
|
|
723
|
+
return _apply("Bessel", "J1", x)
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
def bessel_jn(n: Any, x: Any) -> Any:
|
|
727
|
+
"""Return the Bessel function of the first kind of integer order n (``Bessel.Jn``).
|
|
728
|
+
|
|
729
|
+
Forward recurrence for abs(x) > n; otherwise the continued fraction for Jn/Jn-1 and the backward
|
|
730
|
+
recurrence, normalized by J0 or J1.
|
|
731
|
+
|
|
732
|
+
Parameters
|
|
733
|
+
----------
|
|
734
|
+
n : int or array_like of int
|
|
735
|
+
Orders.
|
|
736
|
+
x : float or array_like
|
|
737
|
+
Arguments; arrays broadcast with ``n``.
|
|
738
|
+
|
|
739
|
+
Returns
|
|
740
|
+
-------
|
|
741
|
+
float or numpy.ndarray
|
|
742
|
+
Jn(x), in the broadcast shape.
|
|
743
|
+
"""
|
|
744
|
+
return _bessel_n("Jn", n, x)
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def bessel_y0(x: Any) -> Any:
|
|
748
|
+
"""Return the Bessel function of the second kind of order 0 (``Bessel.Y0``).
|
|
749
|
+
|
|
750
|
+
Parameters
|
|
751
|
+
----------
|
|
752
|
+
x : float or array_like
|
|
753
|
+
Positive arguments.
|
|
754
|
+
|
|
755
|
+
Returns
|
|
756
|
+
-------
|
|
757
|
+
float or numpy.ndarray
|
|
758
|
+
Y0(x), shaped like ``x``.
|
|
759
|
+
"""
|
|
760
|
+
return _apply("Bessel", "Y0", x)
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
def bessel_y1(x: Any) -> Any:
|
|
764
|
+
"""Return the Bessel function of the second kind of order 1 (``Bessel.Y1``).
|
|
765
|
+
|
|
766
|
+
Parameters
|
|
767
|
+
----------
|
|
768
|
+
x : float or array_like
|
|
769
|
+
Positive arguments.
|
|
770
|
+
|
|
771
|
+
Returns
|
|
772
|
+
-------
|
|
773
|
+
float or numpy.ndarray
|
|
774
|
+
Y1(x), shaped like ``x``.
|
|
775
|
+
"""
|
|
776
|
+
return _apply("Bessel", "Y1", x)
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
def bessel_yn(n: Any, x: Any) -> Any:
|
|
780
|
+
"""Return the Bessel function of the second kind of integer order n (``Bessel.Yn``).
|
|
781
|
+
|
|
782
|
+
Forward recurrence from Y0 and Y1.
|
|
783
|
+
|
|
784
|
+
Parameters
|
|
785
|
+
----------
|
|
786
|
+
n : int or array_like of int
|
|
787
|
+
Orders.
|
|
788
|
+
x : float or array_like
|
|
789
|
+
Positive arguments; arrays broadcast with ``n``.
|
|
790
|
+
|
|
791
|
+
Returns
|
|
792
|
+
-------
|
|
793
|
+
float or numpy.ndarray
|
|
794
|
+
Yn(x), in the broadcast shape.
|
|
795
|
+
"""
|
|
796
|
+
return _bessel_n("Yn", n, x)
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
def debye3(x: Any) -> Any:
|
|
800
|
+
"""Return the order-3 Debye function D3(x) = 3 / x**3 * int_0^x t**3 / (e**t - 1) dt (``Debye.Function``).
|
|
801
|
+
|
|
802
|
+
Parameters
|
|
803
|
+
----------
|
|
804
|
+
x : float or array_like
|
|
805
|
+
Positive arguments.
|
|
806
|
+
|
|
807
|
+
Returns
|
|
808
|
+
-------
|
|
809
|
+
float or numpy.ndarray
|
|
810
|
+
D3(x), shaped like ``x``.
|
|
811
|
+
"""
|
|
812
|
+
return _apply("Debye", "Function", x)
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
def debye1(x: Any) -> Any:
|
|
816
|
+
"""Return the order-1 Debye function D1(x) = 1 / x * int_0^x t / (e**t - 1) dt (``Debye.FunctionOrderOne``).
|
|
817
|
+
|
|
818
|
+
Parameters
|
|
819
|
+
----------
|
|
820
|
+
x : float or array_like
|
|
821
|
+
Positive arguments.
|
|
822
|
+
|
|
823
|
+
Returns
|
|
824
|
+
-------
|
|
825
|
+
float or numpy.ndarray
|
|
826
|
+
D1(x), shaped like ``x``.
|
|
827
|
+
"""
|
|
828
|
+
return _apply("Debye", "FunctionOrderOne", x)
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
def factorial(n: Any) -> Any:
|
|
832
|
+
"""Return n! as a double (``Factorial.Function``, the ``long`` overload).
|
|
833
|
+
|
|
834
|
+
Exact through 22!; above 170 the result is +inf.
|
|
835
|
+
|
|
836
|
+
Parameters
|
|
837
|
+
----------
|
|
838
|
+
n : int or array_like of int
|
|
839
|
+
Non-negative integers.
|
|
840
|
+
|
|
841
|
+
Returns
|
|
842
|
+
-------
|
|
843
|
+
float or numpy.ndarray
|
|
844
|
+
The factorials, shaped like ``n``.
|
|
845
|
+
|
|
846
|
+
Raises
|
|
847
|
+
------
|
|
848
|
+
ValueError
|
|
849
|
+
If ``n`` is negative (raised by Numerics).
|
|
850
|
+
"""
|
|
851
|
+
return broadcast_loop(_typed_member("Factorial", "Function", "Int64"), n, kinds=(int,))
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
def log_factorial(n: Any) -> Any:
|
|
855
|
+
"""Return ln(n!) (``Factorial.LogFactorial``).
|
|
856
|
+
|
|
857
|
+
Parameters
|
|
858
|
+
----------
|
|
859
|
+
n : int or array_like of int
|
|
860
|
+
Non-negative integers.
|
|
861
|
+
|
|
862
|
+
Returns
|
|
863
|
+
-------
|
|
864
|
+
float or numpy.ndarray
|
|
865
|
+
The values, shaped like ``n``.
|
|
866
|
+
"""
|
|
867
|
+
return broadcast_loop(_typed_member("Factorial", "LogFactorial", "Int32"), n, kinds=(int,))
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
def binomial_coefficient(n: Any, k: Any) -> Any:
|
|
871
|
+
"""Return the binomial coefficient n choose k (``Factorial.BinomialCoefficient``).
|
|
872
|
+
|
|
873
|
+
Correctly rounded, and exact below 2**53; invalid arguments (n < 0, k < 0 or k > n) give 0.
|
|
874
|
+
|
|
875
|
+
Parameters
|
|
876
|
+
----------
|
|
877
|
+
n, k : int or array_like of int
|
|
878
|
+
The counts; arrays broadcast.
|
|
879
|
+
|
|
880
|
+
Returns
|
|
881
|
+
-------
|
|
882
|
+
float or numpy.ndarray
|
|
883
|
+
The coefficients, in the broadcast shape.
|
|
884
|
+
"""
|
|
885
|
+
member = _typed_member("Factorial", "BinomialCoefficient", "Int32", "Int32")
|
|
886
|
+
return broadcast_loop(member, n, k, kinds=(int, int))
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
def find_combinations(m: int, n: int) -> np.ndarray:
|
|
890
|
+
"""Return every increasing index combination of size m from n items (``Factorial.FindCombinations``).
|
|
891
|
+
|
|
892
|
+
Parameters
|
|
893
|
+
----------
|
|
894
|
+
m : int
|
|
895
|
+
The combination size.
|
|
896
|
+
n : int
|
|
897
|
+
The number of items.
|
|
898
|
+
|
|
899
|
+
Returns
|
|
900
|
+
-------
|
|
901
|
+
numpy.ndarray
|
|
902
|
+
A ``(n choose m, m)`` int32 array, one combination per row in lexicographic order.
|
|
903
|
+
"""
|
|
904
|
+
rows = [to_numpy_ints(row) for row in _special().Factorial.FindCombinations(int(m), int(n))]
|
|
905
|
+
return np.vstack(rows) if rows else np.empty((0, int(m)), dtype=np.int32)
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
def all_combinations(n: int) -> np.ndarray:
|
|
909
|
+
"""Return every non-empty subset of n items as a 0/1 indicator row (``Factorial.AllCombinations``).
|
|
910
|
+
|
|
911
|
+
Parameters
|
|
912
|
+
----------
|
|
913
|
+
n : int
|
|
914
|
+
The number of items.
|
|
915
|
+
|
|
916
|
+
Returns
|
|
917
|
+
-------
|
|
918
|
+
numpy.ndarray
|
|
919
|
+
A ``(2**n - 1, n)`` int32 array; rows ordered by subset size, then lexicographically.
|
|
920
|
+
"""
|
|
921
|
+
table = _special().Factorial.AllCombinations(int(n))
|
|
922
|
+
return _numpy_rectangular(table, np.int32)
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
def iter_all_combinations(n: int) -> Iterator[np.ndarray]:
|
|
926
|
+
"""Yield the indices of every non-empty subset of n items lazily (``Factorial.AllCombinationsLazy``).
|
|
927
|
+
|
|
928
|
+
The order is that of :func:`all_combinations`, without forming the indicator table.
|
|
929
|
+
|
|
930
|
+
Parameters
|
|
931
|
+
----------
|
|
932
|
+
n : int
|
|
933
|
+
The number of items.
|
|
934
|
+
|
|
935
|
+
Yields
|
|
936
|
+
------
|
|
937
|
+
numpy.ndarray
|
|
938
|
+
The int32 indices of one subset.
|
|
939
|
+
"""
|
|
940
|
+
for combination in _special().Factorial.AllCombinationsLazy(int(n)):
|
|
941
|
+
yield to_numpy_ints(combination)
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
def next_combination(combination: Any, n: int) -> tuple[bool, np.ndarray]:
|
|
945
|
+
"""Advance a k-combination of [0, n) to its lexicographic successor (``Factorial.NextCombination``).
|
|
946
|
+
|
|
947
|
+
Parameters
|
|
948
|
+
----------
|
|
949
|
+
combination : array_like of int
|
|
950
|
+
The current strictly increasing index tuple; it is not modified.
|
|
951
|
+
n : int
|
|
952
|
+
The number of items.
|
|
953
|
+
|
|
954
|
+
Returns
|
|
955
|
+
-------
|
|
956
|
+
advanced : bool
|
|
957
|
+
False when ``combination`` was the last one.
|
|
958
|
+
successor : numpy.ndarray
|
|
959
|
+
The int32 indices Numerics left in the array (the successor when ``advanced``).
|
|
960
|
+
"""
|
|
961
|
+
net = to_net_ints(combination)
|
|
962
|
+
advanced = bool(_special().Factorial.NextCombination(net, int(n)))
|
|
963
|
+
return advanced, to_numpy_ints(net)
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
def _polynomial(name: str, coefficients: Any, x: Any, *extra: int) -> Any:
|
|
967
|
+
"""Evaluate ``Evaluate.<name>`` with the coefficients copied once and ``x`` element by element."""
|
|
968
|
+
member = getattr(_special().Evaluate, name)
|
|
969
|
+
net = to_net_doubles(coefficients)
|
|
970
|
+
return loop(x, lambda v: member(net, v, *extra))
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
def polynomial(coefficients: Any, x: Any) -> Any:
|
|
974
|
+
"""Evaluate sum c[i] x**i with ``coefficients[0]`` the constant term (``Evaluate.Polynomial``).
|
|
975
|
+
|
|
976
|
+
Parameters
|
|
977
|
+
----------
|
|
978
|
+
coefficients : array_like
|
|
979
|
+
The coefficients, constant term first.
|
|
980
|
+
x : float or array_like
|
|
981
|
+
Points.
|
|
982
|
+
|
|
983
|
+
Returns
|
|
984
|
+
-------
|
|
985
|
+
float or numpy.ndarray
|
|
986
|
+
The polynomial values, shaped like ``x``.
|
|
987
|
+
"""
|
|
988
|
+
return _polynomial("Polynomial", coefficients, x)
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
def polynomial_reversed(coefficients: Any, x: Any, n: int | None = None) -> Any:
|
|
992
|
+
"""Evaluate a polynomial with the constant term last by Horner's rule (``Evaluate.PolynomialRev``).
|
|
993
|
+
|
|
994
|
+
``coefficients[0] * x**n + ... + coefficients[n]``, the convention of ``numpy.polyval``.
|
|
995
|
+
|
|
996
|
+
Parameters
|
|
997
|
+
----------
|
|
998
|
+
coefficients : array_like
|
|
999
|
+
The coefficients, highest power first.
|
|
1000
|
+
x : float or array_like
|
|
1001
|
+
Points.
|
|
1002
|
+
n : int, optional
|
|
1003
|
+
Use only the first n + 1 coefficients; None (the Numerics default, -1) uses them all.
|
|
1004
|
+
|
|
1005
|
+
Returns
|
|
1006
|
+
-------
|
|
1007
|
+
float or numpy.ndarray
|
|
1008
|
+
The polynomial values, shaped like ``x``.
|
|
1009
|
+
|
|
1010
|
+
Raises
|
|
1011
|
+
------
|
|
1012
|
+
ValueError
|
|
1013
|
+
If ``n`` exceeds the number of coefficients (raised by Numerics).
|
|
1014
|
+
"""
|
|
1015
|
+
return _polynomial("PolynomialRev", coefficients, x, -1 if n is None else int(n))
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
def polynomial_reversed_monic(coefficients: Any, x: Any) -> Any:
|
|
1019
|
+
"""Evaluate the monic polynomial x**N + c[0] x**(N-1) + ... + c[N-1] (``Evaluate.PolynomialRev_1``).
|
|
1020
|
+
|
|
1021
|
+
Parameters
|
|
1022
|
+
----------
|
|
1023
|
+
coefficients : array_like
|
|
1024
|
+
The N coefficients after the implicit leading 1, highest power first.
|
|
1025
|
+
x : float or array_like
|
|
1026
|
+
Points.
|
|
1027
|
+
|
|
1028
|
+
Returns
|
|
1029
|
+
-------
|
|
1030
|
+
float or numpy.ndarray
|
|
1031
|
+
The polynomial values, shaped like ``x``.
|
|
1032
|
+
"""
|
|
1033
|
+
return _polynomial("PolynomialRev_1", coefficients, x)
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
def chebyshev(coefficients: Any, x: Any, terms: int | None = None) -> Any:
|
|
1037
|
+
"""Sum the Chebyshev series c[0]/2 + sum c[k] T_k(x/2) by the Clenshaw recurrence (``Evaluate.Chebyshev``).
|
|
1038
|
+
|
|
1039
|
+
The argument is twice the Chebyshev variable, the convention of the Cephes routine ``chbevl``,
|
|
1040
|
+
so ``chebyshev(c, x)`` equals ``numpy.polynomial.chebyshev.chebval(x / 2, c)`` with ``c[0]`` halved.
|
|
1041
|
+
|
|
1042
|
+
Parameters
|
|
1043
|
+
----------
|
|
1044
|
+
coefficients : array_like
|
|
1045
|
+
The coefficients, order-zero term first.
|
|
1046
|
+
x : float or array_like
|
|
1047
|
+
Points in [-2, 2].
|
|
1048
|
+
terms : int, optional
|
|
1049
|
+
Sum only the first ``terms`` coefficients; None sums them all.
|
|
1050
|
+
|
|
1051
|
+
Returns
|
|
1052
|
+
-------
|
|
1053
|
+
float or numpy.ndarray
|
|
1054
|
+
The series values, shaped like ``x``.
|
|
1055
|
+
|
|
1056
|
+
Raises
|
|
1057
|
+
------
|
|
1058
|
+
ValueError
|
|
1059
|
+
If ``terms`` is below one or exceeds the number of coefficients (raised by Numerics).
|
|
1060
|
+
"""
|
|
1061
|
+
if terms is None:
|
|
1062
|
+
return _polynomial("Chebyshev", coefficients, x)
|
|
1063
|
+
return _polynomial("Chebyshev", coefficients, x, int(terms))
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
__all__ = [
|
|
1067
|
+
"all_combinations", "bessel_i0", "bessel_i0e", "bessel_i1", "bessel_i1e", "bessel_in", "bessel_j0", "bessel_j1",
|
|
1068
|
+
"bessel_jn", "bessel_k0", "bessel_k1", "bessel_kn", "bessel_y0", "bessel_y1", "bessel_yn",
|
|
1069
|
+
"beta_continued_fraction1", "beta_continued_fraction2", "beta_function", "beta_incomplete",
|
|
1070
|
+
"beta_incomplete_inverse", "beta_incomplete_ratio", "beta_power_series", "binomial_coefficient", "chebyshev",
|
|
1071
|
+
"debye1", "debye3",
|
|
1072
|
+
"digamma", "erf", "erfc", "factorial", "find_combinations", "gamma_function", "gamma_max", "incomplete_gamma",
|
|
1073
|
+
"inverse_erf", "inverse_erfc", "inverse_lower_incomplete_gamma", "inverse_upper_incomplete_gamma",
|
|
1074
|
+
"iter_all_combinations", "lanczos_gamma", "log_beta", "log_factorial", "log_gamma", "lower_incomplete_gamma",
|
|
1075
|
+
"next_combination", "polynomial", "polynomial_reversed", "polynomial_reversed_monic", "stirling_gamma", "trigamma",
|
|
1076
|
+
"upper_incomplete_gamma",
|
|
1077
|
+
]
|
|
1078
|
+
|
|
1079
|
+
translate_public(globals())
|