Skip to content

Commit

Permalink
* More testing.
Browse files Browse the repository at this point in the history
* Updated stubs.
* Testing new powspec_spline2d.py.
  • Loading branch information
vitenti committed Mar 22, 2024
1 parent 943e027 commit 5f207cb
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 31 deletions.
18 changes: 9 additions & 9 deletions numcosmo/math/ncm_powspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ ncm_powspec_get_nknots (NcmPowspec *powspec, guint *Nz, guint *Nk)
/**
* ncm_powspec_prepare:
* @powspec: a #NcmPowspec
* @model: a #NcmModel
* @model: (allow-none): a #NcmModel
*
* Prepares the power spectrum @powspec using the model @model.
*
Expand All @@ -700,7 +700,7 @@ ncm_powspec_prepare (NcmPowspec *powspec, NcmModel *model)
/**
* ncm_powspec_prepare_if_needed:
* @powspec: a #NcmPowspec
* @model: a #NcmModel
* @model: (allow-none): a #NcmModel
*
* Prepares the object @powspec using the model @model if it was changed
* since last preparation.
Expand All @@ -719,7 +719,7 @@ ncm_powspec_prepare_if_needed (NcmPowspec *powspec, NcmModel *model)
/**
* ncm_powspec_eval:
* @powspec: a #NcmPowspec
* @model: a #NcmModel
* @model: (allow-none): a #NcmModel
* @z: time $z$
* @k: mode $k$
*
Expand All @@ -736,7 +736,7 @@ ncm_powspec_eval (NcmPowspec *powspec, NcmModel *model, const gdouble z, const g
/**
* ncm_powspec_eval_vec:
* @powspec: a #NcmPowspec
* @model: a #NcmModel
* @model: (allow-none): a #NcmModel
* @z: time $z$
* @k: a #NcmVector
* @Pk: a #NcmVector
Expand All @@ -754,7 +754,7 @@ ncm_powspec_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, Ncm
/**
* ncm_powspec_get_spline_2d:
* @powspec: a #NcmPowspec
* @model: a #NcmModel compatible with @powspec
* @model: (allow-none): a #NcmModel
*
* Compute a 2D spline for the power spectrum.
*
Expand Down Expand Up @@ -810,7 +810,7 @@ _ncm_powspec_var_tophat_R_integ (gpointer user_data, gdouble lnk, gdouble weight
/**
* ncm_powspec_var_tophat_R:
* @powspec: a #NcmPowspec
* @model: a #NcmModel
* @model: (allow-none): a #NcmModel
* @reltol: relative tolerance for integration
* @z: the value of $z$
* @R: the value of $R$
Expand Down Expand Up @@ -851,7 +851,7 @@ ncm_powspec_var_tophat_R (NcmPowspec *powspec, NcmModel *model, const gdouble re
/**
* ncm_powspec_sigma_tophat_R:
* @powspec: a #NcmPowspec
* @model: a #NcmModel
* @model: (allow-none): a #NcmModel
* @reltol: relative tolerance for integration
* @z: the value of $z$
* @R: the value of $R$
Expand Down Expand Up @@ -881,7 +881,7 @@ _ncm_powspec_corr3D_integ (gpointer user_data, gdouble lnk, gdouble weight)
/**
* ncm_powspec_corr3d:
* @powspec: a #NcmPowspec
* @model: a #NcmModel
* @model: (allow-none): a #NcmModel
* @reltol: relative tolerance for integration
* @z: the value of $z$
* @r: the value of $r$
Expand Down Expand Up @@ -932,7 +932,7 @@ _ncm_powspec_sproj_integ (gpointer user_data, gdouble lnk, gdouble weight)
/**
* ncm_powspec_sproj:
* @powspec: a #NcmPowspec
* @model: a #NcmModel
* @model: (allow-none): a #NcmModel
* @reltol: relative tolerance for integration
* @ell: the value of $\ell$
* @z1: the value of $z_1$
Expand Down
2 changes: 1 addition & 1 deletion numcosmo/math/ncm_powspec_spline2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ enum
PROP_SPLINE2D,
};

G_DEFINE_TYPE_WITH_PRIVATE (NcmPowspecSpline2d, ncm_powspec_spline2d, G_TYPE_OBJECT)
G_DEFINE_TYPE_WITH_PRIVATE (NcmPowspecSpline2d, ncm_powspec_spline2d, NCM_TYPE_POWSPEC)

static void
ncm_powspec_spline2d_init (NcmPowspecSpline2d *ps_s2d)
Expand Down
7 changes: 3 additions & 4 deletions numcosmo_py/nc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15572,7 +15572,7 @@ class PowspecMLSpline(PowspecML):
Object NcPowspecMLSpline

Properties from NcPowspecMLSpline:
spline -> gchararray: spline
spline -> NcmSpline: spline
Spline representing Pk at z=0

Properties from NcPowspecML:
Expand Down Expand Up @@ -15602,7 +15602,7 @@ class PowspecMLSpline(PowspecML):
"""

class Props:
spline: str
spline: NumCosmoMath.Spline
kmax: float
kmin: float
zf: float
Expand All @@ -15611,14 +15611,13 @@ class PowspecMLSpline(PowspecML):
props: Props = ...
def __init__(
self,
spline: str = ...,
spline: NumCosmoMath.Spline = ...,
kmax: float = ...,
kmin: float = ...,
zf: float = ...,
zi: float = ...,
reltol: float = ...,
): ...
def load_from_file(self, filename: str) -> None: ...
@classmethod
def new(cls, Pk: NumCosmoMath.Spline) -> PowspecMLSpline: ...
def peek_spline(self) -> NumCosmoMath.Spline: ...
Expand Down
107 changes: 90 additions & 17 deletions numcosmo_py/ncm.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7595,25 +7595,31 @@ class Powspec(GObject.Object):
): ...
@staticmethod
def clear(powspec: Powspec) -> None: ...
def corr3d(self, model: Model, reltol: float, z: float, r: float) -> float: ...
def do_eval(self, model: Model, z: float, k: float) -> float: ...
def do_eval_vec(self, model: Model, z: float, k: Vector, Pk: Vector) -> None: ...
def corr3d(
self, model: Optional[Model], reltol: float, z: float, r: float
) -> float: ...
def do_eval(self, model: Optional[Model], z: float, k: float) -> float: ...
def do_eval_vec(
self, model: Optional[Model], z: float, k: Vector, Pk: Vector
) -> None: ...
def do_get_nknots(self) -> Tuple[int, int]: ...
def do_get_spline_2d(self, model: Model) -> Spline2d: ...
def do_prepare(self, model: Model) -> None: ...
def eval(self, model: Model, z: float, k: float) -> float: ...
def eval_vec(self, model: Model, z: float, k: Vector, Pk: Vector) -> None: ...
def do_get_spline_2d(self, model: Optional[Model] = None) -> Spline2d: ...
def do_prepare(self, model: Optional[Model] = None) -> None: ...
def eval(self, model: Optional[Model], z: float, k: float) -> float: ...
def eval_vec(
self, model: Optional[Model], z: float, k: Vector, Pk: Vector
) -> None: ...
def free(self) -> None: ...
def get_kmax(self) -> float: ...
def get_kmin(self) -> float: ...
def get_nknots(self) -> Tuple[int, int]: ...
def get_reltol_spline(self) -> float: ...
def get_spline_2d(self, model: Model) -> Spline2d: ...
def get_spline_2d(self, model: Optional[Model] = None) -> Spline2d: ...
def get_zf(self) -> float: ...
def get_zi(self) -> float: ...
def peek_model_ctrl(self) -> ModelCtrl: ...
def prepare(self, model: Model) -> None: ...
def prepare_if_needed(self, model: Model) -> None: ...
def prepare(self, model: Optional[Model] = None) -> None: ...
def prepare_if_needed(self, model: Optional[Model] = None) -> None: ...
def ref(self) -> Powspec: ...
def require_kmax(self, kmax: float) -> None: ...
def require_kmin(self, kmin: float) -> None: ...
Expand All @@ -7625,11 +7631,11 @@ class Powspec(GObject.Object):
def set_zf(self, zf: float) -> None: ...
def set_zi(self, zi: float) -> None: ...
def sigma_tophat_R(
self, model: Model, reltol: float, z: float, R: float
self, model: Optional[Model], reltol: float, z: float, R: float
) -> float: ...
def sproj(
self,
model: Model,
model: Optional[Model],
reltol: float,
ell: int,
z1: float,
Expand All @@ -7638,7 +7644,7 @@ class Powspec(GObject.Object):
xi2: float,
) -> float: ...
def var_tophat_R(
self, model: Model, reltol: float, z: float, R: float
self, model: Optional[Model], reltol: float, z: float, R: float
) -> float: ...

class PowspecClass(GObject.GPointer):
Expand All @@ -7650,11 +7656,11 @@ class PowspecClass(GObject.GPointer):
PowspecClass()
"""
parent_class: GObject.ObjectClass = ...
prepare: Callable[[Powspec, Model], None] = ...
eval: Callable[[Powspec, Model, float, float], float] = ...
eval_vec: Callable[[Powspec, Model, float, Vector, Vector], None] = ...
prepare: Callable[[Powspec, Optional[Model]], None] = ...
eval: Callable[[Powspec, Optional[Model], float, float], float] = ...
eval_vec: Callable[[Powspec, Optional[Model], float, Vector, Vector], None] = ...
get_nknots: Callable[[Powspec], Tuple[int, int]] = ...
get_spline_2d: Callable[[Powspec, Model], Spline2d] = ...
get_spline_2d: Callable[[Powspec, Optional[Model]], Spline2d] = ...
padding: list[None] = ...

class PowspecCorr3d(GObject.Object):
Expand Down Expand Up @@ -7918,6 +7924,73 @@ class PowspecSphereProjClass(GObject.GPointer):
"""
parent_class: PowspecClass = ...

class PowspecSpline2d(Powspec):
r"""
:Constructors:
::
PowspecSpline2d(**properties)
new(spline2d:NumCosmoMath.Spline2d) -> NumCosmoMath.PowspecSpline2d
Object NcmPowspecSpline2d
Properties from NcmPowspecSpline2d:
spline2d -> NcmSpline2d: spline2d
Spline2d representing the values of the power-spectrum
Properties from NcmPowspec:
zi -> gdouble: zi
Initial time
zf -> gdouble: zf
Final time
kmin -> gdouble: kmin
Minimum mode value
kmax -> gdouble: kmax
Maximum mode value
reltol -> gdouble: reltol
Relative tolerance on the interpolation error
Signals from GObject:
notify (GParam)
"""

class Props:
spline2d: Spline2d
kmax: float
kmin: float
reltol: float
zf: float
zi: float
props: Props = ...
def __init__(
self,
spline2d: Spline2d = ...,
kmax: float = ...,
kmin: float = ...,
reltol: float = ...,
zf: float = ...,
zi: float = ...,
): ...
@staticmethod
def clear(ps_s2d: PowspecSpline2d) -> None: ...
def free(self) -> None: ...
@classmethod
def new(cls, spline2d: Spline2d) -> PowspecSpline2d: ...
def peek_spline2d(self) -> Spline2d: ...
def ref(self) -> PowspecSpline2d: ...
def set_spline2d(self, spline2d: Spline2d) -> None: ...

class PowspecSpline2dClass(GObject.GPointer):
r"""
:Constructors:
::
PowspecSpline2dClass()
"""
parent_class: PowspecClass = ...

class Prior(MSetFunc):
r"""
:Constructors:
Expand Down
4 changes: 4 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ python_tests = [
'name': 'py_powspec_ml_spline',
'source': 'test_py_powspec_ml_spline.py',
},
{
'name': 'py_powspec_spline2d',
'source': 'test_py_powspec_spline2d.py',
},
]

if mpi_c_dep.found()
Expand Down
36 changes: 36 additions & 0 deletions tests/test_ncm_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void test_ncm_mpi_job_test_basic (void);
void test_ncm_mpi_job_fit_basic (void);
void test_ncm_mpi_job_mcmc_basic (void);
void test_ncm_mpi_job_feval_basic (void);
void test_ncm_powspec_spline2d_basic (void);

gint
main (gint argc, gchar *argv[])
Expand All @@ -66,6 +67,7 @@ main (gint argc, gchar *argv[])
g_test_add_func ("/ncm/mpi_job_fit/basic", test_ncm_mpi_job_fit_basic);
g_test_add_func ("/ncm/mpi_job_mcmc/basic", test_ncm_mpi_job_mcmc_basic);
g_test_add_func ("/ncm/mpi_job_feval/basic", test_ncm_mpi_job_feval_basic);
g_test_add_func ("/ncm/powspec_spline2d/basic", test_ncm_powspec_spline2d_basic);

g_test_run ();
}
Expand Down Expand Up @@ -301,3 +303,37 @@ test_ncm_mpi_job_feval_basic (void)
NCM_TEST_FREE (ncm_mset_free, mset);
}

void
test_ncm_powspec_spline2d_basic (void)
{
gdouble x[6] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
gdouble y[7] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
gdouble z[42] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, };
NcmVector *xv = ncm_vector_new_data_static (x, 6, 1);
NcmVector *yv = ncm_vector_new_data_static (y, 7, 1);
NcmMatrix *zm = ncm_matrix_new_data_static (z, 7, 6);
NcmSpline *sc = ncm_spline_cubic_notaknot_new ();
NcmSpline2d *sb2d = ncm_spline2d_bicubic_new (sc);
NcmPowspecSpline2d *ps_s2d = ncm_powspec_spline2d_new (NCM_SPLINE2D (sb2d));
NcmPowspecSpline2d *ps_s2d2;

ncm_spline2d_set (NCM_SPLINE2D (sb2d), xv, yv, zm, FALSE);

g_assert_true (ps_s2d != NULL);
g_assert_true (NCM_IS_POWSPEC_SPLINE2D (ps_s2d));

ps_s2d2 = ncm_powspec_spline2d_ref (ps_s2d);
ncm_powspec_spline2d_clear (&ps_s2d2);
g_assert_true (ps_s2d2 == NULL);

g_assert_true (NCM_IS_POWSPEC_SPLINE2D (ps_s2d));

ncm_vector_free (xv);
ncm_vector_free (yv);
ncm_matrix_free (zm);
ncm_spline_free (NCM_SPLINE (sc));

NCM_TEST_FREE (ncm_powspec_spline2d_free, ps_s2d);
NCM_TEST_FREE (ncm_spline2d_free, NCM_SPLINE2D (sb2d));
}

Loading

0 comments on commit 5f207cb

Please sign in to comment.