Skip to content

Commit da748f6

Browse files
author
Dag Sverre Seljebotn
committed
Change API to be able to support spin-weighted Legendre functions in the future
1 parent a93db0b commit da748f6

4 files changed

Lines changed: 30 additions & 23 deletions

File tree

libsharp/sharp_legendre_table.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,19 +1417,16 @@ New high-level wrapper
14171417

14181418
void sharp_normalized_associated_legendre_table(
14191419
ptrdiff_t m,
1420+
int spin,
14201421
ptrdiff_t lmax,
14211422
ptrdiff_t ntheta,
1422-
/* contigious 1D array of theta values to compute for,
1423-
contains ntheta values */
14241423
double *theta,
1425-
/* number of columns in out; see below. Should be >= (lmax - m). */
1426-
ptrdiff_t ncols,
1427-
/* contigiuos 2D array, in "theta-major ordering". Has `ntheta`
1428-
rows and `ncols` columns. Indexed as out[itheta * ncols + (l - m)].
1429-
If `ncols > lmax - m` then those entries are not accessed.
1430-
*/
1424+
ptrdiff_t theta_stride,
1425+
ptrdiff_t l_stride,
1426+
ptrdiff_t spin_stride,
14311427
double *out
14321428
) {
1429+
if (spin != 0) UTIL_FAIL ("sharp_normalized_associated_legendre_table: only spin=0 has been implemented so far");
14331430

14341431
Ylmgen_C ctx;
14351432
ptrdiff_t itheta, l, lmin;
@@ -1444,14 +1441,14 @@ void sharp_normalized_associated_legendre_table(
14441441
Ylmgen_recalc_Ylm_sse2(&ctx);
14451442
lmin = IMIN(*ctx.firstl, lmax + 1);
14461443
for (l = m; l < lmin; ++l) {
1447-
out[itheta * ncols + l - m] = 0;
1448-
out[(itheta + 1) * ncols + l - m ] = 0;
1444+
out[itheta * theta_stride + (l - m) * l_stride + spin * spin_stride] = 0;
1445+
out[(itheta + 1) * theta_stride + (l - m) * l_stride + spin * spin_stride] = 0;
14491446
}
14501447
for (l = IMAX(lmin, m); l <= lmax; ++l) {
14511448
double v1, v2;
14521449
read_v2df(ctx.ylm_sse2[l], &v1, &v2);
1453-
out[itheta * ncols + l - m] = v1;
1454-
out[(itheta + 1) * ncols + l - m] = v2;
1450+
out[itheta * theta_stride + (l - m) * l_stride + spin * spin_stride] = v1;
1451+
out[(itheta + 1) * theta_stride + (l - m) * l_stride + spin * spin_stride] = v2;
14551452
}
14561453
}
14571454
#endif
@@ -1460,10 +1457,10 @@ void sharp_normalized_associated_legendre_table(
14601457
Ylmgen_recalc_Ylm(&ctx);
14611458
lmin = IMIN(*ctx.firstl, lmax + 1);
14621459
for (l = m; l < lmin; ++l) {
1463-
out[itheta * ncols + l - m] = 0;
1460+
out[itheta * theta_stride + (l - m) * l_stride + spin * spin_stride] = 0;
14641461
}
14651462
for (l = IMAX(lmin, m); l <= lmax; ++l) {
1466-
out[itheta * ncols + l - m] = ctx.ylm[l];
1463+
out[itheta * theta_stride + (l - m) * l_stride + spin * spin_stride] = ctx.ylm[l];
14671464
}
14681465
}
14691466
Ylmgen_destroy(&ctx);

libsharp/sharp_legendre_table.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,37 @@ extern "C" {
5454
(Internally, sin(theta) is also used for part of the computation, making theta
5555
the most convenient argument.)
5656
57-
\param m The m-value to compute a table for
57+
NOTE: Support for spin-weighted Legendre functions is on the TODO-list. Only spin=0
58+
is supported now.
59+
60+
\param m The m-value to compute a table for; must be >= 0
61+
\param spin The spin parameter; pass 0 for the regular associated Legendre functions.
62+
NOTE: This is present for future compatability, currently only 0 is supported.
5863
\param lmax A table will be provided for l = m .. lmax
5964
\param ntheta How many theta values to evaluate for
6065
\param theta Contiguous 1D array of theta values
61-
\param ncols Number of columns in the out-array; should have ncols >= (lmax - m)
62-
\param out Contiguous 2D array that will receive the output. Each output entry
63-
is assigned to out[itheta * ncols + (l - m)].
66+
\param theta_stride See below
67+
\param l_stride See below
68+
\param spin_stride See below. "ispin" will always be 0 if spin==0, or 0 for positive spin
69+
and 1 for the corresponding negative spin otherwise.
70+
\param out Contiguous 3D array that will receive the output. Each output entry
71+
is assigned to out[itheta * theta_stride + (l - m) * l_stride + ispin * spin_stride].
6472
*/
6573
void sharp_normalized_associated_legendre_table(
6674
ptrdiff_t m,
75+
int spin,
6776
ptrdiff_t lmax,
6877
ptrdiff_t ntheta,
6978
/* contiguous 1D array of theta values to compute for,
7079
contains ntheta values */
7180
double *theta,
72-
/* number of columns in out; see below. Should be >= (lmax - m). */
73-
ptrdiff_t ncols,
7481
/* contiguous 2D array, in "theta-major ordering". Has `ntheta`
7582
rows and `ncols` columns. Indexed as out[itheta * ncols + (l - m)].
7683
If `ncols > lmax - m` then those entries are not accessed.
7784
*/
85+
ptrdiff_t theta_stride,
86+
ptrdiff_t l_stride,
87+
ptrdiff_t spin_stride,
7888
double *out
7989
);
8090

python/libsharp/libsharp.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ cdef extern from "sharp.h":
5959
sharp_alm_info *alm_info, int ntrans, int flags, double *time,
6060
unsigned long long *opcnt) nogil
6161

62-
void sharp_normalized_associated_legendre_table(int m, int lmax, int ntheta,
63-
double *theta, int ncols, double *out) nogil
62+
void sharp_normalized_associated_legendre_table(int m, int spin, int lmax, int ntheta,
63+
double *theta, int theta_stride, int l_stride, int spin_stride, double *out) nogil
6464

6565

6666
cdef extern from "sharp_geomhelpers.h":

python/libsharp/libsharp.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,5 @@ def normalized_associated_legendre_table(int lmax, int m, theta):
267267
if lmax < m:
268268
raise ValueError("lmax < m")
269269
with nogil:
270-
sharp_normalized_associated_legendre_table(m, lmax, theta_.shape[0], &theta_[0], lmax - m + 1, &out_[0,0])
270+
sharp_normalized_associated_legendre_table(m, 0, lmax, theta_.shape[0], &theta_[0], lmax - m + 1, 1, 1, &out_[0,0])
271271
return out

0 commit comments

Comments
 (0)