Commit b3bbe2912b3e7171174a79eb7f679d22c027bbd5
1 parent
5f825e13
add clear() method
Showing
2 changed files
with
20 additions
and
5 deletions
include/GVector.hpp
| ... | ... | @@ -104,8 +104,9 @@ public: |
| 104 | 104 | GVector operator- () const; |
| 105 | 105 | |
| 106 | 106 | // Vector methods |
| 107 | - int size() const; // Return dimension of vector | |
| 108 | - int non_zeros() const; // Returns # of non zeros in vector | |
| 107 | + void clear(void); | |
| 108 | + int size(void) const; | |
| 109 | + int non_zeros(void) const; | |
| 109 | 110 | |
| 110 | 111 | private: |
| 111 | 112 | // Private methods |
| ... | ... | @@ -115,8 +116,8 @@ private: |
| 115 | 116 | void free_members(void); |
| 116 | 117 | |
| 117 | 118 | // Private data area |
| 118 | - int m_num; //!< Number of elements in vector | |
| 119 | - double* m_data; //!< Vector array | |
| 119 | + int m_num; //!< Number of elements in vector | |
| 120 | + double* m_data; //!< Vector array | |
| 120 | 121 | }; |
| 121 | 122 | |
| 122 | 123 | ... | ... |
src/linalg/GVector.cpp
| ... | ... | @@ -136,9 +136,23 @@ GVector& GVector::operator= (const GVector& v) |
| 136 | 136 | ==========================================================================*/ |
| 137 | 137 | |
| 138 | 138 | /***********************************************************************//** |
| 139 | + * @brief Set vector elements to 0 | |
| 140 | + ***************************************************************************/ | |
| 141 | +void GVector::clear(void) | |
| 142 | +{ | |
| 143 | + // Set all elements to 0 | |
| 144 | + for (int i = 0; i < m_num; ++i) | |
| 145 | + m_data[i] = 0.0; | |
| 146 | + | |
| 147 | + // Return | |
| 148 | + return; | |
| 149 | +} | |
| 150 | + | |
| 151 | + | |
| 152 | +/***********************************************************************//** | |
| 139 | 153 | * @brief Returns number of non-zero elements in vector |
| 140 | 154 | ***************************************************************************/ |
| 141 | -int GVector::non_zeros() const | |
| 155 | +int GVector::non_zeros(void) const | |
| 142 | 156 | { |
| 143 | 157 | // Initialise number of non-zeros |
| 144 | 158 | int non_zeros = 0; | ... | ... |