aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-30 12:07:31 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-03-30 12:07:31 +0000
commitf3ae55de67780ae938b22b78f3e785eb3bef945d (patch)
treed9c2382563ddf0b2565808e1ea3752be76ee082b
parent47f0843c5dac8832c5a3a0842464f794d71e1ab1 (diff)
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
-rw-r--r--src/mtx_pivot.c40
1 files changed, 29 insertions, 11 deletions
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; k<min_rowcol-1; k++){
+ for (k=0; k<min_rowcol; k++){
// 1. find max_element
- t_matrixfloat max = 0;
+ t_matrixfloat tmp = fabsf(buffer[k*(1+col)]);
pivot_row = pivot_col = k;
for(i=k; i<row; i++){
@@ -76,14 +89,14 @@ static void mtx_pivot_matrix(t_mtx_pivot *x, t_symbol *s, int argc, t_atom *argv
j=col-k;
while(j--){
t_matrixfloat f = fabsf(*buf++);
- if (f>max) {
- max=f;
+ if ((ascending && f>tmp) || (!ascending && f<tmp)) {
+ tmp=f;
pivot_row = i;
pivot_col = col-j-1;
}
}
}
- // 2. move max el to [k,k]
+ // 2. move tmp el to [k,k]
// 2a swap rows
if (k-pivot_row) {
t_matrixfloat *oldrow=buffer+col*k;
@@ -127,7 +140,9 @@ static void mtx_pivot_matrix(t_mtx_pivot *x, t_symbol *s, int argc, t_atom *argv
}
i=row;
m_pre = x->m_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"));