Skip to content

Commit

Permalink
add minimal vectorized example
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Nov 14, 2023
1 parent 944fdca commit d664638
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 6 additions & 1 deletion capi/examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ int main() {
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));
printf("alphas(q2=%f) = %f\n", q2, alphasq2(q2));

double q2_vectorized[] = {1.65, 10.65};
double* as_vectorized = alphasq2(q2_vectorized, 2);

printf("alphas(q2=%f) = %f\n", q2_vectorized[0], as_vectorized[0]);
printf("alphas(q2=%f) = %f\n", q2_vectorized[1], as_vectorized[1]);

return 0;
}
2 changes: 1 addition & 1 deletion capi/src/pdfflow/pdfflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ extern void mkpdf(const char *fname, const char * dirname);

extern double xfxq2(int pid, double x, double q2);

extern double alphasq2(double q2);
extern double *alphasq2(double *q2, int n);
7 changes: 5 additions & 2 deletions capi/src/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is part of
from cpdfflow import ffi
from pdfflow import pflow
import numpy as np

pdf = None

Expand All @@ -21,7 +22,9 @@ def xfxq2(pid, x, q2):


@ffi.def_extern()
def alphasq2(q2):
def alphasq2(q2, n):
"""Returns the alpha strong coupling at specific q2 value."""
global pdf
return pdf.alphasQ2([q2])
q2_numpy = np.frombuffer(ffi.buffer(q2, n*ffi.sizeof('double')), dtype='double')
ret = pdf.alphasQ2(q2_numpy).numpy()
return ffi.cast("double*", ffi.from_buffer(ret))

0 comments on commit d664638

Please sign in to comment.