# | Line 35 | Line 35 | |
---|---|---|
35 | * | |
36 | * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | |
37 | * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | |
38 | < | * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
38 | > | * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 | * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). | |
40 | * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | |
41 | */ | |
# | Line 109 | Line 109 | namespace OpenMD { | |
109 | ~DynamicRectMatrix() { deallocate();} | |
110 | ||
111 | /** copy assignment operator */ | |
112 | < | DynamicRectMatrix<Real> operator =(const DynamicRectMatrix<Real> m) { |
112 | > | DynamicRectMatrix<Real> operator =(const DynamicRectMatrix<Real> &m) { |
113 | if (this == &m) | |
114 | return *this; | |
115 | if (nrow_ != m.getNRow() || ncol_ != m.getNCol()) { | |
# | Line 233 | Line 233 | namespace OpenMD { | |
233 | /** | |
234 | * Tests if this matrix is identical to matrix m | |
235 | * @return true if this matrix is equal to the matrix m, return false otherwise | |
236 | < | * @m matrix to be compared |
236 | > | * @param m matrix to be compared |
237 | * | |
238 | * @todo replace operator == by template function equal | |
239 | */ | |
240 | < | bool operator ==(const DynamicRectMatrix<Real> m) { |
240 | > | bool operator ==(const DynamicRectMatrix<Real> &m) { |
241 | assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); | |
242 | for (unsigned int i = 0; i < nrow_; i++) | |
243 | for (unsigned int j = 0; j < ncol_; j++) | |
# | Line 250 | Line 250 | namespace OpenMD { | |
250 | /** | |
251 | * Tests if this matrix is not equal to matrix m | |
252 | * @return true if this matrix is not equal to the matrix m, return false otherwise | |
253 | < | * @m matrix to be compared |
253 | > | * @param m matrix to be compared |
254 | */ | |
255 | < | bool operator !=(const DynamicRectMatrix<Real> m) { |
255 | > | bool operator !=(const DynamicRectMatrix<Real> &m) { |
256 | return !(*this == m); | |
257 | } | |
258 | ||
# | Line 267 | Line 267 | namespace OpenMD { | |
267 | * Sets the value of this matrix to the negation of matrix m. | |
268 | * @param m the source matrix | |
269 | */ | |
270 | < | inline void negate(const DynamicRectMatrix<Real> m) { |
270 | > | inline void negate(const DynamicRectMatrix<Real> &m) { |
271 | for (unsigned int i = 0; i < nrow_; i++) | |
272 | for (unsigned int j = 0; j < ncol_; j++) | |
273 | this->data_[i][j] = -m.data_[i][j]; | |
# | Line 277 | Line 277 | namespace OpenMD { | |
277 | * Sets the value of this matrix to the sum of itself and m (*this += m). | |
278 | * @param m the other matrix | |
279 | */ | |
280 | < | inline void add( const DynamicRectMatrix<Real> m ) { |
280 | > | inline void add( const DynamicRectMatrix<Real> &m ) { |
281 | assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); | |
282 | for (unsigned int i = 0; i < nrow_; i++) | |
283 | for (unsigned int j = 0; j < ncol_; j++) | |
# | Line 289 | Line 289 | namespace OpenMD { | |
289 | * @param m1 the first matrix | |
290 | * @param m2 the second matrix | |
291 | */ | |
292 | < | inline void add( const DynamicRectMatrix<Real> m1, const DynamicRectMatrix<Real> m2 ) { |
292 | > | inline void add( const DynamicRectMatrix<Real> &m1, const DynamicRectMatrix<Real> &m2 ) { |
293 | assert(m1.getNRow() == m2.getNRow() && m1.getNCol() == m2.getNCol()); | |
294 | for (unsigned int i = 0; i < nrow_; i++) | |
295 | for (unsigned int j = 0; j < ncol_; j++) | |
# | Line 300 | Line 300 | namespace OpenMD { | |
300 | * Sets the value of this matrix to the difference of itself and m (*this -= m). | |
301 | * @param m the other matrix | |
302 | */ | |
303 | < | inline void sub( const DynamicRectMatrix<Real> m ) { |
303 | > | inline void sub( const DynamicRectMatrix<Real> &m ) { |
304 | assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); | |
305 | for (unsigned int i = 0; i < nrow_; i++) | |
306 | for (unsigned int j = 0; j < ncol_; j++) | |
# | Line 312 | Line 312 | namespace OpenMD { | |
312 | * @param m1 the first matrix | |
313 | * @param m2 the second matrix | |
314 | */ | |
315 | < | inline void sub( const DynamicRectMatrix<Real> m1, const DynamicRectMatrix<Real> m2){ |
315 | > | inline void sub( const DynamicRectMatrix<Real> &m1, const DynamicRectMatrix<Real> &m2){ |
316 | assert(m1.getNRow() == m2.getNRow() && m1.getNCol() == m2.getNCol()); | |
317 | for (unsigned int i = 0; i < nrow_; i++) | |
318 | for (unsigned int j = 0; j < ncol_; j++) | |
# | Line 334 | Line 334 | namespace OpenMD { | |
334 | * @param s the scalar value | |
335 | * @param m the matrix | |
336 | */ | |
337 | < | inline void mul( Real s, const DynamicRectMatrix<Real> m ) { |
337 | > | inline void mul( Real s, const DynamicRectMatrix<Real> &m ) { |
338 | assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); | |
339 | for (unsigned int i = 0; i < nrow_; i++) | |
340 | for (unsigned int j = 0; j < ncol_; j++) | |
# | Line 356 | Line 356 | namespace OpenMD { | |
356 | * @param s the scalar value | |
357 | * @param m the matrix | |
358 | */ | |
359 | < | inline void div( Real s, const DynamicRectMatrix<Real> m ) { |
359 | > | inline void div( Real s, const DynamicRectMatrix<Real> &m ) { |
360 | assert(nrow_ == m.getNRow() && ncol_ == m.getNCol()); | |
361 | for (unsigned int i = 0; i < nrow_; i++) | |
362 | for (unsigned int j = 0; j < ncol_; j++) | |
# | Line 440 | Line 440 | namespace OpenMD { | |
440 | unsigned int nrow_; | |
441 | unsigned int ncol_; | |
442 | private: | |
443 | < | void allocate(int nrow, int ncol) { |
444 | < | nrow_ = nrow; |
445 | < | ncol_ = ncol; |
446 | < | data_ = new Real*[nrow_]; |
447 | < | for (int i = 0; i < nrow_; ++i) |
448 | < | data_[i] = new Real[ncol_]; |
443 | > | void allocate( int nrow, int ncol ) { |
444 | > | nrow_ = (unsigned int) nrow; |
445 | > | ncol_ = (unsigned int) ncol; |
446 | > | data_ = new Real*[nrow_]; |
447 | > | for (unsigned int i = 0; i < nrow_; ++i) |
448 | > | data_[i] = new Real[ncol_]; |
449 | } | |
450 | < | |
450 | > | |
451 | void deallocate() { | |
452 | < | for (int i = 0; i < nrow_; ++i) |
452 | > | for (unsigned int i = 0; i < nrow_; ++i) |
453 | delete data_[i]; | |
454 | delete []data_; | |
455 | < | |
455 | > | |
456 | nrow_ = 0; | |
457 | ncol_ = 0; | |
458 | data_ = NULL; | |
# | Line 462 | Line 462 | namespace OpenMD { | |
462 | ||
463 | /** Negate the value of every element of this matrix. */ | |
464 | template<typename Real> | |
465 | < | inline DynamicRectMatrix<Real> operator -(const DynamicRectMatrix<Real> m) { |
465 | > | inline DynamicRectMatrix<Real> operator -(const DynamicRectMatrix<Real> &m) { |
466 | DynamicRectMatrix<Real> result(m); | |
467 | ||
468 | result.negate(); | |
# | Line 477 | Line 477 | namespace OpenMD { | |
477 | * @param m2 the second matrix | |
478 | */ | |
479 | template<typename Real> | |
480 | < | inline DynamicRectMatrix<Real> operator + (const DynamicRectMatrix<Real> m1,const DynamicRectMatrix<Real> m2) { |
480 | > | inline DynamicRectMatrix<Real> operator + (const DynamicRectMatrix<Real> &m1, const DynamicRectMatrix<Real> &m2) { |
481 | ||
482 | DynamicRectMatrix<Real> result(m1.getNRow(), m1.getNCol()); | |
483 | ||
# | Line 493 | Line 493 | namespace OpenMD { | |
493 | * @param m2 the second matrix | |
494 | */ | |
495 | template<typename Real> | |
496 | < | inline DynamicRectMatrix<Real> operator - (const DynamicRectMatrix<Real> m1, const DynamicRectMatrix<Real> m2) { |
496 | > | inline DynamicRectMatrix<Real> operator - (const DynamicRectMatrix<Real> &m1, const DynamicRectMatrix<Real> &m2) { |
497 | DynamicRectMatrix<Real> result(m1.getNRow(), m1.getNCol()); | |
498 | ||
499 | result.sub(m1, m2); | |
# | Line 508 | Line 508 | namespace OpenMD { | |
508 | * @param s the scalar | |
509 | */ | |
510 | template<typename Real> | |
511 | < | inline DynamicRectMatrix<Real> operator *(const DynamicRectMatrix<Real> m, Real s) { |
511 | > | inline DynamicRectMatrix<Real> operator *(const DynamicRectMatrix<Real> &m, Real s) { |
512 | DynamicRectMatrix<Real> result(m.getNRow(), m.getNCol()); | |
513 | ||
514 | result.mul(s, m); | |
# | Line 523 | Line 523 | namespace OpenMD { | |
523 | * @param m the matrix | |
524 | */ | |
525 | template<typename Real> | |
526 | < | inline DynamicRectMatrix<Real> operator *(Real s, const DynamicRectMatrix<Real> m) { |
526 | > | inline DynamicRectMatrix<Real> operator *(Real s, const DynamicRectMatrix<Real> &m) { |
527 | DynamicRectMatrix<Real> result(m.getNRow(), m.getNCol()); | |
528 | ||
529 | result.mul(s, m); | |
# | Line 559 | Line 559 | namespace OpenMD { | |
559 | * @param v the vector | |
560 | */ | |
561 | template<typename Real> | |
562 | < | inline DynamicVector<Real> operator *(const DynamicRectMatrix<Real> m, const DynamicVector<Real>& v) { |
562 | > | inline DynamicVector<Real> operator *(const DynamicRectMatrix<Real> &m, const DynamicVector<Real> &v) { |
563 | int nrow = m.getNRow(); | |
564 | int ncol = m.getNCol(); | |
565 | < | assert(ncol = v.size()); |
565 | > | assert(ncol == v.size()); |
566 | DynamicVector<Real> result(nrow); | |
567 | ||
568 | for (unsigned int i = 0; i < nrow ; i++) | |
# | Line 579 | Line 579 | namespace OpenMD { | |
579 | * @param s the scalar | |
580 | */ | |
581 | template<typename Real> | |
582 | < | inline DynamicRectMatrix<Real> operator /(const DynamicRectMatrix<Real> m, Real s) { |
582 | > | inline DynamicRectMatrix<Real> operator /(const DynamicRectMatrix<Real> &m, Real s) { |
583 | DynamicRectMatrix<Real> result(m.getNRow(), m.getNCol()); | |
584 | ||
585 | result.div(s, m); | |
# | Line 591 | Line 591 | namespace OpenMD { | |
591 | * Write to an output stream | |
592 | */ | |
593 | template<typename Real> | |
594 | < | std::ostream &operator<< ( std::ostream& o, const DynamicRectMatrix<Real> m) { |
594 | > | std::ostream &operator<< ( std::ostream& o, const DynamicRectMatrix<Real> &m) { |
595 | for (unsigned int i = 0; i < m.getNRow() ; i++) { | |
596 | o << "("; | |
597 | for (unsigned int j = 0; j < m.getNCol() ; j++) { |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |