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

Function numeric_zipwith_loop

pure/runtime.cc:14839–14887  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14837 typename in2_mat_type,
14838 typename out_mat_type >
14839pure_expr*
14840numeric_zipwith_loop
14841( pure_expr *f, //the function being zipped
14842 in1_mat_type *in1, //the 1st operand matrix
14843 in2_mat_type *in2, //the 2nd operand matrix
14844 out_mat_type *out, //the result matrix
14845 size_t *lasti, //last row and column written to
14846 size_t *lastj ) // before bailing out in the event that
14847 // the output of f is not the right type
14848{
14849 typedef typename element_of<in1_mat_type>::type in1_elem_type;
14850 typedef typename element_of<in2_mat_type>::type in2_elem_type;
14851 typedef typename element_of<out_mat_type>::type out_elem_type;
14852
14853 //need casts for complex case, when data pointer is double*, but
14854 //we really want complex*
14855 in1_elem_type *inp1 = (reinterpret_cast<in1_elem_type*>(in1->data ))+1;
14856 in2_elem_type *inp2 = (reinterpret_cast<in2_elem_type*>(in2->data ))+1;
14857 out_elem_type *outp = (reinterpret_cast<out_elem_type*>(out->data))+1;
14858 pure_expr *r; //result expression
14859 out_elem_type v; //result value
14860
14861 //we already performed the first zipwith, so now we apply f to all but the
14862 //first column in the first row..
14863 *lasti=0;
14864 for (size_t j=1; j<in1->size2 && j<in2->size2; ++j,++inp1,++inp2,++outp) {
14865 *lastj=j;
14866 r = pure_appl( f, 2, to_expr(*inp1), to_expr(*inp2) );
14867 if (!from_expr(r,v)) return r;
14868 *outp = v;
14869 pure_freenew(r);
14870 }
14871
14872 //..then the rest of the rows
14873 for (size_t i=1; i<in1->size1 && i<in2->size1; ++i) {
14874 *lasti=i;
14875 inp1 = (reinterpret_cast<in1_elem_type*>(in1->data))+i*in1->tda;
14876 inp2 = (reinterpret_cast<in2_elem_type*>(in2->data))+i*in2->tda;
14877 outp = (reinterpret_cast<out_elem_type*>(out->data))+i*out->tda;
14878 for (size_t j=0; j<in1->size2 && j<in2->size2; ++j,++inp1,++inp2,++outp) {
14879 *lastj=j;
14880 r = pure_appl( f, 2, to_expr(*inp1), to_expr(*inp2) );
14881 if (!from_expr(r,v)) return r;
14882 *outp = v;
14883 pure_freenew(r);
14884 }
14885 }
14886 return 0;
14887}
14888
14889
14890//symbolic zipwith loop : zipped function results in heterogenous /

Callers 1

matrix_zipwithFunction · 0.85

Calls 4

pure_applFunction · 0.85
to_exprFunction · 0.85
from_exprFunction · 0.85
pure_freenewFunction · 0.85

Tested by

no test coverage detected