Changeset 1789
- Timestamp:
- Feb 10, 2009, 5:11:04 PM (12 years ago)
- Location:
- trunk/yat/utility
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/Matrix.cc
r1786 r1789 24 24 25 25 #include "Matrix.h" 26 #include "stl_utility.h"27 26 #include "Vector.h" 28 27 #include "VectorBase.h" -
trunk/yat/utility/MatrixWeighted.cc
r1706 r1789 28 28 #include "DataIterator.h" 29 29 #include "Matrix.h" 30 #include "utility.h" 30 31 #include "WeightIterator.h" 31 32 … … 112 113 void MatrixWeighted::copy(const Matrix& data) 113 114 { 114 Matrix weight;115 nan(data, weight);116 copy(data, weight);117 }118 119 120 void MatrixWeighted::copy(const Matrix& data, const Matrix& weight)121 {122 assert(data.rows()==weight.rows());123 assert(data.columns()==weight.columns());124 115 columns_ = data.columns(); 125 116 resize(data.rows(), data.columns()); … … 127 118 assert(columns()==data.columns()); 128 119 std::copy(data.begin(), data.end(), data_iterator(vec_.begin())); 129 std::copy(weight.begin(), weight.end(), weight_iterator(vec_.begin()));120 BinaryWeight()(data.begin(), data.end(), weight_iterator(vec_.begin())); 130 121 } 131 122 -
trunk/yat/utility/MatrixWeighted.h
r1706 r1789 38 38 class Matrix; 39 39 40 /// 41 /// @brief Weighted Matrix 42 /// 40 /** 41 \brief Weighted Matrix 42 43 \since New in yat 0.5 44 45 */ 43 46 class MatrixWeighted 44 47 { … … 46 49 /** 47 50 value_type is DataWeight 48 49 \since New in yat 0.550 51 */ 51 52 typedef DataWeight value_type; … … 118 119 119 120 Data is copied from \a other and weights are calculated using 120 the nan function.121 the BinaryWeight functor. 121 122 */ 122 123 explicit MatrixWeighted(const Matrix& other); … … 211 212 212 213 /** 214 \brief Resize Matrix 215 216 \note this function may invalidate iterators. 217 */ 218 void resize(size_t rows, size_t columns); 219 220 /** 221 \return The number of rows in the matrix. 222 */ 223 size_t rows(void) const; 224 225 /** 213 226 \brief swap objects 214 227 215 228 Takes constant time. Invalidates iterators. 229 There is no requirement on the size of \a other. 216 230 */ 217 231 void swap(MatrixWeighted& other); 218 219 /**220 \brief Resize Matrix221 222 \note this function may invalidate iterators.223 */224 void resize(size_t, size_t);225 226 /**227 \return The number of rows in the matrix.228 */229 size_t rows(void) const;230 232 231 233 /** … … 254 256 private: 255 257 void copy(const Matrix&); 256 void copy(const Matrix& data, const Matrix& weight);257 258 258 259 std::vector<DataWeight> vec_; -
trunk/yat/utility/stl_utility.h
r1786 r1789 77 77 inline T operator()(T x) const 78 78 { return std::abs(x); } 79 };80 81 82 /**83 For each element in resulting range assign it to 0.0 if84 corresponding element in input range is NaN else assign it to85 1.0.86 87 \since New in yat 0.588 */89 struct BinaryWeight90 {91 /**92 \return true if there is at least one NaN in input range93 [first, last).94 */95 template<typename InputIterator, typename OutputIterator>96 bool inline operator()(InputIterator first, InputIterator last,97 OutputIterator result) const98 {99 bool nan=false;100 while (first!=last) {101 if (std::isnan(*first)) {102 *result=0;103 nan=true;104 }105 else106 *result = 1.0;107 ++first;108 ++result;109 }110 return nan;111 }112 79 }; 113 80 -
trunk/yat/utility/utility.h
r1500 r1789 34 34 #include "deprecate.h" 35 35 36 #include <cmath> 36 37 #include <limits> 37 38 #include <string> … … 45 46 namespace utility { 46 47 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 48 66 49 67 /** … … 99 117 bool is_nan(const std::string& s); 100 118 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 101 139 // template implementations 102 140 template<typename T>
Note: See TracChangeset
for help on using the changeset viewer.