static void RemoveRegFromLRBlock(regs *reg) { if(elementsInSet(reg->reglives.usedpCodes) == 2) { pCode *pc1; /* only continue if there are just 2 uses of the register, * in in the local *entry* block and one in the local *exit* block */ /* search for entry block */ pc1 = indexSet(reg->reglives.usedpCodes, 1); if(insideLRBlock( pc1 )) { fprintf(stderr, "usedpCodes[0] inside LR block\n"); deleteSetItem(&pc1->pb->tregisters, PCOR(PCI(pc1)->pcop)->r); Remove1pcode(pc1, reg); } pc1 = indexSet(reg->reglives.usedpCodes, 0); if(insideLRBlock( pc1 )) { fprintf(stderr, "usedpCodes[1] inside LR block\n"); deleteSetItem(&pc1->pb->tregisters, PCOR(PCI(pc1)->pcop)->r); Remove1pcode(pc1, reg); } /* remove r0x00 */ reg->isFree = 1; reg->wasUsed = 0; } }
void CoinPackedVector::append(const CoinPackedVectorBase & caboose) { const int cs = caboose.getNumElements(); if (cs == 0) { return; } if (testForDuplicateIndex()) { // Just to initialize the index heap indexSet("append (1st call)", "CoinPackedVector"); } const int s = nElements_; // Make sure there is enough room for the caboose if ( capacity_ < s + cs) reserve(CoinMax(s + cs, 2 * capacity_)); const int * cind = caboose.getIndices(); const double * celem = caboose.getElements(); CoinDisjointCopyN(cind, cs, indices_ + s); CoinDisjointCopyN(celem, cs, elements_ + s); CoinIotaN(origIndices_ + s, cs, s); nElements_ += cs; if (testForDuplicateIndex()) { std::set<int>& is = *indexSet("append (2nd call)", "CoinPackedVector"); for (int i = 0; i < cs; ++i) { if (!is.insert(cind[i]).second) throw CoinError("duplicate index", "append", "CoinPackedVector"); } } }
TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, LexographicLess ) { success = true; // Build sorted index set of dimension d and order p typedef Stokhos::TotalOrderIndexSet<ordinal_type> index_set_type; typedef index_set_type::multiindex_type multiindex_type; typedef Stokhos::LexographicLess<multiindex_type> less_type; typedef std::set<multiindex_type, less_type> multiindex_set; typedef multiindex_set::iterator iterator; index_set_type indexSet(setup.d, 0, setup.p); multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end()); // Print sorted index set std::ostream_iterator<multiindex_type> out_iterator(out, "\n"); out << std::endl << "Sorted lexicographic index set (dimension = " << setup.d << ", order = " << setup.p << "):" << std::endl; std::copy(sortedIndexSet.begin(), sortedIndexSet.end(), out_iterator); // Ensure orders of each index are increasing iterator prev = sortedIndexSet.begin(); iterator curr = prev; ++curr; while (curr != sortedIndexSet.end()) { ordinal_type i = 0; while (i < setup.d && (*prev)[i] == (*curr)[i]) ++i; if (i == setup.d || (*prev)[i] >= (*curr)[i]) { out << "previous index " << *prev << " and current index " << *curr << " are out of order" << std::endl; success = false; } prev = curr; ++curr; } }
TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, LexographicMapping ) { success = true; // Build sorted index set of dimension d and order p typedef Stokhos::TotalOrderIndexSet<ordinal_type> index_set_type; typedef index_set_type::multiindex_type multiindex_type; typedef Stokhos::LexographicLess<multiindex_type> less_type; typedef std::set<multiindex_type, less_type> multiindex_set; typedef multiindex_set::iterator iterator; index_set_type indexSet(setup.d, 0, setup.p); multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end()); // Loop over each index set element and test if mapping // computes proper global index iterator i = sortedIndexSet.begin(); ordinal_type idx = 0; while (i != sortedIndexSet.end()) { ordinal_type idx_mapping = lexicographicMapping(*i,setup.p); out << *i << ": index = " << idx << " mapped index = " << idx_mapping << ": "; if (idx == idx_mapping) out << "passed"; else { out << "failed"; success = false; } out << std::endl; ++i; ++idx; } }
void CoinPackedVectorBase::duplicateIndex(const char *methodName, const char *className) const { if (testForDuplicateIndex()) indexSet(methodName, className); testedDuplicateIndex_ = true; }
bool CoinPackedVectorBase::isExistingIndex(int i) const { if (!testedDuplicateIndex_) duplicateIndex("indexExists", "CoinPackedVectorBase"); const std::set< int > &sv = *indexSet("indexExists", "CoinPackedVectorBase"); return sv.find(i) != sv.end(); }
TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, TotalOrderBasis ) { success = true; // Build index set of dimension d and order p typedef Stokhos::TotalOrderIndexSet<ordinal_type> index_set_type; typedef index_set_type::multiindex_type multiindex_type; typedef index_set_type::iterator iterator; index_set_type indexSet(setup.d, 0, setup.p); // Build total-order basis from index set typedef Stokhos::TensorProductElement<ordinal_type,ordinal_type> coeff_type; typedef Stokhos::TotalOrderLess<coeff_type> less_type; typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type; typedef basis_set_type::iterator basis_set_iterator; typedef Teuchos::Array<coeff_type> basis_map_type; basis_set_type basis_set; basis_map_type basis_map; Stokhos::ProductBasisUtils::buildProductBasis( indexSet, basis_set, basis_map); // Build total-order basis directly ordinal_type sz; Teuchos::Array< Stokhos::MultiIndex<ordinal_type> > terms; Teuchos::Array<ordinal_type> num_terms; Stokhos::CompletePolynomialBasisUtils<ordinal_type,value_type>:: compute_terms(setup.p, setup.d, sz, terms, num_terms); // Check sizes TEUCHOS_TEST_EQUALITY(static_cast<ordinal_type>(basis_set.size()), static_cast<ordinal_type>(basis_map.size()), out, success); TEUCHOS_TEST_EQUALITY(static_cast<ordinal_type>(basis_set.size()), static_cast<ordinal_type>(terms.size()), out, success); TEUCHOS_TEST_EQUALITY(sz, static_cast<ordinal_type>(terms.size()), out, success); std::ostream_iterator<ordinal_type> out_iterator(out, " "); for (ordinal_type i=0; i<sz; i++) { // Verify terms match out << "term " << basis_map[i] << " == " << terms[i] << " : "; bool is_equal = true; for (ordinal_type j=0; j<setup.d; j++) is_equal = is_equal && terms[i][j] == basis_map[i][j]; if (is_equal) out << "passed" << std::endl; else { out << "failed" << std::endl; success = false; } // Verify global index mapping matches TEUCHOS_TEST_EQUALITY(basis_set[basis_map[i]], i, out, success); } }
TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, TensorProductBasis ) { success = true; // Build index set of dimension d and order p typedef Stokhos::TensorProductIndexSet<ordinal_type> index_set_type; typedef index_set_type::multiindex_type multiindex_type; typedef index_set_type::iterator iterator; index_set_type indexSet(setup.d, 0, setup.p); // Build total-order basis from index set typedef Stokhos::TensorProductElement<ordinal_type,ordinal_type> coeff_type; typedef Stokhos::TotalOrderLess<coeff_type> less_type; typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type; typedef basis_set_type::iterator basis_set_iterator; typedef Teuchos::Array<coeff_type> basis_map_type; basis_set_type basis_set; basis_map_type basis_map; Stokhos::ProductBasisUtils::buildProductBasis( indexSet, basis_set, basis_map); // Compute expected size ordinal_type sz = 1; for (ordinal_type i=0; i<setup.d; ++i) sz *= setup.p+1; // Check sizes TEUCHOS_TEST_EQUALITY(static_cast<ordinal_type>(basis_set.size()), static_cast<ordinal_type>(basis_map.size()), out, success); TEUCHOS_TEST_EQUALITY(sz, static_cast<ordinal_type>(basis_set.size()), out, success); std::ostream_iterator<ordinal_type> out_iterator(out, " "); for (ordinal_type i=0; i<sz; i++) { // Verify terms match out << "term " << basis_map[i] << " <= " << setup.p << " : "; bool is_less = true; for (ordinal_type j=0; j<setup.d; j++) is_less = is_less && basis_map[i][j] <= setup.p; if (is_less) out << "passed" << std::endl; else { out << "failed" << std::endl; success = false; } // Verify global index mapping matches TEUCHOS_TEST_EQUALITY(basis_set[basis_map[i]], i, out, success); } }
std::vector<int> permuteInsertionDomainIndices(const std::vector<int> &domainIndices, const Dune::GridFactory<DuneGrid> &factory, const DuneGrid &grid) { std::vector<int> output(domainIndices.size()); auto view = grid.leafGridView(); const auto &indexSet = view.indexSet(); for (auto it = grid.template leafbegin<0>(); it != grid.template leafend<0>(); ++it) { const typename DuneGrid::template Codim<0>::Entity &element = *it; int insertionIndex = factory.insertionIndex(element); output[indexSet.index(element)] = domainIndices[insertionIndex]; } return output; }
TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, AnisotropicTotalOrderIndexSet ) { success = true; // Build index set of dimension d and order p typedef Stokhos::AnisotropicTotalOrderIndexSet<ordinal_type> index_set_type; typedef index_set_type::multiindex_type multiindex_type; typedef index_set_type::iterator iterator; multiindex_type upper(setup.d); for (ordinal_type i=0; i<setup.d; ++i) upper[i] = i+1; index_set_type indexSet(setup.p, upper); // Print index set out << std::endl << "Anisotropic total order index set (dimension = " << setup.d << ", order = " << setup.p << ", and component orders = " << upper << "):" << std::endl; std::ostream_iterator<multiindex_type> out_iterator(out, "\n"); std::copy(indexSet.begin(), indexSet.end(), out_iterator); // Verify each index lies appropriatly in the set for (iterator i=indexSet.begin(); i!=indexSet.end(); ++i) { if (i->order() < 0 || i->order() > setup.p || !i->termWiseLEQ(upper)) { out << "index " << *i << " does not lie in total order set! " << std::endl; success = false; } } // Need to figure out how to compute the size of such an index set /* // Put indices in sorted container -- this will ensure there are no // duplicates, if we get the right size typedef Stokhos::TotalOrderLess<multiindex_type> less_type; typedef std::set<multiindex_type, less_type> multiindex_set; multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end()); out << "sorted index set size = " << sortedIndexSet.size() << std::endl; out << "expected index set size = " << Stokhos::n_choose_k(setup.p+setup.d,setup.d) << std::endl; if (static_cast<ordinal_type>(sortedIndexSet.size()) != Stokhos::n_choose_k(setup.p+setup.d,setup.d)) success = false; */ }
void CoinPackedVector::insert( int index, double element ) { const int s = nElements_; if (testForDuplicateIndex()) { std::set<int>& is = *indexSet("insert", "CoinPackedVector"); if (! is.insert(index).second) throw CoinError("Index already exists", "insert", "CoinPackedVector"); } if( capacity_ <= s ) { reserve( CoinMax(5, 2*capacity_) ); assert( capacity_ > s ); } indices_[s] = index; elements_[s] = element; origIndices_[s] = s; ++nElements_; }
double CoinPackedVectorBase::operator[](int i) const { if (!testedDuplicateIndex_) duplicateIndex("operator[]", "CoinPackedVectorBase"); // Get a reference to a map of full storage indices to // packed storage location. const std::set< int > &sv = *indexSet("operator[]", "CoinPackedVectorBase"); #if 1 if (sv.find(i) == sv.end()) return 0.0; return getElements()[findIndex(i)]; #else // LL: suggested change, somthing is wrong with this const size_t ind = std::distance(sv.begin(), sv.find(i)); return (ind == sv.size()) ? 0.0 : getElements()[ind]; #endif }
void testRangeConstructor() { std::vector<int> myInts = {1, 2, 3, 4, 5}; IndexableSet<int> indexSet(myInts.begin() , myInts.end()); ASSERT_EQUAL(3, indexSet[2]); }
SICALLBACK aaOcean_Evaluate( ICENodeContext& in_ctxt ) { aaOcean *pOcean = (aaOcean *)(CValue::siPtrType)in_ctxt.GetUserData(); CIndexSet indexSet(in_ctxt, ID_IN_PointID ); CDataArrayLong PointID(in_ctxt, ID_IN_PointID ); CDataArrayBool bEnable(in_ctxt, ID_IN_ENABLE); CDataArrayFloat uCoord(in_ctxt, ID_IN_U); CDataArrayFloat vCoord(in_ctxt, ID_IN_V); CDataArrayBool enableFoam( in_ctxt, ID_IN_ENABLEFOAM); CDataArrayMatrix4f transform(in_ctxt, ID_IN_TRANSFORM); const int count = PointID.GetCount(); float worldSpaceVec[3] = {0.0f, 0.0f, 0.0f}; float localSpaceVec[3] = {0.0f, 0.0f, 0.0f}; int transformArraySize = 0; bool transformSingleton = TRUE; if(transform.GetCount() > 1) transformSingleton = FALSE; ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( ); switch( out_portID ) { case ID_OUT_OCEAN: { CDataArrayVector3f outData( in_ctxt ); if(bEnable[0]) { #pragma omp parallel for private(worldSpaceVec, localSpaceVec) for(int i = 0; i<count; ++i) { // get ocean displacement vector worldSpaceVec[1] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eHEIGHTFIELD); if(pOcean->isChoppy()) { worldSpaceVec[0] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eCHOPX); worldSpaceVec[2] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eCHOPZ); } // multiply displacement vector by input transform matrix if(!transformSingleton) transformArraySize = i; multiplyMatrix(&worldSpaceVec[0], &localSpaceVec[0], transform, transformArraySize); outData[i].PutX(localSpaceVec[0]); outData[i].PutY(localSpaceVec[1]); outData[i].PutZ(localSpaceVec[2]); outData[i].PutX(worldSpaceVec[0]); outData[i].PutY(worldSpaceVec[1]); outData[i].PutZ(worldSpaceVec[2]); } } else { #pragma omp parallel for for(int i = 0; i<count; ++i) { outData[i].PutX(0.f); outData[i].PutY(0.f); outData[i].PutZ(0.f); } } } break; case ID_OUT_FOAM: { if(pOcean->isChoppy() && bEnable[0] && enableFoam[0]) { CDataArrayFloat outData( in_ctxt ); // output raw (unscaled) foam in ICE deformer #pragma omp parallel for for(int i = 0; i<count; ++i) outData[i] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eFOAM); } } break; case ID_OUT_EIGEN_MINUS: { CDataArrayVector3f outData( in_ctxt ); if(pOcean->isChoppy() && bEnable[0] && enableFoam[0]) { #pragma omp parallel for private(worldSpaceVec, localSpaceVec) for(int i = 0; i<count; ++i) { worldSpaceVec[0] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eEIGENMINUSX); worldSpaceVec[2] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eEIGENMINUSZ); multiplyMatrix(&worldSpaceVec[0], &localSpaceVec[0], transform, transformArraySize); outData[i].PutX(localSpaceVec[0]); outData[i].PutY(0.0f); outData[i].PutZ(localSpaceVec[2]); } } else { #pragma omp parallel for for(int i = 0; i<count; ++i){ outData[i].PutX(0);outData[i].PutY(0);outData[i].PutZ(0);} } } break; case ID_OUT_EIGEN_PLUS: { CDataArrayVector3f outData( in_ctxt ); if(pOcean->isChoppy() && bEnable[0] && enableFoam[0]) { #pragma omp parallel for private(worldSpaceVec, localSpaceVec) for(int i = 0; i<count; ++i) { worldSpaceVec[0] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eEIGENPLUSX); worldSpaceVec[2] = pOcean->getOceanData(uCoord[i], vCoord[i], aaOcean::eEIGENPLUSZ); multiplyMatrix(&worldSpaceVec[0], &localSpaceVec[0], transform, transformArraySize); outData[i].PutX(localSpaceVec[0]); outData[i].PutY(0.0f); outData[i].PutZ(localSpaceVec[2]); } } else { #pragma omp parallel for for(int i = 0; i<count; ++i){ outData[i].PutX(0); outData[i].PutY(0); outData[i].PutZ(0);} } } break; } return CStatus::OK; }
TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, LexographicMapping2 ) { success = true; // Build sorted index set of dimension d and order p ordinal_type d = setup.d; ordinal_type p = setup.p; typedef Stokhos::TotalOrderIndexSet<ordinal_type> index_set_type; typedef index_set_type::multiindex_type multiindex_type; typedef Stokhos::LexographicLess<multiindex_type> less_type; typedef std::set<multiindex_type, less_type> multiindex_set; typedef multiindex_set::iterator iterator; index_set_type indexSet(d, 0, p); multiindex_set sortedIndexSet(indexSet.begin(), indexSet.end()); // Loop over lexicographically sorted multi-indices, compute global index // using combinatorial number system, and test if it is correct multiindex_type index(d), num_terms(d), orders(d,p); bool stop = false; ordinal_type idx = 0; index[d-1] = -1; num_terms[d-1] = -1; while (!stop) { // Increment index to next lexicographic term ordinal_type dim = d-1; ++index[dim]; while (dim > 0 && index[dim] > orders[dim]) { index[dim] = 0; --dim; ++index[dim]; } for (ordinal_type i=dim+1; i<d; ++i) orders[i] = orders[i-1] - index[i-1]; if (index[dim] > orders[dim]) stop = true; else { // Update num_terms: num_terms[dim] = number of terms with // order < index[dim] and dimension d-dim-1 num_terms[dim] += Stokhos::n_choose_k(orders[dim]-index[dim]+d-dim, d-dim-1); for (ordinal_type i=dim+1; i<d; ++i) num_terms[i] = 0; // Compute global index ordinal_type I = num_terms.order(); //ordinal_type I = lexicographicMapping(index, p); out << index << ": index = " << idx << " mapped index = " << I << ": "; if (idx == I) out << "passed"; else { out << "failed"; success = false; } out << std::endl; } ++idx; } }
TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, TotalOrderSparse3TensorNew ) { success = true; // ordinal_type dim = setup.d; // ordinal_type order = setup.p; ordinal_type dim = 2; ordinal_type order = 3; // Build index set of dimension d and order p typedef Stokhos::TotalOrderIndexSet<ordinal_type> index_set_type; typedef index_set_type::multiindex_type multiindex_type; typedef index_set_type::iterator iterator; index_set_type indexSet(dim, 0, order); // Build total-order basis from index set typedef Stokhos::TensorProductElement<ordinal_type,ordinal_type> coeff_type; typedef Stokhos::TotalOrderLess<coeff_type> less_type; typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type; typedef basis_set_type::iterator basis_set_iterator; typedef Teuchos::Array<coeff_type> basis_map_type; basis_set_type basis_set; basis_map_type basis_map; Stokhos::ProductBasisUtils::buildProductBasis( indexSet, basis_set, basis_map); // 1-D bases Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<ordinal_type,value_type> > > bases(dim); for (ordinal_type i=0; i<dim; i++) bases[i] = Teuchos::rcp(new Stokhos::LegendreBasis<ordinal_type,value_type>(order, true)); // Build Cijk tensor typedef Stokhos::Sparse3Tensor<ordinal_type,value_type> Cijk_type; total_order_predicate<ordinal_type> pred(dim, order); //general_predicate<basis_set_type> pred(basis_set); Teuchos::RCP<Cijk_type> Cijk = Stokhos::ProductBasisUtils::computeTripleProductTensorNew<ordinal_type,value_type>(bases, basis_set, basis_map, pred, pred, false); // Build Cijk tensor using original approach Teuchos::RCP<const Stokhos::CompletePolynomialBasis<ordinal_type,value_type> > basis = Teuchos::rcp(new Stokhos::CompletePolynomialBasis<ordinal_type,value_type>(bases)); Teuchos::RCP<Cijk_type> Cijk2 = basis->computeTripleProductTensor(); // Check sizes TEUCHOS_TEST_EQUALITY(Cijk->num_k(), Cijk2->num_k(), out, success); TEUCHOS_TEST_EQUALITY(Cijk->num_entries(), Cijk2->num_entries(), out, success); // Check tensors match for (Cijk_type::k_iterator k_it=Cijk2->k_begin(); k_it!=Cijk2->k_end(); ++k_it) { int k = Stokhos::index(k_it); for (Cijk_type::kj_iterator j_it = Cijk2->j_begin(k_it); j_it != Cijk2->j_end(k_it); ++j_it) { int j = Stokhos::index(j_it); for (Cijk_type::kji_iterator i_it = Cijk2->i_begin(j_it); i_it != Cijk2->i_end(j_it); ++i_it) { int i = Stokhos::index(i_it); double c = Cijk->getValue(i,j,k); double c2 = Stokhos::value(i_it); double tol = setup.atol + c2*setup.rtol; double err = std::abs(c-c2); bool s = err < tol; if (!s) { out << std::endl << "Check: rel_err( C(" << i << "," << j << "," << k << ") )" << " = " << "rel_err( " << c << ", " << c2 << " ) = " << err << " <= " << tol << " : "; if (s) out << "Passed."; else out << "Failed!"; out << std::endl; } success = success && s; } } } }