Ejemplo n.º 1
0
Archivo: test.cpp Proyecto: yak1ex/ccf
int main(int argc, char** argv)
{
#if defined(MEM_OK) || defined(MEM_BAD)
#if defined(MEM_OK)
	std::vector<int> vv(220*1024); // OK
#endif
#if defined(MEM_BAD)
	std::vector<int> vv(221*1024); // Bad
#endif
	vv.back() = 5;
#endif

#if defined(CPU_OK) || defined(CPU_BAD)
#if defined(CPU_OK)
	for(int i=0;i<100000000;++i); // OK
#endif
#if defined(CPU_BAD)
	for(int i=0;i<1000000000;++i) // Bad
		for(int j=0;j<1000000000;++j);
#endif
#endif

	int v[5] = { 3, 4, 5, 6, 7 };
	std::cout << std::accumulate(v, v+sizeof(v)/sizeof(v[0]), 0) << std::endl;
	unlink("sandbox.log");
	system("cl.exe /? > help.txt 2>&1");

	return 0;
}
Ejemplo n.º 2
0
  forceinline
  Incremental<View>::Incremental(Home home, ViewArray<View>& x,
                                 const TupleSet& t)
    : Base<View,false>(home,x,t), support_data(NULL),
      unassigned(x.size()), ac(home) {
    init_support(home);

    // Post advisors
    for (int i = x.size(); i--; )
      if (x[i].assigned()) {
        --unassigned;
      } else {
        x[i].subscribe(home,*new (home) SupportAdvisor(home,*this,ac,i));
      }

    Region r(home);

    // Add initial supports
    BitSet* dom = r.alloc<BitSet>(x.size());
    init_dom(home, dom);
    for (int i = x.size(); i--; )
      for (ViewValues<View> vv(x[i]); vv(); ++vv)
        find_support(home, dom, i, vv.val());

    // Work to be done or subsumption
    if (!w_support.empty() || !w_remove.empty() || (unassigned == 0))
      View::schedule(home,*this,
                     (unassigned != x.size()) ? ME_INT_VAL : ME_INT_DOM);
  }
Ejemplo n.º 3
0
int main(int argc,char* argv[])
{
	Matrix mat(1,2);
	mat(0,0) = 2;
	mat(0,1) = 1;
	Matrix mtm;
	mat.mtm(mtm);
	std::cout<<"m is "<<mat<<std::endl;
	std::cout<<mat.transpose()<<std::endl;   
	std::cout<<mat.transpose()*mat<<std::endl;
	std::cout<<mtm<<std::endl;
	std::cout<<mat.transMulti(mat)<<std::endl;

	Vector v(1);
	v(0) = 1.0;
	Matrix  m = mat.transpose();
	std::cout<<"test is "<<std::endl<<m.transMulti(mat.transpose());


	Vector vv(2);
	vv(0) = 1.0; vv(1) = 1.0;
	std::cout<<"squared norm is "<<vv.squaredNorm()<<std::endl;
	// std::cout<<m*vv <<std::endl;
	// std::cout<<mat*mtm<<std::endl;
	// std::cout<<mat.transpose()*mat.col(0)<<std::endl; 

	for ( int i = 0 ; i < 4 ; ++ i )
		std::cout<<mtm.dataPtr()[i]<<std::endl; 


	// clock_t t1,t2,at1,at2;
	// at1 = clock();
	// t1 = clock();
	// Matrix m = Matrix::random(5,2);
	// mat = m;
	// m = Matrix::random(5,2);
	// Vector v = Vector::random(4);
	// std::cout<<"m is "<<m<<std::endl;
	// std::cout<<"mat is "<<mat<<std::endl;
	// std::cout<<" m+mat is "<<m+mat<<std::endl;
	// std::cout<<" m-mat is "<<m-mat<<std::endl;
	// t2 = clock();
	// std::cout<<"generation costs "<<(double)(t2-t1)/CLOCKS_PER_SEC<<std::endl;
	// t1 = clock();
	// mat = m;the
	// t2 = clock();
	// std::cout<<"assignment costs "<<(double)(t2-t1)/CLOCKS_PER_SEC<<std::endl;  
	// t1 = clock();
	// Vector r = m*v;
	// t2 = clock();
	// std::cout<<" multiplicatioin costs "<<(double)(t2-t1)/CLOCKS_PER_SEC<<std::endl;
	// // t1 = clock();
	// m.mtm(mtm);
	// t2 = clock();
	// std::cout<<" level 3 operation costs "<<(double)(t2-t1)/CLOCKS_PER_SEC<<std::endl;
	// m.transpose()*m;
	// at2 = clock();
	// std::cout<<" all costs "<<(double)(at2-at1)/CLOCKS_PER_SEC<<std::endl;
}
//---------------------------------------------------------------------------
void ludcmp(Matrix& a, Matrix& indx, double& d)
{
  const double TINY = 1.0e-20;
  int i, imax, j, k;
  double big, dum, sum, temp;

  int n = a.numRows();
  Matrix vv(n,1);
  d = 1.0;
  for (i = 0; i < n; i++)
  {
    big = 0.0;
    for (j = 0; j < n; j++)
      if ((temp=fabs(a(i,j))) > big) big = temp;
    if (big == 0.0) exit(-1);  // singular matrix
    vv(i,0) = 1.0/big;
  }

  for (j = 0; j < n; j++)
  {
    for (i = 0; i < j; i++)
    {
      sum = a(i,j);
      for (k = 0; k < i; k++) sum -= a(i,k)*a(k,j);
      a(i,j) = sum;
    }
    big = 0.0;
    for (i = j; i < n; i++)
    {
      sum = a(i,j);
      for (k = 0; k < j; k++) sum -= a(i,k)*a(k,j);
      a(i,j) = sum;
      if ((dum=vv(i,0)*fabs(sum)) >= big)
      {
        big = dum;
        imax = i;
      }
    }
    if (j != imax)
    {
      for (k = 0; k < n; k++)
      {
        dum = a(imax,k);
        a(imax,k) = a(j,k);
        a(j,k) = dum;
      }
      d = -d;
      vv(imax,0) = vv(j,0);
    }
    indx(j,0) = imax;
    if (a(j,j) == 0.0) a(j,j) = TINY;
    if (j != n-1)
    {
      dum = 1.0/(a(j,j));
      for (i = j+1; i < n; i++) a(i,j) *= dum;
    }
  }
}
Ejemplo n.º 5
0
 forceinline void
 Base<View,subscribe>::init_dom(Space& home, Domain dom) {
   unsigned int domsize = ts()->domsize;
   for (int i = x.size(); i--; ) {
     dom[i].init(home, domsize);
     for (ViewValues<View> vv(x[i]); vv(); ++vv)
       dom[i].set(static_cast<unsigned int>(vv.val()-ts()->min));
   }
 }
Ejemplo n.º 6
0
  ExecStatus
  Basic<View,shared>::propagate(Space& home, const ModEventDelta&) {
    // Set up datastructures

    // Bit-sets for amortized O(1) access to domains
    Region r(home);
    BitSet* dom = r.alloc<BitSet>(x.size());
    init_dom(home, dom);

    // Bit-sets for processed values.
    BitSet* has_support = r.alloc<BitSet>(x.size());
    for (int i = x.size(); i--; )
      has_support[i].init(home, ts()->domsize);


    // Values to prune
    Support::StaticStack<int,Region> nq(r,static_cast<int>(ts()->domsize));

    // Run algorithm

    // Check consistency for each view-value pair
    for (int i = x.size(); i--; ) {
      for (ViewValues<View> vv(x[i]); vv(); ++vv) {
        // Value offset for indexing
        int val = vv.val() - ts()->min;
        if (!has_support[i].get(static_cast<unsigned int>(val))) {
          // Find support for value vv.val() in view
          Tuple l = find_support(dom, i, val);
          if (l == NULL) {
            // No possible supports left
            nq.push(vv.val());
          } else {
            // Mark values as supported
            // Only forward direction marking is needed since all
            // previous values have been checked
            for (int j = i; j--; ) {
              has_support[j].set(static_cast<unsigned int>(l[j]- ts()->min));
              assert(has_support[j].get(l[j] - ts()->min));
            }
          }
        }
      }

      // Prune values for x[i] which do not have support anymore
      while (!nq.empty())
        GECODE_ME_CHECK(x[i].nq(home,nq.pop()));
    }

    for (int i = x.size(); i--; )
      if (!x[i].assigned())
        return shared ? ES_NOFIX : ES_FIX;
    return home.ES_SUBSUMED(*this);
  }
Ejemplo n.º 7
0
    void HouseholderLRMult(
        const GenVector<T1>& v, T1 beta, SymMatrixView<T2> m)
    {
        // The input vector, v, is taken to be the vector for a  
        // Householder matrix, H.  This routine takes m <- H m Ht
        // if m is Hermitian or H m HT if m is symmetric.
        TMVAssert(m.size() > 0);
        TMVAssert(v.size() == m.size()-1);

        // If m is Hermitian:
        //
        // H m Ht = (I - beta v vt) m (I - beta* v vt)
        //        = m - beta v vt m - beta* m v vt + |beta|^2 v vt m v vt
        //        = m - beta v (mv)t - beta* (mv) vt + (|beta|^2 vt (mv)) v vt
        //
        // If m is symmetric:
        //
        // H m HT = (I - beta v vt) m (I - beta v* vT)
        //        = m - beta v vt m - beta m v* vT + beta^2 v vt m v* vT
        //        = m - beta v (mv*)T - beta (mv*) vT + (beta^2 vt (mv*)) v vT
        //
        ptrdiff_t N = m.size();
        if (N > 0 && beta != T1(0)) {
            // Normally, I take the unit first element of v to be implicit, 
            // but this calculation is more complicated, so for now I just 
            // copy the vector to a temporary Vector (vv).  
            // Someday maybe I'll change this to not need this temporary.
            Vector<T1> vv(N);
            vv(0) = T1(1);
            vv.subVector(1,N) = v;

            T2 betasqvtmv;
            Vector<T2> mv(N);
            if (m.isherm()) {
                mv = m*vv;
                betasqvtmv = TMV_NORM(beta)*vv.conjugate()*mv;
            } else {
                mv = m*vv.conjugate();
                betasqvtmv = beta*beta*vv.conjugate()*mv;
            }
            Rank2Update<true>(T2(-beta),vv,mv,m);
            if (m.issym()) {
                m += betasqvtmv * (vv^vv);
            } else {
                // imag part is 0 - make it exact.
                m += TMV_REAL(betasqvtmv) * (vv^vv.conjugate());
            }
        }
    }
Ejemplo n.º 8
0
int main(int argc,char **argv)
{
  std::allocator<int> alloc;
  std::vector<int> v(5,7);
  auto p = alloc.allocate(v.size() *3);
  auto q = std::uninitialized_copy(v.begin(),v.end(),p);
  

  for(int i=0; i < 5; i++ )
  {
      std::cout<<*p++<<" ";
  }
  std::cout<<std::endl;
  std::vector<int> vv(5,6);
  std::uninitialized_copy(vv.begin(),vv.end(),q);

  for(int j = 0; j < 5; j++)
  {
    std::cout<<*q++<<" ";
  }
  std::cout<<std::endl;

  std::vector<int> vvv(5,5);
  std::uninitialized_fill_n(q,vvv.size(),5);


  for(int j = 0; j < 5; j++)
  {
    std::cout<<*q++<<" ";
  }
  std::cout<<std::endl;
  return 0;
}
Ejemplo n.º 9
0
static std::list<VersionedValue> * readResults(std::istream* inputStream) {
    std::list<VersionedValue>* responseList = 
        new std::list<VersionedValue>();

    try {
        uint32_t resultSize;
        READ_INT(inputStream, resultSize);

        for (uint32_t i = 0; i < resultSize; i++) {
            uint32_t valueSize;
            READ_INT(inputStream, valueSize);
            VectorClock* vc = NULL;
            std::string* value = NULL;
            int vcsize = 0;
            try {
                vc = readVectorClock(inputStream, vcsize);
                value = readBytes(inputStream, valueSize - vcsize);
            } catch (...) {
                if (vc) delete vc;
                if (value) delete value;
                throw;
            }
            VersionedValue vv(value, vc);
            responseList->push_back(vv);
        }
        return responseList;

    } catch (...) {
        if (responseList) delete responseList;
        throw;
    }
}
void RecipientToString2(ews_recipient * r, int c, nsString & v) {
    std::string vv("");

    RecipientToStdString(r, c, vv);

    v.AssignLiteral(vv.c_str());
}
Ejemplo n.º 11
0
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        vector<vector<string>> res;
        const int size = strs.size();
        if (size == 0) {
            return res;
        }
        map<vector<int>, vector<string> > mm;
        while(!strs.empty()){
            auto& s = strs[strs.size()-1];
            vector<int> vv(26,0);
            for(auto c: s) {
                ++vv[c - 'a'];
            }
            mm[vv].push_back(move(s));
            strs.pop_back();
        }

        while(!mm.empty()) {
            auto item = mm.begin();
            sort(item->second.begin(), item->second.end());
            res.push_back(move(item->second));
            mm.erase(item->first);
        }

        return res;
    }
Ejemplo n.º 12
0
void contractor_pseq::init() {
    DREAL_LOG_DEBUG << "contractor_pseq::prune";

    auto const num_thread = min(thread::hardware_concurrency(), static_cast<unsigned>(m_vec.size()));

    cerr << m_vec.size() << " constraints\t"
         << num_thread << " threads" << endl;

    if (m_vec.size() < num_thread) {
        m_ctc = mk_contractor_seq(m_vec);
        m_use_threads = false;
        return;
    }

    vector<vector<contractor>> vv(num_thread);
    vector<contractor> v(num_thread);
    for (unsigned i = 0; i < m_vec.size(); i++) {
        vv[i % num_thread].push_back(m_vec[i]);
    }
    for (unsigned i = 0; i < num_thread; i++) {
        cerr << "vv[" << i << "].size() = "
             << vv[i].size() << endl;
        v[i] = mk_contractor_seq(vv[i]);
    }
    m_ctc = mk_contractor_parallel_all(v);
    m_use_threads = true;
}
Ejemplo n.º 13
0
TEST(ServerParameters, Vector1) {
    vector<string> v;

    ExportedServerParameter<vector<string>, ServerParameterType::kStartupOnly> vv(NULL, "vv", &v);

    BSONObj x = BSON("x" << BSON_ARRAY("a"
                                       << "b"
                                       << "c"));
    ASSERT_TRUE(vv.set(x.firstElement()).isOK());

    ASSERT_EQUALS(3U, v.size());
    ASSERT_EQUALS("a", v[0]);
    ASSERT_EQUALS("b", v[1]);
    ASSERT_EQUALS("c", v[2]);

    BSONObjBuilder b;

    OperationContextNoop opCtx;
    vv.append(&opCtx, b, vv.name());

    BSONObj y = b.obj();
    ASSERT(x.firstElement().woCompare(y.firstElement(), false) == 0);


    ASSERT_TRUE(vv.setFromString("d,e").isOK());
    ASSERT_EQUALS(2U, v.size());
    ASSERT_EQUALS("d", v[0]);
    ASSERT_EQUALS("e", v[1]);
}
Ejemplo n.º 14
0
void Doc_plugin_interface::addImage(int handle, QPointF *start, QPointF *uvr, QPointF *vvr,
                                    int w, int h, QString name, int br, int con, int fade){
    if (doc!=NULL) {
        RS_Vector ip(start->x(), start->y());
        RS_Vector uv(uvr->x(), uvr->y());
        RS_Vector vv(vvr->x(), vvr->y());
        RS_Vector size(w, h);

        RS_Image* image =
            new RS_Image(
                doc,
                RS_ImageData(handle /*QString(data.ref.c_str()).toInt(NULL, 16)*/,
                         ip, uv, vv,
                         size,
                         name,
                         br,
                         con,
                         fade));

        doc->addEntity(image);
        if (!haveUndo) {
            doc->startUndoCycle();
            haveUndo = true;
        }
        doc->addUndoable(image);
    } else
        RS_DEBUG->print("Doc_plugin_interface::addImage: currentContainer is NULL");
}
Ejemplo n.º 15
0
std::vector<unsigned char> decodeUrlSafe(std::vector<unsigned char> const& v)
{
    std::vector<unsigned char> vv(v);
    // 62nd char of encoding
    std::replace(vv.begin(), vv.end(), '-', '+');
    // 63rd char of encoding
    std::replace(vv.begin(), vv.end(), '_', '/');
    switch (vv.size() % 4)
    {
    case 0:
        break;  // No pad chars in this case
    case 2:
        vv.push_back('=');  // Two pad chars
        vv.push_back('=');
        break;
    case 3:
        vv.push_back('=');  // One pad char
        break;
    default:
        vv.clear();     // encoding error!
        break;
    }
    // Standard base64 decoder
    return decode(vv);
}
Ejemplo n.º 16
0
void CrankNicolson(vec &v, int Nx, int Nt, double dx, double dt){
    double d1 = dt/(dx*dx);
    double d2 = 2-2*d1;
    double d3 = 2+2*d1;

    vec a = -d1*ones(Nx);
    vec b = d3*ones(Nx);
    vec c = a;

    vec vv     = v;
    mat sol    = zeros(Nx,Nt);
    vec us     = 1-linspace(0,1,Nx);
    sol.col(0) = v+us; // Save real solution u = v + us

    for (int j=1; j<Nt; j++){
        for (int i=1; i<Nx-1; i++){
            vv(i) = d1*v(i-1) + d2*v(i) + d1*v(i+1);
            cout << "j=" << j << ", i=" << i << endl;

        }
        v = TriDiag(a, b, c, vv, Nx);
        sol.col(j) = v+us;
    }
    sol.save("CrankNicolson.dat",raw_ascii);

}
Ejemplo n.º 17
0
template<class T> void do_test_fluid()
{
  std::cout << "Size\ttable (c/e)\ttable (s)\tvector (c/e)\tvector (s)\tG(c/e)\tG(s)\n";

  for(int N=4;N<=2048;N*=2)
    //std::size_t N = 6;
  {
    std::cout.precision(3);
    std::cout << N*2*N << "\t";
    Compute<T> tt(N,2*N,-.28319, .28319);
    nt2::unit::benchmark_result<nt2::details::cycles_t> dv;
    nt2::unit::perform_benchmark( tt, 1., dv);
    nt2::unit::benchmark_result<double> tv;
    nt2::unit::perform_benchmark( tt, 1., tv);
    std::cout << std::scientific << dv.median/(double)(N*2*N) << "\t";
    std::cout << std::scientific << tv.median << "\t";

    Compute_scalar<T> vv(N,2*N,-.28319, .28319);
    nt2::unit::benchmark_result<nt2::details::cycles_t> dw;
    nt2::unit::perform_benchmark( vv, 1., dw);
    nt2::unit::benchmark_result<double> tw;
    nt2::unit::perform_benchmark( vv, 1., tw);
    std::cout << std::scientific << dw.median/(double)(N*N) << "\t";
    std::cout << std::scientific << tw.median << "\t";

    std::cout << std::fixed << (double)dw.median/dv.median << "\t";
    std::cout << std::fixed << (double)tw.median/tv.median << "\n";

  }
}
Ejemplo n.º 18
0
void
Cell::
pop_up(float w, float h)
{
  /*;
    set the z's:
   */
  m_final_text_node->z_order(text_z-1000);
  m_final_image_node->z_order(image_z-1000);
  m_rect_node->z_order(rect_z-1000);
  
  /*
    futz with m_parent_node.
    We want to make the cell centered taking up
    middle 2/3
   */
  vec2 vv(w,h);
  /*
    scale factor that we would apply
    in each dimension..
   */
  vv=2.0f*vv/(3.0f*m_size);

  m_new_scale_factor=std::min(vv.x(), vv.y());
  m_new_tr.x() = (w - m_new_scale_factor*m_size.x())/2.0f;
  m_new_tr.y() = (h - m_new_scale_factor*m_size.y())/2.0f;

  m_old_tr=m_parent_node->global_values().m_transformation.translation();

  m_parent_node->parent(NULL);
  m_state=popping_up;
  m_pop_time.restart();
}
Ejemplo n.º 19
0
//////////////////////////// 
// GET     VID   AND   PID
void windozeHelpers::GetVidAndPid( const uint16_t DeviceNum, 
                                  uint16_t & vid,
                                  uint16_t & pid )
{

    CString Path;
    windozeHelpers::FetchUsbDevicePath( DeviceNum, Path );
    
    CString vv( _T("vid_") );
    int32_t start = Path.Find( vv );
    int32_t stop = Path.Find( _T("&"), start);
    start = start + vv.GetLength();
    int32_t len = stop-start;
    

    CString vidStr = Path.Mid( start, len );

    vid = static_cast<uint16_t>( _tcstoul(vidStr, 0, 16) );

    CString pp( _T("pid_") );
    start = Path.Find( pp );
    stop =Path.Find( _T("#"), start);
    start = start + pp.GetLength();
    len = stop-start;
    

    CString pidStr = Path.Mid( start, len );

    pid = static_cast<uint16_t>( _tcstoul(pidStr, 0, 16) );
}
Ejemplo n.º 20
0
template<class T> void do_test()
{
  std::cout << "Size\ttable (c/e)\ttable (s)\tvector (c/e)\tvector (s)\tG(c/e)\tG(s)\n";

  for(int N=1;N<=4096;N*=2)
  {
    std::cout.precision(3);
    std::cout << N << "^2\t";
    table_test<T> tt(N,N,-.28319, .28319);
    nt2::unit::benchmark_result<nt2::details::cycles_t> dv;
    nt2::unit::perform_benchmark( tt, 1., dv);
    nt2::unit::benchmark_result<double> tv;
    nt2::unit::perform_benchmark( tt, 1., tv);
    std::cout << std::scientific << dv.median/(double)(N*N) << "\t";
    std::cout << std::scientific << tv.median << "\t";

    vector_test<T> vv(N,N,-.28319, .28319);
    nt2::unit::benchmark_result<nt2::details::cycles_t> dw;
    nt2::unit::perform_benchmark( vv, 1., dw);
    nt2::unit::benchmark_result<double> tw;
    nt2::unit::perform_benchmark( vv, 1., tw);
    std::cout << std::scientific << dw.median/(double)(N*N) << "\t";
    std::cout << std::scientific << tw.median << "\t";

    std::cout << std::fixed << (double)dw.median/dv.median << "\t";
    std::cout << std::fixed << (double)tw.median/tv.median << "\n";
  }
}
Ejemplo n.º 21
0
void
vpMatrix::LUDcmp(unsigned int *perm, int& d)
{
  unsigned int n = rowNum;

  unsigned int i,imax=0,j,k;
  double big,dum,sum_,temp;
  vpColVector vv(n);

  d=1;
  for (i=0;i<n;i++) {
    big=0.0;
    for (j=0;j<n;j++)
      if ((temp=fabs(rowPtrs[i][j])) > big) big=temp;
    //if (big == 0.0)
    if (std::fabs(big) <= std::numeric_limits<double>::epsilon())
    {
      //vpERROR_TRACE("Singular vpMatrix in  LUDcmp") ;
      throw(vpMatrixException(vpMatrixException::matrixError,
                              "Singular vpMatrix in  LUDcmp")) ;
    }
    vv[i]=1.0/big;
  }
  for (j=0;j<n;j++) {
    for (i=0;i<j;i++) {
      sum_=rowPtrs[i][j];
      for (k=0;k<i;k++) sum_ -= rowPtrs[i][k]*rowPtrs[k][j];
      rowPtrs[i][j]=sum_;
    }
    big=0.0;
    for (i=j;i<n;i++) {
      sum_=rowPtrs[i][j];
      for (k=0;k<j;k++)
        sum_ -= rowPtrs[i][k]*rowPtrs[k][j];
      rowPtrs[i][j]=sum_;
      if ( (dum=vv[i]*fabs(sum_)) >= big) {
        big=dum;
        imax=i;
      }
    }
    if (j != imax) {
      for (k=0;k<n;k++) {
        dum=rowPtrs[imax][k];
        rowPtrs[imax][k]=rowPtrs[j][k];
        rowPtrs[j][k]=dum;
      }
      d *= -1;
      vv[imax]=vv[j];
    }
    perm[j]=imax;
    //if (rowPtrs[j][j] == 0.0)
    if (std::fabs(rowPtrs[j][j]) <= std::numeric_limits<double>::epsilon())
      rowPtrs[j][j]=TINY;
    if (j != n) {
      dum=1.0/(rowPtrs[j][j]);
      for (i=j+1;i<n;i++) rowPtrs[i][j] *= dum;
    }
  }
}
Ejemplo n.º 22
0
	void velocity(const Scene* scene, const shared_ptr<Node>& n) override {
		// http://en.wikipedia.org/wiki/Simple_harmonic_motion
		Real omega=2*M_PI*freq;
		Real vMag=amp*omega*cos(omega*(scene->time-t0));
		Vector3r& vv(n->getData<DemData>().vel);
		if(!perpFree) vv=dir*vMag;
		else{ /*subtract projection on dir*/ vv-=vv.dot(dir)*dir; /* apply new value instead */ vv+=vMag*dir; }
	}
Ejemplo n.º 23
0
	void velocity(const Scene* scene, const shared_ptr<Node>& n) override {
		Vector3r& vv(n->getData<DemData>().vel);
		for(int ax:{0,1,2}){
			if(isnan(freqs[ax])||isnan(amps[ax])) continue;
			Real omega=2*M_PI*freqs[ax];
			vv[ax]=amps[ax]*omega*cos(omega*scene->time);
		}
	}
Ejemplo n.º 24
0
// distance of (x,y) and v0v1v2 triangle (of its edge)
double edge(Vector2 v0, Vector2 v1, Vector2 v2, double x, double y) {
    Vector2 vv(x,y);
    double d1 = dist(v0,v1,vv);
    double d2 = dist(v0,v2,vv);
    double d3 = dist(v1,v2,vv);
    if (d2 > d3) d2 = d3;
    if (d1 > d2) d1 = d2;
    return d1;
}
Ejemplo n.º 25
0
static int value(int x,int y,int race)
{
  char te_v[10],i;
  if(chess[x-1][y-1]) return -100;
  for(i=0;i<10;i++) te_v[i]=0;
  for(i=0;i<4;i++) te_v[vv(x,y,race,i,-1)]++;
  return
 (te_v[9]+te_v[8]+te_v[7]+te_v[6]+te_v[5]+te_v[4])*15+te_v[3]*9+te_v[2]*3+te_v[1]*2;
}
VecF32 DistributionMultiVariateRegularStep::randomVariable()const {
    F32 u = this->uni.randomVariable();
    std::vector<F32>::const_iterator low=std::upper_bound (_repartition.begin(), _repartition.end(),u ); //
    I32 indice = I32(low- _repartition.begin()) ;
    if(_xmin.size()==2){
        Vec2I32 v;
        v(0)= indice/_mat2d.sizeJ();
        v(1)= indice-v(0)*_mat2d.sizeJ();
        VecF32 vv(2);
        vv(0)=v(0)*_step+_xmin(0);vv(1)=v(1)*_step+_xmin(1);
        return vv;
    }
    else{
        std::cerr<<"work only for two variates";
        return VecF32();
    }

}
Ejemplo n.º 27
0
VoxelImage *makeTree()
{
  int vw=256;

  FastVoxelView vv(vw,vw,Pos3D(256,512,0),false,1);
  drawPlane(vv,vw);
  drawTree(vv,Pos3D(128,0,128),140);
  return new VoxelImage(vv.getSurface(),Pos3D(0,0,0));
}
Ejemplo n.º 28
0
static int read_mem(void *dst, int fd, off_t start, size_t len)
{
    int rc;
    size_t bytes_read=0;
    if (lseek(fd, start, SEEK_SET) == (off_t)-1) {
        fprintf(stderr, "lseek failed: %s\n", strerror(errno));
        return -1;
    }
    while ( len && ((rc=read(fd, (char*)dst+bytes_read, len)) > 0)) {
        len -= rc;
        bytes_read += rc;
    }
    if (rc==-1) {
        vv("read_mem failed (%s)\n",strerror(errno));
    }
    if ((len != 0 && rc >= 0)) {
        vv("INTERNAL ERROR\n");
    }
    return (rc == -1) ? -1 : 0;
}
Ejemplo n.º 29
0
MathVector MathVector::vectP(MathVector v) {
	/*
	 * Ux = Vy * Wz - Wy * Vz;
	 * Uy = Vz * Wx - Wz * Vx;
	 * Uz = Vx * Wy - Wx * Vy;
	 */
	MathVector vv(y * v.z - v.y * z,
				  z * v.x - v.z * x,
				  x * v.y - v.x * y);
	return vv;
}
Ejemplo n.º 30
0
void search(const Graph g)
{
    std::vector<Vertex> bfs;
    vertex_visitor vv(bfs);

    breadth_first_search(g, S, visitor(vv));

    std::cout << "breath first search" << std::endl;
    BOOST_FOREACH(Vertex v, bfs){
        std::cout << Names[v] << std::endl;
        // get(vertex_name, G, v)
    }