00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef JSPACE_VECTOR_UTIL_HPP
00027 #define JSPACE_VECTOR_UTIL_HPP
00028
00029 #include <vector>
00030 #include <iosfwd>
00031 #include <math.h>
00032
00033
00034 namespace jspace {
00035
00036
00037 template<typename container_t>
00038 bool compare(container_t const & lhs, container_t const & rhs, typename container_t::value_type precision)
00039 {
00040 if (&lhs == &rhs) {
00041 return true;
00042 }
00043 if (lhs.size() != rhs.size()) {
00044 return false;
00045 }
00046 typename container_t::const_iterator il(lhs.begin());
00047 typename container_t::const_iterator ir(rhs.begin());
00048 typename container_t::const_iterator il_end(lhs.end());
00049 for (; il != il_end; ++il, ++ir) {
00050 if (fabs(*il - *ir) > precision) {
00051 return false;
00052 }
00053 }
00054 return true;
00055 }
00056
00057
00058 template<typename container_t>
00059 void zero(container_t & vv)
00060 {
00061 std::fill(vv.begin(), vv.end(), 0);
00062 }
00063
00064 }
00065
00066 namespace std {
00067
00068 ostream & operator << (ostream & os, vector<double> const & rhs);
00069
00070 }
00071
00072 #endif // JSPACE_VECTOR_UTIL_HPP