-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* parallelized integ_spline * missing omp for * parallelized fftlog * visible from python
- Loading branch information
Showing
8 changed files
with
315 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
%module ccl_utils | ||
|
||
%{ | ||
/* put additional #include here */ | ||
%} | ||
|
||
%include "../include/ccl_utils.h" | ||
|
||
%apply (double* IN_ARRAY1, int DIM1) { | ||
(double *x_in, int n_in_x), | ||
(double *ys_in, int n_in_y)}; | ||
%apply (int DIM1, double* ARGOUT_ARRAY1) {(int nout, double* output)}; | ||
|
||
|
||
%feature("pythonprepend") spline_integrate %{ | ||
if n_integ * x_in.size != ys_in.size: | ||
raise CCLError("Input size for `ys_in` must match `n_integ * x_in.size`") | ||
|
||
if nout != n_integ: | ||
raise CCLError("Input shape for `output` must match n_integ") | ||
%} | ||
|
||
%inline %{ | ||
|
||
|
||
void spline_integrate(int n_integ, | ||
double *x_in, int n_in_x, | ||
double *ys_in, int n_in_y, | ||
double a, double b, | ||
int nout, double *output, | ||
int *status) | ||
{ | ||
int ii; | ||
|
||
double **_ys_in=NULL; | ||
_ys_in = malloc(n_integ*sizeof(double *)); | ||
if(_ys_in==NULL) | ||
*status = CCL_ERROR_MEMORY; | ||
|
||
if(*status==0) { | ||
for(ii=0;ii<n_integ;ii++) | ||
_ys_in[ii]=&(ys_in[ii*n_in_x]); | ||
|
||
ccl_integ_spline(n_integ, n_in_x, x_in, _ys_in, | ||
a, b, output, gsl_interp_akima, | ||
status); | ||
} | ||
|
||
free(_ys_in); | ||
} | ||
|
||
%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import numpy as np | ||
import pytest | ||
from pyccl.pyutils import _spline_integrate | ||
from pyccl.errors import CCLError | ||
|
||
|
||
def yf(x, pw): | ||
return x**pw | ||
|
||
|
||
def yf_int(x, pw): | ||
return x**(pw + 1) / (pw + 1) | ||
|
||
|
||
def test_intspline_accuracy(): | ||
nx = 1024 | ||
x_arr = np.linspace(-2, 2, nx) | ||
y_arr = np.array([yf(x_arr, p) | ||
for p in [2, 4]]) | ||
int_spline = _spline_integrate(x_arr, y_arr, -1, 1) | ||
int_exact = np.array([yf_int(1, p) - yf_int(-1, p) | ||
for p in [2, 4]]) | ||
assert np.all(np.fabs(int_spline / int_exact - 1) < 1E5-5) | ||
|
||
|
||
def test_intspline_raises_shapes(): | ||
x = np.linspace(0, 1, 10) | ||
y = np.zeros([4, 10]) | ||
|
||
# x is 0- or 2-D | ||
with pytest.raises(ValueError): | ||
_spline_integrate(x[0], y, 0, 1) | ||
|
||
with pytest.raises(ValueError): | ||
_spline_integrate(y, y, 0, 1) | ||
|
||
# y is 0-D | ||
with pytest.raises(ValueError): | ||
_spline_integrate(x, y[0, 0], 0, 1) | ||
|
||
# Mismatching x and y | ||
with pytest.raises(ValueError): | ||
_spline_integrate(x[1:], y, 0, 1) | ||
|
||
# Limits as arrays | ||
with pytest.raises(TypeError): | ||
_spline_integrate(x, y, np.zeros(10), 1) | ||
|
||
|
||
def test_intspline_raises_internal(): | ||
x = np.linspace(0, 1, 10) | ||
y = np.zeros([4, 10]) | ||
|
||
# Function is not splineable | ||
with pytest.raises(CCLError): | ||
_spline_integrate(0 * x, y, 0, 1) | ||
|
||
|
||
def test_intspline_smoke(): | ||
x = np.linspace(0, 1, 10) | ||
y = yf(x, 2) | ||
|
||
r = _spline_integrate(x, y, 0, 1) | ||
assert np.all(~np.isnan(r)) | ||
|
||
r = _spline_integrate(x, np.array([y, y]), 0, 1) | ||
assert np.all(~np.isnan(r)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.