//--------------------------------------------------------------------------- amgclHandle STDCALL amgcl_precond_create_f( int n, const int *ptr, const int *col, const double *val, amgclHandle prm ) { BOOST_AUTO( ptr_c, boost::make_transform_iterator(ptr, std::bind2nd(std::minus<int>(), 1)) ); BOOST_AUTO( col_c, boost::make_transform_iterator(col, std::bind2nd(std::minus<int>(), 1)) ); BOOST_AUTO( A, boost::make_tuple( n, boost::make_iterator_range(ptr_c, ptr_c + n + 1), boost::make_iterator_range(col_c, col_c + ptr[n]), boost::make_iterator_range(val, val + ptr[n]) ) ); if (prm) return static_cast<amgclHandle>(new AMG(A, *static_cast<Params*>(prm))); else return static_cast<amgclHandle>(new AMG(A)); }
bool verify(std::string const& caseid, MultiPolygon const& mp, MultiPolygon const& buffer, Settings const& settings) { bool result = true; // Area of buffer must be larger than of original polygon BOOST_AUTO(area_mp, bg::area(mp)); BOOST_AUTO(area_buf, bg::area(buffer)); if (area_buf < area_mp) { result = false; } if (result) { typedef boost::range_value<MultiPolygon const>::type polygon_type; BOOST_FOREACH(polygon_type const& polygon, mp) { typename bg::point_type<polygon_type>::type point; bg::point_on_border(point, polygon); if (! bg::within(point, buffer)) { result = false; } } }
void test_geometry(std::string const& wkt1, std::string const& wkt2, RingIdVector const& expected_ids, WithinVector const& expected_withins) { typedef bg::detail::overlay::ring_properties<typename bg::point_type<Geometry1>::type> properties; Geometry1 geometry1; Geometry2 geometry2; bg::read_wkt(wkt1, geometry1); bg::read_wkt(wkt2, geometry2); typedef std::map<bg::ring_identifier, properties> map_type; map_type selected; std::map<bg::ring_identifier, int> empty; bg::detail::overlay::select_rings<OverlayType>(geometry1, geometry2, empty, selected); BOOST_CHECK_EQUAL(selected.size(), expected_ids.size()); BOOST_CHECK_EQUAL(selected.size(), expected_withins.size()); if (selected.size() <= expected_ids.size()) { BOOST_AUTO(eit, expected_ids.begin()); BOOST_AUTO(wit, expected_withins.begin()); for(typename map_type::const_iterator it = selected.begin(); it != selected.end(); ++it, ++eit, ++wit) { bg::ring_identifier const ring_id = it->first; BOOST_CHECK_EQUAL(ring_id.source_index, eit->source_index); BOOST_CHECK_EQUAL(ring_id.multi_index, eit->multi_index); BOOST_CHECK_EQUAL(ring_id.ring_index, eit->ring_index); BOOST_CHECK_EQUAL(it->second.within_code, *wit); } } }
void test_integer(bool check_types) { typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; point_type p1, p2; bg::assign_values(p1, 12345678, 23456789); bg::assign_values(p2, 98765432, 87654321); typedef bg::strategy::distance::pythagoras<> pythagoras_type; pythagoras_type pythagoras; BOOST_AUTO(distance, pythagoras.apply(p1, p2)); BOOST_CHECK_CLOSE(distance, 107655455.02347542, 0.001); typedef typename bg::strategy::distance::services::comparable_type < pythagoras_type >::type comparable_type; comparable_type comparable; BOOST_AUTO(cdistance, comparable.apply(p1, p2)); BOOST_CHECK_EQUAL(cdistance, 11589696996311540); typedef BOOST_TYPEOF(cdistance) cdistance_type; typedef BOOST_TYPEOF(distance) distance_type; distance_type distance2 = sqrt(distance_type(cdistance)); BOOST_CHECK_CLOSE(distance, distance2, 0.001); if (check_types) { BOOST_CHECK((boost::is_same<distance_type, double>::type::value)); // comparable_distance results in now double too, obviously because // comp.distance point-segment can be fraction, even for integer input BOOST_CHECK((boost::is_same<cdistance_type, double>::type::value)); } }
inline void test_integer(bool check_types) { typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type; typedef bg::model::box<point_type> box_type; point_type p; box_type b; bg::assign_values(b, 0, 0, 12345678, 23456789); bg::assign_values(p, 98765432, 87654321); typedef bg::strategy::distance::pythagoras_point_box<> pythagoras_pb_type; pythagoras_pb_type pythagoras_pb; BOOST_AUTO(distance, pythagoras_pb.apply(p, b)); BOOST_CHECK_CLOSE(distance, 107655455.02347542, 0.001); typedef typename bg::strategy::distance::services::comparable_type < pythagoras_pb_type >::type comparable_type; comparable_type comparable; BOOST_AUTO(cdistance, comparable.apply(p, b)); BOOST_CHECK_EQUAL(cdistance, 11589696996311540); typedef BOOST_TYPEOF(cdistance) cdistance_type; typedef BOOST_TYPEOF(distance) distance_type; distance_type distance2 = sqrt(distance_type(cdistance)); BOOST_CHECK_CLOSE(distance, distance2, 0.001); if (check_types) { BOOST_CHECK((boost::is_same<distance_type, double>::type::value)); BOOST_CHECK((boost::is_same<cdistance_type, boost::long_long_type>::type::value)); } }
void odr_no_uns2() { odr_test_1 t1; odr_test_2 t2; BOOST_AUTO(v1, t1); BOOST_AUTO(v2, t2); }
int main() { my_db db; db.insert(my_db::data_t(1, "alexander", "*****@*****.**", 26)); db.insert(my_db::data_t(2, "alexander", "*****@*****.**", 30)); BOOST_AUTO(range, db.select<name>("alexander")); for( BOOST_AUTO(iter, range.first); iter != range.second; ++iter) { // print some fileds LOG( " name: " << my_db::get_field<name>(iter) << " email: " << my_db::get_field<email>(iter) << " | " << // print whole line my_db::get(iter) ); } return 0; }
void bi::MarginalSISHandler<B,A,S>::handleAdapterSamples( boost::mpi::communicator child, boost::mpi::status status) { typedef typename temp_host_matrix<real>::type matrix_type; static const int N = B::NP; /* add samples */ boost::optional<int> n = status.template count<real>(); if (n) { matrix_type Z(N + T, *n / (N + T)); child.recv(status.source(), status.tag(), Z.buf(), *n); for (int j = 0; j < Z.size2(); ++j) { adapter.add(subrange(column(Z,j), 0, N), subrange(column(Z,j), N, T)); } } /* send new proposal if necessary */ if (adapter.stop(t)) { adapter.adapt(t); BOOST_AUTO(q, adapter.get(t)); BOOST_AUTO(iter, node.children.begin()); for (; iter != node.children.end(); ++iter) { node.requests.push_front(iter->isend(0, MPI_TAG_ADAPTER_PROPOSAL, q)); } ///@todo Serialize q into archive just once, then send to all. This may ///be how broadcast is already implemented in Boost.MPI. } }
inline void bi::exp_rows(M2 X, const V2& is) { BOOST_AUTO(iter, is.begin()); BOOST_AUTO(end, is.end()); for (; iter != end; ++iter) { BOOST_AUTO(row1, row(X, *iter)); exp_elements(row1, row1); } }
inline void bi::exp_columns(M2 X, const V2& is) { BOOST_AUTO(iter, is.begin()); BOOST_AUTO(end, is.end()); for (; iter != end; ++iter) { BOOST_AUTO(col, column(X, *iter)); exp_elements(col, col); } }
inline void bi::exp_vector(V2 x, const V3& is) { BOOST_AUTO(iter, is.begin()); BOOST_AUTO(end, is.end()); for (; iter != end; ++iter) { BOOST_AUTO(elem, subrange(x, *iter, 1)); exp_elements(elem, elem); } }
void bi::det_rows(const M2 X, const V2& is, V3 det) { BOOST_AUTO(iter, is.begin()); BOOST_AUTO(end, is.end()); set_elements(det, 1.0); for (; iter != end; ++iter) { mul_elements(det, column(X, *iter), det); } }
real bi::det_vector(const V2 x, const V3& is) { BOOST_AUTO(iter, is.begin()); BOOST_AUTO(end, is.end()); real det = 1.0; for (; iter != end; ++iter) { det *= *(x.begin() + *iter); } return det; }
// Copy matrix from builtin backend. static boost::shared_ptr<matrix> copy_matrix(boost::shared_ptr< typename builtin<real>::matrix > A, const params &prm) { precondition(!prm.context().empty(), "Empty VexCL context!"); const typename builtin<real>::matrix &a = *A; BOOST_AUTO(Aptr, a.ptr_data()); BOOST_AUTO(Acol, a.col_data()); BOOST_AUTO(Aval, a.val_data()); return boost::make_shared<matrix>(prm.context(), rows(*A), cols(*A), Aptr, Acol, Aval); }
typename result<convert_farm(LHS, RHS, State, BackEnd)>::type operator()(LHS const& lhs, RHS const& rhs, State& s, BackEnd const& be) const { convert<tag::process_network_> callee; // Pre-compute environment to not copy it twice BOOST_AUTO(lhe, callee(lhs,s,be) ); BOOST_AUTO(rhe, callee(rhs,lhe,be)); return make_environment ( join_network(lhe.network(),rhe.network()) , rhe.next_pid() ); }
void output(const FileList& flist) { for (BOOST_AUTO(iter, flist.begin()); iter != flist.end(); ++iter) { BOOST_AUTO(&fmeta, iter->second); std::vector<char> buffer; std::cout << "name : " << GetFileName(fmeta.mName, buffer) << "\n, " << "meta : {" << fmeta.mMeta << "}, \n" << "offset: " << fmeta.mOffset << ", \n" << "fsize : " << fmeta.mFileSize << ", \n" << "wbsize: " << fmeta.mWriteBSize << "\n" << std::endl; } }
void pop_all(DecodeFilePtr decoder) { int i = 0; const FileList& flist = decoder->filelist(); for (BOOST_AUTO(iter, flist.begin()); iter != flist.end(); ++iter) { BOOST_AUTO(&fmeta, iter->second); std::vector<char> buffer; Slice fileid = fmeta.mName; Slice filename = GetFileName(fileid, buffer); std::cout << "decode: \"" << filename << "\":\n" << std::endl; Slice outfile = fileid.substr(fileid.rfind(PATH_SEP) + 1); decoder->pop(fileid, outfile); std::cout << "---------------------------" << std::endl; } }
int main() { //double x=1,y=2; triqs::arrays::array<double,1> A(3); A(0)=1; A(1)=2; A(2)=3; triqs::arrays::array_view<double,1> V(A); //double a = 2; BOOST_AUTO( exp , x_ + A); std::cerr<< " -------------"<<std::endl; TEST( tqa::make_array( tql::eval( 2.0*x_ , x_ =A) )); TEST( tqa::make_array( tql::eval(2.0*x_ , x_ =3*A) )); TEST( tqa::make_array( tql::eval (A + 2*x_ , x_ =A) )); TEST( ( tql::eval (A + 2*x_ , x_ =A) )); TEST( A(i_)); TEST( tql::eval( A(i_), i_=1)); triqs::arrays::array<double,2> B(2,2); B(1,1) = 10; TEST( tql::eval( B(i_,j_) , i_ = 1, j_ = 1)); B(i_,j_) = 10*i_ + j_; std::cout <<B<<std::endl; B(j_,i_) = 10*i_ + j_; B(j_,i_) = 10*i_ + j_ +1; B(j_,i_) = 10*i_ + 2*j_; B(j_,i_) = 10*i_ - j_; B(j_,i_) = i_ + j_; B(j_,i_) = 1+2+ 10*i_ + j_; B(j_,i_) = 10*i_ + j_; B(j_,i_) = 10*i_ + j_ +1; B(j_,i_) = 10*i_ + 2*j_; B(j_,i_) = 10*i_ - j_; B(j_,i_) = i_ + j_; B(j_,i_) = 1+2+ 10*i_ + j_; B(j_,i_) = 10*i_ + j_/1.0; B(j_,i_) = 10*i_ + j_/3.8 +1; B(j_,i_) = 10*i_ + 2*j_/8.1; B(j_,i_) = 10*i_ - j_/9.0; B(j_,i_) = i_ + j_/8.1; B(j_,i_) = 1+2+ 10*i_ + j_/7.2; B(j_,i_) = 1+2+ 10*i_ + j_/2.0; B(j_,i_) = 11*i_ + j_; B(j_,i_) = 12*i_ + j_; B(j_,i_) = 13*i_ + j_; B(j_,i_) = 14*i_ + j_; B(j_,i_) = 15*i_ + j_; B(j_,i_) = 20*i_ + j_; B(j_,i_) = 30*i_ + j_; B(j_,i_) = 40*i_ + j_; B(j_,i_) = 50*i_ + j_; std::cout <<B<<std::endl; }
void LServer::tick( ) { base::TimeInfo info; while(!stop_) { if ( 1 ) { ScopedLock lock(lock_); BOOST_AUTO(it, connections_.begin()); for ( ;it != connections_.end(); ++it) { CmdPtr msg = it->second->recvCmd( ); for( ; msg; msg = it->second->recvCmd()) { it->second->sendCmd(msg.get()); } } } base::thisThreadSleep(1); info.update(); if(info.diffDay() || info.diffHour()) { regLog(info.diffHour(), info.diffDay()); } if(((info.sysRunTime()/1000)%5) == 0) { } } }
int main() { F1 f(7); TEST((x_ >>2*x_ +1)(10)); triqs::clef::function<double(double,double)> f2; f2(x_,y_) = x_ + y_; TEST(f2(2,3)); f2(x_,y_) = x_ + 2*y_; TEST(f2(2,3)); boost::function<double(double,double)> ff2(f2); TEST(ff2(2,3)); triqs::clef::function<double(double)> f1 ( f(x_) + 2*x_ ,x_); TEST(f1(3)); triqs::clef::function<double(double,double)> g2; g2(x_,y_) = x_ - y_ + f2(x_,2*y_); TEST(g2(2,3)); boost::function<double(double,double)> ff8 = make_function( x_ + y_, x_, y_); TEST(ff8(2,3)); boost::function<double(double)> f3; f3 = x_>> f(x_) + 2*x_; TEST(f3(3)); BOOST_AUTO (h , make_function( 2*x_ + y_ + 1, x_)); // is a lazy expression expression with placeholder y_, returning a function... std::cout << tql::eval(h, y_=1) << std::endl; TEST(tql::eval( h, y_=1) (10)); TEST(h); }
std::pair< typename graph<Matrix>::adjacency_iterator, typename graph<Matrix>::adjacency_iterator > adjacent_vertices(ptrdiff_t v, const graph<Matrix> &G) { BOOST_AUTO(Aptr, G.A.ptr_data()); BOOST_AUTO(Acol, G.A.col_data()); typename Matrix::ptr_type row_beg = Aptr[v]; typename Matrix::ptr_type row_end = Aptr[v + 1]; return std::make_pair( Acol + row_beg, Acol + row_end ); }
void ObservationDirectionDataPointsFilter<T>::inPlaceFilter(DataPoints& cloud) { const int dim(cloud.features.rows() - 1); const int featDim(cloud.features.cols()); if (dim != 2 && dim != 3) { throw InvalidField( (boost::format("ObservationDirectionDataPointsFilter: Error, works only in 2 or 3 dimensions, cloud has %1% dimensions.") % dim).str() ); } Vector center(dim); center[0] = centerX; center[1] = centerY; if (dim == 3) center[2] = centerZ; cloud.allocateDescriptor("observationDirections", dim); BOOST_AUTO(observationDirections, cloud.getDescriptorViewByName("observationDirections")); for (int i = 0; i < featDim; ++i) { // Check normal orientation const Vector p(cloud.features.block(0, i, dim, 1)); observationDirections.col(i) = center - p; } }
//沿着连接搜索 bool Framework::walkCycle(RigidPtr rp,Joint* parent,JointVec& map) { if(rp) { for(JointVec::iterator i=rp->mJoints.begin();i!=rp->mJoints.end();++i) { if(*i!=parent) { BOOST_AUTO(it,find(map.begin(),map.end(),*i)); if( it!=map.end() ) { //发现重复 return false; } RigidPtr g = (*i)->other(rp); if( g ) { map.push_back(*i); if( !walkCycle(g,*i,map) ) return false; //发现 map.pop_back(); } } } } return true; }
bool serialization_roundtrip(Value const &value, Format const &format) { typedef typename boost::remove_const<Value>::type mutable_value; std::vector<char> generated; { BOOST_AUTO(sink, szn::make_container_sink(generated)); szn::serialize(sink, value, format); } BOOST_AUTO(source, szn::make_range_source(generated)); mutable_value readValue; szn::deserialize(source, readValue, format); return Equal()(value, readValue); }
To round(const duration<Rep, Period>& d) { To t0 = duration_cast<To>(d); To t1 = t0; ++t1; BOOST_AUTO(diff0, d - t0); BOOST_AUTO(diff1, t1 - d); if (diff0 == diff1) { if (t0.count() & 1) return t1; return t0; } else if (diff0 < diff1) return t0; return t1; }
void assert_all_close( ArrayType1 const & A, ArrayType2 const & B, double precision, bool relative = false) { typedef typename ArrayType1::value_type F; BOOST_AUTO( Abs , map( boost::function<double(F)> (assert_abs<F>) )); auto r = max_element (Abs(A-B)); auto r2 = max_element (Abs(A) + Abs(B)); if ( r > (relative ? precision * r2 : precision) ) TRIQS_RUNTIME_ERROR<<"assert_all_close error : \n\n"<<".. A = "<<A<<"\n\n"<<".. B= "<<B<<"\n\n"<< ".. Residue is r = "<<r; }
inline void assign_max_facets(dataset_t &ds,Titer b,Titer e) { cellid_t f[10]; BOOST_AUTO(cmp,bind(&dataset_t::compare_cells<dim-1>,&ds,_1,_2)); for(;b!=e;++b) ds.max_fct(*b) = *max_element(f,f+ds.get_cets<DES>(*b,f),cmp); }
void Framework::removeJoint( JointPtr j ) { BOOST_AUTO(it,find(mJoints.begin(),mJoints.end(),j) ); if(it!=mJoints.end()) { j->breakAllRigid(); //断开 mJoints.erase(it); } }
explicit plugin_info(const boost::filesystem::path& path_name) : library_(path_name) , creator_(library_.get<plugin_api::create_shared>("create_shared")) { BOOST_AUTO(instance, creator_()); type_ = instance->type(); puid_ = instance->uid(); name_ = instance->name(); version_ = instance->version(); }
void bi::InputNetCDFBuffer::readMask(const size_t k, const VarType type, Mask<ON_HOST>& mask) { typedef temp_host_matrix<real>::type temp_matrix_type; mask.resize(m.getNumVars(type), false); Var* var; int r; long start, len; for (r = 0; r < int(recDims.size()); ++r) { if (timeVars[r] >= 0) { start = recStarts[k][r]; len = recLens[k][r]; if (len > 0) { BOOST_AUTO(range, modelVars.equal_range(r)); BOOST_AUTO(iter, range.first); BOOST_AUTO(end, range.second); if (coordVars[r] >= 0) { /* sparse mask */ temp_matrix_type C(iter->second->getNumDims(), len); readCoords(coordVars[r], start, len, C); for (; iter != end; ++iter) { var = iter->second; if (var->getType() == type) { mask.addSparseMask(var->getId(), len); serialiseCoords(var, C, mask.getIndices(var->getId())); } } } else { /* dense mask */ for (; iter != end; ++iter) { var = iter->second; if (var->getType() == type) { mask.addDenseMask(var->getId(), var->getSize()); } } } } } } }