|
1 | 1 | import hashlib
|
2 | 2 |
|
3 | 3 | import numpy
|
| 4 | +import scipy |
4 | 5 | from numpy.polynomial.legendre import leggauss
|
| 6 | +from packaging.version import parse as parse_version |
5 | 7 | from scipy import integrate
|
6 |
| -from scipy.special import gamma, gammaln, lpmn |
| 8 | +from scipy.special import gamma, gammaln |
| 9 | + |
| 10 | +_SCIPY_VERSION = parse_version(scipy.__version__) |
| 11 | +if _SCIPY_VERSION < parse_version("1.15"): # pragma: no cover |
| 12 | + from scipy.special import lpmn |
| 13 | +else: |
| 14 | + from scipy.special import assoc_legendre_p_all |
7 | 15 |
|
8 | 16 | from ..util import conversion, coords
|
9 | 17 | from ..util._optional_deps import _APY_LOADED
|
@@ -412,7 +420,17 @@ def _compute(self, funcTilde, R, z, phi):
|
412 | 420 | N, L, M = Acos.shape
|
413 | 421 | r, theta, phi = coords.cyl_to_spher(R, z, phi)
|
414 | 422 |
|
415 |
| - PP = lpmn(M - 1, L - 1, numpy.cos(theta))[0].T ##Get the Legendre polynomials |
| 423 | + ## Get the Legendre polynomials |
| 424 | + if _SCIPY_VERSION < parse_version("1.15"): # pragma: no cover |
| 425 | + PP = lpmn(M - 1, L - 1, numpy.cos(theta))[0].T |
| 426 | + else: |
| 427 | + PP = numpy.swapaxes( |
| 428 | + assoc_legendre_p_all(L - 1, M - 1, numpy.cos(theta), branch_cut=2)[ |
| 429 | + 0, :, :M |
| 430 | + ], |
| 431 | + 0, |
| 432 | + 1, |
| 433 | + ).T |
416 | 434 | func_tilde = funcTilde(r, N, L) ## Tilde of the function of interest
|
417 | 435 |
|
418 | 436 | func = numpy.zeros(
|
@@ -515,9 +533,15 @@ def _computeforce(self, R, z, phi=0, t=0):
|
515 | 533 | dPhi_dphi = self._cached_dPhi_dphi
|
516 | 534 |
|
517 | 535 | else:
|
518 |
| - PP, dPP = lpmn( |
519 |
| - M - 1, L - 1, numpy.cos(theta) |
520 |
| - ) ##Get the Legendre polynomials |
| 536 | + ## Get the Legendre polynomials |
| 537 | + if _SCIPY_VERSION < parse_version("1.15"): # pragma: no cover |
| 538 | + PP, dPP = lpmn(M - 1, L - 1, numpy.cos(theta)) |
| 539 | + else: |
| 540 | + PP, dPP = assoc_legendre_p_all( |
| 541 | + L - 1, M - 1, numpy.cos(theta), branch_cut=2, diff_n=1 |
| 542 | + ) |
| 543 | + PP = numpy.swapaxes(PP[:, :M], 0, 1) |
| 544 | + dPP = numpy.swapaxes(dPP[:, :M], 0, 1) |
521 | 545 | PP = PP.T[None, :, :]
|
522 | 546 | dPP = dPP.T[None, :, :]
|
523 | 547 | phi_tilde = self._phiTilde(r, N, L)[:, :, numpy.newaxis]
|
@@ -924,14 +948,13 @@ def integrand(xi, costheta):
|
924 | 948 | r = _xiToR(xi, a)
|
925 | 949 | R = r * numpy.sqrt(1 - costheta**2.0)
|
926 | 950 | z = r * costheta
|
927 |
| - Legandre = lpmn(0, L - 1, costheta)[0].T[numpy.newaxis, :, 0] |
| 951 | + if _SCIPY_VERSION < parse_version("1.15"): # pragma: no cover |
| 952 | + PP = lpmn(0, L - 1, costheta)[0].T[numpy.newaxis, :, 0] |
| 953 | + else: |
| 954 | + PP = assoc_legendre_p_all(L - 1, 0, costheta, branch_cut=2)[0].T |
928 | 955 | dV = (1.0 + xi) ** 2.0 * numpy.power(1.0 - xi, -4.0)
|
929 | 956 | phi_nl = (
|
930 |
| - a**3 |
931 |
| - * (1.0 + xi) ** l |
932 |
| - * (1.0 - xi) ** (l + 1.0) |
933 |
| - * _C(xi, N, L)[:, :] |
934 |
| - * Legandre |
| 957 | + a**3 * (1.0 + xi) ** l * (1.0 - xi) ** (l + 1.0) * _C(xi, N, L)[:, :] * PP |
935 | 958 | )
|
936 | 959 | param[0] = R
|
937 | 960 | param[1] = z
|
@@ -1089,15 +1112,22 @@ def integrand(xi, costheta, phi):
|
1089 | 1112 | r = _xiToR(xi, a)
|
1090 | 1113 | R = r * numpy.sqrt(1 - costheta**2.0)
|
1091 | 1114 | z = r * costheta
|
1092 |
| - Legandre = lpmn(L - 1, L - 1, costheta)[0].T[numpy.newaxis, :, :] |
| 1115 | + if _SCIPY_VERSION < parse_version("1.15"): # pragma: no cover |
| 1116 | + PP = lpmn(L - 1, L - 1, costheta)[0].T[numpy.newaxis, :, :] |
| 1117 | + else: |
| 1118 | + PP = numpy.swapaxes( |
| 1119 | + assoc_legendre_p_all(L - 1, L - 1, costheta, branch_cut=2)[0][:, :L], |
| 1120 | + 0, |
| 1121 | + 1, |
| 1122 | + ).T[numpy.newaxis, :, :] |
1093 | 1123 | dV = (1.0 + xi) ** 2.0 * numpy.power(1.0 - xi, -4.0)
|
1094 | 1124 |
|
1095 | 1125 | phi_nl = (
|
1096 | 1126 | -(a**3)
|
1097 | 1127 | * (1.0 + xi) ** l
|
1098 | 1128 | * (1.0 - xi) ** (l + 1.0)
|
1099 | 1129 | * _C(xi, N, L)[:, :, numpy.newaxis]
|
1100 |
| - * Legandre |
| 1130 | + * PP |
1101 | 1131 | )
|
1102 | 1132 |
|
1103 | 1133 | return (
|
|
0 commit comments