- Timestamp:
- Dec 21, 2018, 2:08:48 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- 1f382d6
- Parents:
- 9e2c1a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/src/test-fmat.c
r9e2c1a1 rfce8496 5 5 // and j the column. 6 6 7 void assert_fmat_all_equal(fmat_t *mat, smpl_t scalar) 8 { 9 uint_t i, j; 10 for ( i = 0; i < mat->height; i++ ) { 11 for ( j = 0; j < mat->length; j++ ) { 12 assert(mat->data[i][j] == scalar); 13 } 14 } 15 } 16 7 17 int main (void) 8 18 { 9 uint_t height = 3, length = 9, i, j; 19 uint_t i, j; 20 uint_t height = 3, length = 9; 21 10 22 // create fmat_t object 11 fmat_t * mat = new_fmat (height, length); 12 for ( i = 0; i < mat->height; i++ ) { 13 for ( j = 0; j < mat->length; j++ ) { 23 fmat_t * mat = new_fmat(height, length); 24 fmat_t * other_mat = new_fmat(height, length); 25 26 assert(mat); 27 assert(other_mat); 28 29 assert(mat->length == length); 30 assert(mat->height == height); 31 32 for (i = 0; i < mat->height; i++) { 33 for (j = 0; j < mat->length; j++) { 14 34 // all elements are already initialized to 0. 15 35 assert(mat->data[i][j] == 0); 16 36 // setting element of row i, column j 17 mat->data[i][j] = i * 1 . + j *.1;37 mat->data[i][j] = i * 10. + j; 18 38 } 19 39 } 40 41 // print out matrix 42 fmat_print(mat); 43 44 // helpers 45 fmat_rev(mat); 46 fmat_print(mat); 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); 50 } 51 } 52 53 fmat_set_sample(mat, 3, 1, 1); 54 assert(fmat_get_sample(mat, 1, 1) == 3.); 55 56 fmat_ones(mat); 57 assert_fmat_all_equal(mat, 1.); 58 59 fmat_set(other_mat, .5); 60 assert_fmat_all_equal(other_mat, .5); 61 62 fmat_weight(mat, other_mat); 63 assert_fmat_all_equal(mat, .5); 64 20 65 fvec_t channel_onstack; 21 66 fvec_t *channel = &channel_onstack; 22 67 fmat_get_channel(mat, 1, channel); 23 fvec_print (channel); 24 // print out matrix 25 fmat_print(mat); 26 // destroy it 27 del_fmat(mat); 68 assert(channel->data == mat->data[1]); 69 70 // copy of the same size 71 fmat_copy(mat, other_mat); 72 del_fmat(other_mat); 73 74 // copy to undersized 75 other_mat = new_fmat(height - 1, length); 76 fmat_copy(mat, other_mat); 77 del_fmat(other_mat); 78 79 // copy from undersized 80 other_mat = new_fmat(height, length + 1); 81 fmat_copy(mat, other_mat); 82 83 // wrong parameters 84 assert(new_fmat(-1, length) == NULL); 85 assert(new_fmat(height, -1) == NULL); 86 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); 90 91 if (mat) 92 del_fmat(mat); 93 if (other_mat) 94 del_fmat(other_mat); 28 95 return 0; 29 96 } 30
Note: See TracChangeset
for help on using the changeset viewer.