本文整理汇总了C++中KstVectorPtr::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ KstVectorPtr::resize方法的具体用法?C++ KstVectorPtr::resize怎么用?C++ KstVectorPtr::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KstVectorPtr
的用法示例。
在下文中一共展示了KstVectorPtr::resize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: 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();
//.........这里部分代码省略.........
示例4: update
KstObject::UpdateType EventMonitorEntry::update(int updateCounter) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
bool force = dirty();
setDirty(false);
if (KstObject::checkUpdateCounter(updateCounter) && !force) {
return lastUpdateResult();
}
writeLockInputsAndOutputs();
if (!_pExpression) {
reparse();
}
KstVectorPtr xv = *_xVector;
KstVectorPtr yv = *_yVector;
int ns = 1;
for (KstVectorMap::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();
}
}
Equation::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;
}
if (xv) {
xv->setDirty();
xv->update(updateCounter);
}
if (yv) {
yv->setDirty();
yv->update(updateCounter);
}
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
示例5: 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];
}
//.........这里部分代码省略.........
示例6: crossspectrum
void CrossPowerSpectrum::crossspectrum() {
KstVectorPtr v1 = *_inputVectors.find(VECTOR_ONE);
KstVectorPtr v2 = *_inputVectors.find(VECTOR_TWO);
KstScalarPtr fft = *_inputScalars.find(FFT_LENGTH);
KstScalarPtr sample = *_inputScalars.find(SAMPLE_RATE);
KstVectorPtr real = *_outputVectors.find(REAL);
KstVectorPtr imaginary = *_outputVectors.find(IMAGINARY);
KstVectorPtr frequency = *_outputVectors.find(FREQUENCY);
double SR = sample->value(); // sample rate
double df;
int i, xps_len;
double *a, *b;
double mean_a, mean_b;
int dv0, dv1, v_len;
int i_subset, n_subsets;
int i_samp, copyLen;
double norm_factor;
/* parse fft length */
xps_len = int( fft->value() - 0.99);
if ( xps_len > KSTPSDMAXLEN ) xps_len = KSTPSDMAXLEN;
if ( xps_len<2 ) xps_len = 2;
xps_len = int ( pow( 2, xps_len ) );
/* input vector lengths */
v_len = ( ( v1->length() < v2->length() ) ?
v1->length() : v2->length() );
dv0 = v_len/v1->length();
dv1 = v_len/v2->length();
while ( xps_len > v_len ) xps_len/=2;
// allocate the lengths
if ( real->length() != xps_len ) {
real->resize( xps_len, false );
imaginary->resize( xps_len, false );
frequency->resize( xps_len, false );
}
/* Fill the frequency and zero the xps */
df = SR/( 2.0*double( xps_len-1 ) );
for ( i=0; i<xps_len; i++ ) {
frequency->value()[i] = double( i ) * df;
real->value()[i] = 0.0;
imaginary->value()[i] = 0.0;
}
/* allocate input arrays */
int ALen = xps_len * 2;
a = new double[ALen];
b = new double[ALen];
/* do the fft's */
n_subsets = v_len/xps_len + 1;
for ( i_subset=0; i_subset<n_subsets; i_subset++ ) {
/* copy each chunk into a[] and find mean */
if (i_subset*xps_len + ALen <= v_len) {
copyLen = ALen;
} else {
copyLen = v_len - i_subset*xps_len;
}
mean_b = mean_a = 0;
for (i_samp = 0; i_samp < copyLen; i_samp++) {
i = ( i_samp + i_subset*xps_len )/dv0;
mean_a += (
a[i_samp] = v1->value()[i]
);
i = ( i_samp + i_subset*xps_len )/dv1;
mean_b += (
b[i_samp] = v2->value()[i]
);
}
if (copyLen>1) {
mean_a/=(double)copyLen;
mean_b/=(double)copyLen;
}
/* Remove Mean and apodize */
for (i_samp=0; i_samp<copyLen; i_samp++) {
a[i_samp] -= mean_a;
b[i_samp] -= mean_b;
}
for (;i_samp < ALen; i_samp++) {
a[i_samp] = 0.0;
b[i_samp] = 0.0;
}
/* fft */
rdft(ALen, 1, a);
rdft(ALen, 1, b);
/* sum each bin into psd[] */
real->value()[0] += ( a[0]*b[0] );
real->value()[xps_len-1] += ( a[1]*b[1] );
for (i_samp=1; i_samp<xps_len-1; i_samp++) {
//.........这里部分代码省略.........