static status swapVector(Vector v, Int e1, Int e2) { int n1 = indexVector(v, e1); int n2 = indexVector(v, e2); Any tmp; validIndex(v, n1); validIndex(v, n2); tmp = v->elements[n1]; /* do not use assign() here: tmp */ v->elements[n1] = v->elements[n2]; /* might drop out in that case (JW) */ v->elements[n2] = tmp; succeed; }
void GLC_Lod::copyIboToClientSide() { if (m_IndexBuffer.isCreated() && (m_IndexVector.isEmpty())) { m_IndexVector= indexVector(); } }
static status insertVector(Vector v, Int where, Any obj) { int size = valInt(v->size); int offset = valInt(v->offset); int i; Any *s, *p; if ( valInt(where) <= offset+1 ) { assign(v, offset, toInt(offset+1)); return elementVector(v, where, obj); } if ( valInt(where) > size+offset ) return elementVector(v, where, obj); elementVector(v, toInt(size+offset+1), NIL); i = indexVector(v, where); s = &v->elements[i]; p = &v->elements[valInt(v->size)-1]; /* point to last element */ for( ; p>s; p-- ) { p[0] = p[-1]; } v->elements[i] = NIL; assignVector(v, i, obj); succeed; }
Any getElementVector(Vector v, Int e) { int n = indexVector(v, e); validIndex(v, n); answer(v->elements[n]); }
void DeepImage::addSample(int y, int x, std::vector<DeepDataType> list) { auto channelNameIter = mChannelNamesInOrder.begin(); for (auto inputIter = list.begin(); inputIter != list.end(); ++inputIter) { mChannelData[*channelNameIter].push_back(*inputIter); channelNameIter++; } int index = mChannelData[DEPTH].size() - 1; indexVector(y, x)->push_back(index); }
const HitList & PhraseQueryNode::evaluateHits(HitList & hl) const { hl.clear(); _fieldInfo.clear(); if ( ! AndQueryNode::evaluate()) return hl; HitList tmpHL; unsigned int fullPhraseLen = size(); unsigned int currPhraseLen = 0; std::vector<unsigned int> indexVector(fullPhraseLen, 0); auto curr = static_cast<const QueryTerm *> ((*this)[currPhraseLen].get()); bool exhausted( curr->evaluateHits(tmpHL).empty()); for (; !exhausted; ) { auto next = static_cast<const QueryTerm *>((*this)[currPhraseLen+1].get()); unsigned int & currIndex = indexVector[currPhraseLen]; unsigned int & nextIndex = indexVector[currPhraseLen+1]; const auto & currHit = curr->evaluateHits(tmpHL)[currIndex]; size_t firstPosition = currHit.pos(); uint32_t currElemId = currHit.elemId(); uint32_t currContext = currHit.context(); const HitList & nextHL = next->evaluateHits(tmpHL); int diff(0); size_t nextIndexMax = nextHL.size(); while ((nextIndex < nextIndexMax) && ((nextHL[nextIndex].context() < currContext) || ((nextHL[nextIndex].context() == currContext) && (nextHL[nextIndex].elemId() <= currElemId))) && ((diff = nextHL[nextIndex].pos()-firstPosition) < 1)) { nextIndex++; } if ((diff == 1) && (nextHL[nextIndex].context() == currContext) && (nextHL[nextIndex].elemId() == currElemId)) { currPhraseLen++; if ((currPhraseLen+1) == fullPhraseLen) { Hit h = nextHL[indexVector[currPhraseLen]]; hl.push_back(h); const QueryTerm::FieldInfo & fi = next->getFieldInfo(h.context()); updateFieldInfo(h.context(), hl.size() - 1, fi.getFieldLength()); currPhraseLen = 0; indexVector[0]++; } } else { currPhraseLen = 0; indexVector[currPhraseLen]++; } curr = static_cast<const QueryTerm *>((*this)[currPhraseLen].get()); exhausted = (nextIndex >= nextIndexMax) || (indexVector[currPhraseLen] >= curr->evaluateHits(tmpHL).size()); } return hl; }
status elementVector(Vector v, Int e, Any obj) { int n = indexVector(v, e); if ( n < 0 ) { int nsize = valInt(v->size)-n; Any *newElements = alloc(nsize*sizeof(Any)); int m; if ( v->elements ) { cpdata(&newElements[-n], v->elements, Any, valInt(v->size)); unalloc(valInt(v->allocated)*sizeof(Any), v->elements); } v->elements = newElements; for( m = 0; m < -n; m++ ) v->elements[m] = NIL; assignVector(v, 0, obj); assign(v, size, toInt(nsize)); assign(v, allocated, toInt(nsize)); assign(v, offset, toInt(valInt(e)-1)); succeed; } if ( n >= valInt(v->size) ) { int m; if ( n >= valInt(v->allocated) ) { int nalloc = max(valInt(v->allocated)*2, n+1); Any *newElements = alloc(nalloc * sizeof(Any)); if ( v->elements ) { cpdata(newElements, v->elements, Any, valInt(v->size)); unalloc(valInt(v->allocated)*sizeof(Any), v->elements); } v->elements = newElements; assign(v, allocated, toInt(nalloc)); } for( m = valInt(v->size); m <= n ; m++ ) v->elements[m] = NIL; assignVector(v, n, obj); assign(v, size, toInt(n+1)); succeed; } assignVector(v, n, obj); succeed; }
void DeepImage::addSampleNormalized(float z, float y, float x, std::vector<DeepDataType> list) { int iy = std::max(std::min(int(y * height()), height() - 1), 0); int ix = std::max(std::min(int(x * width()), width() - 1), 0); auto channelNameIter = mChannelNamesInOrder.begin(); for (auto inputIter = list.begin(); inputIter != list.end(); ++inputIter) { mChannelData[*channelNameIter].push_back(*inputIter); channelNameIter++; } mChannelData[DEPTH].push_back(z); int index = mChannelData[DEPTH].size() - 1; indexVector(iy, ix)->push_back(index); }
const HitList & SameElementQueryNode::evaluateHits(HitList & hl) const { hl.clear(); if ( !AndQueryNode::evaluate()) return hl; HitList tmpHL; unsigned int numFields = size(); unsigned int currMatchCount = 0; std::vector<unsigned int> indexVector(numFields, 0); auto curr = static_cast<const QueryTerm *> ((*this)[currMatchCount].get()); bool exhausted( curr->evaluateHits(tmpHL).empty()); for (; !exhausted; ) { auto next = static_cast<const QueryTerm *>((*this)[currMatchCount+1].get()); unsigned int & currIndex = indexVector[currMatchCount]; unsigned int & nextIndex = indexVector[currMatchCount+1]; const auto & currHit = curr->evaluateHits(tmpHL)[currIndex]; uint32_t currElemId = currHit.elemId(); const HitList & nextHL = next->evaluateHits(tmpHL); size_t nextIndexMax = nextHL.size(); while ((nextIndex < nextIndexMax) && (nextHL[nextIndex].elemId() < currElemId)) { nextIndex++; } if (nextHL[nextIndex].elemId() == currElemId) { currMatchCount++; if ((currMatchCount+1) == numFields) { Hit h = nextHL[indexVector[currMatchCount]]; hl.emplace_back(0, h.context(), h.elemId(), h.weight()); currMatchCount = 0; indexVector[0]++; } } else { currMatchCount = 0; indexVector[currMatchCount]++; } curr = static_cast<const QueryTerm *>((*this)[currMatchCount].get()); exhausted = (nextIndex >= nextIndexMax) || (indexVector[currMatchCount] >= curr->evaluateHits(tmpHL).size()); } return hl; }
QVector<GLuint> GLC_Lod::indexVector() const { if (m_IndexBuffer.isCreated()) { // VBO created get data from VBO const int sizeOfIbo= m_IndexSize; const GLsizeiptr dataSize= sizeOfIbo * sizeof(GLuint); QVector<GLuint> indexVector(sizeOfIbo); const_cast<QGLBuffer&>(m_IndexBuffer).bind(); GLvoid* pIbo = const_cast<QGLBuffer&>(m_IndexBuffer).map(QGLBuffer::ReadOnly); memcpy(indexVector.data(), pIbo, dataSize); const_cast<QGLBuffer&>(m_IndexBuffer).unmap(); const_cast<QGLBuffer&>(m_IndexBuffer).release(); return indexVector; } else { return m_IndexVector; } }
void GLC_Lod::setIboUsage(bool usage) { if (usage && !m_IndexVector.isEmpty()) { createIBO(); // Copy index from client side to serveur m_IndexBuffer.bind(); const GLsizei indexNbr= static_cast<GLsizei>(m_IndexVector.size()); const GLsizeiptr indexSize = indexNbr * sizeof(GLuint); m_IndexBuffer.allocate(m_IndexVector.data(), indexSize); m_IndexBuffer.release(); m_IndexSize= m_IndexVector.size(); m_IndexVector.clear(); } else if (!usage && m_IndexBuffer.isCreated()) { m_IndexVector= indexVector(); m_IndexBuffer.destroy(); } }
int main( int argumentCount, char* argumentCharArray[] ) { if( 3 != argumentCount ) { std::cout << std::endl << "this testing program requires the name of 2 SLHA files to read in!"; std::cout << std::endl; } else { std::string firstFileName( argumentCharArray[ 1 ] ); std::string secondFileName( argumentCharArray[ 2 ] ); bool const isVerbose( true ); /* first, a demonstration where one picks the blocks to read: here MINPAR * & NMIX were chosen. the user has to know what format they are, so that * the parser knows how to interpret the data. MODSEL is a set of doubles * ordered with a single index, & all indices from 1 to [maximum index] * must be present, so SparseSinglyIndexedBlock< double > would be * appropriate, except most of the time the values are integers (& nobody * ever seems to use MODSEL 12, which specifies the largest Q scale, which * itself almost always is just the value for the EWSB scale. hence, * SparseSinglyIndexedBlock< int > is chosen for demonstration. MINPAR is a * set of doubles ordered with a single index, & all indices from 1 to * [maximum index] must be present, so DenseSinglyIndexedBlock< double > is * appropriate. likewise, NMIX is a set of doubles ordered by 2 indices, & * no indices should be skipped so DenseDoublyIndexedBlock< double > is * appropriate. */ LHPC::SLHA::SparseSinglyIndexedBlock< int > modselBlock( "MODSEL", -1, isVerbose ); LHPC::SLHA::DenseSinglyIndexedBlock< double > minparBlock( "MINPAR", 0.0, isVerbose ); LHPC::SLHA::DenseDoublyIndexedBlock< double > nmixBlock( "NMIX", 0.0, isVerbose ); // a parser is also needed, to do the actual reading of the file & passing // of strings to the blocks: LHPC::SlhaParser testParser( isVerbose ); // true as the argument so that warnings are printed. // the blocks have to register with the parser: testParser.registerBlock( modselBlock ); testParser.registerBlock( minparBlock ); testParser.registerBlock( nmixBlock ); // one can also register a spectrum of particles, which automatically // groups masses & decays together for each mass eigenstate: LHPC::MassSpectrumClass::MSSM testSpectrum( isVerbose, false, true ); // 2nd argument false -> neutrinos are not Majorana. // 3rd argument true -> flavor-conserving sfermions. // the spectrum has to be registered with the parser: testParser.registerSpectrum( testSpectrum ); std::cout << std::endl << "reading in \"" << firstFileName << "\""; std::cout << std::endl; // this line now does all the work! testParser.readFile( firstFileName ); demonstrateWithRegisteredBlocksAndSpectrum( modselBlock, minparBlock, nmixBlock, testSpectrum ); std::cout << std::endl << "reading in \"" << secondFileName << "\""; std::cout << std::endl; // now the 2nd file is read in, which does all the work: testParser.readFile( secondFileName ); demonstrateWithRegisteredBlocksAndSpectrum( modselBlock, minparBlock, nmixBlock, testSpectrum ); // now a demonstration where one uses a set of pre-bundled blocks: // a parser is needed for the block bundle: LHPC::SlhaParser testParserForBlockSet( isVerbose ); // for demonstration, this has all the blocks specified in SLHA1 & SLHA2, & // also includes some SPheno-specific blocks: LHPC::SlhaTwoWithSpheno testSlhaSet( testParserForBlockSet, isVerbose ); // for demonstration, this has all the blocks specified in FLHA: LHPC::FlhaOne testFlhaSet( testParserForBlockSet, isVerbose ); // this is for showing that the const versions of the block member // functions work: LHPC::SLHA::DenseDoublyIndexedBlock< double > const& constNmix( testSlhaSet.NMIX ); std::cout << std::endl << "reading in \"" << firstFileName << "\""; std::cout << std::endl; // again, this line does all the work! testParserForBlockSet.readFile( firstFileName ); demonstrateWithBlockBundle( testSlhaSet, testFlhaSet, constNmix ); std::cout << std::endl << "reading in \"" << secondFileName << "\""; std::cout << std::endl; // again, this line does all the work! testParserForBlockSet.readFile( secondFileName ); demonstrateWithBlockBundle( testSlhaSet, testFlhaSet, constNmix ); LHPC::SLHA::SparseManyIndexedBlock< double > alternativeNmix( "NMIX", 2, -10.0, isVerbose ); testParser.registerBlock( alternativeNmix ); // again, this line does all the work, now reading in data to // alternativeNmix as well. testParser.readFile( firstFileName ); std::vector< int > indexVector( 2, 0 ); indexVector[ 0 ] = 4; indexVector[ 1 ] = 3; std::cout << std::endl << "alternative NMIX block accessed with the vector { 4, 3 } = " << alternativeNmix( indexVector ); std::cout << std::endl; indexVector[ 0 ] = 1; indexVector[ 1 ] = 1; std::cout << std::endl << "alternative NMIX accessed with the vector { 1, 1 } = " << alternativeNmix( indexVector ); std::cout << std::endl; std::cout << std::endl << "alternative NMIX accessed with the string \"3, 2\" = " << alternativeNmix( "3, 2" ); std::cout << std::endl; LHPC::SlhaSimplisticInterpreter slhaSimplisticInterpreter( firstFileName ); std::cout << std::endl << "simplistic interpreter, \"" << firstFileName << "\":"; std::cout << std::endl; std::string blockNameAndIndices( "GAUGE[ 3 ]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "MASS[ 1.000021E+06 ]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "NMIX[ 1, 3 ]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "NMIX[3][3]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "NMIX[ 2 2. ]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "NMIX(4;3)" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "ALPHA" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "GAUGE" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; if( slhaSimplisticInterpreter.readFile( secondFileName ) ) { std::cout << std::endl << "successfully read \"" << secondFileName << "\""; std::cout << std::endl; blockNameAndIndices.assign( "GAUGE[ 3 ]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "MASS[ 1.000021E+06 ]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "NMIX[ 1, 3 ]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "NMIX[3][3]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "NMIX[ 2 2. ]" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; blockNameAndIndices.assign( "NMIX(4;3)" ); std::cout << "\"" << blockNameAndIndices << "\" => \"" << slhaSimplisticInterpreter( blockNameAndIndices ) << "\""; std::cout << std::endl; std::cout << "\"" << blockNameAndIndices << "\" as a double (rather than as a string) => " << slhaSimplisticInterpreter.getDouble( blockNameAndIndices ); std::cout << std::endl; } LHPC::SlhaParser::copyWithoutBlock( firstFileName, "nmix", ( firstFileName + ".stripped_copy" ) ); std::cout << std::endl << "ended successfully, I hope."; std::cout << std::endl; } // end of if correct number of arguments was given. // this was a triumph! I'm making a note here: return EXIT_SUCCESS; }