From: Diemo S. <di...@us...> - 2007-01-10 13:13:10
|
Update of /cvsroot/jmax/jmax/packages/data/c/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2291 Modified Files: fvec.c fmat.c Log Message: added pow methods Index: fvec.c =================================================================== RCS file: /cvsroot/jmax/jmax/packages/data/c/src/fvec.c,v retrieving revision 1.160 retrieving revision 1.161 diff -C2 -d -r1.160 -r1.161 *** fvec.c 21 Dec 2006 09:58:34 -0000 1.160 --- fvec.c 10 Jan 2007 13:12:59 -0000 1.161 *************** *** 1346,1349 **** --- 1346,1396 ---- } + + static fts_method_status_t + fvec_pow_fvec(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) + { + fvec_t *self = (fvec_t *)o; + fts_object_t *right = fts_get_object(at); + float *l, *r; + int l_size, r_size; + int l_stride, r_stride; + int size; + int i; + + fvec_get_vector(self, &l, &l_size, &l_stride); + fmat_or_slice_vector(right, &r, &r_size, &r_stride); + + if(l_size < r_size) + size = l_size; + else + size = r_size; + + for(i=0; i<size; i++) + l[i * l_stride] = pow(l[i * l_stride], r[i * r_stride]); + + fts_set_object(ret, o); + + return fts_ok; + } + + static fts_method_status_t + fvec_pow_number(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) + { + fvec_t *self = (fvec_t *)o; + float r = (float)fts_get_number_float(at); + float *l; + int size, stride; + int i; + + fvec_get_vector(self, &l, &size, &stride); + + for(i=0; i<size*stride; i+=stride) + l[i] = pow(l[i], r); + + fts_set_object(ret, o); + + return fts_ok; + } + static fts_method_status_t fvec_bus_fvec(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) *************** *** 2258,2261 **** --- 2305,2309 ---- fvec_message(cl, fts_new_symbol("mul"), fvec_mul_fvec, fvec_mul_number); fvec_message(cl, fts_new_symbol("div"), fvec_div_fvec, fvec_div_number); + fvec_message(cl, fts_new_symbol("pow"), fvec_pow_fvec, fvec_pow_number); fvec_message(cl, fts_new_symbol("bus"), fvec_bus_fvec, fvec_bus_number); fvec_message(cl, fts_new_symbol("vid"), fvec_vid_fvec, fvec_vid_number); *************** *** 2338,2341 **** --- 2386,2390 ---- fts_class_doc(cl, fts_new_symbol("mul"), "<num|fvec: operand>", "multiply current values by given scalar, fvec (element by element)"); fts_class_doc(cl, fts_new_symbol("div"), "<num|fvec: operand>", "divide current values by given scalar, fvec (element by element)"); + fts_class_doc(cl, fts_new_symbol("pow"), "<num|fvec: operand>", "take current values to the power of given scalar, fvec (element by element)"); fts_class_doc(cl, fts_new_symbol("bus"), "<num|fvec: operand>", "subtract current values from given scalar, fvec (element by element)"); fts_class_doc(cl, fts_new_symbol("vid"), "<num|fvec: operand>", "divide given scalar, fvec (element by element) by current values"); Index: fmat.c =================================================================== RCS file: /cvsroot/jmax/jmax/packages/data/c/src/fmat.c,v retrieving revision 1.151 retrieving revision 1.152 diff -C2 -d -r1.151 -r1.152 *** fmat.c 21 Dec 2006 09:58:34 -0000 1.151 --- fmat.c 10 Jan 2007 13:13:00 -0000 1.152 *************** *** 2236,2239 **** --- 2236,2290 ---- } + + static fts_method_status_t + fmat_pow_fmat(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) + { + fmat_t *self = (fmat_t *)o; + fmat_t *right = (fmat_t *)fts_get_object(at); + int m = fmat_get_m(self); + int n = fmat_get_n(self); + + if(m > fmat_get_m(right)) + m = fmat_get_m(right); + + if(fmat_get_n(right) == n) + { + float *l = fmat_get_ptr(self); + float *r = fmat_get_ptr(right); + int size = m * n; + int i; + + for(i=0; i<size; i++) + l[i] = pow(l[i], r[i]); + + fts_object_changed(o); + fts_set_object(ret, o); + } + else + fmat_error_dimensions(self, right, "pow"); + + return fts_ok; + } + + + static fts_method_status_t + fmat_pow_number(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) + { + fmat_t *self = (fmat_t *)o; + float r = (float)fts_get_number_float(at); + int size = fmat_get_m(self) * fmat_get_n(self); + float *p = fmat_get_ptr(self); + int i; + + for(i=0; i<size; i++) + p[i] = pow(p[i], r); + + fts_object_changed(o); + fts_set_object(ret, o); + + return fts_ok; + } + + static fts_method_status_t fmat_bus_fmat(fts_object_t *o, fts_symbol_t s, int ac, const fts_atom_t *at, fts_atom_t *ret) *************** *** 4363,4366 **** --- 4414,4418 ---- fmat_message(cl, fts_new_symbol("mul"), fmat_mul_fmat, fmat_mul_number); fmat_message(cl, fts_new_symbol("div"), fmat_div_fmat, fmat_div_number); + fmat_message(cl, fts_new_symbol("pow"), fmat_pow_fmat, fmat_pow_number); fmat_message(cl, fts_new_symbol("bus"), fmat_bus_fmat, fmat_bus_number); fmat_message(cl, fts_new_symbol("vid"), fmat_vid_fmat, fmat_vid_number); *************** *** 4487,4490 **** --- 4539,4543 ---- fts_class_doc(cl, fts_new_symbol("mul"), "<num|fmat: operand>", "multiply current values by given scalar or fmat (element by element)"); fts_class_doc(cl, fts_new_symbol("div"), "<num|fmat: operand>", "divide current values by given scalar or fmat (element by element)"); + fts_class_doc(cl, fts_new_symbol("pow"), "<num|fmat: operand>", "take current values to the power of the given scalar or fmat (element by element)"); fts_class_doc(cl, fts_new_symbol("bus"), "<num|fmat: operand>", "subtract current values from given scalar or fmat (element by element)"); fts_class_doc(cl, fts_new_symbol("vid"), "<num|fmat: operand>", "divide given scalar or fmat (element by element) by current values"); *************** *** 4528,4531 **** --- 4581,4585 ---- fts_class_doc(cl, fts_new_symbol("apply"), "<expr: expression>", "apply expression each value (use $self and $x)"); + fts_class_doc(cl, fts_new_symbol("find"), "<expr: expression>", "leave indices where expression is true (use $x, $i and $self)"); fts_class_doc(cl, sym_rect, NULL, "convert complex polar vector to complex rectangular vector (matrix of 2 columns)"); |