MCPcopy Create free account
hub / github.com/agraef/pure-lang / numeric_map_loop

Function numeric_map_loop

pure/runtime.cc:14624–14668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14622template < typename in_mat_type,
14623 typename out_mat_type >
14624pure_expr*
14625numeric_map_loop
14626( pure_expr *f, //the function being mapped
14627 in_mat_type *in, //the operand matrix
14628 out_mat_type *out, //the result matrix
14629 size_t *lasti, //last row and column written to
14630 size_t *lastj ) // before bailing out in the event that
14631 // the output of f is not the right type
14632{
14633 typedef typename element_of< in_mat_type>::type in_elem_type;
14634 typedef typename element_of<out_mat_type>::type out_elem_type;
14635
14636 //need casts for complex case, when data pointer is double*, but
14637 //we really want complex*
14638 in_elem_type *inp = (reinterpret_cast<in_elem_type* >(in->data ))+1;
14639 out_elem_type *outp = (reinterpret_cast<out_elem_type*>(out->data))+1;
14640 pure_expr *r; //result expression
14641 out_elem_type v; //result value
14642
14643 //we already performed the first map, so now we apply f to all but the first
14644 //column in the first row..
14645 *lasti=0;
14646 for (size_t j=1; j<in->size2; ++j,++inp,++outp) {
14647 *lastj=j;
14648 r = pure_app( f, to_expr(*inp) );
14649 if (!from_expr(r,v)) return r;
14650 *outp = v;
14651 pure_freenew(r);
14652 }
14653
14654 //..then the rest of the rows
14655 for (size_t i=1; i<in->size1; ++i) {
14656 *lasti=i;
14657 inp = (reinterpret_cast< in_elem_type*>( in->data))+i*in->tda;
14658 outp = (reinterpret_cast<out_elem_type*>(out->data))+i*out->tda;
14659 for (size_t j=0; j<in->size2; ++j,++inp,++outp) {
14660 *lastj=j;
14661 r = pure_app( f, to_expr(*inp) );
14662 if (!from_expr(r,v)) return r;
14663 *outp = v;
14664 pure_freenew(r);
14665 }
14666 }
14667 return 0;
14668}
14669
14670
14671//symbolic map loop : mapped function results in heterogenous / non-numerical

Callers 1

matrix_mapFunction · 0.85

Calls 4

pure_appFunction · 0.85
to_exprFunction · 0.85
from_exprFunction · 0.85
pure_freenewFunction · 0.85

Tested by

no test coverage detected