// If a plugin provides a Parameters Vector, then scalars will be created, as well as a label. void BasicPlugin::createScalars() { // Assumes that this is called with a write lock in place on this object Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED); if (hasParameterVector()) { VectorPtr vectorParam = _outputVectors["Parameters Vector"]; if (vectorParam) { QString paramName; int i = 0; int length = vectorParam->length(); Q_ASSERT(store()); for (paramName = parameterName(i); !paramName.isEmpty() && i < length; paramName = parameterName(++i)) { double scalarValue = vectorParam->value(i); if (!_outputScalars.contains(paramName)) { ScalarPtr s = store()->createObject<Scalar>(); s->setProvider(this); s->setSlaveName(paramName); s->setValue(scalarValue); s->writeLock(); _outputScalars.insert(paramName, s); } else { _outputScalars[paramName]->setValue(scalarValue); } } } } }
void VectorSelector::fillVectors() { if (!_store) { return; } int current_index = _vector->currentIndex(); VectorPtr current = selectedVector(); QHash<QString, VectorPtr> vectors; VectorList vectorList = _store->getObjects<Vector>(); VectorList::ConstIterator it = vectorList.constBegin(); for (; it != vectorList.constEnd(); ++it) { VectorPtr vector = (*it); if (vector->isScalarList()) continue; vector->readLock(); vectors.insert(vector->CleanedName(), vector); vector->unlock(); } QStringList list = vectors.keys(); qSort(list); _vector->clear(); foreach (const QString &string, list) { VectorPtr v = vectors.value(string); _vector->addItem(string, qVariantFromValue(v.data())); }
/** @brief Update by mean vectors and covariance matrices */ TEST_F(TestBCM, CovTest) { // pointer should be NULL initially EXPECT_FALSE(m_pSumOfWeightedMeans); EXPECT_FALSE(m_pSumOfInvCovs); // prediction 1 update(pMean1, pCov1); EXPECT_TRUE(m_pSumOfInvCovs->isApprox(*pSumOfInvCovs1)); EXPECT_TRUE(m_pSumOfWeightedMeans->isApprox(*pSumOfWeightedMeansByCov1)); // prediction 2 update(pMean2, pCov2); EXPECT_TRUE(m_pSumOfInvCovs->isApprox(*pSumOfInvCovs2)); EXPECT_TRUE(m_pSumOfWeightedMeans->isApprox(*pSumOfWeightedMeansByCov2)); // prediction 3 update(pMean3, pCov3); EXPECT_TRUE(m_pSumOfInvCovs->isApprox(*pSumOfInvCovs3)); EXPECT_TRUE(m_pSumOfWeightedMeans->isApprox(*pSumOfWeightedMeansByCov3)); // final VectorPtr pMean; MatrixPtr pCov; get(pMean, pCov); EXPECT_TRUE(pCov->isApprox(pCovFinal->diagonal())); // get a variance!!! EXPECT_TRUE(pMean->isApprox(*pMeanByCovFinal)); }
/** @brief Update by mean vectors and variance vectors */ TEST_F(TestBCM, VarTest) { // pointer should be NULL initially EXPECT_FALSE(m_pSumOfWeightedMeans); EXPECT_FALSE(m_pSumOfInvCovs); // prediction 1 update(pMean1, pVar1); EXPECT_TRUE(m_pSumOfInvCovs->isApprox(*pSumOfInvVar1)); EXPECT_TRUE(m_pSumOfWeightedMeans->isApprox(*pSumOfWeightedMeansByVar1)); // prediction 2 update(pMean2, pVar2); EXPECT_TRUE(m_pSumOfInvCovs->isApprox(*pSumOfInvVar2)); EXPECT_TRUE(m_pSumOfWeightedMeans->isApprox(*pSumOfWeightedMeansByVar2)); // prediction 3 update(pMean3, pVar3); EXPECT_TRUE(m_pSumOfInvCovs->isApprox(*pSumOfInvVar3)); EXPECT_TRUE(m_pSumOfWeightedMeans->isApprox(*pSumOfWeightedMeansByVar3)); // final VectorPtr pMean; MatrixPtr pCov; get(pMean, pCov); EXPECT_TRUE(pCov->isApprox(*pVarFinal)); EXPECT_TRUE(pMean->isApprox(*pMeanByVarFinal)); }
void Histogram::AutoBin(VectorPtr V, int *n, double *max, double *min) { double m; *max = V->max(); *min = V->min(); *n = V->length(); if (*max < *min) { m = *max; *max = *min; *min = m; } if (*max == *min) { *max += 1.0; *min -= 1.0; } // we can do a better job auto-ranging using the tick rules from plot... // this has not been done yet, you will notice... *n /= 50; if (*n < 6) { *n = 6; } if (*n > 60) { *n = 60; } m = (*max - *min)/(100.0*double(*n)); *max += m; *min -= m; }
void BasicPlugin::setOutputVector(const QString &type, const QString &name) { QString txt = !name.isEmpty() ? name : type; Q_ASSERT(store()); VectorPtr v = store()->createObject<Vector>(); v->setProvider(this); v->setSlaveName(txt); _outputVectors.insert(type, v); }
rho::net::CNetResponseWrapper CNetRequestWrapper::pushMultipartData(const String& strUrl, CMultipartItem& oItem, IRhoSession* oSession, Hashtable<String,String>* pHeaders) { VectorPtr<CMultipartItem*> arItems; arItems.addElement(&oItem); rho::net::CNetResponseWrapper oResp = pushMultipartData(strUrl, arItems, oSession, pHeaders); arItems[0] = 0; //do not delete item return oResp; }
void Curve::point(int i, double &x, double &y) const { VectorPtr xv = xVector(); if (xv) { x = xv->interpolate(i, NS); } VectorPtr yv = yVector(); if (yv) { y = yv->interpolate(i, NS); } }
QString DataObjectSI::outputVector(QString& command) { QString key = getArg(command); VectorPtr vout = _dataObject->outputVector(key); if (vout) { return vout->shortName(); } else { return "Invalid"; } }
INetResponse* CNetRequest::pushMultipartData(const String& strUrl, CMultipartItem& oItem, IRhoSession* oSession, Hashtable<String,String>* pHeaders) { m_bCancel = false; VectorPtr<CMultipartItem*> arItems; arItems.addElement(&oItem); INetResponse* pResp = pushMultipartData(strUrl, arItems, oSession, pHeaders); arItems[0] = 0; //do not delete item return pResp; }
void CSD::setVector(VectorPtr new_v) { VectorPtr v = _inputVectors[CSD_INVECTOR]; if (v) { if (v == new_v) { return; } v->unlock(); } _inputVectors.remove(CSD_INVECTOR); new_v->writeLock(); _inputVectors[CSD_INVECTOR] = new_v; }
void CSD::internalUpdate() { VectorPtr inVector = _inputVectors[CSD_INVECTOR]; writeLockInputsAndOutputs(); double *tempOutput, *input; int tempOutputLen = PSDCalculator::calculateOutputVectorLength(_windowSize, _average, _averageLength); _length = tempOutputLen; tempOutput = new double[tempOutputLen]; input = inVector->value(); int xSize = 0; for (int i=0; i < inVector->length(); i+= _windowSize) { //ensure there is enough data left. if (i + _windowSize >= inVector->length()) { break; //If there isn't enough left for a complete window. } _psdCalculator.calculatePowerSpectrum(input + i, _windowSize, tempOutput, tempOutputLen, _removeMean, false, _average, _averageLength, _apodize, _apodizeFxn, _gaussianSigma, _outputType, _frequency); // resize output matrix _outMatrix->resize(xSize+1, tempOutputLen); if (_outMatrix->sampleCount() == (xSize+1)*tempOutputLen) { // all is well. // copy elements to output matrix for (int j=0; j < tempOutputLen; j++) { _outMatrix->setValueRaw(xSize, j, tempOutput[j]); } } else { Debug::self()->log(i18n("Could not allocate sufficient memory for CSD."), Debug::Error); break; } xSize++; } delete[] tempOutput; double frequencyStep = .5*_frequency/(double)(tempOutputLen-1); _outMatrix->change(xSize, tempOutputLen, 0, 0, _windowSize/_frequency, frequencyStep); unlockInputsAndOutputs(); return; }
void CSD::change(VectorPtr in_V, double in_freq, bool in_average, bool in_removeMean, bool in_apodize, ApodizeFunction in_apodizeFxn, int in_windowSize, int in_length, double in_gaussianSigma, PSDType in_outputType, const QString& in_vectorUnits, const QString& in_rateUnits) { _inputVectors[CSD_INVECTOR] = in_V; QString vecName = in_V ? in_V->Name() : QString(); _frequency = in_freq; _average = in_average; _apodize = in_apodize; _windowSize = in_windowSize; _apodizeFxn = in_apodizeFxn; _gaussianSigma = in_gaussianSigma; _removeMean = in_removeMean; _averageLength = in_length; _vectorUnits = in_vectorUnits; _rateUnits = in_rateUnits; _outputType = in_outputType; if (_frequency <= 0.0) { _frequency = 1.0; } _outMatrix->setLabel(i18n("Power \\[%1/%2^{1/2 }\\]").arg(_vectorUnits).arg(_rateUnits)); _outMatrix->setXLabel(i18n("Time \\[s\\]")); _outMatrix->setYLabel(i18n("Frequency \\[%1\\]").arg(_rateUnits)); updateMatrixLabels(); }
/*******************************获取定长数组坐标********************************/ int Jce2Php::getSuffix(const TypeIdPtr &pPtr) const { BuiltinPtr bPtr = BuiltinPtr::dynamicCast(pPtr->getTypePtr()); if(bPtr && bPtr->kind() == Builtin::KindString && bPtr->isArray()) { return bPtr->getSize(); } VectorPtr vPtr = VectorPtr::dynamicCast(pPtr->getTypePtr()); if(vPtr && vPtr->isArray()) { return vPtr->getSize(); } return -1; }
void HistogramTab::generateAutoBin() { VectorPtr selectedVector = vector(); if (selectedVector) { selectedVector->readLock(); // Hmm should we really lock here? AutoBin should I think int n; double max, min; Histogram::AutoBin(selectedVector, &n, &max, &min); selectedVector->unlock(); _numberOfBins->setValue(n); _min->setText(QString::number(min)); _max->setText(QString::number(max)); } }
void CSD::change(VectorPtr in_V, double in_freq, bool in_average, bool in_removeMean, bool in_apodize, ApodizeFunction in_apodizeFxn, int in_windowSize, int in_length, double in_gaussianSigma, PSDType in_outputType, const QString& in_vectorUnits, const QString& in_rateUnits) { _inputVectors[CSD_INVECTOR] = in_V; QString vecName = in_V ? in_V->Name() : QString(); _frequency = in_freq; _average = in_average; _apodize = in_apodize; _windowSize = in_windowSize; _apodizeFxn = in_apodizeFxn; _gaussianSigma = in_gaussianSigma; _removeMean = in_removeMean; _averageLength = in_length; _vectorUnits = in_vectorUnits; _rateUnits = in_rateUnits; _outputType = in_outputType; if (_frequency <= 0.0) { _frequency = 1.0; } updateMatrixLabels(); }
void PSD::setVector(VectorPtr new_v) { Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED); VectorPtr v = _inputVectors[INVECTOR]; if (v) { if (v == new_v) { return; } v->unlock(); } _inputVectors.remove(INVECTOR); new_v->writeLock(); _inputVectors[INVECTOR] = new_v; _changed = true; }
void DataObject::replaceDependency(VectorPtr oldVector, VectorPtr newVector) { for (VectorMap::Iterator j = _inputVectors.begin(); j != _inputVectors.end(); ++j) { if (j.value() == oldVector) { _inputVectors[j.key()] = newVector; } } QHashIterator<QString, Scalar*> scalarDictIter(oldVector->scalars()); for (ScalarMap::Iterator j = _inputScalars.begin(); j != _inputScalars.end(); ++j) { while (scalarDictIter.hasNext()) { scalarDictIter.next(); if (scalarDictIter.value() == j.value()) { _inputScalars[j.key()] = (newVector->scalars())[scalarDictIter.key()]; } } } }
void Matrix::createScalars(ObjectStore *store) { Q_ASSERT(store); ScalarPtr sp; VectorPtr vp; _scalars.insert("max", sp=store->createObject<Scalar>()); sp->setProvider(this); sp->setSlaveName("Max"); _scalars.insert("min", sp=store->createObject<Scalar>()); sp->setProvider(this); sp->setSlaveName("Min"); _scalars.insert("mean", sp=store->createObject<Scalar>()); sp->setProvider(this); sp->setSlaveName("Mean"); _scalars.insert("sigma", sp=store->createObject<Scalar>()); sp->setProvider(this); sp->setSlaveName("Sigma"); _scalars.insert("rms", sp=store->createObject<Scalar>()); sp->setProvider(this); sp->setSlaveName("Rms"); _scalars.insert("ns", sp=store->createObject<Scalar>()); sp->setProvider(this); sp->setSlaveName("NS"); _scalars.insert("sum", sp=store->createObject<Scalar>()); sp->setProvider(this); sp->setSlaveName("Sum"); _scalars.insert("sumsquared", sp=store->createObject<Scalar>()); sp->setProvider(this); sp->setSlaveName("SumSquared"); _scalars.insert("minpos", sp=store->createObject<Scalar>()); sp->setProvider(this); sp->setSlaveName("MinPos"); _vectors.insert("z", vp = store->createObject<Vector>()); vp->setProvider(this); vp->setSlaveName("Z"); }
string TarsAnalyzer::tostrVector(const VectorPtr &pPtr) { //数组类型 if(pPtr->isArray()) { return tostr(pPtr->getTypePtr()); } //指针类型 if(pPtr->isPointer()) { return tostr(pPtr->getTypePtr())+" *"; } string s = Builtin::builtinTable[Builtin::KindVector] + string("<") + tostr(pPtr->getTypePtr()); if(MapPtr::dynamicCast(pPtr->getTypePtr()) || VectorPtr::dynamicCast(pPtr->getTypePtr())) { s += " >"; } else { s += ">"; } return s; }
TEST(Arguments, Vector) { VectorPtr vector = Vector::create(100, false); CheckBufferArg check = [=](const BufferArg& arg) { EXPECT_EQ(arg.shape().ndims(), 1U); EXPECT_EQ(arg.shape()[0], 100U); EXPECT_EQ(arg.data(), vector->getData()); CpuVector inVector = arg.vector<real, DEVICE_TYPE_CPU>(); EXPECT_EQ(inVector.getSize(), vector->getSize()); EXPECT_EQ(inVector.getData(), vector->getData()); }; BufferArgs argments; argments.addArg(*vector); std::vector<CheckBufferArg> checkFunc; checkFunc.push_back(check); testBufferArgs(argments, checkFunc); }
void Win32WindowManager::getWindows(VectorPtr<PlatformWindow*> &windows) { Win32Window *win = mWindowListHead; while(win) { windows.push_back(win); win = win->mNextWindow; } }
void PSD::internalUpdate() { writeLockInputsAndOutputs(); VectorPtr iv = _inputVectors[INVECTOR]; const int v_len = iv->length(); _last_n_new += iv->numNew(); assert(_last_n_new >= 0); int n_subsets = (v_len)/_PSDLength; // determine if the PSD needs to be updated. // if not using averaging, then we need at least _PSDLength/16 new data points. // if averaging, then we want enough new data for a complete subset. // ... unless we are counting from end at fixed length (scrolling data). bool scrolling_data = (_last_n == iv->length()); if ( (!_changed) && ((_last_n_new < _PSDLength/16) || (_Average && scrolling_data && (_last_n_new < _PSDLength/16)) || (_Average && !scrolling_data && (n_subsets - _last_n_subsets < 1))) && iv->length() != iv->numNew()) { unlockInputsAndOutputs(); return; } _changed = false; _adjustLengths(); double *psd = _sVector->value(); double *f = _fVector->value(); int i_samp; for (i_samp = 0; i_samp < _PSDLength; ++i_samp) { f[i_samp] = i_samp * 0.5 * _Frequency / (_PSDLength - 1); } //f[0] = -1E-280; // really 0 (this shouldn't be needed...) _psdCalculator.calculatePowerSpectrum(iv->value(), v_len, psd, _PSDLength, _RemoveMean, _interpolateHoles, _Average, _averageLength, _Apodize, _apodizeFxn, _gaussianSigma, _Output, _Frequency); _last_n_subsets = n_subsets; _last_n_new = 0; _last_n = iv->length(); updateVectorLabels(); // should be updated by the update manager //_sVector->update(); //_fVector->update(); unlockInputsAndOutputs(); return; }
inline int indexNearX(double x, VectorPtr& xv, int NS) { // monotonically rising: we can do a binary search // should be reasonably fast if (xv->isRising()) { int i_top = NS - 1; int i_bot = 0; // don't pre-check for x outside of the curve since this is not // the common case. It will be correct - just slightly slower... while (i_bot + 1 < i_top) { int i0 = (i_top + i_bot)/2; double rX = xv->interpolate(i0, NS); if (x < rX) { i_top = i0; } else { i_bot = i0; } } double xt = xv->interpolate(i_top, NS); double xb = xv->interpolate(i_bot, NS); if (xt - x < x - xb) { return i_top; } else { return i_bot; } } else { // Oh Oh... not monotonically rising - we have to search the entire curve! // May be unbearably slow for large vectors double rX = xv->interpolate(0, NS); double dx0 = fabs(x - rX); int i0 = 0; for (int i = 1; i < NS; ++i) { rX = xv->interpolate(i, NS); double dx = fabs(x - rX); if (dx < dx0) { dx0 = dx; i0 = i; } } return i0; } }
bool TSShapeImport::import(TSShape* shape,ITRGeometry* geometry) { // printf("TSShape Import\n"); // VectorPtr<TSPartList*> partStack; partStack.push_back(dynamic_cast<TSPartList*>(shape)); while (!partStack.empty()) { TSPartList& partList = *partStack.last(); partStack.decrement(); for (int i = 0; i < partList.getPartCount(); i++) if (TSPartList *pl = dynamic_cast<TSPartList*>(partList[i])) partStack.push_back(pl); else if (TSMesh* pm = dynamic_cast<TSMesh*>(partList[i])) { if (!import(pm,shape->getMaterialList(),geometry)) return false; } } printf(" Vertices: %d\n",geometry->point3List.size()); printf(" Surfaces: %d\n",geometry->surfaceList.size()); printf(" Polygons: %d\n",geometry->polyList.size()); printf(" Planes: %d\n",geometry->planeList.size()); return true; }
EventMonitorEntry::EventMonitorEntry(ObjectStore *store) : DataObject(store) { _level = Debug::Warning; _logDebug = true; _logEMail = false; _logELOG = false; const int NS = 1; _numDone = 0; _isValid = false; _pExpression = 0L; _typeString = staticTypeString; _type = "Event"; _initializeShortName(); VectorPtr xv = store->createObject<Vector>(); xv->resize(NS); xv->setProvider(this); _xVector = _outputVectors.insert(OUTXVECTOR, xv); VectorPtr yv = store->createObject<Vector>(); yv->resize(NS); yv->setProvider(this); _yVector = _outputVectors.insert(OUTYVECTOR, yv); }
void generateMask(Parameter *para) { VectorPtr maskTemp = Vector::create(para->getSize(), false); maskTemp->zeroMem(); real *maskTempData = maskTemp->getData(); size_t nonZeroNum = para->getSize() * (1 - sparsityRatio_); VectorPtr paraVec = para->getBuf(PARAMETER_VALUE); VectorPtr paraCpuCopy = Vector::create(para->getSize(), false); paraCpuCopy->copyFrom(*paraVec); std::vector<std::pair<real, size_t>> param; for (size_t i = 0; i < para->getSize(); i++) param.push_back(std::make_pair(fabs(paraCpuCopy->getData()[i]), i)); std::partial_sort( param.begin(), param.begin() + nonZeroNum, param.end(), sortPairAscend); for (size_t i = 0; i < nonZeroNum; i++) maskTempData[param[i].second] = 1.0; // Currently just use a mask vector for hack. if (para->useGpu()) { maskVec_ = Vector::create(para->getSize(), para->useGpu()); maskVec_->copyFrom(*maskTemp); } else { maskVec_ = maskTemp; } }
QString BasicPlugin::label(int precision) const { Q_UNUSED(precision) QString label; QString paramName; label = Name(); if (hasParameterVector()) { VectorPtr vectorParam = _outputVectors["Parameters Vector"]; int length = vectorParam->length(); int i=0; for (paramName = parameterName(i); !paramName.isEmpty() && i < length; paramName = parameterName(++i)) { if (_outputScalars.contains(paramName)) { label += QString("\n%1: [%2]").arg(paramName).arg(_outputScalars[paramName]->Name()); } } } return label; }
void EventMonitorEntry::internalUpdate() { writeLockInputsAndOutputs(); if (!_pExpression) { reparse(); } VectorPtr xv = *_xVector; VectorPtr yv = *_yVector; int ns = 1; for (VectorMap::ConstIterator i = _vectorsUsed.begin(); i != _vectorsUsed.end(); ++i) { ns = qMax(ns, i.value()->length()); } double *rawValuesX = 0L; double *rawValuesY = 0L; if (xv && yv) { if (xv->resize(ns)) { rawValuesX = xv->value(); } if (yv->resize(ns)) { rawValuesY = yv->value(); } } Equations::Context ctx; ctx.sampleCount = ns; ctx.x = 0.0; if (needToEvaluate()) { if (_pExpression) { for (ctx.i = _numDone; ctx.i < ns; ++ctx.i) { const double value = _pExpression->value(&ctx); if (value != 0.0) { // The expression evaluates to true log(ctx.i); if (rawValuesX && rawValuesY) { rawValuesX[ctx.i] = ctx.i; rawValuesY[ctx.i] = 1.0; } } else { if (rawValuesX && rawValuesY) { rawValuesX[ctx.i] = ctx.i; rawValuesY[ctx.i] = 0.0; } } } _numDone = ns; logImmediately(); } } else { _numDone = ns; } unlockInputsAndOutputs(); return; }
ObjectList<Primitive> Matrix::outputPrimitives() const { PrimitiveList primitive_list; int n; n = _scalars.count(); for (int i = 0; i< n; ++i) { primitive_list.append(kst_cast<Primitive>(_scalars.values().at(i))); } n = _strings.count(); for (int i = 0; i< n; ++i) { primitive_list.append(kst_cast<Primitive>(_strings.values().at(i))); } n = _vectors.count(); for (int i = 0; i< n; ++i) { VectorPtr V = _vectors.values().at(i); primitive_list.append(kst_cast<Primitive>(V)); primitive_list.append(V->outputPrimitives()); } return primitive_list; }