[PD-cvs] externals/iem/iemmatrix/src mtx_fill.c,1.8,1.9

Franz Zotter fzotter at users.sourceforge.net
Mon Aug 14 14:43:55 CEST 2006


Update of /cvsroot/pure-data/externals/iem/iemmatrix/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6228

Modified Files:
	mtx_fill.c 
Log Message:
corrections to mtx_fill:
passive inlet matrix can pass through if invalid indices/ empty indexing vectors are defined. this is useful when combining with mtx_find and the 
result of mtx_find is empty or undefined (=0 indices). 



Index: mtx_fill.c
===================================================================
RCS file: /cvsroot/pure-data/externals/iem/iemmatrix/src/mtx_fill.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** mtx_fill.c	9 Aug 2006 19:26:19 -0000	1.8
--- mtx_fill.c	14 Aug 2006 12:43:53 -0000	1.9
***************
*** 18,22 ****
  typedef enum {
     FILL_SUBMATRIX,
!    FILL_INDEXED_ELEMENTS
  } FillStyle;
  
--- 18,23 ----
  typedef enum {
     FILL_SUBMATRIX,
!    FILL_INDEXED_ELEMENTS,
!    DONT_FILL_JUST_PASS
  } FillStyle;
  
***************
*** 36,39 ****
--- 37,41 ----
     int *index;
     int index_size;
+    int num_idcs_used;
     int max_index;
  
***************
*** 42,46 ****
     t_outlet *list_outlet;
  
-    t_atom *list_in;
     t_atom *list_out;
  };
--- 44,47 ----
***************
*** 48,53 ****
  static void deleteMTXFill (MTXfill *mtx_fill_obj) 
  {
-    if (mtx_fill_obj->list_in)
-       freebytes (mtx_fill_obj->list_in, sizeof(t_atom)*(mtx_fill_obj->size+2));
     if (mtx_fill_obj->list_out)
        freebytes (mtx_fill_obj->list_out, sizeof(t_atom)*(mtx_fill_obj->size+2));
--- 49,52 ----
***************
*** 107,111 ****
     // size check
     if (!size) {
!       post("mtx_fill: invalid dimensions/invalid start index");
        return;
     }
--- 106,110 ----
     // size check
     if (!size) {
!       mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
        return;
     }
***************
*** 114,117 ****
--- 113,117 ----
        if ((rows<1) || (columns<1)){
  	 post("mtx_fill: row and column indices must be >0");
+ 	 mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
  	 return;
        }
***************
*** 121,125 ****
     }
     else if (list_size<size) {
!       post("mtx_fill: sparse matrix not yet supported: use \"mtx_check\"");
        return;
     }
--- 121,125 ----
     }
     else if (list_size<size) {
!       mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
        return;
     }
***************
*** 133,151 ****
  		  sizeof (t_atom) * (size + 2));
  	 mtx_fill_obj->index_size = size;
        }
        mtx_fill_obj->max_index = 
  	 copyNonZeroAtomsToIntegerArrayMax (&size, argv++, index);
!       if (!size) {
! 	 post("mtx_fill: indexing matrix contains zero-values only!!!");
! 	 return;
!       }
!       if (size != mtx_fill_obj->index_size) {
! 	 index = (int *)  resizebytes (index,
! 		  sizeof (int) * (mtx_fill_obj->index_size+2),
! 		  sizeof (t_atom) * (size + 2));
! 	 mtx_fill_obj->index_size = size;
!       }
!       mtx_fill_obj->fill_type = FILL_INDEXED_ELEMENTS;
!       mtx_fill_obj->index = index;
     }
  }
--- 133,145 ----
  		  sizeof (t_atom) * (size + 2));
  	 mtx_fill_obj->index_size = size;
+ 	 mtx_fill_obj->index = index;
        }
        mtx_fill_obj->max_index = 
  	 copyNonZeroAtomsToIntegerArrayMax (&size, argv++, index);
!       mtx_fill_obj->num_idcs_used = size;
!       if (!size) 
! 	 mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
!       else 
! 	 mtx_fill_obj->fill_type = FILL_INDEXED_ELEMENTS;
     }
  }
***************
*** 155,161 ****
     MTXfill *mtx_fill_obj = (MTXfill *) pd_new (mtx_fill_class);
    
     mtx_fill_obj->fill_startrow = 1;
     mtx_fill_obj->fill_startcol = 1;
!    mtx_fill_obj->fill_type = FILL_SUBMATRIX;
     error("[mtx_fill]: this object _might_ change in the future!");
     if (argc) {
--- 149,156 ----
     MTXfill *mtx_fill_obj = (MTXfill *) pd_new (mtx_fill_class);
    
+    mtx_fill_obj->size = 0;
     mtx_fill_obj->fill_startrow = 1;
     mtx_fill_obj->fill_startcol = 1;
!    mtx_fill_obj->fill_type = DONT_FILL_JUST_PASS;
     error("[mtx_fill]: this object _might_ change in the future!");
     if (argc) {
***************
*** 175,183 ****
        int argc, t_atom *argv)
  {
!    int rows = atom_getint (argv++);
!    int columns = atom_getint (argv++);
     int size = rows * columns;
     int list_size = argc - 2;
-    t_atom *list_in = mtx_fill_obj->list_in;
     t_atom *list_out = mtx_fill_obj->list_out;
  
--- 170,177 ----
        int argc, t_atom *argv)
  {
!    int rows = atom_getint (argv);
!    int columns = atom_getint (argv+1);
     int size = rows * columns;
     int list_size = argc - 2;
     t_atom *list_out = mtx_fill_obj->list_out;
  
***************
*** 199,208 ****
  	       sizeof (t_atom) * (mtx_fill_obj->size+2),
  	       sizeof (t_atom) * (size + 2));
-       if (!list_in)
- 	 list_in = (t_atom *) getbytes (sizeof (t_atom) * (size + 2));
-       else
- 	 list_in = (t_atom *) resizebytes (list_in,
- 	       sizeof (t_atom) * (mtx_fill_obj->size+2),
- 	       sizeof (t_atom) * (size + 2));
     }
  
--- 193,196 ----
***************
*** 211,217 ****
     mtx_fill_obj->rows = rows;
     mtx_fill_obj->list_out = list_out;
-    mtx_fill_obj->list_in = list_in;
  
!    copyList (size, argv, list_in);
  }
  
--- 199,204 ----
     mtx_fill_obj->rows = rows;
     mtx_fill_obj->list_out = list_out;
  
!    memcpy(list_out,argv,argc*sizeof(t_atom));
  }
  
***************
*** 233,264 ****
  {
     t_atom *list_out = mtx_fill_obj->list_out;
-    t_atom *list_in = mtx_fill_obj->list_in;
     int rows = mtx_fill_obj->rows;
     int columns = mtx_fill_obj->columns;
-    if (mtx_fill_obj->fill_type == FILL_INDEXED_ELEMENTS) {
-       if (mtx_fill_obj->max_index > mtx_fill_obj->size) {
- 	 post("mtx_fill: index matrix index exceeds matrix borders");
- 	 return;
-       }
-       else if (mtx_fill_obj->size == 0) {
- 	 post("mtx_fill: no matrix defined for filling");
- 	 return;
-       }
  
!       // main part
!       list_out += 2;
!       copyList (mtx_fill_obj->size, list_in, list_out);
! 
!       writeFloatIndexedIntoMatrix (mtx_fill_obj->index_size,
! 	    mtx_fill_obj->index, f,list_out);
!       list_out = mtx_fill_obj->list_out;
!       SETSYMBOL(list_out, gensym("matrix"));
!       SETFLOAT(list_out, rows);
!       SETFLOAT(&list_out[1], columns);
!       outlet_anything(mtx_fill_obj->list_outlet, gensym("matrix"), 
! 	    mtx_fill_obj->size+2, list_out);
     }
-    else
-       post("mtx_fill: scalar fill for submatrices not supported yet");
  }
  
--- 220,246 ----
  {
     t_atom *list_out = mtx_fill_obj->list_out;
     int rows = mtx_fill_obj->rows;
     int columns = mtx_fill_obj->columns;
  
!    switch (mtx_fill_obj->fill_type) {
!       case FILL_SUBMATRIX:
! 	 post("mtx_fill: scalar fill for submatrices not supported yet");
! 	 return;
! 	 break;
!       case FILL_INDEXED_ELEMENTS:
! 	 if (mtx_fill_obj->max_index > mtx_fill_obj->size) {
! 	    post("mtx_fill: index matrix index exceeds matrix borders");
! 	    return;
! 	 }
! 	 if (mtx_fill_obj->size == 0) {
! 	    post("mtx_fill: no matrix defined for filling");
! 	    return;
! 	 }
! 	 // main part
! 	 writeFloatIndexedIntoMatrix (mtx_fill_obj->num_idcs_used,
! 	       mtx_fill_obj->index, f,list_out+2);
!       default:
! 	 mTXFillBang(mtx_fill_obj);
     }
  }
  
***************
*** 274,282 ****
     int columns = mtx_fill_obj->columns;
     t_atom *fill_mtx = argv;
-    t_atom *list_in = mtx_fill_obj->list_in;
     t_atom *list_out = mtx_fill_obj->list_out;
     int stopcol = mtx_fill_obj->fill_startcol+fill_columns-1;
     int stoprow = mtx_fill_obj->fill_startrow+fill_rows-1;
  
     // size check
     if (!list_size) {
--- 256,268 ----
     int columns = mtx_fill_obj->columns;
     t_atom *fill_mtx = argv;
     t_atom *list_out = mtx_fill_obj->list_out;
     int stopcol = mtx_fill_obj->fill_startcol+fill_columns-1;
     int stoprow = mtx_fill_obj->fill_startrow+fill_rows-1;
  
+    if (mtx_fill_obj->fill_type == DONT_FILL_JUST_PASS) {
+       mTXFillBang(mtx_fill_obj);
+       return;
+    }
+ 
     // size check
     if (!list_size) {
***************
*** 297,301 ****
  	 break;
        case FILL_INDEXED_ELEMENTS:
! 	 if (list_size < mtx_fill_obj->index_size) {
  	    post("mtx_fill: fill matrix smaller than indexing vector");
  	    return;
--- 283,287 ----
  	 break;
        case FILL_INDEXED_ELEMENTS:
! 	 if (list_size < mtx_fill_obj->num_idcs_used) {
  	    post("mtx_fill: fill matrix smaller than indexing vector");
  	    return;
***************
*** 312,320 ****
     }
     
- 
     // main part
-    list_out += 2;
-    copyList (mtx_fill_obj->size, list_in, list_out);
- 
     switch (mtx_fill_obj->fill_type) {
        case FILL_SUBMATRIX:
--- 298,302 ----
***************
*** 322,338 ****
  	    mtx_fill_obj->fill_startcol-1;
  	 writeFillMatrixIntoList (fill_rows, fill_columns, 
! 	       columns, fill_mtx, list_out);
  	 break;
        case FILL_INDEXED_ELEMENTS:
! 	 writeIndexedValuesIntoMatrix (mtx_fill_obj->index_size,
! 	       mtx_fill_obj->index, fill_mtx,list_out);
  	 break;
     }
!    list_out = mtx_fill_obj->list_out;
!    SETSYMBOL(list_out, gensym("matrix"));
!    SETFLOAT(list_out, rows);
!    SETFLOAT(&list_out[1], columns);
!    outlet_anything(mtx_fill_obj->list_outlet, gensym("matrix"), 
! 	 mtx_fill_obj->size+2, list_out);
  }
  
--- 304,315 ----
  	    mtx_fill_obj->fill_startcol-1;
  	 writeFillMatrixIntoList (fill_rows, fill_columns, 
! 	       columns, fill_mtx, list_out+2);
  	 break;
        case FILL_INDEXED_ELEMENTS:
! 	 writeIndexedValuesIntoMatrix (mtx_fill_obj->num_idcs_used,
! 	       mtx_fill_obj->index, fill_mtx,list_out+2);
  	 break;
     }
!    mTXFillBang(mtx_fill_obj);
  }
  





More information about the Pd-cvs mailing list