void aol::Vector<_DataType>::pushBackValues ( const aol::Vector<_DataType> &otherVector ) { const int currentSize = this->size(); this->growBy ( otherVector.size() ); for ( int i = 0; i < otherVector.size(); ++i ) { this->set ( currentSize + i, otherVector.get ( i ) ); } }
void aol::Vector<_DataType>::absDiff ( aol::Vector<_DataType> const& Vec1, aol::Vector<_DataType> const& Vec2 ) { if ( Vec1.size() != _size || Vec2.size() != _size ) { throw aol::Exception ( "dimensions don't match", "aol::Vector::absDiff" ); } for ( int i = 0; i < _size; ++i ) { _pData[ i ] = static_cast< DataType > ( aol::Abs ( Vec1._pData[i] - Vec2._pData[i] ) ); } }
void aol::Vector<_DataType>::setSum ( const aol::Vector<_DataType>& Vec1, const aol::Vector<_DataType>& Vec2, _DataType Factor ) { if ( Vec1.size() != _size || Vec2.size() != _size ) { cerr << "ERROR in add: incompatible vectorlengths...\n"; return; } DataType *ptr = _pData; for ( int i = 0; i < _size; ++i ) { *ptr = Vec1.get ( i ) + Vec2.get ( i ) * Factor; ptr++; } }
typename aol::Vector<_DataType>::RealType aol::Vector<_DataType>:: getWeightedMedianValue( const aol::Vector<RealType> &Weights ) const { const int numVals = this->size(); if ( numVals != Weights.size() ) throw Exception ( "aol::Vector<DataType>::getWeightedMedianValue: numVals != Weights.size() !\n", __FILE__, __LINE__ ); if ( Weights.getMinValue() <= 0 ) throw Exception ( "aol::Vector<DataType>::getWeightedMedianValue: Nonpositive weights are not supported!\n", __FILE__, __LINE__ ); std::vector<std::pair<_DataType, RealType> > valuesAndWeights; valuesAndWeights.reserve ( numVals ); for ( int i = 0; i < numVals; ++i ) valuesAndWeights.push_back ( std::pair<_DataType, RealType> ( this->get ( i ), Weights[i] ) ); std::sort( valuesAndWeights.begin(), valuesAndWeights.end() ); const RealType halfOfTotalWeight = 0.5 * Weights.sum(); RealType weight = 0; for ( int i = 0; i < numVals; ++i ) { weight += valuesAndWeights[i].second; if ( ( weight > halfOfTotalWeight ) || ( i == ( numVals - 1 ) ) ) return valuesAndWeights[i].first; else if ( aol::appeqAbsolute ( weight, halfOfTotalWeight ) ) { return ( valuesAndWeights[i].first * valuesAndWeights[i].second + valuesAndWeights[i+1].first * valuesAndWeights[i+1].second ) / ( valuesAndWeights[i].second + valuesAndWeights[i+1].second ); } } return valuesAndWeights[numVals-1].first; }
_DataType aol::Vector<_DataType>::operator* ( const aol::Vector<_DataType> &c ) const { if ( c.size() != _size ) { throw aol::Exception ( "Vector::operator*: Vectorlengths not equal...", __FILE__, __LINE__ ); } else { return ScalarProduct<DataType> ( this->_pData, c.getData(), _size ); } return 0; }
void aol::Vector<_DataType>::addBlock ( int start, const aol::Vector<_DataType>& block ) { int siz = block.size (); if ( start + siz > size () ) throw aol::Exception ( "aol::Vector<T,R>::addBlock: Parameter mismatch: Block does not fit", __FILE__, __LINE__ ); for ( int i = 0; i < siz; ++i ) add ( start + i, block.get ( i ) ); }
_DataType aol::Vector<_DataType>::sumWeighted ( aol::Vector<_DataType> const& weight ) const { #ifdef BOUNDS_CHECK if ( weight.size() < _size ) { char error[1024]; sprintf ( error, "Vector<DataType>::sumWeighted: weight vector not long enough (%d), should be %d at least.\n", weight.size(), _size ); throw OutOfBoundsException ( error, __FILE__, __LINE__ ); } #endif _DataType ret = 0.; _DataType *ptr = _pData; for ( int i = 0; i < _size; ++i ) ret += *ptr++ * weight[i]; return ret; }