const uint8_t * woffGetMetadata(const uint8_t * woffData, uint32_t woffLen, uint32_t * metaLen, uint32_t * pStatus) { const woffHeader * header; uint32_t offset, compLen; uLong origLen; uint8_t * data = NULL; uint32_t status = eWOFF_ok; if (pStatus && WOFF_FAILURE(*pStatus)) { return NULL; } status = sanityCheck(woffData, woffLen); if (WOFF_FAILURE(status)) { FAIL(status); } header = (const woffHeader *) (woffData); offset = READ32BE(header->metaOffset); compLen = READ32BE(header->metaCompLen); origLen = READ32BE(header->metaOrigLen); if (offset == 0 || compLen == 0 || origLen == 0) { return NULL; } if (compLen > woffLen || offset > woffLen - compLen) { FAIL(eWOFF_invalid); } data = malloc(origLen); if (!data) { FAIL(eWOFF_out_of_memory); } if (uncompress((Bytef *)data, &origLen, (const Bytef *)woffData + offset, compLen) != Z_OK || origLen != READ32BE(header->metaOrigLen)) { FAIL(eWOFF_compression_failure); } if (metaLen) { *metaLen = origLen; } if (pStatus) { *pStatus |= status; } return data; failure: if (data) { free(data); } if (pStatus) { *pStatus = status; } return NULL; }
void chunk::updateNodeCoords(int nNode, double *coord, int nEl) { int i; #if 1 // do some error checking if (nEl != numElements || nNode != numNodes) { CkPrintf("ERROR: inconsistency in REFINE2D's updateNodeCoords on chunk %d:\n" " your nEl (%d); my numElements (%d)\n" " your nNode (%d); my numNodes (%d)\n", cid, nEl, numElements, nNode,numNodes); CkAbort("User code/library numbering inconsistency in REFINE2D"); } #endif // update node coordinates from coord for (i=0; i<numNodes; i++){ theNodes[i].init(coord[2*i], coord[2*i + 1]); CkPrintf("[tmr] Chunk %d Node %d %.8lf %.8lf \n",cid,i,theNodes[i].X(),theNodes[i].Y()); } // recalculate and cache new areas for each element for (i=0; i<numElements; i++){ theElements[i].calculateArea(); CkPrintf("[tmr] Chunk %d Element %d area = %.8lf \n",cid,i, theElements[i].getArea()); } sanityCheck(); }
g_val_t cpu_nice_func ( void ) { char *p; static g_val_t val; static struct timeval stamp={0, 0}; static JT last_nice_jiffies, nice_jiffies, last_total_jiffies, total_jiffies, diff; p = update_file(&proc_stat); if((proc_stat.last_read.tv_sec != stamp.tv_sec) && (proc_stat.last_read.tv_usec != stamp.tv_usec)) { stamp = proc_stat.last_read; p = skip_token(p); p = skip_token(p); nice_jiffies = strtod( p , (char **)NULL ); total_jiffies = total_jiffies_func(); diff = (nice_jiffies - last_nice_jiffies); if ( diff ) val.f = ((double)diff/(double)(total_jiffies - last_total_jiffies)) * 100.0; else val.f = 0.0; val.f = sanityCheck( __LINE__, __FILE__, __FUNCTION__, val.f, (double)diff, (double)(total_jiffies - last_total_jiffies), nice_jiffies, last_nice_jiffies, total_jiffies, last_total_jiffies ); last_nice_jiffies = nice_jiffies; last_total_jiffies = total_jiffies; } return val; }
void ElementFragmentAlgorithm::updateTopology(bool mergeUncutVirtualEdges) { // If mergeUncutVirtualEdges=true, this algorithm replicates the // behavior of classical XFEM. If false, it gives the behavior of // the Richardson et. al. (2011) paper _new_nodes.clear(); _child_elements.clear(); _parent_elements.clear(); // _merged_edge_map.clear(); unsigned int first_new_node_id = Efa::getNewID(_permanent_nodes); createChildElements(); connectFragments(mergeUncutVirtualEdges); sanityCheck(); updateCrackTipElements(); std::map<unsigned int, EFANode *>::iterator mit; for (mit = _permanent_nodes.begin(); mit != _permanent_nodes.end(); ++mit) { if (mit->first >= first_new_node_id) _new_nodes.push_back(mit->second); } clearPotentialIsolatedNodes(); // _new_nodes and _permanent_nodes may change here }
void woffGetFontVersion(const uint8_t * woffData, uint32_t woffLen, uint16_t * major, uint16_t * minor, uint32_t * pStatus) { const woffHeader * header; uint32_t status = eWOFF_ok; if (pStatus && WOFF_FAILURE(*pStatus)) { return; } status = sanityCheck(woffData, woffLen); if (WOFF_FAILURE(status)) { FAIL(status); } if (!major || !minor) { FAIL(eWOFF_bad_parameter); } *major = *minor = 0; header = (const woffHeader *) (woffData); *major = READ16BE(header->majorVersion); *minor = READ16BE(header->minorVersion); failure: if (pStatus) { *pStatus = status; } }
uint32_t woffGetDecodedSize(const uint8_t * woffData, uint32_t woffLen, uint32_t * pStatus) { uint32_t status = eWOFF_ok; uint32_t totalLen = 0; if (pStatus && WOFF_FAILURE(*pStatus)) { return 0; } status = sanityCheck(woffData, woffLen); if (WOFF_FAILURE(status)) { FAIL(status); } totalLen = READ32BE(((const woffHeader *) (woffData))->totalSfntSize); /* totalLen must be correctly rounded up to 4-byte alignment, otherwise sanityCheck would have failed */ failure: if (pStatus) { *pStatus = status; } return totalLen; }
void Calibrate::mouseReleaseEvent( QMouseEvent * ) { if ( !pressed ) return; pressed = false; if ( timer->isActive() ) return; bool doMove = true; qLog(Input)<< "Location:"<< location << penPos.x() << penPos.y(); cd.devPoints[location] = penPos; if ( location < QWSPointerCalibrationData::LastLocation ) { location = (QWSPointerCalibrationData::Location)((int)location + 1); } else { if ( sanityCheck() ) { reset(); anygood = true; goodcd = cd; hide(); doMove = false; } else { location = QWSPointerCalibrationData::TopLeft; } } if ( doMove ) { QPoint target = fromDevice( cd.screenPoints[location] ); dx = (target.x() - crossPos.x())/10; dy = (target.y() - crossPos.y())/10; timer->start( 30 ); } }
void Reflector::commonConstructor() { try { oAlphabet = new Alphabet(recReflector.value("alphabetid").toInt(), this); recAlphabet = oAlphabet->getAlphabetRec(); alphabetMap = oAlphabet->getAlphabetMap(); // This has to be set before a space is prepended alphabetSize = alphabetMap.size(); // Place a space at the start of the string so that pin // numbers need not be zero based. alphabetMap.prepend(" "); alphabetName = oAlphabet->getAlphabetName(); reflectorMap = recReflector.value("pinright").toString(); // Place a space at the start of the string so that pin // numbers need not be zero based. reflectorMap.prepend(" "); reflectorName = recReflector.value("name").toString(); qDebug("reflector [%s] alphabet [%s]", recReflector.value("name").toString().toStdString().data(), recAlphabet.value("name").toString().toStdString().data()); sanityCheck(); } catch (EnigmaException &e) { throw e; } }
void TrueOnlineSarsaLearner::evaluatePolicy(ALEInterface& ale, Features *features){ double reward = 0; double cumReward = 0; double prevCumReward = 0; //Repeat (for each episode): for(int episode = 0; episode < numEpisodesEval; episode++){ //Repeat(for each step of episode) until game is over: for(int step = 0; !ale.game_over() && step < episodeLength; step++){ //Get state and features active on that state: F.clear(); features->getActiveFeaturesIndices(ale.getScreen(), ale.getRAM(), F); updateQValues(F, Q); //Update Q-values for each possible action currentAction = epsilonGreedy(Q); //Take action, observe reward and next state: reward = 0; for(int i = 0; i < numStepsPerAction && !ale.game_over() ; i++){ reward += ale.act(actions[currentAction]); } cumReward += reward; } ale.reset_game(); sanityCheck(); printf("%d, %f, %f \n", episode + 1, (double)cumReward/(episode + 1.0), cumReward-prevCumReward); prevCumReward = cumReward; } }
/** * @brief CreateEntity::redo */ void CreateEntity::redo() { auto &&factory = entity::EntityFactory::instance(); auto project = G_ASSERT(factory.project()); if (!m_Done) { // FIXME: don't use factory to get scope, project, scene, etc.. Pass them instead. // Set aux, TODO eliminate { m_Scope = G_ASSERT(G_ASSERT(factory.db())->scope(m_ScopeID)); m_Scene = factory.scene(); m_TreeModel = G_ASSERT(factory.treeModel()); m_ProjectName = project->name(); // } m_Entity = G_ASSERT(factory.make(m_KindOfType, m_Pos, m_ScopeID)); m_GraphicEntity = G_ASSERT_C(G_ASSERT(project->database())->graphicsEntity(m_Entity->id()), m_Scene); m_Done = true; } else { sanityCheck(); m_Scope->addExistsType(m_Entity); if (m_Scene && m_GraphicEntity) { m_Scene->addItem(m_GraphicEntity.data()); project->database()->registerGraphicsEntity(m_GraphicEntity); } m_TreeModel->addType(m_Entity, m_Scope->id(), m_ProjectName); m_CleaningRequired = false; } }
/** * @brief RenameEntity::redo */ void RenameEntity::redo() { sanityCheck(); m_OldName = m_Entity->name(); m_Entity->setName(m_NewName); }
/** * Performs cubic spline interpolation from input to output * @param input A histogram from which to interpolate * @param output A histogram where to store the interpolated values */ void interpolateCSplineInplace(const Histogram &input, Histogram &output) { sanityCheck(input, output, minSizeForCSplineInterpolation()); const auto &points = input.points().rawData(); const auto &y = input.y().rawData(); const auto &interpPoints = output.points(); auto &newY = output.mutableY(); interpolateInplace(points, y, interpPoints, newY, InterpolationType::CSPLINE); }
void mainWin::slotInstallClicked() { // Sanity check our install choices if (!sanityCheck()) return; // Start the installation doUpdates(); }
petabricks::MaximaWrapper::MaximaWrapper() : _fd(-1) , _stackDepth(0) { #ifdef MAXIMA_LOG _fd = forkopen(&launchMaximaWithLogging); #else _fd = forkopen(&launchMaxima); #endif maximain = fdopen(_fd, "rw"); readFormulaFromMaxima();//initial prompt #ifdef DEBUG sanityCheck(); #endif runCommand(theInitCode); #ifdef DEBUG sanityCheck(); #endif }
const uint8_t * woffGetPrivateData(const uint8_t * woffData, uint32_t woffLen, uint32_t * privLen, uint32_t * pStatus) { const woffHeader * header; uint32_t offset, length; uint8_t * data = NULL; uint32_t status = eWOFF_ok; if (pStatus && WOFF_FAILURE(*pStatus)) { return NULL; } status = sanityCheck(woffData, woffLen); if (WOFF_FAILURE(status)) { FAIL(status); } header = (const woffHeader *) (woffData); offset = READ32BE(header->privOffset); length = READ32BE(header->privLen); if (offset == 0 || length == 0) { return NULL; } if (length > woffLen || offset > woffLen - length) { FAIL(eWOFF_invalid); } data = malloc(length); if (!data) { FAIL(eWOFF_out_of_memory); } memcpy(data, woffData + offset, length); if (privLen) { *privLen = length; } if (pStatus) { *pStatus |= status; } return data; failure: if (data) { free(data); } if (pStatus) { *pStatus = status; } return NULL; }
virtual ~AutoDvmReader() { if (!getVolts(v2)){ err("failed to read volts, baling out"); exit(-1); } *client_volts = (v1 + v2)/2; sanityCheck(); dbg(2, "01 setting client to mean %.4f V", *client_volts); }
/** * Interpolate through the y values of a histogram using a cubic spline, * assuming that the calculated "nodes" are stepSize apart. * Currently errors are ignored. * @param input Input histogram defining x values and containing calculated * Y values at stepSize intervals. It is assumed that the first/last points * are always calculated points. * @param stepSize The space, in indices, between the calculated points * @return A new Histogram with the y-values from the result of a linear * interpolation. The XMode of the output will match the input histogram. */ Histogram interpolateCSpline(const Histogram &input, const size_t stepSize) { sanityCheck(input, stepSize, minSizeForCSplineInterpolation(), CSPLINE_NAME); HistogramY ynew(input.y().size()); interpolateYCSplineInplace(input, stepSize, ynew); // Cheap copy Histogram output(input); if (output.yMode() == Histogram::YMode::Counts) { output.setCounts(ynew); } else { output.setFrequencies(ynew); } return output; }
int StatCache::Node::lstat(const std::string& path, struct stat* buf, time_t lastRefresh /* = 0 */) { bool cached; { SimpleLock lock(m_lock); if (validate(path, cached)) { return -1; } m_lpaths.insert(std::make_pair(path, this)); memcpy(buf, &m_lstat, sizeof(struct stat)); } if (debug && cached) { sanityCheck(path, false, buf, lastRefresh); } return 0; }
g_val_t cpu_system_func ( void ) { char *p; static g_val_t val; static struct timeval stamp={0, 0}; static JT last_system_jiffies, system_jiffies, last_total_jiffies, total_jiffies, diff; p = update_file(&proc_stat); if((proc_stat.last_read.tv_sec != stamp.tv_sec) && (proc_stat.last_read.tv_usec != stamp.tv_usec)) { stamp = proc_stat.last_read; p = skip_token(p); p = skip_token(p); p = skip_token(p); system_jiffies = strtod( p, (char **)NULL ); if (num_cpustates > NUM_CPUSTATES_24X) { p = skip_token(p); p = skip_token(p); p = skip_token(p); system_jiffies += strtod( p, (char **)NULL ); /* "intr" counted in system */ p = skip_token(p); system_jiffies += strtod( p, (char **)NULL ); /* "sintr" counted in system */ } total_jiffies = total_jiffies_func(); diff = system_jiffies - last_system_jiffies; if ( diff ) val.f = ((double)diff/(double)(total_jiffies - last_total_jiffies)) * 100.0; else val.f = 0.0; val.f = sanityCheck( __LINE__, __FILE__, __FUNCTION__, val.f, (double)diff, (double)(total_jiffies - last_total_jiffies), system_jiffies, last_system_jiffies, total_jiffies, last_total_jiffies ); last_system_jiffies = system_jiffies; last_total_jiffies = total_jiffies; } return val; }
const uint8_t * woffDecode(const uint8_t * woffData, uint32_t woffLen, uint32_t * sfntLen, uint32_t * pStatus) { uint32_t status = eWOFF_ok; uint8_t * sfntData = NULL; uint32_t bufLen; if (pStatus && WOFF_FAILURE(*pStatus)) { return NULL; } status = sanityCheck(woffData, woffLen); if (WOFF_FAILURE(status)) { FAIL(status); } bufLen = READ32BE(((const woffHeader *) (woffData))->totalSfntSize); sfntData = (uint8_t *) malloc(bufLen); if (!sfntData) { FAIL(eWOFF_out_of_memory); } woffDecodeToBufferInternal(woffData, woffLen, sfntData, bufLen, sfntLen, &status); if (WOFF_FAILURE(status)) { FAIL(status); } if (pStatus) { *pStatus |= status; } return sfntData; failure: if (sfntData) { free(sfntData); } if (pStatus) { *pStatus = status; } return NULL; }
std::shared_ptr<ComPWA::FunctionTree> FormFactorDecorator::createFunctionTree(const ParameterList &DataSample, unsigned int pos, const std::string &suffix) const { // size_t sampleSize = DataSample.mDoubleValue(pos)->values().size(); size_t sampleSize = DataSample.mDoubleValue(0)->values().size(); std::string NodeName = "BreitWignerWithProductionFormFactor(" + Name + ")" + suffix; auto tr = std::make_shared<FunctionTree>(NodeName, MComplex("", sampleSize), std::make_shared<MultAll>(ParType::MCOMPLEX)); std::string ffNodeName = "ProductionFormFactor(" + Name + ")" + suffix; auto ffTree = std::make_shared<FunctionTree>(ffNodeName, MDouble("", sampleSize), std::make_shared<FormFactorStrategy>()); // add L and FFType as double value leaf, since there is no int leaf ffTree->createLeaf("OrbitalAngularMomentum", (double ) L, ffNodeName); ffTree->createLeaf("MesonRadius", MesonRadius, ffNodeName); ffTree->createLeaf("FormFactorType", (double) FFType, ffNodeName); ffTree->createLeaf("MassA", Daughter1Mass, ffNodeName); ffTree->createLeaf("MassB", Daughter2Mass, ffNodeName); ffTree->createLeaf("Data_mSq[" + std::to_string(pos) + "]", DataSample.mDoubleValue(pos), ffNodeName); ffTree->parameter(); tr->insertTree(ffTree, NodeName); std::shared_ptr<ComPWA::FunctionTree> breitWignerTree = UndecoratedBreitWigner->createFunctionTree(DataSample, pos, suffix); breitWignerTree->parameter(); tr->insertTree(breitWignerTree, NodeName); if (!tr->sanityCheck()) throw std::runtime_error( "FormFactorDecorator::createFunctionTree() | " "Tree didn't pass sanity check!"); return tr; };
/** * @brief CreateEntity::undo */ void CreateEntity::undo() { sanityCheck(); // TODO: move to the RemoveEntity command (when it'll be created) if (m_GraphicEntity && m_GraphicEntity) { m_Scene->removeItem(m_GraphicEntity); // TODO eliminate { auto &&factory = entity::EntityFactory::instance(); auto project = G_ASSERT(factory.project()); // } project->database()->unregisterGraphicsEntity(m_GraphicEntity); } m_Scope->removeType(m_Entity->id()); m_TreeModel->removeType(m_ProjectName, m_ScopeID, m_Entity->id()); m_CleaningRequired = true; }
/** * @brief This file implements an interface to add unary factors to an opengm model in MatLab. * * This routine accepts a vector of variable ids and a matrix, where each column * represents the function values for the corresponding variable. The number of * columns must match the number of variables and the number of rows must at * least match the maximum number of states of the stated variables. * * @param[in] nlhs number of output arguments expected from MatLab. * (needs to be 0). * @param[out] plhs pointer to the mxArrays containing the results. * @param[in] nrhs number of input arguments provided from MatLab. * (needs to be 3) * @param[in] prhs pointer to the mxArrays containing the input data provided by * matlab. prhs[0] needs to contain the handle for the model. * prhs[1] needs to contain a vector of variable ids. prhs[2] needs to contain a * matrix where each column represents the function values for the corresponding * variable. The number of columns must match the number of variables and the * number of rows must at least match the maximum number of states of the stated * variables. */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { //check if data is in correct format if(nrhs != 3) { mexErrMsgTxt("Wrong number of input variables specified (three needed)\n"); } if(nlhs != 0) { mexErrMsgTxt("Wrong number of output variables specified (zero needed)\n"); } // get model out of handle typedef opengm::interface::MatlabModelType::GmType GmType; GmType& gm = opengm::interface::handle<GmType>::getObject(prhs[0]); // perform sanity check OPENGM_ASSERT(sanityCheck(gm, prhs[1], prhs[2])); // add unary factors typedef opengm::interface::helper::getDataFromMXArray<addPairwiseFunctor> pairwiseAdder; addPairwiseFunctor functor(gm, prhs[2]); pairwiseAdder()(functor, prhs[1]); }
g_val_t cpu_aidle_func ( void ) { char *p; g_val_t val; JT idle_jiffies, total_jiffies; p = update_file(&proc_stat); p = skip_token(p); p = skip_token(p); p = skip_token(p); p = skip_token(p); idle_jiffies = (JT) strtod( p , (char **)NULL ); total_jiffies = total_jiffies_func(); val.f = ((double)(idle_jiffies/total_jiffies)) * 100.0; val.f = sanityCheck( __LINE__, __FILE__, __FUNCTION__, val.f, (double)idle_jiffies, (double)total_jiffies, idle_jiffies, total_jiffies, 0, 0 ); return val; }
bool Spectrum::readSpectrum(const SpectraAggregator& sa, const SingleSpectrumHeader* header, bool indFilterSpectrum) { config_ = sa.getConfig(); const int numPeaksRead = readPeaksToLocalAllocation(sa, header); if (numPeaksRead<5) return false; copyHeaderInformation(); initializePeakList(config_, indFilterSpectrum); if (! sanityCheck()) return false; initializeSpectrum(); return (numPeaks_>0); }
void woffDecodeToBuffer(const uint8_t * woffData, uint32_t woffLen, uint8_t * sfntData, uint32_t bufferLen, uint32_t * pActualSfntLen, uint32_t * pStatus) { uint32_t status = eWOFF_ok; uint32_t totalLen; if (pStatus && WOFF_FAILURE(*pStatus)) { return; } status = sanityCheck(woffData, woffLen); if (WOFF_FAILURE(status)) { FAIL(status); } if (!sfntData) { FAIL(eWOFF_bad_parameter); } totalLen = READ32BE(((const woffHeader *) (woffData))->totalSfntSize); if (bufferLen < totalLen) { FAIL(eWOFF_buffer_too_small); } woffDecodeToBufferInternal(woffData, woffLen, sfntData, bufferLen, pActualSfntLen, pStatus); return; failure: if (pActualSfntLen) { *pActualSfntLen = 0; } if (pStatus) { *pStatus = status; } }
// writes the header and peak list in DAT format // returns the number of bytes written to the buffer size_t PeakList::writeToDatBuffer(char* buffer, const SingleSpectrumHeader* newHeader) const { const size_t headerSize = newHeader->writeHeaderToDatBuffer(buffer); assert( sanityCheck() ); char* p = buffer + headerSize; // write peaks for (size_t i=0; i<numPeaks_; i++) { mass_t* mt = reinterpret_cast<mass_t*>(p); *mt = peaks_[i].mass; intensity_t* it = reinterpret_cast<intensity_t*>(p+sizeof(mass_t)); *it = peaks_[i].intensity; unsigned char* up = reinterpret_cast<unsigned char*>(p+sizeof(mass_t)+sizeof(intensity_t)); *up++ = peaks_[i].count; *up++ = peaks_[i].maxPossible; unsigned short* us = reinterpret_cast<unsigned short*>(up); *us++ = peaks_[i].charge; p = reinterpret_cast<char*>(us); /* if (peaks_[i].maxPossible > newHeader->getClusterSize()) { cout << "Cluster size: " << newHeader->getClusterSize() << endl; cout << "Num peaks: " << numPeaks_ << endl; cout << "Original : " << newHeader->getOriginalNumPeaks() << endl; this->printPeaks(); } assert(peaks_[i].maxPossible <= newHeader->getClusterSize());*/ } unsigned int* ui = reinterpret_cast<unsigned int*>(buffer); *ui = static_cast<unsigned int>(p-buffer); return (p-buffer); }
std::string StatCache::Node::readlink(const std::string& path, time_t lastRefresh /* = 0 */) { std::string link; bool cached; struct stat buf; { SimpleLock lock(m_lock); if (validate(path, cached) || !isLinkLocked()) { return ""; } if (debug && cached) { memcpy(&buf, &m_lstat, sizeof(struct stat)); } if (m_link.size() == 0) { m_link = readlinkSyscall(path); } link = m_link; } if (debug && cached) { sanityCheck(path, false, &buf, lastRefresh); } return link; }
/** * Cubic spline interpolate across a set of data. (In-place version). See * interpolateCSpline. * @param inOut Input histogram whose points are interpolated in place * @param stepSize See interpolateCSpline */ void interpolateCSplineInplace(Histogram &inOut, const size_t stepSize) { sanityCheck(inOut, stepSize, minSizeForCSplineInterpolation(), CSPLINE_NAME); interpolateYCSplineInplace(inOut, stepSize, inOut.mutableY()); }
/** * Linearly interpolate across a set of data. (In-place version). See * interpolateLinear. * @param inOut Input histogram whose points are interpolated in place * @param stepSize See interpolateLinear */ void interpolateLinearInplace(Histogram &inOut, const size_t stepSize) { sanityCheck(inOut, stepSize, minSizeForLinearInterpolation(), LINEAR_NAME); interpolateYLinearInplace(inOut, stepSize, inOut.mutableY()); }