Ignore:
Timestamp:
Feb 10, 2009, 5:11:04 PM (12 years ago)
Author:
Peter
Message:

Speeding up copying from Matrix to MatrixWeighted? using
BinaryWeight?. Moving BinaryWeight? from stl_utility.h to
utility.h. Improved docs in MatrixWeighted?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/utility.h

    r1500 r1789  
    3434#include "deprecate.h"
    3535
     36#include <cmath>
    3637#include <limits>
    3738#include <string>
     
    4546namespace utility {
    4647
    47   class Matrix;
     48  /**
     49     For each element in resulting range assign it to 0.0 if
     50     corresponding element in input range is NaN else assign it to
     51     1.0.
     52
     53     \since New in yat 0.5
     54   */
     55  struct BinaryWeight
     56  {
     57    /**
     58        \return true if there is at least one NaN in input range
     59        [first, last).
     60     */
     61    template<typename InputIterator, typename OutputIterator>
     62    bool operator()(InputIterator first, InputIterator last,
     63                    OutputIterator result) const;
     64  };
     65
    4866
    4967  /**
     
    99117  bool is_nan(const std::string& s);
    100118
     119
     120  template<typename InputIterator, typename OutputIterator>
     121  bool BinaryWeight::operator()(InputIterator first, InputIterator last,
     122                                OutputIterator result) const
     123  {
     124    bool nan=false;
     125    while (first!=last) {
     126      if (std::isnan(*first)) {
     127        *result=0;
     128        nan=true;
     129      }
     130      else
     131        *result = 1.0;
     132      ++first;
     133      ++result;
     134    }
     135    return nan;
     136  }
     137
     138
    101139  // template implementations
    102140  template<typename T>
Note: See TracChangeset for help on using the changeset viewer.