void FloatArray :: hardResize(int n) // Reallocates the receiver with new size. { int i; double *newValues, *p1, *p2; // if (n <= allocatedSize) {size = n; return;} newValues = allocDouble(n); #ifdef DEBUG if ( !newValues ) { OOFEM_FATAL2("FloatArray :: hardResize - Failed in allocating %d doubles", n); } #endif p1 = values; p2 = newValues; i = min(size, n); while ( i-- ) { * p2++ = * p1++; } if ( values ) { freeDouble(values); } values = newValues; allocatedSize = size = n; }
int Skyline :: setInternalStructure(IntArray *a) { // allocates and built structure according to given // array of maximal column heights // adr = new IntArray(*a); int n = a->giveSize(); nwk = adr->at(n); // check if ( mtrx ) { freeDouble(mtrx); } mtrx = allocDouble(nwk); nRows = nColumns = n - 1; // increment version this->version++; return true; }
void FloatArray :: resize(int n, int allocChunk) { int i; double *newValues, *p1, *p2; #ifdef DEBUG if ( allocChunk < 0 ) { OOFEM_FATAL2("FloatArray :: resize - allocChunk must be non-negative; %d", allocChunk); } #endif if ( n <= allocatedSize ) { size = n; return; } newValues = allocDouble(n + allocChunk); #ifdef DEBUG if ( !newValues ) { OOFEM_FATAL2("FloatArray :: resize - Failed in allocating %d doubles", n + allocChunk); } #endif p1 = values; p2 = newValues; i = size; while ( i-- ) { * p2++ = * p1++; } if ( values ) { freeDouble(values); } values = newValues; allocatedSize = n + allocChunk; size = n; }
SparseMtrx *Skyline :: GiveCopy() const { Skyline *answer; IntArray *adr1; double *mtrx1; int neq, i; neq = this->giveNumberOfRows(); adr1 = new IntArray(neq + 1); for ( i = 1; i <= neq + 1; i++ ) { adr1->at(i) = this->adr->at(i); } mtrx1 = allocDouble(this->nwk); for ( i = 0; i < this->nwk; i++ ) { mtrx1 [ i ] = this->mtrx [ i ]; } answer = new Skyline(neq, this->nwk, mtrx1, adr1); return answer; }
contextIOResultType FloatArray :: restoreYourself(DataStream *stream, ContextMode mode) // reads receiver from stream // warning - overwrites existing data! // returns 0 if file i/o error // -1 if id od class id is not correct { // read size if ( !stream->read(& size, 1) ) { return CIO_IOERR; } if ( size > allocatedSize ) { if ( values != NULL ) { freeDouble(values); } values = allocDouble(size); #ifdef DEBUG if ( !values ) { OOFEM_FATAL2("FloatArray :: restoreYourself - Failed in allocating %d doubles", size); } #endif allocatedSize = size; } // read raw data if ( size ) { if ( !stream->read(values, size) ) { return CIO_IOERR; } } // return result back return CIO_OK; }
FloatArray :: FloatArray(const FloatArray &src) { // copy constructor double *srcVal; allocatedSize = size = src.size; if ( size ) { values = allocDouble(size); #ifdef DEBUG if ( !values ) { OOFEM_FATAL2("FloatArray :: FloatArray - Failed in allocating %d doubles", size); } #endif } else { values = NULL; } srcVal = src.values; for ( int i = 0; i < size; i++ ) { this->values [ i ] = srcVal [ i ]; } }
Object allocDoubleWith(double e){ Double p = allocDouble(); *p = e; return p; }
void RubberBandStretcher::Impl::ChannelData::construct(const std::set<size_t> &windowSizes, size_t initialWindowSize, size_t outbufSize) { size_t maxSize = initialWindowSize; if (!windowSizes.empty()) { // std::set is ordered by value std::set<size_t>::const_iterator i = windowSizes.end(); maxSize = *--i; } if (windowSizes.find(initialWindowSize) == windowSizes.end()) { if (initialWindowSize > maxSize) maxSize = initialWindowSize; } // max size of the real "half" of freq data size_t realSize = (maxSize * oversample)/2 + 1; // std::cerr << "ChannelData::construct([" << windowSizes.size() << "], " << maxSize << ", " << outbufSize << ")" << std::endl; if (outbufSize < maxSize) outbufSize = maxSize; inbuf = new RingBuffer<float>(maxSize); outbuf = new RingBuffer<float>(outbufSize); mag = allocDouble(realSize); phase = allocDouble(realSize); prevPhase = allocDouble(realSize); prevError = allocDouble(realSize); unwrappedPhase = allocDouble(realSize); envelope = allocDouble(realSize); freqPeak = new size_t[realSize]; fltbuf = allocFloat(maxSize); accumulator = allocFloat(maxSize); windowAccumulator = allocFloat(maxSize); for (std::set<size_t>::const_iterator i = windowSizes.begin(); i != windowSizes.end(); ++i) { ffts[*i] = new FFT(*i * oversample); ffts[*i]->initDouble(); } if (windowSizes.find(initialWindowSize) == windowSizes.end()) { ffts[initialWindowSize] = new FFT(initialWindowSize * oversample); ffts[initialWindowSize]->initDouble(); } fft = ffts[initialWindowSize]; dblbuf = fft->getDoubleTimeBuffer(); resampler = 0; resamplebuf = 0; resamplebufSize = 0; reset(); for (size_t i = 0; i < realSize; ++i) { freqPeak[i] = 0; } for (size_t i = 0; i < initialWindowSize * oversample; ++i) { dblbuf[i] = 0.0; } for (size_t i = 0; i < maxSize; ++i) { accumulator[i] = 0.f; windowAccumulator[i] = 0.f; } // Avoid dividing opening sample (which will be discarded anyway) by zero windowAccumulator[0] = 1.f; }
void RubberBandStretcher::Impl::ChannelData::setWindowSize(size_t windowSize) { size_t oldSize = inbuf->getSize(); size_t realSize = (windowSize * oversample) / 2 + 1; // std::cerr << "ChannelData::setWindowSize(" << windowSize << ") [from " << oldSize << "]" << std::endl; if (oldSize >= windowSize) { // no need to reallocate buffers, just reselect fft //!!! we can't actually do this without locking against the //process thread, can we? we need to zero the mag/phase //buffers without interference if (ffts.find(windowSize) == ffts.end()) { //!!! this also requires a lock, but it shouldn't occur in //RT mode with proper initialisation ffts[windowSize] = new FFT(windowSize * oversample); ffts[windowSize]->initDouble(); } fft = ffts[windowSize]; dblbuf = fft->getDoubleTimeBuffer(); for (size_t i = 0; i < windowSize * oversample; ++i) { dblbuf[i] = 0.0; } for (size_t i = 0; i < realSize; ++i) { mag[i] = 0.0; phase[i] = 0.0; prevPhase[i] = 0.0; prevError[i] = 0.0; unwrappedPhase[i] = 0.0; freqPeak[i] = 0; } return; } //!!! at this point we need a lock in case a different client //thread is calling process() -- we need this lock even if we //aren't running in threaded mode ourselves -- if we're in RT //mode, then the process call should trylock and fail if the lock //is unavailable (since this should never normally be the case in //general use in RT mode) RingBuffer<float> *newbuf = inbuf->resized(windowSize); delete inbuf; inbuf = newbuf; // We don't want to preserve data in these arrays mag = allocDouble(mag, realSize); phase = allocDouble(phase, realSize); prevPhase = allocDouble(prevPhase, realSize); prevError = allocDouble(prevError, realSize); unwrappedPhase = allocDouble(unwrappedPhase, realSize); envelope = allocDouble(envelope, realSize); delete[] freqPeak; freqPeak = new size_t[realSize]; fltbuf = allocFloat(fltbuf, windowSize); // But we do want to preserve data in these float *newAcc = allocFloat(windowSize); for (size_t i = 0; i < oldSize; ++i) newAcc[i] = accumulator[i]; freeFloat(accumulator); accumulator = newAcc; newAcc = allocFloat(windowSize); for (size_t i = 0; i < oldSize; ++i) newAcc[i] = windowAccumulator[i]; freeFloat(windowAccumulator); windowAccumulator = newAcc; //!!! and resampler? for (size_t i = 0; i < realSize; ++i) { freqPeak[i] = 0; } for (size_t i = 0; i < windowSize; ++i) { fltbuf[i] = 0.f; } if (ffts.find(windowSize) == ffts.end()) { ffts[windowSize] = new FFT(windowSize * oversample); ffts[windowSize]->initDouble(); } fft = ffts[windowSize]; dblbuf = fft->getDoubleTimeBuffer(); for (size_t i = 0; i < windowSize * oversample; ++i) { dblbuf[i] = 0.0; } }
double *allocDouble(int count) { return allocDouble(0, count); }
int Skyline :: buildInternalStructure(EngngModel *eModel, int di, EquationID ut, const UnknownNumberingScheme &s) { // first create array of // maximal column height for assembled characteristics matrix // int j, js, ieq, maxle; int i, ac1; int neq; if ( s.isDefault() ) { neq = eModel->giveNumberOfDomainEquations(di, ut); } else { neq = s.giveRequiredNumberOfDomainEquation(); if ( neq == 0 ) { OOFEM_ERROR("Undefined Required number of domain equations"); } } IntArray loc; IntArray *mht = new IntArray(neq); Domain *domain = eModel->giveDomain(di); for ( j = 1; j <= neq; j++ ) { mht->at(j) = j; // initialize column height, maximum is line number (since it only stores upper triangular) } int nelem = domain->giveNumberOfElements(); // loop over elements code numbers for ( i = 1; i <= nelem; i++ ) { domain->giveElement(i)->giveLocationArray(loc, ut, s); js = loc.giveSize(); maxle = INT_MAX; for ( j = 1; j <= js; j++ ) { ieq = loc.at(j); if ( ieq != 0 ) { maxle = min(maxle, ieq); } } for ( j = 1; j <= js; j++ ) { ieq = loc.at(j); if ( ieq != 0 ) { mht->at(ieq) = min( maxle, mht->at(ieq) ); } } } // NOTE // add there call to eModel if any possible additional equation added by // eModel // currently not supported // increases number of columns according to size of mht // mht is array containing minimal equation number per column // This method also increases column height. if ( this->adr ) { delete adr; } adr = new IntArray(neq + 1); ac1 = 1; for ( i = 1; i <= neq; i++ ) { adr->at(i) = ac1; ac1 += ( i - mht->at(i) + 1 ); } adr->at(neq + 1) = ac1; nRows = nColumns = neq; nwk = ac1; if ( mtrx ) { freeDouble(mtrx); } mtrx = allocDouble(ac1); delete mht; // increment version this->version++; return true; }