void operator()( Iterator const& first , Iterator const& last , Context const& context , State state , std::string const& rule_name) const { int static indent = 0; switch (state) { case pre_parse: print_indent(indent++); BOOST_SPIRIT_DEBUG_OUT << '<' << rule_name << '>' << std::endl; print_some("try", indent, first, last); break; case successful_parse: print_some("success", indent, first, last); print_indent(indent); BOOST_SPIRIT_DEBUG_OUT << "<attributes>"; traits::print_attribute( BOOST_SPIRIT_DEBUG_OUT, context.attributes ); BOOST_SPIRIT_DEBUG_OUT << "</attributes>"; if (!fusion::empty(context.locals)) BOOST_SPIRIT_DEBUG_OUT << "<locals>" << context.locals << "</locals>"; BOOST_SPIRIT_DEBUG_OUT << std::endl; print_indent(--indent); BOOST_SPIRIT_DEBUG_OUT << "</" << rule_name << '>' << std::endl; break; case failed_parse: print_indent(indent); BOOST_SPIRIT_DEBUG_OUT << "<fail/>" << std::endl; print_indent(--indent); BOOST_SPIRIT_DEBUG_OUT << "</" << rule_name << '>' << std::endl; break; } }
std::vector<float> get_tensor(std::vector<float> image) { int width=sqrt(image.size()); int height=sqrt(image.size()); std::vector<float> flatten(width * height, 0.0); float* fpimage = &image[0]; print_some(fpimage); for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { flatten[i * width + j] = fpimage[i * width + j]; } } return flatten; }
void operator()( OutputIterator& sink, Context const& context , State state, std::string const& rule_name , Buffer const& buffer) const { switch (state) { case pre_generate: print_indent(); ++get_indent(); BOOST_SPIRIT_DEBUG_OUT << '<' << rule_name << '>' << std::endl; print_indent(); ++get_indent(); BOOST_SPIRIT_DEBUG_OUT << "<try>" << std::endl;; print_indent(); BOOST_SPIRIT_DEBUG_OUT << "<attributes>"; traits::print_attribute( BOOST_SPIRIT_DEBUG_OUT, context.attributes ); BOOST_SPIRIT_DEBUG_OUT << "</attributes>" << std::endl; if (!fusion::empty(context.locals)) { print_indent(); BOOST_SPIRIT_DEBUG_OUT << "<locals>" << context.locals << "</locals>" << std::endl; } --get_indent(); print_indent(); BOOST_SPIRIT_DEBUG_OUT << "</try>" << std::endl;; break; case successful_generate: print_indent(); ++get_indent(); BOOST_SPIRIT_DEBUG_OUT << "<success>" << std::endl; print_some("result", buffer); if (!fusion::empty(context.locals)) { print_indent(); BOOST_SPIRIT_DEBUG_OUT << "<locals>" << context.locals << "</locals>" << std::endl; } --get_indent(); print_indent(); BOOST_SPIRIT_DEBUG_OUT << "</success>" << std::endl; --get_indent(); print_indent(); BOOST_SPIRIT_DEBUG_OUT << "</" << rule_name << '>' << std::endl; break; case failed_generate: print_indent(); BOOST_SPIRIT_DEBUG_OUT << "<fail/>" << std::endl; --get_indent(); print_indent(); BOOST_SPIRIT_DEBUG_OUT << "</" << rule_name << '>' << std::endl; break; } }