本文整理汇总了C++中arr::reshape方法的典型用法代码示例。如果您正苦于以下问题:C++ arr::reshape方法的具体用法?C++ arr::reshape怎么用?C++ arr::reshape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arr
的用法示例。
在下文中一共展示了arr::reshape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getConstraints
void SocSystem_Analytical::getConstraints(arr& cdir,arr& coff,uint t,const arr& qt){
cdir.clear();
coff.clear();
#ifndef USE_TRUNCATION
return;
#endif
uint i,M=obstacles.d0;
arr d;
#if 0 //direct and clean way to do it -- but depends simple scenario
cdir.resize(M,x.N);
coff.resize(M);
for(i=0;i<M;i++){
cdir[i] = qt-obstacles[i];
coff(i) = scalarProduct(cdir[i],obstacles[i]);
}
#elif 1 //assume that the task vector is a list of scalars, each constrained >0
arr J,y;
for(i=0;i<M;i++){
real haty = norm(x-obstacles[i]);
if(haty>.5) continue; //that's good enough -> don't add the constraint
J = (x-obstacles[i])/norm(x-obstacles[i]);
coff.append(-haty + scalarProduct(J,x));
cdir.append(J);
}
cdir.reshape(coff.N,x.N);
coff.reshape(coff.N);
#else //messy: try to combine all constraints into a single scalar, doesn't really work...
//first compute squared collision meassure...
arr J(1,qt.N),phiHatQ(1);
J.setZero();
phiHatQ.setZero();
for(i=0;i<obstacles.d0;i++){
real margin = .25;
real d = 1.-norm(x-obstacles[i])/margin;
//if(d<0) continue;
//phiHatQ(0) += d*d;
//J += (2.*d/margin)*(obstacles[i]-x)/norm(x-obstacles[i]);
phiHatQ(0) += d;
J += (1./margin)*(obstacles[i]-x)/norm(x-obstacles[i]);
}
//...then add a single constraint
if(phiHatQ(0)>0.){ //potential violation, else discard
cdir.append(-J);
coff.append(phiHatQ-scalarProduct(J,x)-1.);
cdir.reshape(1,x.N);
coff.reshape(1);
}
#endif
}