void processResData_ByRotID( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib ) { // Sort the data to increase efficiency below std::stable_sort( data.begin(), data.end(), sortPsi); std::stable_sort( data.begin(), data.end(), sortPhi); std::stable_sort( data.begin(), data.end(), sortRotID); ContainerType subdata; while( true ) { if( data.size() > 0 && (subdata.size() == 0 || subdata[0].rotID.compare( data.back().rotID,0,4,0 )) ) { subdata.push_back( data.back() ); data.erase(data.end()-1); // rob the end, not the start (ContainerType<> perfomance reasons!) } else { ASSERT( data.size() == (36*36), ParseException, "Assumption error!"); ASSERT( data[0].phi == -180.0 && data[0].psi == -180.0, ParseException, "Wrong phi/psi"); for( size_t j = 1; j < data.size(); j++ ) { ASSERT( data[j].phi == (-180.0+(j/36)*10) && data[j].psi == (-180.0+(j%36)*10), ParseException, "Wrong phi/psi"); } processData( resName, subdata, _RotLib, 40.0 ); // 40 degree tollerance delta from data[0] subdata.clear(); if( data.size() == 0 ) { return; } } } }
inline void checkInOrder(ContainerType & c, CompareType compare) { typedef typename ContainerType::iterator IteratorType; IteratorType it; for(it = c.begin(); it != c.end(); ++it) { IteratorType itNext = it; ++itNext; if(itNext != c.end()) { GCHECK(compare(*it, *itNext)); } } }
void append(ContainerType* pContainer, const ContainerType& other) { pContainer->insert( pContainer->end(), other.begin(), other.end()); }
inline void clearCointainerOfPointers(ContainerType& container_) { typename ContainerType::iterator it = container_.begin(); while (it != container_.end()) { delete *it; ++it; } container_.clear(); }
void evalRPN(ContainerType& sVec){ stack <string> numbers; int op1,op2; strVecIter sIter = sVec.begin(); while (sIter != sVec.end()){ if (isInteger(*sIter)){ //cout << *sIter <<" is integer" << endl; numbers.push(*sIter); } else { switch (whichOp(*sIter )) { case 1: //cout << "+ operand" << endl; op1=atoi( numbers.top().c_str() ); numbers.pop(); op2=atoi( numbers.top().c_str() ); numbers.pop(); numbers.push( to_string(op2 + op1)); break; case 2: //cout << "- operand" << endl; op1=atoi( numbers.top().c_str() ); numbers.pop(); op2=atoi( numbers.top().c_str() ); numbers.pop(); numbers.push( to_string(op2 - op1)); break; case 3: //cout << "* operand" << endl; op1=atoi( numbers.top().c_str() ); numbers.pop(); op2=atoi( numbers.top().c_str() ); numbers.pop(); numbers.push( to_string(op2 * op1)); break; case 4: //cout << "/ operand" << endl; op1=atoi( numbers.top().c_str() ); numbers.pop(); op2=atoi( numbers.top().c_str() ); numbers.pop(); numbers.push( to_string(op2 / op1)); break; default: cout << "ERROR"; break; } } sIter++; } while (numbers.size()>0){ cout << numbers.top() << " " << endl; numbers.pop(); } }
void FromContainer(const ContainerType &in_container, const char *name_string = NULL) { typename ContainerType::const_iterator iter_b(in_container.begin()); typename ContainerType::const_iterator iter_e(in_container.end()); while (iter_b != iter_e) { Append(iter_b->c_str(), name_string); ++iter_b; } }
void TEST_EmitList(const ContainerType &data_list) { ContainerType::const_iterator iter_b(data_list.begin()); ContainerType::const_iterator iter_e(data_list.end()); for ( ; iter_b != iter_e; ++iter_b) std::cout << iter_b->ToStringTest() << std::endl; }
static void TEST_OutputContainer(const char *container_name, const ContainerType &the_cont) { std::cout << container_name << std::endl; std::cout << std::string(10, '-') << std::endl; std::copy(the_cont.begin(), the_cont.end(), std::ostream_iterator<ContainerType::value_type>(std::cout, "\n")); std::cout << std::string(10, '-') << std::endl; }
// This function is given an entire block of the same residue. The rotamerIDs will of course be different. void processResData( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib, bool switchImportMode ) { // Either there is something fundamental I don't understand, or ... // The dunbrack library has this really annoying thing whereby the 180 and -180 phi/psi torsions, // which are by definition the same thing, are both defined! // We only want one, as both represent the same 10 degree bin! data.erase(std::remove_if(data.begin(),data.end(),removeParseData),data.end()); if( switchImportMode ) { processResData_ByRotID(resName,data,_RotLib); } else { data.erase(std::remove_if(data.begin(),data.end(),removeLowPropensity),data.end()); processResData_ByChis(resName,data,_RotLib); } }
inline bool checkContainerSame(const ContainerType & c1, const ContainerType & c2) { typename ContainerType::const_iterator it1 = c1.begin(); typename ContainerType::const_iterator it2 = c2.begin(); while(it1 != c1.end() && it2 != c2.end()) { if(*it1 != *it2) { return false; } ++it1; ++it2; } if(it1 != c1.end() || it1 != c1.end()) { return false; } return true; }
/// Calculate residual weights for the next `robustifying` iteration. void calculate_residual_weights(const size_t n, const ContainerType& weights, ContainerType& resid_weights) { ValueType r; for (size_t i = 0; i < n; i++) { resid_weights[i] = std::abs(weights[i]); } // *********************************** // Compute pseudo-median (take average even if we have an odd number of // elements), following the original implementation. We could also use a // true median calculation here: // ValueType cmad = 6.0 * median(resid_weights.begin(), resid_weights.end()); // *********************************** size_t m1 = n / 2; // FORTRAN starts with one, CPP with zero // size_t m1 = 1 + n / 2; // original FORTRAN code // size_t m2 = n - m1 + 1; // see below, we don't explicitly sort but use max_element // Use nth element to find element m1, which produces a partially sorted // vector. This means we can get element m2 by looking for the maximum in the // remainder. typename ContainerType::iterator it_m1 = resid_weights.begin() + m1; std::nth_element(resid_weights.begin(), it_m1, resid_weights.end()); typename ContainerType::iterator it_m2 = std::max_element( resid_weights.begin(), it_m1); ValueType cmad = 3.0 * (*it_m1 + *it_m2); ValueType c9 = .999 * cmad; ValueType c1 = .001 * cmad; for (size_t i = 0; i < n; i++) { r = std::abs(weights[i]); if (r <= c1) { // near 0, avoid underflow resid_weights[i] = 1.0; } else if (r > c9) { // near 1, avoid underflow resid_weights[i] = 0.0; } else { resid_weights[i] = pow2(1.0 - pow2(r / cmad)); } } }
inline void checkContainerIteratorIncrement(ContainerType & container) { typename ContainerType::iterator it; it = container.begin(); //__asm int 3; it++; ++it; if(it == container.end()) { it = container.begin(); } }
void show_elements( ContainerType& cont, const string& prefix ) { cout << prefix << " : "; typename ContainerType::const_iterator iter = cont.begin(); typename ContainerType::const_iterator end = cont.end(); while( iter != end ) { cout << *iter << " "; ++iter; } cout << endl; }
ResultType convertObject(const ContainerType &v) { ResultType result(v.dimension()); typedef typename ResultType::ScalarType RScalar; typedef typename ContainerType::ScalarType CScalar; typename ResultType::iterator i = result.begin(); typename ContainerType::const_iterator b = v.begin(), e=v.end(); while(b!=e) { *i = Convert<RScalar,CScalar,(!capd::TypeTraits<RScalar>::isInterval && capd::TypeTraits<CScalar>::isInterval)>::convert(*b); ++i; ++b; } return result; }
void operator()(const ContainerType& new_bit) { for(typename ContainerType::const_iterator ci = new_bit.begin(); ci != new_bit.end(); ++ci) { my_result += *ci; } }
AlignmentElement::AlignmentElement(const ContainerType &alignInfo) { insert_iterator<ContainerType> insertIter( m_collection, m_collection.end() ); copy(alignInfo.begin(), alignInfo.end(), insertIter); };
void DataTest::testColumnList() { typedef std::list<int> ContainerType; typedef Column<ContainerType> ColumnType; MetaColumn mc(0, "mc", MetaColumn::FDT_DOUBLE, 2, 3, true); assert (mc.name() == "mc"); assert (mc.position() == 0); assert (mc.length() == 2); assert (mc.precision() == 3); assert (mc.type() == MetaColumn::FDT_DOUBLE); assert (mc.isNullable()); ContainerType* pData = new ContainerType; pData->push_back(1); pData->push_back(2); pData->push_back(3); pData->push_back(4); pData->push_back(5); ColumnType c(mc, pData); assert (c.rowCount() == 5); assert (c[0] == 1); assert (c[1] == 2); assert (c[2] == 3); assert (c[3] == 4); assert (c[4] == 5); assert (c.name() == "mc"); assert (c.position() == 0); assert (c.length() == 2); assert (c.precision() == 3); assert (c.type() == MetaColumn::FDT_DOUBLE); try { int i; i = c[100]; // to silence gcc fail ("must fail"); } catch (RangeException&) { } ColumnType c1 = c; assert (c1.rowCount() == 5); assert (c1[0] == 1); assert (c1[1] == 2); assert (c1[2] == 3); assert (c1[3] == 4); assert (c1[4] == 5); ColumnType c2(c1); assert (c2.rowCount() == 5); assert (c2[0] == 1); assert (c2[1] == 2); assert (c2[2] == 3); assert (c2[3] == 4); assert (c2[4] == 5); ContainerType vi; vi.assign(c.begin(), c.end()); assert (vi.size() == 5); ContainerType::const_iterator it = vi.begin(); ContainerType::const_iterator end = vi.end(); for (int i = 1; it != end; ++it, ++i) assert (*it == i); c.reset(); assert (c.rowCount() == 0); assert (c1.rowCount() == 0); assert (c2.rowCount() == 0); ContainerType* pV1 = new ContainerType; pV1->push_back(1); pV1->push_back(2); pV1->push_back(3); pV1->push_back(4); pV1->push_back(5); ContainerType* pV2 = new ContainerType; pV2->push_back(5); pV2->push_back(4); pV2->push_back(3); pV2->push_back(2); pV2->push_back(1); Column<ContainerType> c3(mc, pV1); Column<ContainerType> c4(mc, pV2); Poco::Data::swap(c3, c4); assert (c3[0] == 5); assert (c3[1] == 4); assert (c3[2] == 3); assert (c3[3] == 2); assert (c3[4] == 1); assert (c4[0] == 1); assert (c4[1] == 2); assert (c4[2] == 3); assert (c4[3] == 4); assert (c4[4] == 5); std::swap(c3, c4); assert (c3[0] == 1); assert (c3[1] == 2); assert (c3[2] == 3); assert (c3[3] == 4); assert (c3[4] == 5); assert (c4[0] == 5); assert (c4[1] == 4); assert (c4[2] == 3); assert (c4[3] == 2); assert (c4[4] == 1); }
static void map_func(ContainerType& container, Functor func) { for_each(container.begin(), container.end(), func); }
iterator end() { return _buffer.end(); }
TyErrorId extractConfigOptionListImpl( const AnnotatorContext& crclConfig, const UnicodeString* cpclConfigGroup, const ConfigOptionInfo::StOptionInfo& crclOptionInfo, ContainerType& rclTargetContainer, ElementType* /*not used, just for type information since ContainerType::value_type does not work with HP compiler*/ ) { assert(crclOptionInfo.bOptionIsMultiValued); TyErrorId utErrId = UIMA_ERR_NONE; size_t i; #if defined(__HPX_ACC__) || defined(__xlC__) || defined(__GNUC__) ElementType tTemp; #else ContainerType::value_type tTemp; #endif #if defined(__SUNPRO_CC) std::vector<ContainerType::value_type> elements; #else std::vector<ElementType> elements; #endif if (EXISTS(cpclConfigGroup)) { crclConfig.extractValue(*cpclConfigGroup, crclOptionInfo.cpszOptionName, elements); } else { crclConfig.extractValue(crclOptionInfo.cpszOptionName, elements); } for (i = 0; i < elements.size(); ++i) { rclTargetContainer.insert(rclTargetContainer.end(), elements[i]); } if (utErrId != UIMA_ERR_NONE || (elements.size() == 0)) { // could not find option or value(s) if (crclOptionInfo.uiNbrOfValuesRequired != 0 || crclOptionInfo.cpszDefaultValueAsString == NULL) { // required value not there: return error we got from config return utErrId; } std::vector<std::string> vecTmpStrings; delimitedString2Vector( vecTmpStrings, (std::string) crclOptionInfo.cpszDefaultValueAsString, ",", true, // trim strings false // insert empty strings ); // our default value too must have the required nbr of values assert(vecTmpStrings.size() >= crclOptionInfo.uiNbrOfValuesRequired); for (i = 0; i < vecTmpStrings.size(); ++i) { convertFromString(vecTmpStrings[i], tTemp); // assumes rclTargetContainer to be an STL container rclTargetContainer.insert(rclTargetContainer.end(), tTemp); } } if (i < crclOptionInfo.uiNbrOfValuesRequired) { /* taph 8/6/1999: ?? maybe we should have a more precise error id: UIMA_ERR_CONFIG_REQUIRED_OPTION_HAS_NOT_ENOUGH_VALUES */ return UIMA_ERR_CONFIG_REQUIRED_OPTION_IS_EMPTY; } return utErrId; }
void foreach( ContainerType & cont , Functor func ) { std::for_each(cont.begin(),cont.end(),func); }