Skip to content

Commit

Permalink
propagating vec to xfxq2
Browse files Browse the repository at this point in the history
  • Loading branch information
scarrazza committed Nov 15, 2023
1 parent d664638 commit 70b992f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 6 additions & 3 deletions capi/examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ int main() {
mkpdf("NNPDF31_nlo_as_0118/0", "/usr/share/lhapdf/LHAPDF/");

// test xfxq2 and alphasq2
const double x = 0.1, q2 = 1.65;
for (int fl=-5; fl <=5; fl++)
printf("flv=%d - xfx = %f\n", fl, xfxq2(fl, x, q2));
int pid[] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5};
double xs[] = {0.1};
double q2s[] = {1.65};
double *xf_vectorized = xfxq2(pid, 11, xs, 1, q2s, 1);
for (int fl = 0; fl < 11; fl++)
printf("flv=%d - xfx = %f\n", fl-5, xf_vectorized[fl]);

double q2_vectorized[] = {1.65, 10.65};
double* as_vectorized = alphasq2(q2_vectorized, 2);
Expand Down
2 changes: 1 addition & 1 deletion capi/src/pdfflow/pdfflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

extern void mkpdf(const char *fname, const char * dirname);

extern double xfxq2(int pid, double x, double q2);
extern double *xfxq2(int *pid, int n, double *x, int m, double *q2, int o);

extern double *alphasq2(double *q2, int n);
12 changes: 8 additions & 4 deletions capi/src/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ def mkpdf(fname, dirname):


@ffi.def_extern()
def xfxq2(pid, x, q2):
"""Returns the xfxQ2 value for a given PID at specific x and q2."""
def xfxq2(pid, n, x, m, q2, o):
"""Returns the xfxQ2 value for arrays of PID, x and q2 values."""
global pdf
return pdf.xfxQ2([pid], [x], [q2])
pid_numpy = np.frombuffer(ffi.buffer(pid, n*ffi.sizeof('int')), dtype='int32')
x_numpy = np.frombuffer(ffi.buffer(x, m*ffi.sizeof('double')), dtype='double')
q2_numpy = np.frombuffer(ffi.buffer(q2, o*ffi.sizeof('double')), dtype='double')
ret = pdf.xfxQ2(pid_numpy, x_numpy, q2_numpy).numpy()
return ffi.cast("double*", ffi.from_buffer(ret))


@ffi.def_extern()
def alphasq2(q2, n):
"""Returns the alpha strong coupling at specific q2 value."""
"""Returns the alpha strong coupling at for an array of q2 values."""
global pdf
q2_numpy = np.frombuffer(ffi.buffer(q2, n*ffi.sizeof('double')), dtype='double')
ret = pdf.alphasQ2(q2_numpy).numpy()
Expand Down

0 comments on commit 70b992f

Please sign in to comment.