aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranz Zotter <fzotter@users.sourceforge.net>2006-08-28 16:48:51 +0000
committerFranz Zotter <fzotter@users.sourceforge.net>2006-08-28 16:48:51 +0000
commit157bcb825e2815804aed41ba79732fc37d3a9d74 (patch)
tree1ceaecad9e31c6beea9ff015d200e29d7d21acb3
parente593b8e98687f93cced437c72c75e89608b8ce7a (diff)
added a few element wise operations
svn path=/trunk/externals/iem/iemmatrix/; revision=5764
-rw-r--r--doc/mtx_conv-help.pd30
-rw-r--r--src/iemmatrix_sources.c5
-rw-r--r--src/iemmatrix_sources.h5
-rw-r--r--src/mtx_atan.c83
-rw-r--r--src/mtx_dbtopow.c92
-rw-r--r--src/mtx_powtodb.c88
6 files changed, 286 insertions, 17 deletions
diff --git a/doc/mtx_conv-help.pd b/doc/mtx_conv-help.pd
index 31d2905..f975a3a 100644
--- a/doc/mtx_conv-help.pd
+++ b/doc/mtx_conv-help.pd
@@ -8,8 +8,6 @@
#X text 18 63 you can calculate the convolution of a matrix with a
filter matrix kernel (2 dimensional FIR filtering). Of course \, it
can also be used for 1-dimensional FIR convolutions.;
-#X obj 63 196 matrix 1 10;
-#X msg 64 176 element 1 1 1;
#X msg 42 127 bang;
#X obj 42 151 t b b b;
#X obj 64 215 t a a;
@@ -18,16 +16,18 @@ can also be used for 1-dimensional FIR convolutions.;
#X obj 173 197 t a a;
#X obj 200 217 mtx_print filter_kernel;
#X obj 64 304 mtx_print result;
-#X msg 173 174 matrix 2 2 1 1 1 1;
-#X connect 7 0 11 0;
-#X connect 8 0 7 0;
-#X connect 9 0 10 0;
-#X connect 10 0 7 0;
-#X connect 10 1 8 0;
-#X connect 10 2 17 0;
-#X connect 11 0 13 0;
-#X connect 11 1 12 0;
-#X connect 13 0 16 0;
-#X connect 14 0 13 1;
-#X connect 14 1 15 0;
-#X connect 17 0 14 0;
+#X msg 173 174 matrix 2 3 1 1 1 1 1 1 1;
+#X msg 64 176 element 4 4 1;
+#X obj 63 196 matrix 5 5;
+#X connect 7 0 8 0;
+#X connect 8 0 17 0;
+#X connect 8 1 16 0;
+#X connect 8 2 15 0;
+#X connect 9 0 11 0;
+#X connect 9 1 10 0;
+#X connect 11 0 14 0;
+#X connect 12 0 11 1;
+#X connect 12 1 13 0;
+#X connect 15 0 12 0;
+#X connect 16 0 17 0;
+#X connect 17 0 9 0;
diff --git a/src/iemmatrix_sources.c b/src/iemmatrix_sources.c
index 80dc5fe..229b4cf 100644
--- a/src/iemmatrix_sources.c
+++ b/src/iemmatrix_sources.c
@@ -10,6 +10,7 @@ void iemmatrix_sources_setup(void)
iemtx_abs_setup(); /* mtx_abs.c */
iemtx_add_setup(); /* mtx_add.c */
iemtx_and_setup(); /* mtx_and.c */
+ iemtx_atan_setup(); /* mtx_atan.c */
iemtx_binops_setup(); /* mtx_binops.c */
iemtx_bitand_setup(); /* mtx_bitand.c */
iemtx_bitleft_setup(); /* mtx_bitleft.c */
@@ -24,6 +25,7 @@ void iemmatrix_sources_setup(void)
iemtx_conv_setup(); /* mtx_conv.c */
iemtx_cos_setup(); /* mtx_cos.c */
iemtx_cumsum_setup(); /* mtx_cumsum.c */
+ iemtx_dbtopow_setup(); /* mtx_dbtopow.c */
iemtx_dbtorms_setup(); /* mtx_dbtorms.c */
iemtx_decay_setup(); /* mtx_decay.c */
iemtx_diag_setup(); /* mtx_diag.c */
@@ -51,14 +53,15 @@ void iemmatrix_sources_setup(void)
iemtx_mean_setup(); /* mtx_mean.c */
iemtx_min2_setup(); /* mtx_min2.c */
iemtx_minmax_setup(); /* mtx_minmax.c */
- iemtx_mul__setup(); /* mtx_mul~.c */
iemtx_mul_setup(); /* mtx_mul.c */
+ iemtx_mul__setup(); /* mtx_mul~.c */
iemtx_neq_setup(); /* mtx_neq.c */
iemtx_not_setup(); /* mtx_not.c */
iemtx_ones_setup(); /* mtx_ones.c */
iemtx_or_setup(); /* mtx_or.c */
iemtx_pivot_setup(); /* mtx_pivot.c */
iemtx_pow_setup(); /* mtx_pow.c */
+ iemtx_powtodb_setup(); /* mtx_powtodb.c */
iemtx_print_setup(); /* mtx_print.c */
iemtx_prod_setup(); /* mtx_prod.c */
iemtx_rand_setup(); /* mtx_rand.c */
diff --git a/src/iemmatrix_sources.h b/src/iemmatrix_sources.h
index da21ef2..783484d 100644
--- a/src/iemmatrix_sources.h
+++ b/src/iemmatrix_sources.h
@@ -8,6 +8,7 @@
void iemtx_abs_setup(void); /* mtx_abs.c */
void iemtx_add_setup(void); /* mtx_add.c */
void iemtx_and_setup(void); /* mtx_and.c */
+void iemtx_atan_setup(void); /* mtx_atan.c */
void iemtx_binops_setup(void); /* mtx_binops.c */
void iemtx_bitand_setup(void); /* mtx_bitand.c */
void iemtx_bitleft_setup(void); /* mtx_bitleft.c */
@@ -22,6 +23,7 @@ void iemtx_concat_setup(void); /* mtx_concat.c */
void iemtx_conv_setup(void); /* mtx_conv.c */
void iemtx_cos_setup(void); /* mtx_cos.c */
void iemtx_cumsum_setup(void); /* mtx_cumsum.c */
+void iemtx_dbtopow_setup(void); /* mtx_dbtopow.c */
void iemtx_dbtorms_setup(void); /* mtx_dbtorms.c */
void iemtx_decay_setup(void); /* mtx_decay.c */
void iemtx_diag_setup(void); /* mtx_diag.c */
@@ -49,14 +51,15 @@ void iemtx_max2_setup(void); /* mtx_max2.c */
void iemtx_mean_setup(void); /* mtx_mean.c */
void iemtx_min2_setup(void); /* mtx_min2.c */
void iemtx_minmax_setup(void); /* mtx_minmax.c */
-void iemtx_mul__setup(void); /* mtx_mul~.c */
void iemtx_mul_setup(void); /* mtx_mul.c */
+void iemtx_mul__setup(void); /* mtx_mul~.c */
void iemtx_neq_setup(void); /* mtx_neq.c */
void iemtx_not_setup(void); /* mtx_not.c */
void iemtx_ones_setup(void); /* mtx_ones.c */
void iemtx_or_setup(void); /* mtx_or.c */
void iemtx_pivot_setup(void); /* mtx_pivot.c */
void iemtx_pow_setup(void); /* mtx_pow.c */
+void iemtx_powtodb_setup(void); /* mtx_powtodb.c */
void iemtx_print_setup(void); /* mtx_print.c */
void iemtx_prod_setup(void); /* mtx_prod.c */
void iemtx_rand_setup(void); /* mtx_rand.c */
diff --git a/src/mtx_atan.c b/src/mtx_atan.c
new file mode 100644
index 0000000..0da42f8
--- /dev/null
+++ b/src/mtx_atan.c
@@ -0,0 +1,83 @@
+/*
+ * iemmatrix
+ *
+ * objects for manipulating simple matrices
+ * mostly refering to matlab/octave matrix functions
+ *
+ * Copyright (c) IOhannes m zmölnig, forum::für::umläute
+ * IEM, Graz, Austria
+ *
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+ *
+ */
+#include "iemmatrix.h"
+
+/* mtx_atan: B=atan(A); */
+
+static t_class *mtx_atan_class;
+
+static void mtx_atan_matrix(t_mtx_binmtx *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int row=atom_getint(argv++);
+ int col=atom_getint(argv++);
+ t_atom *m;
+ int n = row*col;
+
+ if (argc<2){ post("mtx_atan: crippled matrix"); return; }
+ if ((col<1)||(row<1)) { post("mtx_atan: invalid dimensions"); return; }
+ if (col*row>argc-2){ post("sparse matrix not yet supported : use \"mtx_check\""); return; }
+
+ adjustsize(&x->m, row, col);
+ m = x->m.atombuffer+2;
+
+ while(n--){
+ t_float f = atom_getfloat(argv++);
+ SETFLOAT(m, (t_float)atanf(f));
+ m++;
+ }
+
+ outlet_anything(x->x_obj.ob_outlet, gensym("matrix"), argc, x->m.atombuffer);
+}
+
+static void mtx_atan_list(t_mtx_binscalar *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int n=argc;
+ t_atom *m;
+
+ adjustsize(&x->m, 1, argc);
+ m = x->m.atombuffer;
+
+ while(n--){
+ m->a_type = A_FLOAT;
+ (m++)->a_w.w_float = (t_float)atanf(atom_getfloat(argv++));
+ }
+
+ outlet_list(x->x_obj.ob_outlet, gensym("list"), argc, x->m.atombuffer);
+}
+
+static void *mtx_atan_new(t_symbol *s)
+{
+ /* element atan */
+ t_matrix *x = (t_matrix *)pd_new(mtx_atan_class);
+ outlet_new(&x->x_obj, 0);
+ x->col = x->row = 0;
+ x->atombuffer = 0;
+ return(x);
+}
+
+void mtx_atan_setup(void)
+{
+ mtx_atan_class = class_new(gensym("mtx_atan"), (t_newmethod)mtx_atan_new, (t_method)mtx_binmtx_free,
+ sizeof(t_mtx_binmtx), 0, A_GIMME, 0);
+ class_addmethod(mtx_atan_class, (t_method)mtx_atan_matrix, gensym("matrix"), A_GIMME, 0);
+ class_addlist (mtx_atan_class, mtx_atan_list);
+ class_addbang (mtx_atan_class, mtx_binmtx_bang);
+
+
+}
+
+void iemtx_atan_setup(void)
+{
+ mtx_atan_setup();
+}
diff --git a/src/mtx_dbtopow.c b/src/mtx_dbtopow.c
new file mode 100644
index 0000000..237c5ea
--- /dev/null
+++ b/src/mtx_dbtopow.c
@@ -0,0 +1,92 @@
+/*
+ * iemmatrix
+ *
+ * objects for manipulating simple matrices
+ * mostly refering to matlab/octave matrix functions
+ *
+ * Copyright (c) IOhannes m zmölnig, forum::für::umläute
+ * IEM, Graz, Austria
+ *
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+ *
+ */
+#include "iemmatrix.h"
+
+#define LOGTEN 2.302585092994
+
+/* mtx_dbtopow: B=log(A); B[n,m]=e^A[n,m] */
+
+static t_class *mtx_dbtopow_class;
+
+static void mtx_dbtopow_matrix(t_mtx_binmtx *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int row=atom_getfloat(argv++);
+ int col=atom_getfloat(argv++);
+ t_atom *m;
+ int n = argc-2;
+
+ if (argc<2){ post("mtx_dbtopow: crippled matrix"); return; }
+ if ((col<1)||(row<1)) { post("mtx_dbtopow: invalid dimensions"); return; }
+ if (col*row>argc-2){ post("sparse matrix not yet supported : use \"mtx_check\""); return; }
+
+ adjustsize(&x->m, row, col);
+ m = x->m.atombuffer+2;
+
+ while(n--){
+ t_float f=atom_getfloat(argv++);
+ t_float v=0;
+ f=(f>485)?485:f;
+ v=(f<=0)?0:exp((LOGTEN*0.1) * (f-100.));
+ SETFLOAT(m, (v<0)?0:v);
+ m++;
+ }
+
+ outlet_anything(x->x_obj.ob_outlet, gensym("matrix"), argc, x->m.atombuffer);
+}
+
+static void mtx_dbtopow_list(t_mtx_binscalar *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int n=argc;
+ t_atom *m;
+
+ adjustsize(&x->m, 1, argc);
+ m = x->m.atombuffer;
+
+ while(n--){
+ t_float f=atom_getfloat(argv++);
+ t_float v=0;
+ f=(f>485)?485:f;
+ v=(f<=0)?0:exp((LOGTEN*0.1) * (f-100.));
+ SETFLOAT(m, (v<0)?0:v);
+ m++;
+ }
+
+ outlet_list(x->x_obj.ob_outlet, gensym("list"), argc, x->m.atombuffer);
+}
+
+static void *mtx_dbtopow_new(t_symbol *s)
+{
+ /* element log */
+ t_matrix *x = (t_matrix *)pd_new(mtx_dbtopow_class);
+ outlet_new(&x->x_obj, 0);
+ x->col = x->row = 0;
+ x->atombuffer = 0;
+ return(x);
+}
+
+void mtx_dbtopow_setup(void)
+{
+ mtx_dbtopow_class = class_new(gensym("mtx_dbtopow"), (t_newmethod)mtx_dbtopow_new, (t_method)mtx_binmtx_free,
+ sizeof(t_mtx_binmtx), 0, A_GIMME, 0);
+ class_addmethod(mtx_dbtopow_class, (t_method)mtx_dbtopow_matrix, gensym("matrix"), A_GIMME, 0);
+ class_addlist (mtx_dbtopow_class, mtx_dbtopow_list);
+ class_addbang (mtx_dbtopow_class, mtx_binmtx_bang);
+
+
+}
+
+void iemtx_dbtopow_setup(void)
+{
+ mtx_dbtopow_setup();
+}
diff --git a/src/mtx_powtodb.c b/src/mtx_powtodb.c
new file mode 100644
index 0000000..4b82561
--- /dev/null
+++ b/src/mtx_powtodb.c
@@ -0,0 +1,88 @@
+/*
+ * iemmatrix
+ *
+ * objects for manipulating simple matrices
+ * mostly refering to matlab/octave matrix functions
+ *
+ * Copyright (c) IOhannes m zmölnig, forum::für::umläute
+ * IEM, Graz, Austria
+ *
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+ *
+ */
+#include "iemmatrix.h"
+
+#define LOGTEN 2.302585092994
+
+/* mtx_powtodb: B=log(A); B[n,m]=e^A[n,m] */
+
+static t_class *mtx_powtodb_class;
+
+static void mtx_powtodb_matrix(t_mtx_binmtx *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int row=atom_getfloat(argv++);
+ int col=atom_getfloat(argv++);
+ t_atom *m;
+ int n = argc-2;
+
+ if (argc<2){ post("mtx_powtodb: crippled matrix"); return; }
+ if ((col<1)||(row<1)) { post("mtx_powtodb: invalid dimensions"); return; }
+ if (col*row>argc-2){ post("sparse matrix not yet supported : use \"mtx_check\""); return; }
+
+ adjustsize(&x->m, row, col);
+ m = x->m.atombuffer+2;
+
+ while(n--){
+ t_float f=atom_getfloat(argv++);
+ t_float v=(f<0)?0.:(100+10./LOGTEN * log(f));
+ SETFLOAT(m, (v<0)?0:v);
+ m++;
+ }
+
+ outlet_anything(x->x_obj.ob_outlet, gensym("matrix"), argc, x->m.atombuffer);
+}
+
+static void mtx_powtodb_list(t_mtx_binscalar *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int n=argc;
+ t_atom *m;
+
+ adjustsize(&x->m, 1, argc);
+ m = x->m.atombuffer;
+
+ while(n--){
+ t_float f=atom_getfloat(argv++);
+ t_float v=(f<0)?0.:(100+10./LOGTEN * log(f));
+ SETFLOAT(m, (v<0)?0:v);
+ m++;
+ }
+
+ outlet_list(x->x_obj.ob_outlet, gensym("list"), argc, x->m.atombuffer);
+}
+
+static void *mtx_powtodb_new(t_symbol *s)
+{
+ /* element log */
+ t_matrix *x = (t_matrix *)pd_new(mtx_powtodb_class);
+ outlet_new(&x->x_obj, 0);
+ x->col = x->row = 0;
+ x->atombuffer = 0;
+ return(x);
+}
+
+void mtx_powtodb_setup(void)
+{
+ mtx_powtodb_class = class_new(gensym("mtx_powtodb"), (t_newmethod)mtx_powtodb_new, (t_method)mtx_binmtx_free,
+ sizeof(t_mtx_binmtx), 0, A_GIMME, 0);
+ class_addmethod(mtx_powtodb_class, (t_method)mtx_powtodb_matrix, gensym("matrix"), A_GIMME, 0);
+ class_addlist (mtx_powtodb_class, mtx_powtodb_list);
+ class_addbang (mtx_powtodb_class, mtx_binmtx_bang);
+
+
+}
+
+void iemtx_powtodb_setup(void)
+{
+ mtx_powtodb_setup();
+}