Changeset 28


Ignore:
Timestamp:
Aug 20, 2003, 3:57:08 PM (14 years ago)
Author:
daniel
Message:

Added two operators: "*" which is defined as dotproduct and
mul_elements which is def as elementwise multiplication (returning a vector).

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/vector.cc

    r27 r28  
    167167
    168168
    169 vector vector::operator*( const vector &other ) const
    170 {
    171   assert( size() == other.size() );
    172   vector res( *this );
    173   gsl_vector_mul( res.get_gsl_vector(), other.get_gsl_vector() );
     169double vector::operator*( const vector &other ) const
     170{
     171  assert( size() == other.size() );
     172  double res = 0.0;;
     173  for ( size_t i = 0; i < other.size(); ++i )
     174    {
     175     res += other.get( i ) * get( i );
     176    }
    174177  return res;
    175178}
     
    200203
    201204
     205
     206vector vector::mul_elements( const vector& other )
     207{
     208  assert( size() == other.size() );
     209  vector res( *this );
     210  gsl_vector_mul( res.get_gsl_vector(), other.get_gsl_vector() );
     211  return res;
     212}
     213
    202214std::ostream& thep_gsl_api::operator<< ( std::ostream& s_out,
    203215                                         const vector& a )
  • trunk/src/vector.h

    r27 r28  
    153153    int operator/=( const double& c );
    154154    int operator/=( const vector& other ) const;
    155     vector operator*( const vector &other ) const;
     155    /**
     156       This operator is implemented as dot-product.
     157       I case of discussions later on; Jari decided
     158       this!
     159    */
     160    double operator*( const vector &other ) const;
    156161
     162    /**
     163       This function multiplies all elements in two vectors
     164       and returns a third vector containing the result.
     165       res = a*b; where size(a) = size(b) = size(res)
     166    */
     167    vector vector::mul_elements( const vector& other );
     168   
     169   
    157170    /**
    158         standard output operator is defined
     171        standard output operator is defined
    159172    */
    160173    friend std::ostream& operator<< ( std::ostream&, const vector& );
    161 
    162 
    163 
     174   
    164175
    165176  private:
Note: See TracChangeset for help on using the changeset viewer.