• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ arr类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中arr的典型用法代码示例。如果您正苦于以下问题:C++ arr类的具体用法?C++ arr怎么用?C++ arr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了arr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: J

real SocSystem_Analytical::getCosts(arr& R,arr& r,uint t,const arr& qt){
  uint N=x.N;
  R.resize(N,N); R.setZero();
  r.resize(N);   r.setZero();
  real C=0.;
  
#ifndef USE_TRUNCATION //potentials for collision cost
  arr J(1,qt.N),phiHatQ(1);
  J.setZero();
  phiHatQ.setZero();
  for(uint i=0;i<obstacles.d0;i++){
    real margin = .1;
    real d = (1.-norm(x-obstacles[i])/margin);
    if(d<0) continue;
    phiHatQ(0) += d*d;
    J += ((real)2.*d/margin)*(obstacles[i]-x)/norm(x-obstacles[i]);
  }
  J.reshape(1,J.N);
  arr tJ,target(1);
  target=(real)0.;
  transpose(tJ,J);
  real colprec = (real)5e2;
  C += colprec*sqrDistance(target,phiHatQ);
  R += colprec*tJ*J;
  r += colprec*tJ*(target - phiHatQ + J*qt);
#endif
  
  if(t!=T-1) return C;
  R.setDiag(1.);
  r = x1;
  R *= prec;
  r *= prec;
  C += prec*sqrDistance(x1,x);
  return C;
}
开发者ID:wensun,项目名称:probCollision,代码行数:35,代码来源:soc_system_analytical.cpp


示例2:

void soc::SocSystem_Ors::getqv0(arr& q_){
   if(!WS->Qlin.N) q_.setBlockVector(WS->q0,WS->v0);
   else{
     arr q,qd;
     getqv0(q,qd);
     q_.setBlockVector(q,qd);
   }
}
开发者ID:wensun,项目名称:probCollision,代码行数:8,代码来源:soc_system_ors.cpp


示例3: fs

 virtual double fs(arr& g, arr& H, const arr& x) {
   double A=.5, f=A*x.N;
   for(uint i=0; i<x.N; i++) f += x(i)*x(i) - A*::cos(10.*x(i));
   if(&g) {
     g.resize(x.N);
     for(uint i=0; i<x.N; i++) g(i) = 2*x(i) + 10.*A*::sin(10.*x(i));
   }
   if(&H) {
     H.resize(x.N,x.N);  H.setZero();
     for(uint i=0; i<x.N; i++) H(i,i) = 2 + 100.*A*::cos(10.*x(i));
   }
   return f;
 }
开发者ID:ipa-nhg,项目名称:kukadu,代码行数:13,代码来源:benchmarks.cpp


示例4: rightminarray

arr rightminarray(const arr& hist)
{
		arr out(hist.size());
		stack<int> S;
		for(int i=hist.size()-1 ;i>=0; --i)
		{
				while( !S.empty() && hist[S.top()] >= hist[i]) S.pop();
				if(!S.empty())out[i] = S.top();
				else out[i] = hist.size();
				S.push(i);
		}

		return out;
}
开发者ID:sujeet05,项目名称:GeeksforGeeks,代码行数:14,代码来源:histogram.cpp


示例5: leftminarray

arr leftminarray(const arr& hist)
{
		arr out(hist.size());
		stack<int> S;
		for(int i=0;i<hist.size(); ++i)
		{
				while( !S.empty() && hist[S.top()] >= hist[i]) S.pop();
				if(!S.empty())out[i] = S.top();
				else out[i] = -1;
				S.push(i);
		}

		return out;
}
开发者ID:sujeet05,项目名称:GeeksforGeeks,代码行数:14,代码来源:histogram.cpp


示例6: getPhi

 void getPhi(arr& phiq_i,uint i){ NIY; 
   if(i==1){
     phiq_i.resize(1);
     for(uint i=0;i<obstacles.N;i++){
       phiq_i(0) += norm(x-obstacles[i]);
     }
   }
 }
开发者ID:wensun,项目名称:probCollision,代码行数:8,代码来源:soc_system_analytical.cpp


示例7: lookup_by_name

size_t lookup_by_name(arr &names, const char *name) {
    for (size_t idx = 0; idx < names.size(); ++idx) {
        if (strcmp(name, names[idx]) == 0) {
            return idx;
        }
    }
    return 0;
}
开发者ID:aidush,项目名称:openmpt,代码行数:8,代码来源:paudio.cpp


示例8: PrepRingWeights

// Prepare weights used by map2alm. weight array must be allocated already:
void PrepRingWeights(int col, arr<double> & weight, int nside) {
  double *tempweight;
  int status;
  long i;

  if (USE_WEIGHTS==1) {
    Announce("Loading Healpix map weights... ");
    tempweight = vector<double>(0, 2*nside-1);
    status = ReadHealpixWeights(col, nside, tempweight);
    if (status==0) for (i=0; i<2*nside; i++) weight[i]=1.0+tempweight[i];
    else { 
      warning("PrepRingWeights: could not load Healpix weights, using 1.0 instead.");
      weight.fill(1);
    }
    free_vector(tempweight, 0, 2*nside-1);
    Announce();
  }
  else weight.fill(1);
}
开发者ID:hsxavier,项目名称:windowL,代码行数:20,代码来源:windowL.cpp


示例9: removeElement

//Given an array and a value, remove all instances of that value in place and return the new length.
//The order of elements can be changed.It doesn't matter what you leave beyond the new length(超出新长度的元素可以任意).
int Array::removeElement(arr& nums, int val) 
{
	int i, j;
	for (i = j = nums.size() - 1; i >= 0; i--) 
	{
		if (nums[i] == val && i != j--)
			nums[i] = nums[j + 1];
	}
	return j + 1;
}
开发者ID:bluestein,项目名称:LeetCode,代码行数:12,代码来源:Array.cpp


示例10: getTriNormals

void getTriNormals(const Mesh& m, arr& Tn) {
  uint i;
  ors::Vector a, b, c;
  Tn.resize(m.T.d0, 3); //tri normals
  for(i=0; i<m.T.d0; i++) {
    a.set(&m.V(m.T(i, 0), 0)); b.set(&m.V(m.T(i, 1), 0)); c.set(&m.V(m.T(i, 2), 0));
    b-=a; c-=a; a=b^c; a.normalize();
    Tn(i, 0)=a.x;  Tn(i, 1)=a.y;  Tn(i, 2)=a.z;
  }
}
开发者ID:ipa-nhg,项目名称:kukadu,代码行数:10,代码来源:mesh.cpp


示例11: max_area

int max_area(const arr& hist)
{
		int max_area = INT_MIN;
		arr left  = leftminarray(hist);
		arr right = rightminarray(hist);
		for(int i=0; i < hist.size(); ++i)
		{
				int area = (right[i]-left[i]-1 )*hist[i];
				if( area > max_area) max_area = area;
		}
		return max_area;
}
开发者ID:sujeet05,项目名称:GeeksforGeeks,代码行数:12,代码来源:histogram.cpp


示例12: generateConditionedRandomProjection

void generateConditionedRandomProjection(arr& M, uint n, double condition) {
  uint i,j;
  //let M be a ortho-normal matrix (=random rotation matrix)
  M.resize(n,n);
  rndUniform(M,-1.,1.,false);
  //orthogonalize
  for(i=0; i<n; i++) {
    for(j=0; j<i; j++) M[i]()-=scalarProduct(M[i],M[j])*M[j];
    M[i]()/=length(M[i]);
  }
  //we condition each column of M with powers of the condition
  for(i=0; i<n; i++) M[i]() *= pow(condition, double(i) / (2.*double(n - 1)));
}
开发者ID:ipa-nhg,项目名称:kukadu,代码行数:13,代码来源:benchmarks.cpp


示例13: backward

void sharp_sht::backward(const arr< dcomplex > &in_alm, arr< double > &out_map)
{
    dsharpjob->alm2map(in_alm.begin(), out_map.begin(), false);
}
开发者ID:,项目名称:,代码行数:4,代码来源:


示例14: forward

void sharp_sht::forward(const arr< double > &in_map, arr< dcomplex > &out_alm)
{
    dsharpjob->map2alm(in_map.begin(), out_alm.begin(), false);
}
开发者ID:,项目名称:,代码行数:4,代码来源:


示例15: CHECK

void ParticleAroundWalls::phi_t(arr& phi, arr& J, uint t, const arr& x_bar){
  uint T=get_T(), n=dim_x(), k=get_k();

  //assert some dimensions
  CHECK(x_bar.d0==k+1,"");
  CHECK(x_bar.d1==n,"");
  CHECK(t<=T,"");

  //-- transition costs: append to phi
  if(k==1)  phi = x_bar[1]-x_bar[0]; //penalize velocity
  if(k==2)  phi = x_bar[2]-2.*x_bar[1]+x_bar[0]; //penalize acceleration
  if(k==3)  phi = x_bar[3]-3.*x_bar[2]+3.*x_bar[1]-x_bar[0]; //penalize jerk

  //-- walls: append to phi
  //Note: here we append to phi ONLY in certain time slices: the dimensionality of phi may very with time slices; see dim_phi(uint t)
  double eps=.1, power=2.;
  if(!hardConstrained){
    //-- wall costs
    for(uint i=0;i<n;i++){ //add barrier costs to each dimension
      if(t==T/4)   phi.append(MT::ineqConstraintCost(i+1.-x_bar(k,i), eps, power));  //middle factor: ``greater than i''
      if(t==T/2)   phi.append(MT::ineqConstraintCost(x_bar(k,i)+i+1., eps, power));  //last factor: ``lower than -i''
      if(t==3*T/4) phi.append(MT::ineqConstraintCost(i+1.-x_bar(k,i), eps, power));  //middle factor: ``greater than i''
      if(t==T)     phi.append(MT::ineqConstraintCost(x_bar(k,i)+i+1., eps, power));  //last factor: ``lower than -i''
    }
  }else{
    //-- wall constraints
    for(uint i=0;i<n;i++){ //add barrier costs to each dimension
      if(t==T/4)   phi.append((i+1.-x_bar(k,i)));  //middle factor: ``greater than i''
      if(t==T/2)   phi.append((x_bar(k,i)+i+1.));  //last factor: ``lower than -i''
      if(t==3*T/4) phi.append((i+1.-x_bar(k,i)));  //middle factor: ``greater than i''
      if(t==T)     phi.append((x_bar(k,i)+i+1.));  //last factor: ``lower than -i''
    }
  }

  uint m=phi.N;
  CHECK(m==dim_phi(t),"");

  if(&J){ //we also need to return the Jacobian
    J.resize(m,k+1,n).setZero();

    //-- transition costs
    for(uint i=0;i<n;i++){
      if(k==1){ J(i,1,i) = 1.;  J(i,0,i) = -1.; }
      if(k==2){ J(i,2,i) = 1.;  J(i,1,i) = -2.;  J(i,0,i) = 1.; }
      if(k==3){ J(i,3,i) = 1.;  J(i,2,i) = -3.;  J(i,1,i) = +3.;  J(i,0,i) = -1.; }
    }

    //-- walls
    if(!hardConstrained){
      for(uint i=0;i<n;i++){
        if(t==T/4)   J(n+i,k,i) = -MT::d_ineqConstraintCost(i+1.-x_bar(k,i), eps, power);
        if(t==T/2)   J(n+i,k,i) =  MT::d_ineqConstraintCost(x_bar(k,i)+i+1., eps, power);
        if(t==3*T/4) J(n+i,k,i) = -MT::d_ineqConstraintCost(i+1.-x_bar(k,i), eps, power);
        if(t==T)     J(n+i,k,i) =  MT::d_ineqConstraintCost(x_bar(k,i)+i+1., eps, power);
      }
    }else{
      for(uint i=0;i<n;i++){
        if(t==T/4)   J(n+i,k,i) = -1.;
        if(t==T/2)   J(n+i,k,i) = +1.;
        if(t==3*T/4) J(n+i,k,i) = -1.;
        if(t==T)     J(n+i,k,i) = +1.;
      }
    }
  }
}
开发者ID:ipa-nhg,项目名称:kukadu,代码行数:65,代码来源:benchmarks.cpp


示例16: offset_at

template<typename... Ix> size_t offset_at(const arr& a, Ix&&... idx) { return a.offset_at(idx...); }
开发者ID:aldanor,项目名称:pybind11,代码行数:1,代码来源:test_numpy_array.cpp


示例17: index_at

template<typename... Ix> size_t index_at(const arr& a, Ix&&... idx) { return a.index_at(idx...); }
开发者ID:aldanor,项目名称:pybind11,代码行数:1,代码来源:test_numpy_array.cpp


示例18: data

template<typename... Ix> arr data(const arr& a, Ix&&... index) {
    return arr(a.nbytes() - a.offset_at(index...), (const uint8_t *) a.data(index...));
}
开发者ID:aldanor,项目名称:pybind11,代码行数:3,代码来源:test_numpy_array.cpp


示例19: getProcess

void SocSystem_Analytical::getProcess(arr& A,arr& a,arr& B){
  uint N=x.N;
  A.setDiag(1.,N);
  B.setDiag(1.,N);
  a.resize(N); a.setZero();
}
开发者ID:wensun,项目名称:probCollision,代码行数:6,代码来源:soc_system_analytical.cpp


示例20: step

bool sRprop::step(arr& w, const arr& grad, uint *singleI) {
    if(!stepSize.N) { //initialize
        stepSize.resize(w.N);
        lastGrad.resize(w.N);
        lastGrad.setZero();
        stepSize = delta0;
    }
    CHECK(grad.N==stepSize.N, "Rprop: gradient dimensionality changed!");
    CHECK(w.N==stepSize.N   , "Rprop: parameter dimensionality changed!");

    uint i=0, I=w.N;
    if(singleI) {
        i=*(singleI);
        I=i+1;
    }
    for(; i<I; i++) {
        if(grad.elem(i) * lastGrad(i) > 0) { //same direction as last time
            if(rMax) dMax=fabs(rMax*w.elem(i));
            stepSize(i) = _mymin(dMax, incr * stepSize(i)); //increase step size
            w.elem(i) += stepSize(i) * -_sgn(grad.elem(i)); //step in right direction
            lastGrad(i) = grad.elem(i);                    //memorize gradient
        } else if(grad.elem(i) * lastGrad(i) < 0) { //change of direction
            stepSize(i) = _mymax(dMin, decr * stepSize(i)); //decrease step size
            w.elem(i) += stepSize(i) * -_sgn(grad.elem(i)); //step in right direction (undo half the step)
            lastGrad(i) = 0;                               //memorize to continue below next time
        } else {                              //after change of direcion
            w.elem(i) += stepSize(i) * -_sgn(grad.elem(i)); //step in right direction
            lastGrad(i) = grad.elem(i);                    //memorize gradient
        }
    }

    return stepSize.max() < incr*dMin;
}
开发者ID:ipa-nhg,项目名称:kukadu,代码行数:33,代码来源:opt-rprop.cpp



注:本文中的arr类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ array类代码示例发布时间:2022-05-31
下一篇:
C++ arith_util类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap