Beispiel #1
0
py::list CeresDiffInnerProductVectorVector(const Vec &vec, const Vec &vec2) {
  auto py_array_jac = py::array(py::buffer_info(
      nullptr, sizeof(double), py::format_descriptor<double>::value(), 2,
      {1, 3}, {sizeof(double) * 3, sizeof(double)}));

  auto py_array_result = py::array(py::buffer_info(
      nullptr, sizeof(double), py::format_descriptor<double>::value(), 2,
      {1, 1}, {sizeof(double), sizeof(double)}));

  auto buf_jac = py_array_jac.request();
  auto buf_res = py_array_result.request();

  const double *parameters[2] = {vec.begin(), vec2.begin()};
  double *jacobians[2] = {static_cast<double *>(buf_jac.ptr), nullptr};

  ceres::AutoDiffCostFunction<InnerProductVectorVectorFunctor, 1, 3, 3>(
      new InnerProductVectorVectorFunctor())
      .Evaluate(parameters, static_cast<double *>(buf_res.ptr), jacobians);

  py::list list;
  list.append(py_array_result);
  list.append(py_array_jac);

  return list;
}
Beispiel #2
0
 uint32_t get(uint32_t pos) const
 {
     assert(!v_.empty() && v_[0] == 0);
     Vec::const_iterator i = std::lower_bound(v_.begin(), v_.end(), pos + 1);
     if (i == v_.end()) return (uint32_t)v_.size() - 1;
     return (uint32_t)std::distance(v_.begin(), i) - 1;
 }
Beispiel #3
0
int main(){
	int cases=0;
	while(1){
		int n,q;
		cin>>n>>q;
		if(n==0) break;
		++cases;
		cout<<"CASE# "<<cases<<":"<<endl;
		marble.clear();
		int k;
		for(int i=0;i<n;++i) {cin>>k;marble.push_back(k);}
		sort(marble.begin(),marble.end());
		for(int i=0;i<q;i++){
			cin>>k;
			Vec::iterator it=lower_bound(marble.begin(),marble.end(), k);
			if(it!=marble.end() && *it==k){
				cout<<k<<" found at "<<it-marble.begin()+1<<endl;
			}else{
				cout<<k<<" not found"<<endl;

			}
		}
	}
	return 0;	
}
Beispiel #4
0
int main(){
	int kase =0;
	while(true){
		int c,s,q;
		cin>>c>>s>>q;
		if (c==0) break;
		++kase;
		edges.clear();
		for(int i=0;i<s;++i){
			Edge e;
			cin>>e.from>>e.to>>e.weight;
			edges.push_back(e);
		}
		sort(edges.begin(), edges.end());
		for(int i=1;i<=c;++i){
			nodes[i].parent = nodes+i;
			nodes[i].count = 0;
			nodes[i].edges.clear();
		}
		int count =0;
		for(Vec::iterator it = edges.begin(); count< c-1 && it!= edges.end(); ++it){
			Node *rs = getRoot(it->from), *rt = getRoot(it->to);
			if(rs == rt) continue;
			if (rs->count > rt->count){
				rt->parent = rs;
				rs->count+=rt->count;
			} else {
				rs->parent = rt;
				rt->count += rs->count;
			}
			++count;

			nodes[it->from].edges.push_back(*it);
			int tmp = it->to;
			it->to = it->from; it->from =tmp;
			nodes[it->from].edges.push_back(*it);
		}
		if (kase >1) cout<<endl;
		cout<<"Case #"<<kase<<endl;
		for(int i=0;i<q; ++i){
			int s,t;
			cin>>s>>t;
			CalcResult result = calc(s,t,0);
			if (result.reached) {
				cout<<result.value<<endl;
			} else {
				cout<<"no path"<<endl;
			}
		}
	}
	return 0;
}
Beispiel #5
0
 void init(const Vec &from, VecTo &to)
 {
   base=&*from.begin();
   to.clear();
   for (unsigned i = 0, e = from.size(); i<e; ++i)
     to.push_back(i);
 }
 void
 initDiffApplication()
 {
     swap (seq_, orig_);
     seq_.reserve (orig_.size() * 120 / 100);    // heuristics for storage pre-allocation
     pos_ = orig_.begin();
 }
Beispiel #7
0
py::list CeresDiffRotorGaalop(const double theta, const Vec &a) {
  auto py_array_jac = py::array(py::buffer_info(
      nullptr, sizeof(double), py::format_descriptor<double>::value(), 2,
      {3, 1}, {sizeof(double), sizeof(double)}));

  auto py_array_result = py::array(py::buffer_info(
      nullptr, sizeof(double), py::format_descriptor<double>::value(), 2,
      {3, 1}, {sizeof(double), sizeof(double)}));

  auto buf_jac = py_array_jac.request();
  auto buf_res = py_array_result.request();

  const double *parameters[2] = {&theta, a.begin()};
  double *jacobians[2] = {static_cast<double *>(buf_jac.ptr), nullptr};

  ceres::AutoDiffCostFunction<DiffRotorGaalopFunctor, 3, 1, 3>(
      new DiffRotorGaalopFunctor())
      .Evaluate(parameters, static_cast<double *>(buf_res.ptr), jacobians);

  py::list list;
  list.append(py_array_result);
  list.append(py_array_jac);

  return list;
}
Beispiel #8
0
 static void print(const Vec& u)
 {
   Vec::const_iterator it = u.begin();
   for(;it != u.end(); it ++) {
     printf("v[%d] = %lf\n", it->first, it->second);
   }
 }
Beispiel #9
0
int main(int argc, const char *argv[])
{
    Vec<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;

    while (record.read(cin)) {
        maxlen = max(maxlen, record.name().size());
        students.push_back(record);
    }

    //  
    sort(students.begin(), students.end(), compare);

    for (Vec<double>::size_type i = 0; i != students.size(); i++) {
        cout << students[i].name() << string(maxlen + 1 - students[i].name().size(), ' ');
        try {
            double final_grade = students[i].grade();
            streamsize prec = cout.precision();
            cout << setprecision(3) << final_grade << setprecision(prec) << endl;
        } catch (domain_error e) {
            cout << e.what() << endl;
        }
    }
    return 0;
}
Beispiel #10
0
TEST(CollectionUtilsTest, vecShiftLeftByMoreThanSize) {
    typedef std::vector<size_t> Vec;
    Vec vec;
    
    vec.push_back('a');
    vec.push_back('b');
    vec.push_back('c');
    vec.push_back('d');
    vec.push_back('e');
    vec.push_back('f');
    vec.push_back('g');
    
    Vec leftBy10;
    leftBy10.push_back('d');
    leftBy10.push_back('e');
    leftBy10.push_back('f');
    leftBy10.push_back('g');
    leftBy10.push_back('a');
    leftBy10.push_back('b');
    leftBy10.push_back('c');

    Vec actual = vec;
    VectorUtils::shiftLeft(actual, 10);
    ASSERT_TRUE(std::equal(leftBy10.begin(), leftBy10.end(), actual.begin()));
}
Beispiel #11
0
TEST(CollectionUtilsTest, vecShiftLeftBySize) {
    typedef std::vector<size_t> Vec;
    Vec vec;
    
    vec.push_back('a');
    vec.push_back('b');
    vec.push_back('c');
    vec.push_back('d');
    vec.push_back('e');
    vec.push_back('f');
    vec.push_back('g');
    
    Vec actual = vec;
    VectorUtils::shiftLeft(actual, vec.size());
    ASSERT_TRUE(std::equal(vec.begin(), vec.end(), actual.begin()));
}
Beispiel #12
0
TEST(CollectionUtilsTest, vecShiftRightBy2) {
    typedef std::vector<size_t> Vec;
    Vec vec;
    
    vec.push_back('a');
    vec.push_back('b');
    vec.push_back('c');
    vec.push_back('d');
    vec.push_back('e');
    vec.push_back('f');
    vec.push_back('g');
    
    Vec rightBy2;
    rightBy2.push_back('f');
    rightBy2.push_back('g');
    rightBy2.push_back('a');
    rightBy2.push_back('b');
    rightBy2.push_back('c');
    rightBy2.push_back('d');
    rightBy2.push_back('e');
    
    Vec actual = vec;
    VectorUtils::shiftRight(actual, 2);
    ASSERT_TRUE(std::equal(rightBy2.begin(), rightBy2.end(), actual.begin()));
}
Beispiel #13
0
void apply1_wores_vec (Vec& a, UFunc f)
{
    if(a.is_empty())
        return;
    typedef typename cnc_iterator<Vec>::type Iter;
    for(Iter i = a.begin(), iend = a.end(); i != iend; ++i)
        f(*i);
}
Beispiel #14
0
 void unvectorize(std::vector<Ptr<Sufstat> >  &svec,
                  const Vec &v,
                  bool minimal){
   Vec::const_iterator it=v.begin();
   for(uint i=0; i<svec.size(); ++i){
     it = svec[i]->unvectorize(it, minimal);
   }
 }
Beispiel #15
0
   void ImmediateB (const Vec& s){
     //cout << "ehl" << endl;
     gfx::Glyph::Line(s);
     glPushMatrix();  
     gfx::GL::translate( s.begin() );
     gfx::Glyph::SolidSphere(.05,5,5);
     glPopMatrix();                       
 }
Beispiel #16
0
double average_analysis(const Vec<Student_info>& students)
{
    Vec<double> grades;

    transform(students.begin(), students.end(),
              back_inserter(grades), average_grade);
    return median(grades);
}
Beispiel #17
0
      ~GeneratedCode() {
         /*
          * Deallocate things as previously requested and
          * free shared manager when no longer used.
          */
#if HAVE_LLVM < 0x0306
         Vec::iterator i;

         assert(TheMM);
         for ( i = FunctionBody.begin(); i != FunctionBody.end(); ++i )
            TheMM->deallocateFunctionBody(*i);
#if HAVE_LLVM < 0x0304
         for ( i = ExceptionTable.begin(); i != ExceptionTable.end(); ++i )
            TheMM->deallocateExceptionTable(*i);
#endif /* HAVE_LLVM < 0x0304 */
#endif /* HAVE_LLVM < 0x0306 */
      }
Beispiel #18
0
int main(int argc, char* argv[])
{
    int rank,size,offset;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
  
    ostringstream convert;
    convert << rank+1;
    string file = "data"+ convert.str();
    int numLocal, totalNode;
    Graph g(rank,file);

    Matpair buf(4);
    Vec F;
    numLocal = g.localNode();
    offset = rank*numLocal;
    int root = 512;
    int finish,localfinish;
    int parents[numLocal];
    for (int i=0;i<numLocal;i++){
        parents[i] = -1;
    }
    if (rank == root/numLocal){
        F.push_back(root);
        parents[root-offset] = -2;}
    localfinish = !F.empty(); 

    Vec nxFr;
   
    int dep=0;
    int depth[numLocal];
    for (int i = 0; i < numLocal; i++){
	    depth[i]=0;
    }

    while(1){
    	localfinish=!F.empty();
	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Allreduce(&localfinish,&finish,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
    	if (finish==0)
		break;
        if (!F.empty()){
	   for (Vec::iterator i = F.begin();i != F.end(); i++){
		depth[*i-offset] = dep+1;
		cout << "node "<< *i <<" depth: "<<dep+1<<endl;
	   }
	}

        nextFrBuf(g,F,rank,size,buf,offset);
        alltoallPersonalized(buf,parents,nxFr,size,offset);
	F=nxFr;
	dep++;
    } 

    MPI_Finalize();
    return 0;
}
Beispiel #19
0
 void Immediate (const Vec& s){
   //cout << "vec" << endl; 
     gfx::Glyph::Line(s);
   glPushMatrix();  
     gfx::GL::translate( s.begin() );
     gfx::GL::rotate( AA(s).begin() );  
     Glyph::Cone();
   glPopMatrix();
 }  
Beispiel #20
0
int main() {
        string s;
        while (getline(cin, s)) {
                Vec<string> v = find_urls(s);
                for (Vec<string>::const_iterator i = v.begin();
                        i != v.end(); ++i)
                        cout << *i << endl;
        }
        return 0;
}
Beispiel #21
0
Vec<unsigned> symamd(const Vec<Vec<unsigned> > &ind) {
    Vec<int> lines; lines.resize( ind.size() + 1 );
    Vec<int> indices;
    
    unsigned nb_ind = 0;
    for(unsigned i=0;i<ind.size();++i)
        nb_ind += ind[i].size();
    indices.reserve( nb_ind ); 
    
    lines[0] = 0;
    for(unsigned i=0;i<ind.size();++i) {
        for(unsigned j=0;j<ind[i].size();++j)
            indices.push_back( ind[i][j] );
        lines[i+1] = indices.size();
    }
    Vec<unsigned> P; P.resize( ind.size() );
    amd_order( ind.size(), lines.begin(), indices.begin(), (int *)P.begin(), (double *)NULL, (double *)NULL );
    return P;
}
Beispiel #22
0
    void repack() {
        // dump();

        const int oWidth = (m_vec.size() - 1 - 1) / 2, nWidth = 2 * oWidth; // half widths
        Vec v(2 * nWidth + 1 + 1);
        copy(m_vec.begin() + 1, m_vec.end(), v.begin() + oWidth + 1);
        if ( ! m_vec.empty())
            v[0] = m_vec[0];
        swap(m_vec, v);
        m_minKey -= oWidth; m_maxKey += oWidth;
    }
 T pop() {
     if (front->empty()) {
         js::Reverse(back->begin(), back->end());
         Vec *tmp = front;
         front = back;
         back = tmp;
     }
     T item = front->back();
     front->popBack();
     return item;
 }        
Beispiel #24
0
void apply2_wores_vec_by_val (Vec& a, Val& b, BinOp f)
{
    if(a.is_empty())return;

    typename cnc_iterator<Vec>::type
        ai = a.begin(),
        aend = a.end();

    for(; ai != aend; ++ai)
        f(*ai, b);
}
Beispiel #25
0
void apply2_wores_val_by_vec (Val& a, Vec& b, BinOp f)
{
    if(b.is_empty())return;

    typename cnc_iterator<Vec>::type
        bi = b.begin(),
        bend = b.end();

    for(; bi != bend; ++bi)
        f(a, *bi);
}
Beispiel #26
0
bool allcmp_val_by_vec (const Val& val, const Vec& a, Cmp cmp)
{
    typename Vec::const_iterator
        ia = a.begin(),
        iaend = a.end();

    for(; ia != iaend; ++ia)
        if(!cmp(val, *ia))
            return false;

    return true;
}
Beispiel #27
0
double Lib::median(Vec x)
{
        typedef std::vector<double>::size_type vec_sz;

        vec_sz size = x.size();
        if(size==0)
                throw std::domain_error("median of an empty vector");

        std::sort(x.begin(),x.end());
        vec_sz mid = size/2;
        return size%2 == 0 ? (x[mid]+x[mid-1])/2 : x[mid];
}
Beispiel #28
0
 Vec rep(const Vec &x, uint n){
   uint m = x.size();
   Vec ans(m*n);
   Vec::const_iterator b = x.begin();
   Vec::const_iterator e = x.end();
   Vec::iterator out = ans.begin();
   for(uint i=0; i<n; ++i){
     std::copy(b,e,out);
     out+=m;
   }
   return ans;
 }
Beispiel #29
0
int main()
{
	string s;
	while (getline(cin, s))
	{
		Vec<string> v = find_urls(s);
		for (Vec<string>::const_iterator it = v.begin(); it != v.end(); ++it)
			cout << *it << endl;
	}

	system("pause");
	return 0;
}
Beispiel #30
0
int main()
{
    Str s;
    Vec<Str> v;
    while(getline(std::cin, s)) {
        v = findurl(s);
    }
    
    for(Vec<Str>::const_iterator i = v.begin(); i != v.end(); ++i)
        std::cout << *i << std::endl;
    
     return 0;
}