本文整理汇总了C++中Index::atMaxId方法的典型用法代码示例。如果您正苦于以下问题:C++ Index::atMaxId方法的具体用法?C++ Index::atMaxId怎么用?C++ Index::atMaxId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Index
的用法示例。
在下文中一共展示了Index::atMaxId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evalTest
void evalTest(const std::size_t p_size, const std::size_t p_samples) {
Polynomial<T,Dim> P;
Index<Dim> polyIdx;
{
typename Shape<Dim>::type polyShape;
polyShape.fill(p_size);
P.reshape(polyShape).applyToCoefficients([](T& ak, const Index<Dim>& idx){
ak = T(idx())/T(idx.maxId());
});
}
std::array<T,Dim> X;
T dX;
{
const T a = T(0);
const T b = T(1);
dX = (b-a)/(p_samples-1);
}
typename Shape<Dim>::type sampleShape;
sampleShape.fill(p_samples);
Index<Dim> sampleIdx(sampleShape);
while(!sampleIdx.atMaxId()) {
for (std::size_t d=0; d < Dim; d++)
X[d] = sampleIdx[d]*dX;
T lhs, rhs;
lhs = P(X);
rhs = T(0);
polyIdx.reset(P.shape());
while(!polyIdx.atMaxId()) {
T val = T(1);
for (std::size_t d=0; d<Dim; d++)
val *= std::pow(X[d],polyIdx[d]);
rhs += T(polyIdx())/T(polyIdx.maxId())*val;
++polyIdx;
}
ASSERT_LE(std::abs(rhs-lhs),std::pow(10,Dim)*std::numeric_limits<T>::epsilon());
++sampleIdx;
}
}
示例2: test
void test(std::size_t p_maxOrder, bool includePeriodicBds=false) {
typename Shape<Dim>::type shape;
typename Domain<T,Dim>::DomainSize domainSize;
Domain<T,Dim> ref, inBuffer, outBuffer;
Domain<T,Dim>& in = inBuffer;
Domain<T,Dim>& out = outBuffer;
std::array<int,Dim> order;
shape.fill(8);
domainSize.fill(2*hysop::constants::pi);
T eps = std::numeric_limits<T>::epsilon();
const std::size_t N = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<std::size_t>());
ref.resize(domainSize).reshape(shape);
in = ref;
out = ref;
typename Shape<Dim>::type maxOrder, testCases;
maxOrder.fill(p_maxOrder+1);
testCases.fill(nExtensionsPair);
Index<Dim> orderId(maxOrder);
Index<Dim> testCaseId;
std::size_t testCaseCount;
while(!(++orderId).atMaxId()) {
std::cout << " ::Order::" << orderId.ids() << (verbose ? "\n" : "");
std::array<T,3> meanDists;
meanDists.fill(0);
testCaseId.reset(testCases);
testCaseCount = testCaseId.maxId();
while(!testCaseId.atMaxId()) {
std::copy(orderId.ids().begin(),orderId.ids().end(), order.begin());
/* generate transform configuration */
std::array<std::pair<fft::Extension,fft::Extension>, Dim> extConfig;
for (std::size_t k=0; k<Dim; k++) {
std::size_t id = testCaseId[k];
extConfig[k] = pext[id];
if(pext[id].first==fft::Extension::NONE)
order[k] = 0;
}
fft::FftDomainConfiguration<Dim> domainConfig(extConfig, includePeriodicBds);
const std::size_t orderSum = std::accumulate(order.begin(), order.end(), 0);
if(orderSum == 0) {
testCaseCount--;
++testCaseId;
continue;
}
T orderPow = std::pow(T(10),T(orderSum));
if(std::is_same<T,long double>::value) /* just in case long doubles are not hardware supported... */
orderPow *= 1e3;
const auto criteria = std::make_tuple(orderPow*eps*N,orderPow*eps*sqrt(N),2*orderPow*eps);
const auto f = [&](const typename Domain<T,Dim>::SpaceVariable &x) {
T val = func<T>(testCaseId[0])(x[0]);
for (std::size_t d=1; d < Dim; d++)
val *= func<T>(testCaseId[d])(x[d]);
return val;
};
const auto d = [&](const typename Domain<T,Dim>::SpaceVariable &x) {
T val = derivative<T>(testCaseId[0],order[0])(x[0]);
for (std::size_t d=1; d < Dim; d++)
val *= derivative<T>(testCaseId[d],order[d])(x[d]);
return val;
};
{
ref.resetDomainConfiguration(domainConfig.boundariesConfiguration());
in = ref;
out = ref;
in.apply(f);
ref.apply(d);
out.data().apply([](T& v){ v=T(0);});
}
solver::FftDiffSolver<T,Dim> solver(domainSize, domainConfig, FFTW_MEASURE, includePeriodicBds, includePeriodicBds);
solver.apply(in.data(), out.data(), order);
std::stringstream ss;
ss << "[";
for (std::size_t k=0; k<Dim-1; k++)
ss << extConfig[k].first << "/" << extConfig[k].second << ",";
ss << extConfig[Dim-1].first << "/" << extConfig[Dim-1].second;
ss << "]";
const auto dist = out.distance(ref);
const bool pass = (std::get<0>(dist) < std::get<0>(criteria))
&& (std::get<1>(dist) < std::get<1>(criteria))
&& (std::get<2>(dist) < std::get<2>(criteria));
if((pass && verbose) || !pass) {
std::cout << (pass ? GREEN : RED);
std::cout << "\t" << std::setw(Dim*15) << ss.str() << " => " << (pass ? "OK" : "KO")
<< " " << RESET << std::scientific << std::setprecision(2) << dist << std::endl;
}
if(!pass) {
//.........这里部分代码省略.........