本文整理汇总了C++中KstVectorPtr::length方法的典型用法代码示例。如果您正苦于以下问题:C++ KstVectorPtr::length方法的具体用法?C++ KstVectorPtr::length怎么用?C++ KstVectorPtr::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KstVectorPtr
的用法示例。
在下文中一共展示了KstVectorPtr::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: algorithm
//swap input vector
bool Reverse::algorithm() {
KstVectorPtr input = inputVector(INPUT);
KstVectorPtr output = outputVector(OUTPUT);
output->resize(input->length());
int length = input->length();
for (int i = 0; i < length; i++){
output->value()[length-i-1] = input->value()[i];
}
return true;
}
示例2: createFitScalars
// FIXME: KstPlugin should not know about fit scalars!!
void KstPlugin::createFitScalars() {
// Assumes that this is called with a write lock in place on this object
if (_plugin->data()._isFit && _outputVectors.contains("Parameters")) {
KstVectorPtr vectorParam = _outputVectors["Parameters"];
if (vectorParam) {
QString paramName;
int i = 0;
int length = vectorParam->length();
for (paramName = _plugin->parameterName(i);
!paramName.isEmpty() && i < length;
paramName = _plugin->parameterName(++i)) {
double scalarValue = vectorParam->value(i);
if (!_outputScalars.contains(paramName)) {
QString scalarName = i18n("%1-%2").arg(tagName()).arg(paramName);
KstScalarPtr s = new KstScalar(scalarName, this, scalarValue);
s->KstObject::writeLock();
_outputScalars.insert(paramName, s);
++_outScalarCnt;
} else {
_outputScalars[paramName]->setValue(scalarValue);
}
}
}
}
}
示例3: createFitScalars
void KstCPlugin::createFitScalars() {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
// Assumes that this is called with a write lock in place on this object
if (_plugin->data()._isFit && _outputVectors.contains("Parameters")) {
KstVectorPtr vectorParam = _outputVectors["Parameters"];
if (vectorParam) {
QString paramName;
int i = 0;
int length = vectorParam->length();
KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
KST::scalarList.setUpdateDisplayTags(false);
for (paramName = _plugin->parameterName(i);
!paramName.isEmpty() && i < length;
paramName = _plugin->parameterName(++i)) {
double scalarValue = vectorParam->value(i);
if (!_outputScalars.contains(paramName)) {
KstScalarPtr s = new KstScalar(KstObjectTag(paramName, tag()), this, scalarValue);
s->KstObject::writeLock(); // must write lock, since fit scalars are created from update()
_outputScalars.insert(paramName, s);
++_outScalarCnt;
} else {
_outputScalars[paramName]->setValue(scalarValue);
}
}
KST::scalarList.setUpdateDisplayTags(true);
}
}
}
示例4: vectorToFile
int KST::vectorToFile(KstVectorPtr v, QFile *f) {
int rc = 0;
#define BSIZE 128
char buf[BSIZE];
int _size = v->length();
double *_v = v->value();
register int modval;
KProgressDialog *kpd = new KProgressDialog(0L, "vector save", i18n("Saving Vector"), i18n("Saving vector %1...").arg(v->tagName()));
kpd->setAllowCancel(false);
kpd->progressBar()->setTotalSteps(_size);
kpd->show();
modval = QMAX(_size/100, 100);
for (int i = 0; i < _size; i++) {
int l = snprintf(buf, BSIZE, "%d %g\n", i, _v[i]);
f->writeBlock(buf, l);
if (i % 100 == 0) {
kpd->progressBar()->setProgress(i);
kapp->processEvents();
}
}
kpd->progressBar()->setProgress(_size);
delete kpd;
#undef BSIZE
return rc;
}
示例5: AutoBin
void KstHistogram::AutoBin(KstVectorPtr 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;
}
示例6: doTest
bool doTest(const char *equation, double x, double result, const double tol = 0.00000000001) {
yy_scan_string(equation);
int rc = yyparse();
if (rc == 0) {
vectorsUsed.clear();
Equation::Node *eq = static_cast<Equation::Node*>(ParsedEquation);
assert(eq);
ParsedEquation = 0L;
Equation::Context ctx;
ctx.sampleCount = 2;
ctx.noPoint = NOPOINT;
ctx.x = x;
ctx.xVector = xVector;
if (xVector) {
ctx.sampleCount = xVector->length();
}
Equation::FoldVisitor vis(&ctx, &eq);
if (eq->isConst() && !dynamic_cast<Equation::Number*>(eq)) {
if (!optimizerFailed) {
optimizerFailed = true;
::rc--;
printf("Optimizer bug: found an unoptimized const equation. Optimizing for coverage purposes.\n");
}
double v = eq->value(&ctx);
delete eq;
eq = new Equation::Number(v);
}
KstScalarMap scm;
KstStringMap stm;
eq->collectObjects(vectorsUsed, scm, stm);
//
// do not use -1 in the call to eq->update( ... )
// as this will simply return without updating the plugin,
// unless an underlying data object was updated...
//
eq->update(0, &ctx);
double v = eq->value(&ctx);
delete eq;
if (fabs(v - result) < tol || (result != result && v != v) || (result == INF && v == INF) || (result == -INF && v == -INF)) {
return true;
} else {
printf("Result: %.16f\n", v);
return false;
}
} else {
// Parse error
printf("Failures on [%s] -------------------------\n", equation);
for (QStringList::ConstIterator i = Equation::errorStack.constBegin(); i != Equation::errorStack.constEnd(); ++i) {
printf("%s\n", (*i).latin1());
}
printf("------------------------------------------\n");
delete (Equation::Node*)ParsedEquation;
ParsedEquation = 0L;
return false;
}
}
示例7: AutoSize
void BinnedMap::AutoSize(KstVectorPtr x, KstVectorPtr y, int *nx, double *minx, double *maxx, int *ny, double *miny, double *maxy) {
// use a very simple guess at nx and ny... One could imagine something more
// clever in principle.
*nx = *ny = (int)sqrt(x->length())/2;
if (*nx<2) *nx = 2;
if (*ny<2) *ny = 2;
*minx = x->min();
*maxx = x->max();
*miny = y->min();
*maxy = y->max();
}
示例8: algorithm
bool Differentiation::algorithm() {
KstVectorPtr inputvector = inputVector(INPUTVECTOR);
KstScalarPtr time_step = inputScalar(TIME_STEP);
KstVectorPtr derivative = outputVector(DERIVATIVE);
/* Memory allocation */
if (derivative->length() != inputvector->length()) {
derivative->resize(inputvector->length(), true);
}
derivative->value()[0] = (inputvector->value()[1] - inputvector->value()[0]) / time_step->value();
int i = 1;
for (; i < inputvector->length()-1; i++) {
derivative->value()[i] = (inputvector->value()[i+1] - inputvector->value()[i-1])/(2*time_step->value());
}
derivative->value()[i] = (inputvector->value()[i] - inputvector->value()[i-1]) / time_step->value();
return true;
}
示例9: update
KstObject::UpdateType KstPSD::update(int update_counter) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
bool force = dirty();
setDirty(false);
if (KstObject::checkUpdateCounter(update_counter) && !force) {
return lastUpdateResult();
}
if (recursed()) {
return setLastUpdateResult(NO_CHANGE);
}
writeLockInputsAndOutputs();
KstVectorPtr iv = _inputVectors[INVECTOR];
if (update_counter <= 0) {
assert(update_counter == 0);
force = true;
}
bool xUpdated = KstObject::UPDATE == iv->update(update_counter);
const int v_len = iv->length();
// Don't touch _last_n_new if !xUpdated since it will certainly be wrong.
if (!xUpdated && !force) {
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
_last_n_new += iv->numNew();
assert(_last_n_new >= 0);
int n_subsets = v_len/_PSDLen;
// determine if the PSD needs to be updated. if not using averaging, then we need at least _PSDLen/16 new data points. if averaging, then we want enough new data for a complete subset.
if ( ((_last_n_new < _PSDLen/16) || (_Average && (n_subsets - _last_n_subsets < 1))) && iv->length() != iv->numNew() && !force) {
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
_adjustLengths();
double *psd = (*_sVector)->value();
double *f = (*_fVector)->value();
int i_samp;
for (i_samp = 0; i_samp < _PSDLen; ++i_samp) {
f[i_samp] = i_samp * 0.5 * _Freq / (_PSDLen - 1);
}
_psdCalculator.calculatePowerSpectrum(iv->value(), v_len, psd, _PSDLen, _RemoveMean, _interpolateHoles, _Average, _averageLen, _Apodize, _apodizeFxn, _gaussianSigma, _Output, _Freq);
_last_n_subsets = n_subsets;
_last_n_new = 0;
updateVectorLabels();
(*_sVector)->setDirty();
(*_sVector)->update(update_counter);
(*_fVector)->setDirty();
(*_fVector)->update(update_counter);
unlockInputsAndOutputs();
return setLastUpdateResult(UPDATE);
}
示例10: algorithm
bool CrossCorrelate::algorithm() {
KstVectorPtr array_one = inputVector(ARRAY_ONE);
KstVectorPtr array_two = inputVector(ARRAY_TWO);
KstVectorPtr step_value = outputVector(STEP_VALUE);
KstVectorPtr correlated = outputVector(CORRELATED);
if (array_one->length() <= 0 ||
array_two->length() <= 0 ||
array_one->length() != array_two->length()) {
return false;
}
double* pdArrayOne;
double* pdArrayTwo;
double* pdResult[2];
double dReal;
double dImag;
int iLength;
int iLengthNew;
bool iReturn = false;
//
// zero-pad the array...
//
iLength = array_one->length();
iLength *= 2;
step_value->resize(array_one->length(), false);
correlated->resize(array_two->length(), false);
//
// round iLength up to the nearest power of two...
//
iLengthNew = 64;
while( iLengthNew < iLength && iLengthNew > 0) {
iLengthNew *= 2;
}
iLength = iLengthNew;
if (iLength <= 0)
return false;
pdArrayOne = new double[iLength];
pdArrayTwo = new double[iLength];
if (pdArrayOne != NULL && pdArrayTwo != NULL) {
//
// zero-pad the two arrays...
//
memset( pdArrayOne, 0, iLength * sizeof( double ) );
memcpy( pdArrayOne, array_one->value(), array_one->length() * sizeof( double ) );
memset( pdArrayTwo, 0, iLength * sizeof( double ) );
memcpy( pdArrayTwo, array_two->value(), array_two->length() * sizeof( double ) );
//
// calculate the FFTs of the two functions...
//
if (gsl_fft_real_radix2_transform( pdArrayOne, 1, iLength ) == 0) {
if (gsl_fft_real_radix2_transform( pdArrayTwo, 1, iLength ) == 0) {
//
// multiply one FFT by the complex conjugate of the other...
//
for (int i=0; i<iLength/2; i++) {
if (i==0 || i==(iLength/2)-1) {
pdArrayOne[i] = pdArrayOne[i] * pdArrayTwo[i];
} else {
dReal = pdArrayOne[i] * pdArrayTwo[i] + pdArrayOne[iLength-i] * pdArrayTwo[iLength-i];
dImag = pdArrayOne[i] * pdArrayTwo[iLength-i] - pdArrayOne[iLength-i] * pdArrayTwo[i];
pdArrayOne[i] = dReal;
pdArrayOne[iLength-i] = dImag;
}
}
//
// do the inverse FFT...
//
if (gsl_fft_halfcomplex_radix2_inverse( pdArrayOne, 1, iLength ) == 0) {
if (step_value->length() != array_one->length()) {
pdResult[0] = (double*)realloc( step_value->value(), array_one->length() * sizeof( double ) );
} else {
pdResult[0] = step_value->value();
}
if (correlated->length() != array_two->length()) {
pdResult[1] = (double*)realloc( correlated->value(), array_two->length() * sizeof( double ) );
} else {
pdResult[1] = correlated->value();
}
if (pdResult[0] != NULL && pdResult[1] != NULL) {
for (int i = 0; i < array_one->length(); ++i) {
step_value->value()[i] = pdResult[0][i];
}
for (int i = 0; i < array_two->length(); ++i) {
correlated->value()[i] = pdResult[1][i];
}
//.........这里部分代码省略.........
示例11: binnedmap
void BinnedMap::binnedmap() {
KstVectorPtr x = *_inputVectors.find(VECTOR_X);
KstVectorPtr y = *_inputVectors.find(VECTOR_Y);
KstVectorPtr z = *_inputVectors.find(VECTOR_Z);
KstMatrixPtr map = *_outputMatrices.find(MAP);
KstMatrixPtr hitsMap = *_outputMatrices.find(HITSMAP);
KstScalarPtr autobin = *_inputScalars.find(AUTOBIN);
if (autobin) {
if (autobin->value() != 0.0) {
_autoBin = true;
} else {
_autoBin = false;
}
}
if (_autoBin) {
double minx, miny, maxx, maxy;
int nx, ny;
autoSize(X(), Y(), &nx, &minx, &maxx, &ny, &miny, &maxy);
setNX(nx);
setNY(ny);
setXMin(minx);
setXMax(maxx);
setYMin(miny);
setYMax(maxy);
} else {
KstScalarPtr xmin = *_inputScalars.find(XMIN);
KstScalarPtr xmax = *_inputScalars.find(XMAX);
KstScalarPtr ymin = *_inputScalars.find(YMIN);
KstScalarPtr ymax = *_inputScalars.find(YMAX);
KstScalarPtr nx = *_inputScalars.find(NX);
KstScalarPtr ny = *_inputScalars.find(NY);
if (xmin) {
_xMin = xmin->value();
}
if (xmax) {
_xMax = xmax->value();
}
if (ymin) {
_yMin = ymin->value();
}
if (ymax) {
_yMax = ymax->value();
}
if (nx) {
_nx = (int)nx->value();
}
if (ny) {
_ny = (int)ny->value();
}
}
bool needsresize = false;
if (_nx < 2) {
_nx = 2;
needsresize = true;
}
if (_ny < 2) {
_ny = 2;
needsresize = true;
}
if ((map->xNumSteps() != _nx) || (map->yNumSteps() != _ny) ||
(map->minX() != _xMin) || (map->minY() != _yMin)) {
needsresize = true;
}
if (map->xStepSize() != (_xMax - _xMin)/double(_nx-1)) {
needsresize = true;
}
if (map->yStepSize() != (_yMax - _yMin)/double(_ny-1)) {
needsresize = true;
}
if (needsresize) {
map->change(map->tag(), _nx, _ny, _xMin, _yMin,
(_xMax - _xMin)/double(_nx-1), (_yMax - _yMin)/double(_ny-1));
map->resize(_nx, _ny);
hitsMap->change(hitsMap->tag(), _nx, _ny, _xMin, _yMin,
(_xMax - _xMin)/double(_nx-1), (_yMax - _yMin)/double(_ny-1));
hitsMap->resize(_nx, _ny);
}
map->zero();
hitsMap->zero();
int ns = z->length(); // the z vector defines the number of points.
double n,p, x0, y0, z0;
for (int i=0; i<ns; i++) {
x0 = x->interpolate(i, ns);
y0 = y->interpolate(i, ns);
z0 = z->interpolate(i, ns);
p = map->value(x0, y0)+z0;
map->setValue(x0, y0, p);
//.........这里部分代码省略.........
示例12: update
KstObject::UpdateType KstCSD::update(int update_counter) {
KstVectorPtr inVector = _inputVectors[INVECTOR];
bool force = dirty();
setDirty(false);
if (KstObject::checkUpdateCounter(update_counter) && !force) {
return lastUpdateResult();
}
if (update_counter <= 0) {
assert(update_counter == 0);
force = true;
}
bool xUpdated = KstObject::UPDATE == inVector->update(update_counter);
// if vector was not changed, don't update the CSD
if ((!xUpdated) && !force ) {
return setLastUpdateResult(NO_CHANGE);
}
// create a psd generator
KstPSDGenerator psdGenerator(0L, _frequency, _average, _length,
_apodize, _removeMean, _apodizeFxn, _gaussianSigma);
int xSize = 0;
for (int i=0; i < inVector->length(); i+= _windowSize + 1) {
int vectorSize = _windowSize;
// determine size of actual input data
if (i + _windowSize >= inVector->length()) {
if (i == 0) {
// if this is the one and only window, get a PSD
vectorSize = i + _windowSize - inVector->length();
} else {
// don't PSD the last window if it is chopped off
break;
}
}
// copy input vector elements into subvector
QValueVector<double> psdInputVector(_windowSize, 0);
double* inVectorArray = inVector->value();
for (int j=0; j < vectorSize; j++) {
psdInputVector[j] = inVectorArray[i+j];
}
// set the vector and calculate PSD
psdGenerator.setInputVector(&psdInputVector);
psdGenerator.updateNow();
// resize output matrix
(*_outMatrix)->resize(xSize+1, psdGenerator.powerVector()->size());
// copy elements to output matrix
for (uint j=0; j < psdGenerator.powerVector()->size(); j++) {
(*_outMatrix)->setValueRaw(xSize, j, psdGenerator.powerVector()->at(j));
}
xSize++;
}
(*_outMatrix)->change((*_outMatrix)->tagName(), xSize, psdGenerator.frequencyVector()->size(), 0, 0, _windowSize, psdGenerator.frequencyVectorStep());
(*_outMatrix)->update(update_counter);
return setLastUpdateResult(UPDATE);
}
示例13: fitChanged
void KstViewFitsDialog::fitChanged(const QString& strFit) {
KstCPluginList fits;
KstCPluginPtr plugin;
double* params = 0L;
double* covars = 0L;
double chi2Nu = 0.0;
int numParams = 0;
int numCovars = 0;
int i;
fits = kstObjectSubList<KstDataObject,KstCPlugin>(KST::dataObjectList);
plugin = *(fits.findTag(strFit));
if (plugin) {
KstScalarPtr scalarChi2Nu;
KstVectorPtr vectorParam;
plugin->readLock();
const KstScalarMap& scalars = plugin->outputScalars();
scalarChi2Nu = scalars["chi^2/nu"];
if (scalarChi2Nu) {
scalarChi2Nu->readLock();
chi2Nu = scalarChi2Nu->value();
scalarChi2Nu->unlock();
}
const KstVectorMap& vectors = plugin->outputVectors();
vectorParam = vectors["Parameters"];
if (vectorParam) {
KstVectorPtr vectorCovar;
vectorParam->readLock();
vectorCovar = vectors["Covariance"];
if (vectorCovar) {
vectorCovar->readLock();
numParams = vectorParam->length();
numCovars = vectorCovar->length();
if (numParams > 0 && numCovars > 0) {
params = new double[numParams];
covars = new double[numCovars];
for (i = 0; i < numParams; i++) {
params[i] = vectorParam->value(i);
}
for (i = 0; i < numCovars; i++) {
covars[i] = vectorCovar->value(i);
}
}
vectorCovar->unlock();
}
vectorParam->unlock();
}
plugin->unlock();
}
_tableFits->setParameters(params, numParams, covars, numCovars, chi2Nu);
if (numParams > 0) {
_tableFits->horizontalHeaderItem(0)->setText(QObject::tr("Value"));
_tableFits->horizontalHeaderItem(1)->setText(QObject::tr("Covariance:"));
_tableFits->verticalHeaderItem(numParams+0)->setText("---");
_tableFits->verticalHeaderItem(numParams+1)->setText(QObject::tr("Chi^2/Nu"));
if (plugin) {
QExplicitlySharedDataPointer<Plugin> pluginBase;
plugin->readLock();
pluginBase = plugin->plugin();
if (pluginBase) {
textLabelFit->setText(pluginBase->data()._readableName);
for (i = 0; i < numParams; i++) {
QString parameterName = pluginBase->parameterName(i);
_tableFits->horizontalHeaderItem(i+2)->setText(parameterName);
_tableFits->verticalHeaderItem(i)->setText(parameterName);
}
}
plugin->unlock();
}
}
_tableFits->update();
}
示例14: update
KstObject::UpdateType KstCPlugin::update(int update_counter) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
if (!isValid()) {
return setLastUpdateResult(NO_CHANGE);
}
if (recursed()) {
return setLastUpdateResult(NO_CHANGE);
}
bool force = dirty();
setDirty(false);
if (KstObject::checkUpdateCounter(update_counter) && !force) {
return lastUpdateResult();
}
#define CLEANUP() do {\
for (unsigned i = 0; i < _outStringCnt; ++i) { \
if (_outStrings[i]) { \
free(_outStrings[i]); \
_outStrings[i] = 0L; \
} \
} \
for (unsigned i = 0; i < _inStringCnt; ++i) { \
if (_inStrings[i]) { \
free(_inStrings[i]); \
_inStrings[i] = 0L; \
} \
} \
} while(0)
writeLockInputsAndOutputs();
const QValueList<Plugin::Data::IOValue>& itable = _plugin->data()._inputs;
const QValueList<Plugin::Data::IOValue>& otable = _plugin->data()._outputs;
int itcnt = 0, vitcnt = 0, sitcnt = 0;
bool doUpdate = force;
// Populate the input scalars and vectors
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!_inputVectors.contains((*it)._name)) {
KstDebug::self()->log(i18n("Input vector [%1] for plugin %2 not found. Unable to continue.").arg((*it)._name).arg(tagName()), KstDebug::Error);
CLEANUP();
return setLastUpdateResult(NO_CHANGE);
}
KstVectorPtr iv = _inputVectors[(*it)._name];
if (!iv) {
kstdFatal() << "Input vector \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == iv->update(update_counter)) || doUpdate;
_inVectors[vitcnt] = iv->value();
_inArrayLens[vitcnt++] = iv->length();
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
KstScalarPtr is = _inputScalars[(*it)._name];
if (!is) {
kstdFatal() << "Input scalar \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == is->update(update_counter)) || doUpdate;
_inScalars[itcnt++] = is->value();
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
KstStringPtr is = _inputStrings[(*it)._name];
if (!is) {
kstdFatal() << "Input string \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == is->update(update_counter)) || doUpdate;
// Maybe we should use UTF-8 instead?
_inStrings[sitcnt++] = strdup(is->value().latin1());
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
_inScalars[itcnt++] = getpid();
}
}
if (!doUpdate) {
CLEANUP();
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
vitcnt = 0;
// Populate the output vectors
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
it != otable.end();
++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!_outputVectors.contains((*it)._name)) {
KstDebug::self()->log(i18n("Output vector [%1] for plugin %2 not found. Unable to continue.").arg((*it)._name).arg(tagName()), KstDebug::Error);
CLEANUP();
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
_outVectors[vitcnt] = _outputVectors[(*it)._name]->value();
_outArrayLens[vitcnt++] = _outputVectors[(*it)._name]->length();
}
}
if (_outStringCnt > 0) {
//.........这里部分代码省略.........
示例15: FillY
bool KstEquation::FillY(bool force) {
int v_shift=0, v_new;
int i0=0;
int ns;
writeLockInputsAndOutputs();
// determine value of Interp
if (_doInterp) {
ns = (*_xInVector)->length();
for (KstVectorMap::ConstIterator i = VectorsUsed.begin(); i != VectorsUsed.end(); ++i) {
if (i.data()->length() > ns) {
ns = i.data()->length();
}
}
} else {
ns = (*_xInVector)->length();
}
if (_ns != (*_xInVector)->length() || ns != (*_xInVector)->length() ||
(*_xInVector)->numShift() != (*_xInVector)->numNew()) {
_ns = ns;
KstVectorPtr xv = *_xOutVector;
KstVectorPtr yv = *_yOutVector;
if (!xv->resize(_ns)) {
// FIXME: handle error?
unlockInputsAndOutputs();
return false;
}
if (!yv->resize(_ns)) {
// FIXME: handle error?
unlockInputsAndOutputs();
return false;
}
yv->zero();
i0 = 0; // other vectors may have diffent lengths, so start over
v_shift = _ns;
} else {
// calculate shift and new samples
// only do shift optimization if all used vectors are same size and shift
v_shift = (*_xInVector)->numShift();
v_new = (*_xInVector)->numNew();
for (KstVectorMap::ConstIterator i = VectorsUsed.begin(); i != VectorsUsed.end(); ++i) {
if (v_shift != i.data()->numShift()) {
v_shift = _ns;
}
if (v_new != i.data()->numNew()) {
v_shift = _ns;
}
if (_ns != i.data()->length()) {
v_shift = _ns;
}
}
if (v_shift > _ns/2 || force) {
i0 = 0;
v_shift = _ns;
} else {
KstVectorPtr xv = *_xOutVector;
KstVectorPtr yv = *_yOutVector;
for (int i = v_shift; i < _ns; i++) {
yv->value()[i - v_shift] = yv->value()[i];
xv->value()[i - v_shift] = xv->value()[i];
}
i0 = _ns - v_shift;
}
}
_numShifted = (*_yOutVector)->numShift() + v_shift;
if (_numShifted > _ns) {
_numShifted = _ns;
}
_numNew = _ns - i0 + (*_yOutVector)->numNew();
if (_numNew > _ns) {
_numNew = _ns;
}
(*_xOutVector)->setNewAndShift(_numNew, _numShifted);
(*_yOutVector)->setNewAndShift(_numNew, _numShifted);
double *rawxv = (*_xOutVector)->value();
double *rawyv = (*_yOutVector)->value();
KstVectorPtr iv = (*_xInVector);
Equation::Context ctx;
ctx.sampleCount = _ns;
ctx.xVector = iv;
if (!_pe) {
if (_equation.isEmpty()) {
unlockInputsAndOutputs();
return true;
}
QMutexLocker ml(&Equation::mutex());
yy_scan_string(_equation.latin1());
int rc = yyparse();
//.........这里部分代码省略.........