Update of /cvsroot/pure-data/externals/iem/iemmatrix/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5466
Modified Files: mtx_pivot.c Log Message: fixed a bug with non-square matrices; added an argument to pivotize to a minimum trace (instead of a maximum)
Index: mtx_pivot.c =================================================================== RCS file: /cvsroot/pure-data/externals/iem/iemmatrix/src/mtx_pivot.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** mtx_pivot.c 21 Mar 2005 14:33:31 -0000 1.1.1.1 --- mtx_pivot.c 30 Mar 2005 12:07:31 -0000 1.2 *************** *** 27,30 **** --- 27,32 ----
t_outlet *pivo, *pre, *post; + + t_int ascending;
} t_mtx_pivot; *************** *** 42,48 **** int pivot_row, pivot_col;
! if (argc<2){ post("mtx_pivot: crippled matrix"); return; } ! if ((col<1)||(row<1)) { post("mtx_pivot: invalid dimensions"); return; } ! if (col*row>argc-2){ post("sparse matrix not yet supported : use "mtx_check""); return; }
adjustsize(&x->m, row, col); --- 44,61 ---- int pivot_row, pivot_col;
! int ascending=(x->ascending); ! ! if (argc<2){ ! post("mtx_pivot: crippled matrix"); ! return; ! } ! if ((col<1)||(row<1)){ ! post("mtx_pivot: invalid dimensions"); ! return; ! } ! if (col*row>argc-2){ ! post("sparse matrix not yet supported : use "mtx_check""); ! return; ! }
adjustsize(&x->m, row, col); *************** *** 66,72 **** /* do the pivot thing */
! for (k=0; k<min_rowcol-1; k++){ // 1. find max_element ! t_matrixfloat max = 0; pivot_row = pivot_col = k;
--- 79,85 ---- /* do the pivot thing */
! for (k=0; k<min_rowcol; k++){ // 1. find max_element ! t_matrixfloat tmp = fabsf(buffer[k*(1+col)]); pivot_row = pivot_col = k;
*************** *** 77,82 **** while(j--){ t_matrixfloat f = fabsf(*buf++); ! if (f>max) { ! max=f; pivot_row = i; pivot_col = col-j-1; --- 90,95 ---- while(j--){ t_matrixfloat f = fabsf(*buf++); ! if ((ascending && f>tmp) || (!ascending && f<tmp)) { ! tmp=f; pivot_row = i; pivot_col = col-j-1; *************** *** 84,88 **** } } ! // 2. move max el to [k,k] // 2a swap rows if (k-pivot_row) { --- 97,101 ---- } } ! // 2. move tmp el to [k,k] // 2a swap rows if (k-pivot_row) { *************** *** 128,132 **** i=row; m_pre = x->m_pre.atombuffer+2; ! while(i--)SETFLOAT(m_pre+i_pre[i]+i*col, 1);
--- 141,147 ---- i=row; m_pre = x->m_pre.atombuffer+2; ! while(i--){ ! SETFLOAT(m_pre+i_pre[i]+i*row, 1); ! }
*************** *** 143,147 **** }
! static void *mtx_pivot_new(void) { t_mtx_pivot *x = (t_mtx_pivot *)pd_new(mtx_pivot_class); --- 158,162 ---- }
! static void *mtx_pivot_new(t_floatarg f) { t_mtx_pivot *x = (t_mtx_pivot *)pd_new(mtx_pivot_class); *************** *** 151,154 **** --- 166,171 ---- x->post = outlet_new(&x->x_obj, 0);
+ x->ascending = (f < 0.f)?0:1; + x->m.atombuffer = x->m_pre.atombuffer = x->m_post.atombuffer = 0; x->m.row = x->m.col = x->m_pre.row = x->m_pre.col = x->m_post.row = x->m_post.col = 0; *************** *** 160,164 **** { mtx_pivot_class = class_new(gensym("mtx_pivot"), (t_newmethod)mtx_pivot_new, (t_method)mtx_pivot_free, ! sizeof(t_mtx_pivot), 0, 0, 0); class_addmethod(mtx_pivot_class, (t_method)mtx_pivot_matrix, gensym("matrix"), A_GIMME, 0);
--- 177,182 ---- { mtx_pivot_class = class_new(gensym("mtx_pivot"), (t_newmethod)mtx_pivot_new, (t_method)mtx_pivot_free, ! sizeof(t_mtx_pivot), 0, ! A_DEFFLOAT, 0); class_addmethod(mtx_pivot_class, (t_method)mtx_pivot_matrix, gensym("matrix"), A_GIMME, 0);