Changeset 791


Ignore:
Timestamp:
Mar 11, 2007, 1:12:34 AM (15 years ago)
Author:
Jari Häkkinen
Message:

Addresses #193. Added missing implementations.

Location:
trunk/yat/utility
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/vector.cc

    r790 r791  
    199199
    200200
    201   gsl_vector* vector::create_gsl_vector_copy(void) const
    202   {
    203     gsl_vector* vec = gsl_vector_alloc(size());
    204     if (!vec)
    205       throw utility::GSL_error("vector::create_gsl_vector_copy failed to allocate memory");
    206     if (gsl_vector_memcpy(vec, proxy_v_))
    207       throw utility::GSL_error("vector::create_gsl_matrix_copy dimension mis-match");
    208     return vec;
    209   }
    210 
    211 
    212201  const vector& vector::clone(const vector& other)
    213202  {
     
    236225    return *this;
    237226  }
     227
     228
     229  gsl_vector* vector::create_gsl_vector_copy(void) const
     230  {
     231    gsl_vector* vec = gsl_vector_alloc(size());
     232    if (!vec)
     233      throw utility::GSL_error("vector::create_gsl_vector_copy failed to allocate memory");
     234    if (gsl_vector_memcpy(vec, proxy_v_))
     235      throw utility::GSL_error("vector::create_gsl_matrix_copy dimension mis-match");
     236    return vec;
     237  }
    238238
    239239
     
    417417
    418418
     419  const vector& vector::operator-=(const double d)
     420  {
     421    assert(v_);
     422    gsl_vector_add_constant(v_, -d);
     423    return *this;
     424  }
     425
     426
    419427  const vector& vector::operator*=(const double d)
    420428  {
     
    468476    gsl_vector_minmax_index(v.gsl_vector_p(), &minmax.first, &minmax.second);
    469477    return minmax;
     478  }
     479
     480
     481  bool nan(const vector& templat, vector& flag)
     482  {
     483    size_t rows=templat.size();
     484    if (rows!=flag.size())
     485      flag.clone(vector(rows,1.0));
     486    else
     487      flag.set_all(1.0);
     488    bool nan=false;
     489    for (size_t i=0; i<rows; i++)
     490      if (std::isnan(templat(i))) {
     491        flag(i)=0;
     492        nan=true;
     493      }
     494    return nan;
    470495  }
    471496
  • trunk/yat/utility/vector.h

    r790 r791  
    512512
    513513  /**
     514     \brief Create a vector \a flag indicating NaN's in another vector
     515     \a templat.
     516
     517     The \a flag vector is changed to contain 1's and 0's only. A 1
     518     means that the corresponding element in the \a templat vector is
     519     valid and a zero means that the corresponding element is a NaN.
     520
     521     \note Space for vector \a flag is reallocated to fit the size of
     522     vector \a templat if sizes mismatch.
     523
     524     \return True if the \a templat vector contains at least one NaN.
     525  */
     526  bool nan(const matrix& templat, matrix& flag);
     527
     528  /**
    514529     \brief Transforms a vector to a basis vector.
    515530
Note: See TracChangeset for help on using the changeset viewer.