#include #include #include #include #include template < typename Left , typename Right > struct make_value_pair { typedef std::pair< Left, Right> result_type ; result_type operator()(Left a_left, Right a_right) { std::pair< Left, Right> a_pair(a_left, a_right); return a_pair; } }; using namespace boost; template< typename T> std::ostream& operator<< ( std::ostream& sout , std::pair ip ) { sout<<"{ "; for( unsigned i=0; ip.first < ip.second; ++i,++ip.first) { if(0 std::ostream& operator<< ( std::ostream& sout , std::pair const& a_pair ) { sout<<"pair( "< multi_array < typename std::result_of::type , NumDimsLeft+NumDimsRight > outer_product ( multi_array< TypeLeft, NumDimsLeft>const& a_left , multi_array< TypeRight, NumDimsRight>const& a_right , OpBinary op_binary ) /**@brief * This code is based on that in section: * 4.5 Outer Product * from book: * _An APL Compiler_ * Timothy Budd * Springer-Verlag 1988 */ { typedef typename std::result_of::type type_result; typedef multi_array_types::size_type size_type; std::size_t const num_dims_result=NumDimsLeft+NumDimsRight; std::vector shape_result( num_dims_result, 0); auto shape_left=a_left.shape(); auto shape_right=a_right.shape(); std::copy ( shape_right , shape_right+NumDimsRight , std::copy ( shape_left , shape_left+NumDimsLeft , shape_result.begin() ) ); multi_array< type_result, num_dims_result> a_result(shape_result); auto data_left=a_left.data(); auto data_right=a_right.data(); auto data_result=a_result.data(); size_type space_left=a_left.num_elements(); size_type space_right=a_right.num_elements(); size_type offset_result=0; for( size_type offset_left=0; offset_left indent_outbuf(std::cout,2); std::size_t const dim_left=1; std::size_t const dim_right=1; typedef std::vector shape_t; shape_t shape_left({2}); shape_t shape_right({2}); { multi_array a_left( shape_left); elem_t const left0=100; a_left.assign ( counting_iterator(left0) , counting_iterator(left0+a_left.num_elements()) ); std::cout<<":a_left=\n"< a_right( shape_right); elem_t const right0=1000; a_right.assign ( counting_iterator(right0) , counting_iterator(right0+a_left.num_elements()) ); std::cout<<":a_right=\n"<() ); std::cout<<":a_result=\n"<