/* TRIVIAL VALUE */ // spmat.h:PREFIX##find_element #define spmat_IMPLEMENT_mix(MATRIX_TYPE,PREFIX,ELEM_TYPE) \ spmat_DECLARE_mix(MATRIX_TYPE,PREFIX,ELEM_TYPE) \ { spmat_pos_t posC = 0; \ PREFIX##_entry_t *eCprev = NULL; /* Last entry stored into {C}. */ \ \ auto void mix_entries \ ( spmat_index_t row, \ spmat_index_t col, \ const ELEM_TYPE Aij, \ const ELEM_TYPE Bij \ ); \ \ void mix_entries \ ( spmat_index_t row, \ spmat_index_t col, \ const ELEM_TYPE Aij, \ const ELEM_TYPE Bij \ ) \ { ELEM_TYPE val; \ if (PREFIX##_elem_is_trivial(Aij)) \ { val = PREFIX##_elem_mul(b, Bij); } \ else if (PREFIX##_elem_is_trivial(Bij)) \ { val = PREFIX##_elem_mul(a, Aij); } \ else \ { ELEM_TYPE va = PREFIX##_elem_mul(a, Aij); \ ELEM_TYPE vb = PREFIX##_elem_mul(b, Bij); \ val = PREFIX##_elem_add(va, vb); \ } \ if (! PREFIX##_elem_is_trivial(val)) \ { PREFIX##_expand(C, posC); \ PREFIX##_entry_t *eC = &(C->e[posC]); \ eC->row = row; eC->col = col; eC->val = val; \ eCprev = eC; \ posC++; \ } \ } \ \ C->rows = A->rows; \ C->cols = A->cols; \ PREFIX##_merge(A, B, &mix_entries); \ PREFIX##_trim(C, posC); \ } /* The parameters {orow,ocol} specify the order of the entries {M->e[posIni..posLim-1]}, as described under {PREFIX##_sort_entries} below; if they are not {0,0} (meaning `arbitrary order') the procedure will use binary search whenever possible. */ #define spmat_DECLARE_TRIVIAL_ELEM(MATRIX_TYPE,PREFIX,ELEM_TYPE) \ ELEM_TYPE PREFIX##_trivial_elem(void) /* This macro declares the function {PREFIX##_trivial_elem}. The call {val = PREFIX##_trivial_elem()} (with no arguments) will append into the variable {val} (of type {ELEM_TYPE}) the value . */ #define spmat_DECLARE_ELEM_IS_TRIVIAL(MATRIX_TYPE,PREFIX,ELEM_TYPE) \ /* This macro declares the function {PREFIX##_elem_is_trivial}. The call {b = PREFIX##_elem_is_trivial(val)} will return the boolean value {TRUE} iff {val} is the element value which is not stored explicitly in the matrix. */ /* GENERIC SPARSE MATRIX DESCRIPTORS */ typedef struct spmat_t /* General sparse matrix descriptor. */ { uint32_t rows; /* Number of rows. */ uint32_t cols; /* Number of columns. */ void *e; /* Pointer to the first explicit entry. */ uint32_t ents; /* Number of explicit entries. */ } spmat_t; /* A {spmat_t} {M} describes a uni-dimensional array of {M.ents} elements of the same size and type, stored in consecutive memory locations, starting at address {M.e}. */