Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitenti committed Apr 13, 2024
1 parent e18e78c commit 41c2699
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
17 changes: 9 additions & 8 deletions numcosmo/math/ncm_data_gauss_cov.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ _ncm_data_gauss_cov_prepare_LLT (NcmData *data)

if (ret != 0) /* if different from 0, something went wrong in the Cholesky decomposition */
{
/* g_error ("_ncm_data_gauss_cov_prepare_LLT[ncm_matrix_cholesky_decomp]: %d.", ret); */
g_warning ("_ncm_data_gauss_cov_prepare_LLT[ncm_matrix_cholesky_decomp]: %d.", ret);
ncm_matrix_log_vals (self->cov, "COV: ", "% 22.15g");
g_error ("_ncm_data_gauss_cov_prepare_LLT[ncm_matrix_cholesky_decomp]: %d.", ret);
self->prepared_LLT = FALSE;
}
else
Expand Down Expand Up @@ -684,10 +682,10 @@ ncm_data_gauss_cov_compute_cov (NcmDataGaussCov *gauss, NcmMSet *mset, gboolean

if (gauss_cov_class->cov_func != NULL)
{
NcmMatrix *cov = ncm_matrix_dup (self->cov);
NcmMatrix *cov = ncm_matrix_dup (self->cov);
gboolean l_updated;

ncm_data_prepare (NCM_DATA(gauss), mset);
ncm_data_prepare (NCM_DATA (gauss), mset);
l_updated = gauss_cov_class->cov_func (gauss, mset, cov);

if (updated != NULL)
Expand Down Expand Up @@ -811,11 +809,14 @@ ncm_data_gauss_cov_compute_mean (NcmDataGaussCov *gauss, NcmMSet *mset)

if (gauss_cov_class->mean_func != NULL)
{
NcmVector *mean = ncm_vector_dup (self->y);
NcmVector *mean = ncm_vector_dup (self->y);

ncm_data_prepare (NCM_DATA(gauss), mset);
ncm_data_prepare (NCM_DATA (gauss), mset);
gauss_cov_class->mean_func (gauss, mset, mean);

return mean;
}

return NULL;
}
}

3 changes: 1 addition & 2 deletions tests/test_nc_cluster_abundance.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ test_nc_cluster_abundance_failing_intp_bin_d2n (TestNcClusterAbundance *test, gc

nc_cluster_abundance_intp_bin_d2n (test->cad, test->cosmo, test->clusterz, test->clusterm, lnM_obs_bin_lower, lnM_obs_bin_upper, NULL, z_obs_bin_upper, z_obs_bin_lower, NULL);


return;
return; /* LCOV_EXCL_LINE */
}

/* Reruns this same test in a subprocess */
Expand Down
26 changes: 26 additions & 0 deletions tests/test_ncm_data_gauss_cov.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct _TestNcmDataGaussCovTest
void test_ncm_data_gauss_cov_test_new (TestNcmDataGaussCovTest *test, gconstpointer pdata);
void test_ncm_data_gauss_cov_test_free (TestNcmDataGaussCovTest *test, gconstpointer pdata);
void test_ncm_data_gauss_cov_test_sanity (TestNcmDataGaussCovTest *test, gconstpointer pdata);
void test_ncm_data_gauss_cov_test_bad_cov (TestNcmDataGaussCovTest *test, gconstpointer pdata);
void test_ncm_data_gauss_cov_test_resample (TestNcmDataGaussCovTest *test, gconstpointer pdata);
void test_ncm_data_gauss_cov_test_bootstrap_resample (TestNcmDataGaussCovTest *test, gconstpointer pdata);
void test_ncm_data_gauss_cov_test_bootstrap_resample_norm (TestNcmDataGaussCovTest *test, gconstpointer pdata);
Expand All @@ -66,6 +67,11 @@ main (gint argc, gchar *argv[])
&test_ncm_data_gauss_cov_test_sanity,
&test_ncm_data_gauss_cov_test_free);

g_test_add ("/ncm/data_gauss_cov/test/bad_cov", TestNcmDataGaussCovTest, NULL,
&test_ncm_data_gauss_cov_test_new,
&test_ncm_data_gauss_cov_test_bad_cov,
&test_ncm_data_gauss_cov_test_free);

g_test_add ("/ncm/data_gauss_cov/test/resample", TestNcmDataGaussCovTest, NULL,
&test_ncm_data_gauss_cov_test_new,
&test_ncm_data_gauss_cov_test_resample,
Expand Down Expand Up @@ -246,6 +252,26 @@ test_ncm_data_gauss_cov_test_sanity (TestNcmDataGaussCovTest *test, gconstpointe
}
}

void
test_ncm_data_gauss_cov_test_bad_cov (TestNcmDataGaussCovTest *test, gconstpointer pdata)
{
if (g_test_subprocess ())
{
NcmDataGaussCov *gauss = NCM_DATA_GAUSS_COV (test->data);
NcmMatrix *cov = ncm_data_gauss_cov_peek_cov (gauss);

ncm_matrix_scale (cov, -1.0);

ncm_data_gauss_cov_get_log_norma (gauss, NULL);

return;
}

g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_stderr ("*_ncm_data_gauss_cov_prepare_LLT[ncm_matrix_cholesky_decomp]*");
g_test_trap_assert_failed ();
}

void
test_ncm_data_gauss_cov_test_resample (TestNcmDataGaussCovTest *test, gconstpointer pdata)
{
Expand Down

0 comments on commit 41c2699

Please sign in to comment.