static result_type apply(ViewT& v) { using namespace vsip_csl::dispatcher; result_type r; // Don't use the default dispatch list here, as that doesn't include the // 'parallel' backend. (The latter then uses the default list for local // dispatches. typedef Make_type_list< be::parallel, be::cbe_sdk, be::cuda, be::cvsip, be::mercury_sal, be::generic>::type list_type; if (is_expr_dense(v.block())) { Dispatcher<op::reduce<ReduceT>, void(result_type&, new_block_type const&, new_order_type, new_dim_type), list_type>:: dispatch(r, new_block_type(const_cast<block_type&>(v.block())), new_order_type(), new_dim_type()); } else { Dispatcher<op::reduce<ReduceT>, void(result_type&, block_type const&, order_type, dim_type), list_type>:: dispatch(r, v.block(), order_type(), dim_type()); } return r; }
typename ViewT::value_type get(ViewT view, stride_type r, stride_type c, stride_type rr, stride_type cc) { if (r + rr >= 0 && r + rr < (stride_type)view.size(0) && c + cc >= 0 && c + cc < (stride_type)view.size(1)) return view.get(r + rr, c + cc); else return typename ViewT::value_type(0); }
void write(std::ostream& os,ViewT v) { vsip::dimension_type const View_dim = ViewT::dim; vsip::Index<View_dim> my_index; vsip::impl::Length<View_dim> v_extent = extent(v); typename ViewT::value_type data; // get num_points vsip::length_type num_points = v.size(); // write all the points for(vsip::index_type i=0;i<num_points;i++) { data = get(v,my_index); os.write(reinterpret_cast<char*>(&data),sizeof(data)); // increment index my_index = vsip::impl::next<typename vsip::impl::Col_major<View_dim>::type> (v_extent,my_index); } // Matlab data blocks must be padded to a multiple of 8 bytes. if (sizeof(data) < 8) { for(vsip::index_type i = 0; i < (num_points % 8/sizeof(data)); i++) { os.write(reinterpret_cast<char*>(&data),sizeof(data)); } } }
void read(std::istream& is,ViewT v,bool swap_bytes) { vsip::dimension_type const View_dim = ViewT::dim; vsip::Index<View_dim> my_index; vsip::impl::Length<View_dim> v_extent = extent(v); T1 data; typedef typename ViewT::value_type scalar_type; // get num_points vsip::length_type num_points = v.size(); // read all the points for(vsip::index_type i=0;i<num_points;i++) { is.read(reinterpret_cast<char*>(&data),sizeof(data)); swap(&data,swap_bytes); put(v,my_index,scalar_type(data)); // increment index my_index = vsip::impl::next<typename vsip::impl::Col_major<View_dim>::type> (v_extent,my_index); } // Matlab data blocks must be padded to a multiple of 8 bytes. if (sizeof(data) < 8) { for(vsip::index_type i = 0; i < (num_points % 8/sizeof(data)); i++) { is.read(reinterpret_cast<char*>(&data),sizeof(data)); } } }
typename ReduceT<typename ViewT::value_type>::result_type reduce(ViewT v) { using namespace vsip_csl::dispatcher; typedef typename ViewT::value_type T; typedef typename ReduceT<T>::result_type result_type; typedef typename ViewT::block_type block_type; typedef typename get_block_layout<block_type>::order_type order_type; typedef Int_type<ViewT::dim> dim_type; result_type r; #if VSIP_IMPL_REF_IMPL Evaluator<op::reduce<ReduceT>, be::cvsip, void(result_type&, block_type const&, order_type, dim_type)>:: exec(r, v.block(), order_type(), dim_type()); #else // This optimization is only applicable to target platforms that provide a // backend that uses direct data access rather than redim_get/put(). // This includes CUDA and Cell backends, but not x86 (as of August 2010). #if defined(VSIP_IMPL_CBE_SDK) || defined(VSIP_IMPL_HAVE_CUDA) bool const redimensionable = (ViewT::dim != 1) && (!is_expr_block<block_type>::value); #else bool const redimensionable = false; #endif r = Reduction_dispatch_helper<ReduceT, ViewT, redimensionable>::apply(v); #endif return r; }
void generate(const ViewT& imgv, TextSurface& text) { //single character size size_t char_w = matcher_->cellWidth(); size_t char_h = matcher_->cellHeight(); //text surface size size_t text_w = text.cols() * char_w; size_t text_h = text.rows() * char_h; //processed image region size size_t roi_w = std::min<size_t>(imgv.width(), text_w); size_t roi_h = std::min<size_t>(imgv.height(), text_h); size_t y = 0, r = 0; for (; y + char_h <= roi_h; y += char_h, ++r) { enqueue(subimage_view(imgv, 0, y, roi_w, char_h), text.row(r)); } if (y < roi_h) { size_t dy = roi_h - y; enqueue(subimage_view(imgv, 0, y, roi_w, dy), text.row(r)); } queue_.wait_empty(); }
void check_block_size(length_type g_size, length_type l_size, ViewT const& view) { test_assert(g_size == view.size(0)); test_assert(g_size == view.block().size(1, 0)); test_assert(l_size == view.local().size(0)); test_assert(l_size == view.local().block().size(1, 0)); test_assert(g_size == view.size()); test_assert(g_size == view.block().size()); test_assert(l_size == view.local().size()); test_assert(l_size == view.local().block().size()); }
Ps_helper(ViewT& view, Stream_pattern const& spatt, bool input) : data_ (view.block()) , addr_ (data_.ptr()) , spatt_ (spatt) , input_ (input) {}
static imagview_type imag(ViewT v) { return v.imag(); }
static realview_type real(ViewT v) { return v.real(); }