From f3ae55de67780ae938b22b78f3e785eb3bef945d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 30 Mar 2005 12:07:31 +0000 Subject: fixed a bug with non-square matrices; added an argument to pivotize to a minimum trace (instead of a maximum) svn path=/trunk/externals/iem/iemmatrix/; revision=2648 --- src/mtx_pivot.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'src/mtx_pivot.c') diff --git a/src/mtx_pivot.c b/src/mtx_pivot.c index 1ac4804..8534021 100644 --- a/src/mtx_pivot.c +++ b/src/mtx_pivot.c @@ -26,6 +26,8 @@ typedef struct _mtx_pivot t_matrix m_post; // the post-multiply matrix t_outlet *pivo, *pre, *post; + + t_int ascending; } t_mtx_pivot; @@ -41,9 +43,20 @@ static void mtx_pivot_matrix(t_mtx_pivot *x, t_symbol *s, int argc, t_atom *argv 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; } + 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); adjustsize(&x->m_pre, row, row); @@ -65,9 +78,9 @@ static void mtx_pivot_matrix(t_mtx_pivot *x, t_symbol *s, int argc, t_atom *argv /* do the pivot thing */ - for (k=0; kmax) { - max=f; + if ((ascending && f>tmp) || (!ascending && fm_pre.atombuffer+2; - while(i--)SETFLOAT(m_pre+i_pre[i]+i*col, 1); + while(i--){ + SETFLOAT(m_pre+i_pre[i]+i*row, 1); + } outlet_anything(x->post, gensym("matrix"), 2+col*col, x->m_post.atombuffer); @@ -142,7 +157,7 @@ static void mtx_pivot_free(t_mtx_pivot *x) matrix_free(&x->m_post); } -static void *mtx_pivot_new(void) +static void *mtx_pivot_new(t_floatarg f) { t_mtx_pivot *x = (t_mtx_pivot *)pd_new(mtx_pivot_class); @@ -150,6 +165,8 @@ static void *mtx_pivot_new(void) x->pre = outlet_new(&x->x_obj, 0); 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; @@ -159,7 +176,8 @@ static void *mtx_pivot_new(void) void mtx_pivot_setup(void) { 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); + sizeof(t_mtx_pivot), 0, + A_DEFFLOAT, 0); class_addmethod(mtx_pivot_class, (t_method)mtx_pivot_matrix, gensym("matrix"), A_GIMME, 0); class_sethelpsymbol(mtx_pivot_class, gensym("iemmatrix/mtx_transpose")); -- cgit v1.2.1