Skip to content

Commit fe9a20f

Browse files
committed
added test to validate the state transformation but has an unknown but. despite that, the state transformation works as expected
1 parent 38f0061 commit fe9a20f

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

modules/cuqdyn-c/src/states_transformer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <nvector/nvector_serial.h>
55
#include <stdio.h>
66
#include <sunmatrix/sunmatrix_dense.h>
7-
#include <unistd.h>
87

98
#include "config.h"
109
#include "matlab.h"
@@ -40,7 +39,7 @@ SUNMatrix transform_states(SUNMatrix states)
4039

4140
N_VDestroy(input);
4241
}
43-
42+
4443
free(output);
4544
SUNMatDestroy(states);
4645
return transformed_result;

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ foreach(test_name
1010
test_ess_obj_function
1111
test_cuqdyn_algo
1212
test_context_and_config
13+
test_transform_states
1314
)
1415
add_executable(${test_name} ${test_name}.c)
1516
target_link_libraries(${test_name} cuqdyn-c)

tests/test_transform_states.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <assert.h>
2+
#include <sunmatrix/sunmatrix_dense.h>
3+
#include "config.h"
4+
#include "cuqdyn.h"
5+
6+
#define CUQDYN_CONF "data/nfkb_cuqdyn_config.xml"
7+
8+
int main()
9+
{
10+
CuqDynContext context = init_cuqdyn_context_from_file(CUQDYN_CONF);
11+
CuqdynConf *conf = get_cuqdyn_conf(context);
12+
13+
sunrealtype states_values[] = {
14+
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
15+
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
16+
};
17+
sunrealtype expected_transformation_values[] = {
18+
0, 1, 2, 1, 3, 1, 1,
19+
1, 2, 4, 2, 6, 2, 2
20+
};
21+
22+
assert(6 == conf->states_transformer.count);
23+
24+
SUNMatrix states = NewDenseMatrix(2, 16);
25+
26+
for (int i = 0; i < 2; ++i) {
27+
for (int j = 0; j < 16; ++j) {
28+
SM_ELEMENT_D(states, i, j) = states_values[16 * i + j];
29+
}
30+
}
31+
32+
SUNMatrix transformation = transform_states(states);
33+
34+
for (int i = 0; i < 2; ++i) {
35+
for (int j = 0; j < 7; ++j) {
36+
// TODO: This transformation works as expected but SM_ELEMENT_D thrown seg fault
37+
assert(expected_transformation_values[7 * i + j] == SM_ELEMENT_D(transformation, i, j));
38+
}
39+
}
40+
41+
destroy_cuqdyn_context(context);
42+
SUNMatDestroy(transformation);
43+
44+
return 0;
45+
}

0 commit comments

Comments
 (0)