22 namespace ProductBasisUtilsUnitTest {
 
   25   template <
typename OrdinalType, 
typename ValueType>
 
   44   template <
typename ordinal_type>
 
   53   template <
typename scalar_type>
 
   56     for (
int i=0; i<x.
size(); i++)
 
   62   template <
typename scalar_type>
 
   65     for (
int i=0; i<x.
size(); i++)
 
   79       out << 
"For n  =" << n << 
", k = " << k << 
", n_choose_k = " << v1
 
   80           << 
" != " << v2 << std::endl;
 
   88       out << 
"For n  =" << n << 
", k = " << k << 
", n_choose_k = " << v1
 
   89           << 
" != " << v2 << std::endl;
 
  100     typedef index_set_type::multiindex_type multiindex_type;
 
  102     typedef std::set<multiindex_type, less_type> multiindex_set;
 
  103     typedef multiindex_set::iterator iterator;
 
  105     multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end());
 
  108     std::ostream_iterator<multiindex_type> out_iterator(out, 
"\n");
 
  109     out << std::endl << 
"Sorted total order index set (dimension = " << 
setup.d
 
  110         << 
", order = " << 
setup.p << 
"):" << std::endl;
 
  111     std::copy(sortedIndexSet.begin(), sortedIndexSet.end(), out_iterator);
 
  114     iterator prev = sortedIndexSet.begin();
 
  115     iterator curr = prev; ++curr;
 
  116     while (curr != sortedIndexSet.end()) {
 
  120       while (i < 
setup.d && order_prev == order_curr) {
 
  121         order_prev -= (*prev)[i];
 
  122         order_curr -= (*curr)[i];
 
  125       if (order_prev >= order_curr) {
 
  126         out << 
"previous index " << *prev << 
" and current index " 
  127             << *curr << 
" are out of order" << std::endl;
 
  140     typedef index_set_type::multiindex_type multiindex_type;
 
  142     typedef std::set<multiindex_type, less_type> multiindex_set;
 
  143     typedef multiindex_set::iterator iterator;
 
  145     multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end());
 
  148     std::ostream_iterator<multiindex_type> out_iterator(out, 
"\n");
 
  149     out << std::endl << 
"Sorted lexicographic index set (dimension = " 
  150         << 
setup.d << 
", order = " << 
setup.p << 
"):" << std::endl;
 
  151     std::copy(sortedIndexSet.begin(), sortedIndexSet.end(), out_iterator);
 
  154     iterator prev = sortedIndexSet.begin();
 
  155     iterator curr = prev; ++curr;
 
  156     while (curr != sortedIndexSet.end()) {
 
  158       while (i < 
setup.d && (*prev)[i] == (*curr)[i]) ++i;
 
  159       if (i == 
setup.d || (*prev)[i] >= (*curr)[i]) {
 
  160         out << 
"previous index " << *prev << 
" and current index " 
  161             << *curr << 
" are out of order" << std::endl;
 
  189     term_type a(2), b(2);
 
  191     a[0] = -0.774597; a[1] = -0.774597;
 
  192     b[0] = -0.774597; b[1] = 0.0;
 
  203     typedef index_set_type::multiindex_type multiindex_type;
 
  204     typedef index_set_type::iterator iterator;
 
  208     out << std::endl << 
"Total order index set (dimension = " << 
setup.d
 
  209         << 
", order = " << 
setup.p << 
"):" << std::endl;
 
  210     std::ostream_iterator<multiindex_type> out_iterator(out, 
"\n");
 
  211     std::copy(indexSet.begin(), indexSet.end(), out_iterator);
 
  214     for (iterator i=indexSet.begin(); i!=indexSet.end(); ++i) {
 
  215       if (i->order() < 0 || i->order() > 
setup.p) {
 
  216         out << 
"index " << *i << 
" does not lie in total order set! " 
  225     typedef std::set<multiindex_type, less_type> multiindex_set;
 
  226     multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end());
 
  228     out << 
"sorted index set size = " << sortedIndexSet.size() << std::endl;
 
  229     out << 
"expected index set size = " 
  231     if (static_cast<ordinal_type>(sortedIndexSet.size()) !=
 
  237                      AnisotropicTotalOrderIndexSet ) {
 
  242     typedef index_set_type::multiindex_type multiindex_type;
 
  243     typedef index_set_type::iterator iterator;
 
  244     multiindex_type upper(
setup.d);
 
  247     index_set_type indexSet(
setup.p, upper);
 
  250     out << std::endl << 
"Anisotropic total order index set (dimension = " 
  251         << 
setup.d << 
", order = " << 
setup.p << 
", and component orders = " 
  252         << upper << 
"):" << std::endl;
 
  253     std::ostream_iterator<multiindex_type> out_iterator(out, 
"\n");
 
  254     std::copy(indexSet.begin(), indexSet.end(), out_iterator);
 
  257     for (iterator i=indexSet.begin(); i!=indexSet.end(); ++i) {
 
  258       if (i->order() < 0 || i->order() > 
setup.p || !i->termWiseLEQ(upper)) {
 
  259         out << 
"index " << *i << 
" does not lie in total order set! " 
  292     typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type;
 
  294     basis_set_type basis_set;
 
  295     basis_map_type basis_map;
 
  297       indexSet, basis_set, basis_map);
 
  308                           static_cast<ordinal_type>(basis_map.size()),
 
  311                           static_cast<ordinal_type>(terms.
size()),
 
  316     std::ostream_iterator<ordinal_type> out_iterator(out, 
" ");
 
  320       out << 
"term " << basis_map[i] << 
" == " << terms[i] << 
" : ";
 
  321       bool is_equal = 
true;
 
  323         is_equal = is_equal && terms[i][
j] == basis_map[i][
j];
 
  325         out << 
"passed" << std::endl;
 
  327         out << 
"failed" << std::endl;
 
  347     typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type;
 
  349     basis_set_type basis_set;
 
  350     basis_map_type basis_map;
 
  352       indexSet, basis_set, basis_map);
 
  361                           static_cast<ordinal_type>(basis_map.size()),
 
  366     std::ostream_iterator<ordinal_type> out_iterator(out, 
" ");
 
  370       out << 
"term " << basis_map[i] << 
" <= " << 
setup.p << 
" : ";
 
  373         is_less = is_less && basis_map[i][
j] <= 
setup.p;
 
  375         out << 
"passed" << std::endl;
 
  377         out << 
"failed" << std::endl;
 
  387   template <
typename ordinal_type>
 
  394     template <
typename term_type>
 
  404   template <
typename basis_set_type>
 
  411     template <
typename term_type>
 
  426     index_set_type indexSet(dim, 0, order);
 
  431     typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type;
 
  433     basis_set_type basis_set;
 
  434     basis_map_type basis_map;
 
  436       indexSet, basis_set, basis_map);
 
  448       Stokhos::ProductBasisUtils::computeTripleProductTensor<ordinal_type,value_type>(bases, basis_set, basis_map, pred, pred);
 
  453       basis->computeTripleProductTensor();
 
  460     for (Cijk_type::k_iterator k_it=Cijk2->k_begin();
 
  461          k_it!=Cijk2->k_end(); ++k_it) {
 
  462       int k = Stokhos::index(k_it);
 
  463       for (Cijk_type::kj_iterator j_it = Cijk2->j_begin(k_it);
 
  464            j_it != Cijk2->j_end(k_it); ++j_it) {
 
  465         int j = Stokhos::index(j_it);
 
  466         for (Cijk_type::kji_iterator i_it = Cijk2->i_begin(j_it);
 
  467              i_it != Cijk2->i_end(j_it); ++i_it) {
 
  468           int i = Stokhos::index(i_it);
 
  469           double c = Cijk->getValue(i,j,k);
 
  470           double c2 = Stokhos::value(i_it);
 
  476                 << 
"Check: rel_err( C(" << i << 
"," << j << 
"," << k << 
") )" 
  477                 << 
" = " << 
"rel_err( " << c << 
", " << c2 << 
" ) = " << err
 
  478                 << 
" <= " << tol << 
" : ";
 
  479             if (s) out << 
"Passed.";
 
  480             else out << 
"Failed!";
 
  483           success = success && s;
 
  498     index_set_type indexSet(dim, 0, order);
 
  503     typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type;
 
  505     basis_set_type basis_set;
 
  506     basis_map_type basis_map;
 
  508       indexSet, basis_set, basis_map);
 
  520       Stokhos::ProductBasisUtils::computeTripleProductTensorNew<ordinal_type,value_type>(bases, basis_set, basis_map, pred, pred, 
false);
 
  525       basis->computeTripleProductTensor();
 
  532     for (Cijk_type::k_iterator k_it=Cijk2->k_begin();
 
  533          k_it!=Cijk2->k_end(); ++k_it) {
 
  534       int k = Stokhos::index(k_it);
 
  535       for (Cijk_type::kj_iterator j_it = Cijk2->j_begin(k_it);
 
  536            j_it != Cijk2->j_end(k_it); ++j_it) {
 
  537         int j = Stokhos::index(j_it);
 
  538         for (Cijk_type::kji_iterator i_it = Cijk2->i_begin(j_it);
 
  539              i_it != Cijk2->i_end(j_it); ++i_it) {
 
  540           int i = Stokhos::index(i_it);
 
  541           double c = Cijk->getValue(i,j,k);
 
  542           double c2 = Stokhos::value(i_it);
 
  548                 << 
"Check: rel_err( C(" << i << 
"," << j << 
"," << k << 
") )" 
  549                 << 
" = " << 
"rel_err( " << c << 
", " << c2 << 
" ) = " << err
 
  550                 << 
" <= " << tol << 
" : ";
 
  551             if (s) out << 
"Passed.";
 
  552             else out << 
"Failed!";
 
  555           success = success && s;
 
  593     for (Cijk_type::k_iterator k_it=Cijk2->k_begin();
 
  594          k_it!=Cijk2->k_end(); ++k_it) {
 
  595       int k = Stokhos::index(k_it);
 
  596       for (Cijk_type::kj_iterator j_it = Cijk2->j_begin(k_it);
 
  597            j_it != Cijk2->j_end(k_it); ++j_it) {
 
  598         int j = Stokhos::index(j_it);
 
  599         for (Cijk_type::kji_iterator i_it = Cijk2->i_begin(j_it);
 
  600              i_it != Cijk2->i_end(j_it); ++i_it) {
 
  601           int i = Stokhos::index(i_it);
 
  602           double c = Cijk->getValue(i,j,k);
 
  603           double c2 = Stokhos::value(i_it);
 
  609                 << 
"Check: rel_err( C(" << i << 
"," << j << 
"," << k << 
") )" 
  610                 << 
" = " << 
"rel_err( " << c << 
", " << c2 << 
" ) = " << err
 
  611                 << 
" <= " << tol << 
" : ";
 
  612             if (s) out << 
"Passed.";
 
  613             else out << 
"Failed!";
 
  616           success = success && s;
 
  627     typedef index_set_type::multiindex_type multiindex_type;
 
  629     typedef std::set<multiindex_type, less_type> multiindex_set;
 
  630     typedef multiindex_set::iterator iterator;
 
  632     multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end());
 
  636     iterator i = sortedIndexSet.begin();
 
  638     while (i != sortedIndexSet.end()) {
 
  640       out << *i << 
":  index = " << idx << 
" mapped index = " << idx_mapping
 
  642       if (idx == idx_mapping)
 
  659     typedef index_set_type::multiindex_type multiindex_type;
 
  661     typedef std::set<multiindex_type, less_type> multiindex_set;
 
  662     typedef multiindex_set::iterator iterator;
 
  664     multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end());
 
  668     iterator i = sortedIndexSet.begin();
 
  670     while (i != sortedIndexSet.end()) {
 
  672       out << *i << 
":  index = " << idx << 
" mapped index = " << idx_mapping
 
  674       if (idx == idx_mapping)
 
  693     typedef index_set_type::multiindex_type multiindex_type;
 
  695     typedef std::set<multiindex_type, less_type> multiindex_set;
 
  696     index_set_type indexSet(d, 0, p);
 
  697     multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end());
 
  701     multiindex_type index(d), num_terms(d), orders(d,p);
 
  710       while (dim > 0 && index[dim] > orders[dim]) {
 
  716         orders[i] = orders[i-1] - index[i-1];
 
  718       if (index[dim] > orders[dim])
 
  732         out << index << 
":  index = " << idx << 
" mapped index = " << I
 
A functor for comparing floating-point numbers to some tolerance. 
 
ordinal_type factorial(const ordinal_type &n)
 
const basis_set_type & basis_set
 
ordinal_type n_choose_k(const ordinal_type &n, const ordinal_type &k)
Compute bionomial coefficient (n ; k) = n!/( k! (n-k)! ) 
 
Teuchos::RCP< Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensorLTO(const TotalOrderBasis< ordinal_type, value_type, LexographicLess< MultiIndex< ordinal_type > > > &product_basis, bool symmetric=false)
 
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
 
Container storing a term in a generalized tensor product. 
 
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format. 
 
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensor() const 
Compute triple product tensor. 
 
TEUCHOS_UNIT_TEST(Stokhos_ProductBasisUtils, NChooseK)
 
static void buildProductBasis(const index_set_type &index_set, const growth_rule_type &growth_rule, basis_set_type &basis_set, basis_map_type &basis_map)
Generate a product basis from an index set. 
 
A comparison functor implementing a strict weak ordering based total-order ordering, recursive on the dimension. 
 
UnitTestSetup< ordinal_type, value_type > setup
 
total_order_predicate(ordinal_type dim_, ordinal_type order_)
 
static int runUnitTestsFromMain(int argc, char *argv[])
 
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
 
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
 
bool operator()(const term_type &term) const 
 
scalar_type quad_func2(const Teuchos::Array< scalar_type > &x)
 
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
 
general_predicate(const basis_set_type &basis_set_)
 
An anisotropic total order index set. 
 
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
 
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
 
Legendre polynomial basis. 
 
Stokhos::Sparse3Tensor< int, double > Cijk_type
 
scalar_type quad_func1(const Teuchos::Array< scalar_type > &x)
 
int main(int argc, char **argv)
 
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
 
An isotropic total order index set. 
 
A comparison functor implementing a strict weak ordering based lexographic ordering. 
 
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
 
bool operator()(const term_type &term) const 
 
ordinal_type lexicographicMapping(const Stokhos::MultiIndex< ordinal_type > &index, ordinal_type max_order)
 
A tensor product index set. 
 
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< RD, RP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value >::type sum(const Kokkos::View< RD, RP...> &r, const Kokkos::View< XD, XP...> &x)
 
static ordinal_type compute_terms(ordinal_type p, ordinal_type d, ordinal_type &sz, Teuchos::Array< MultiIndex< ordinal_type > > &terms, Teuchos::Array< ordinal_type > &num_terms)
Compute the 2-D array of basis terms which maps a basis index into the orders for each basis dimensio...
 
ordinal_type totalOrderMapping(const Stokhos::MultiIndex< ordinal_type > &index)