#include #include #include #include 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< TypeResult, NumDimsLeft+NumDimsRight> outer_product ( multi_array< TypeLeft, NumDimsLeft>const& a_left , multi_array< TypeRight, NumDimsRight>const& a_right , TypeResult (*op_binary)( TypeLeft, TypeRight) ) /**@brief * This code is based on that in section: * 4.5 Outer Product * from book: * _An APL Compiler_ * Timothy Budd * Springer-Verlag 1988 */ { 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< TypeResult, 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 size_right=a_right.num_elements(); size_type space_result=a_result.num_elements(); for( size_type offset_result=0; offset_result mk_elem_t_pair(elem_t a_left, elem_t a_right) { std::pair< elem_t, elem_t> a_pair(a_left, a_right); return a_pair; } int main(void) { iostreams::indent_scoped_ostreambuf 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"<