|
1 | | -from typing import assert_type |
| 1 | +from typing import Any, TypeAlias, assert_type |
2 | 2 |
|
3 | 3 | import numpy as np |
4 | 4 | import optype.numpy as onp |
5 | 5 |
|
6 | | -from scipy.special import legendre_p |
| 6 | +from scipy.special import ( |
| 7 | + assoc_legendre_p, |
| 8 | + assoc_legendre_p_all, |
| 9 | + legendre_p, |
| 10 | + legendre_p_all, |
| 11 | + sph_harm_y, |
| 12 | + sph_harm_y_all, |
| 13 | + sph_legendre_p, |
| 14 | + sph_legendre_p_all, |
| 15 | +) |
7 | 16 |
|
| 17 | +_Float1_D: TypeAlias = onp.Array[onp.AtLeast1D[Any], np.float64] |
| 18 | +_Float3_D: TypeAlias = onp.Array[onp.AtLeast3D[Any], np.float64] |
| 19 | +_Complex0D: TypeAlias = onp.Array0D[np.complex128] |
| 20 | +_Complex2D: TypeAlias = onp.Array2D[np.complex128] |
| 21 | + |
| 22 | +_i64_1d: onp.Array1D[np.int64] |
| 23 | +_f64_1d: onp.Array1D[np.float64] |
| 24 | + |
| 25 | +# legendre_p |
8 | 26 | assert_type(legendre_p(1, 1.0), onp.Array1D[np.float64]) |
9 | 27 | assert_type(legendre_p(1, np.float32(1.0)), onp.Array1D[np.float64]) |
10 | 28 | assert_type(legendre_p(1, 1.0, diff_n=True), onp.Array1D[np.float64]) |
11 | 29 | assert_type(legendre_p(1, 1.0, diff_n=1), onp.Array1D[np.float64]) |
| 30 | + |
| 31 | +# legendre_p_all |
| 32 | +assert_type(legendre_p_all(3, 1.0), _Float3_D) |
| 33 | +assert_type(legendre_p_all(n=3, z=np.float32(1.0)), _Float3_D) |
| 34 | +assert_type(legendre_p_all(3, _f64_1d), _Float3_D) |
| 35 | +assert_type(legendre_p_all(3, 1.0, diff_n=True), _Float3_D) |
| 36 | +assert_type(legendre_p_all(3, 1.0, diff_n=2), _Float3_D) |
| 37 | + |
| 38 | +# assoc_legendre_p |
| 39 | +assert_type(assoc_legendre_p(3, 2, 1.0), _Float1_D) |
| 40 | +assert_type(assoc_legendre_p(n=3, m=2, z=np.float32(1.0)), _Float1_D) |
| 41 | +assert_type(assoc_legendre_p(_i64_1d, 2, 1.0), _Float1_D) |
| 42 | +assert_type(assoc_legendre_p(3, _i64_1d, _f64_1d), _Float1_D) |
| 43 | +assert_type(assoc_legendre_p(3, 2, 1.0, branch_cut=3, norm=True, diff_n=1), _Float1_D) |
| 44 | +assert_type(assoc_legendre_p(3, 2, _f64_1d, branch_cut=_i64_1d, diff_n=2), _Float1_D) |
| 45 | + |
| 46 | +# assoc_legendre_p_all |
| 47 | +assert_type(assoc_legendre_p_all(3, 2, 1.0), onp.Array3D[np.float64]) |
| 48 | +assert_type(assoc_legendre_p_all(n=3, m=2, z=np.float32(1.0)), onp.Array3D[np.float64]) |
| 49 | +assert_type(assoc_legendre_p_all(3, 2, 1.0, branch_cut=3, norm=True, diff_n=1), onp.Array3D[np.float64]) |
| 50 | +assert_type(assoc_legendre_p_all(3, 2, np.float64(1.0), branch_cut=2, diff_n=2), onp.Array3D[np.float64]) |
| 51 | + |
| 52 | +# sph_legendre_p |
| 53 | +assert_type(sph_legendre_p(3, 2, 1.0), onp.Array1D[np.float64]) |
| 54 | +assert_type(sph_legendre_p(n=3, m=2, theta=np.float32(1.0)), onp.Array1D[np.float64]) |
| 55 | +assert_type(sph_legendre_p(3, 2, 1.0, diff_n=True), onp.Array1D[np.float64]) |
| 56 | +assert_type(sph_legendre_p(3, 2, 1.0, diff_n=2), onp.Array1D[np.float64]) |
| 57 | + |
| 58 | +# sph_legendre_p_all |
| 59 | +assert_type(sph_legendre_p_all(3, 2, 1.0), onp.Array3D[np.float64]) |
| 60 | +assert_type(sph_legendre_p_all(n=3, m=2, theta=np.float32(1.0)), onp.Array3D[np.float64]) |
| 61 | +assert_type(sph_legendre_p_all(3, 2, 1.0, diff_n=True), onp.Array3D[np.float64]) |
| 62 | +assert_type(sph_legendre_p_all(3, 2, 1.0, diff_n=2), onp.Array3D[np.float64]) |
| 63 | + |
| 64 | +# sph_harm_y |
| 65 | +assert_type(sph_harm_y(3, 2, 1.0, 2.0), _Complex0D) |
| 66 | +assert_type(sph_harm_y(n=3, m=2, theta=np.float32(1.0), phi=np.float32(2.0)), _Complex0D) |
| 67 | +assert_type(sph_harm_y(3, 2, 1.0, 2.0, diff_n=False), _Complex0D) |
| 68 | +assert_type(sph_harm_y(3, 2, 1.0, 2.0, diff_n=0), _Complex0D) |
| 69 | + |
| 70 | +# sph_harm_y_all |
| 71 | +assert_type(sph_harm_y_all(3, 2, 1.0, 2.0), _Complex2D) |
| 72 | +assert_type(sph_harm_y_all(n=3, m=2, theta=np.float32(1.0), phi=np.float32(2.0)), _Complex2D) |
| 73 | +assert_type(sph_harm_y_all(3, 2, 1.0, 2.0, diff_n=False), _Complex2D) |
| 74 | +assert_type(sph_harm_y_all(3, 2, 1.0, 2.0, diff_n=0), _Complex2D) |
0 commit comments