2 #include "utils_tests.h"
4 // create a new matrix and fill it with i * 1. + j * .1, where i is the row,
7 void assert_fmat_all_equal(fmat_t *mat, smpl_t scalar)
10 for ( i = 0; i < mat->height; i++ ) {
11 for ( j = 0; j < mat->length; j++ ) {
12 assert(mat->data[i][j] == scalar);
20 uint_t height = 3, length = 9;
22 // create fmat_t object
23 fmat_t * mat = new_fmat(height, length);
24 fmat_t * other_mat = new_fmat(height, length);
29 assert(mat->length == length);
30 assert(mat->height == height);
32 for (i = 0; i < mat->height; i++) {
33 for (j = 0; j < mat->length; j++) {
34 // all elements are already initialized to 0.
35 assert(mat->data[i][j] == 0);
36 // setting element of row i, column j
37 mat->data[i][j] = i * 10. + j;
47 for (i = 0; i < mat->height; i++) {
48 for (j = 0; j < mat->length; j++) {
49 assert(mat->data[i][j] == i * 10. + mat->length - 1. - j);
53 fmat_set_sample(mat, 3, 1, 1);
54 assert(fmat_get_sample(mat, 1, 1) == 3.);
57 assert_fmat_all_equal(mat, 1.);
59 fmat_set(other_mat, .5);
60 assert_fmat_all_equal(other_mat, .5);
62 fmat_weight(mat, other_mat);
63 assert_fmat_all_equal(mat, .5);
65 fvec_t channel_onstack;
66 fvec_t *channel = &channel_onstack;
67 fmat_get_channel(mat, 1, channel);
68 assert(channel->data == mat->data[1]);
70 // copy of the same size
71 fmat_copy(mat, other_mat);
75 other_mat = new_fmat(height - 1, length);
76 fmat_copy(mat, other_mat);
79 // copy from undersized
80 other_mat = new_fmat(height, length + 1);
81 fmat_copy(mat, other_mat);
84 assert(new_fmat(-1, length) == NULL);
85 assert(new_fmat(height, -1) == NULL);
87 // methods for wrappers with opaque structure
88 assert (fmat_get_channel_data(mat, 0) == mat->data[0]);
89 assert (fmat_get_data(mat) == mat->data);