Skip to content

Commit c2fc9cd

Browse files
committed
Tests
1 parent 7a118dc commit c2fc9cd

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/c_modules/bayes/libbayes/bayes.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ void bayes_posterior_free(struct bayes_posterior_ctx_s *ctx)
311311

312312
bool bayes_posterior_init(struct bayes_posterior_ctx_s *ctx, int num_dim)
313313
{
314-
bayes_posterior_free(ctx);
315314
ctx->N = num_dim;
316315
ctx->f_integration = calloc(num_dim, sizeof(double));
317316
ctx->f_estimation = calloc(num_dim, sizeof(double));

src/c_modules/bayes/libbayes/bayes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct bayes_posterior_ctx_s
4646
* @param ctx - context
4747
* @param num_frames - number of measurements
4848
* @param F - frames {F_a}, a=0..num_frames-1
49-
* @param f - {f_i} for which we find p({p_i}|{F_a})
49+
* @param f - {f_i} for which we find p({f_i}|{F_a})
5050
* @param d - constant coefficients {d_i}, for dark, sky
5151
* @param v - spatial coefficient {v_i}, for flat
5252
* @param K - contribution coefficients {K_i,a}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <gtest/gtest.h>
2+
#include <bayes.h>
3+
4+
extern "C" double
5+
6+
TEST(dim_1, aposteriori) {
7+
struct bayes_posterior_ctx_s ctx;
8+
bayes_posterior_init(&ctx, 1);
9+
10+
uint64_t F[] = {1, 1, 1, 1, 1}; // Samples
11+
double f[1] = {1}; // target for which find aposteriori
12+
double d[1] = {0}; // darks
13+
double v[1] = {1}; // flats
14+
double Ks[1] = {1}; // K
15+
double lows[1] = {0};
16+
double highs[1] = {10};
17+
double dl = 0.1;
18+
19+
auto apriori = [](const double *f, int N, const void *param) -> double
20+
{
21+
if (f[0] < 0)
22+
return 0;
23+
if (f[0] > 10)
24+
return 0;
25+
return 1.0/10;
26+
};
27+
28+
double posterior = bayes_posterior(&ctx, sizeof(F)/sizeof(F[0]), F, f, d, v, Ks, apriori, NULL, lows, highs, dl);
29+
30+
bayes_posterior_free(&ctx);
31+
}

0 commit comments

Comments
 (0)