diff options
author | Wu, Ke <wuke@cs.umd.edu> | 2014-10-07 17:22:11 -0400 |
---|---|---|
committer | Wu, Ke <wuke@cs.umd.edu> | 2014-10-07 17:22:11 -0400 |
commit | 00968d1ba03c0603440fe5a765b87869b99a0a93 (patch) | |
tree | f264c07d9851b47b117839fc9345d7e1d5e880a2 /utils/synutils/maxent-3.0/mathvec.h | |
parent | f762dbbf10a8204d0d0b82e9acb29feacd3b3bb4 (diff) |
Apply clang-format
Diffstat (limited to 'utils/synutils/maxent-3.0/mathvec.h')
-rw-r--r-- | utils/synutils/maxent-3.0/mathvec.h | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/utils/synutils/maxent-3.0/mathvec.h b/utils/synutils/maxent-3.0/mathvec.h index 4ec82797..f8c60e5d 100644 --- a/utils/synutils/maxent-3.0/mathvec.h +++ b/utils/synutils/maxent-3.0/mathvec.h @@ -5,41 +5,40 @@ #include <iostream> #include <cassert> -class Vec -{ -private: +class Vec { + private: std::vector<double> _v; -public: + + public: Vec(const size_t n = 0, const double val = 0) { _v.resize(n, val); } - Vec(const std::vector<double> & v) : _v(v) {} - const std::vector<double> & STLVec() const { return _v; } - std::vector<double> & STLVec() { return _v; } + Vec(const std::vector<double>& v) : _v(v) {} + const std::vector<double>& STLVec() const { return _v; } + std::vector<double>& STLVec() { return _v; } size_t Size() const { return _v.size(); } - double & operator[](int i) { return _v[i]; } - const double & operator[](int i) const { return _v[i]; } - Vec & operator+=(const Vec & b) { + double& operator[](int i) { return _v[i]; } + const double& operator[](int i) const { return _v[i]; } + Vec& operator+=(const Vec& b) { assert(b.Size() == _v.size()); for (size_t i = 0; i < _v.size(); i++) { _v[i] += b[i]; } return *this; } - Vec & operator*=(const double c) { + Vec& operator*=(const double c) { for (size_t i = 0; i < _v.size(); i++) { _v[i] *= c; } return *this; } - void Project(const Vec & y) { + void Project(const Vec& y) { for (size_t i = 0; i < _v.size(); i++) { // if (sign(_v[i]) != sign(y[i])) _v[i] = 0; - if (_v[i] * y[i] <=0) _v[i] = 0; + if (_v[i] * y[i] <= 0) _v[i] = 0; } } }; -inline double dot_product(const Vec & a, const Vec & b) -{ +inline double dot_product(const Vec& a, const Vec& b) { double sum = 0; for (size_t i = 0; i < a.Size(); i++) { sum += a[i] * b[i]; @@ -47,8 +46,7 @@ inline double dot_product(const Vec & a, const Vec & b) return sum; } -inline std::ostream & operator<<(std::ostream & s, const Vec & a) -{ +inline std::ostream& operator<<(std::ostream& s, const Vec& a) { s << "("; for (size_t i = 0; i < a.Size(); i++) { if (i != 0) s << ", "; @@ -58,8 +56,7 @@ inline std::ostream & operator<<(std::ostream & s, const Vec & a) return s; } -inline const Vec operator+(const Vec & a, const Vec & b) -{ +inline const Vec operator+(const Vec& a, const Vec& b) { Vec v(a.Size()); assert(a.Size() == b.Size()); for (size_t i = 0; i < a.Size(); i++) { @@ -68,8 +65,7 @@ inline const Vec operator+(const Vec & a, const Vec & b) return v; } -inline const Vec operator-(const Vec & a, const Vec & b) -{ +inline const Vec operator-(const Vec& a, const Vec& b) { Vec v(a.Size()); assert(a.Size() == b.Size()); for (size_t i = 0; i < a.Size(); i++) { @@ -78,8 +74,7 @@ inline const Vec operator-(const Vec & a, const Vec & b) return v; } -inline const Vec operator*(const Vec & a, const double c) -{ +inline const Vec operator*(const Vec& a, const double c) { Vec v(a.Size()); for (size_t i = 0; i < a.Size(); i++) { v[i] = a[i] * c; @@ -87,11 +82,6 @@ inline const Vec operator*(const Vec & a, const double c) return v; } -inline const Vec operator*(const double c, const Vec & a) -{ - return a * c; -} - - +inline const Vec operator*(const double c, const Vec& a) { return a * c; } #endif |