# Changeset 4105

Ignore:
Timestamp:
Sep 24, 2021, 6:55:48 AM (2 years ago)
Message:

implement +=, -=, and *= operators for DiagonalMatrix?; prefer using arithmatics provided by Vector class rather than own loops.

Location:
trunk
Files:
3 edited

Unmodified
Added
Removed
• ## trunk/test/diagonal_matrix.cc

 r3660 /* Copyright (C) 2017 Peter Johansson Copyright (C) 2017, 2021 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat suite.out() << "DiagonalMatrix * DiagnoalMatrix\n"; check(D1 * D1, D2 * D2, suite); // test different dimension cases square x square; square x portrait etc for (size_t i=1; i<4; ++i) for (size_t j=1; j<4; ++j) { DiagonalMatrix X1(i,j); Matrix M1(i,j); for (size_t k1=0; k1
• ## trunk/yat/utility/DiagonalMatrix.cc

 r3655 /* Copyright (C) 2017 Peter Johansson Copyright (C) 2017, 2021 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat #include "Matrix.h" #include "VectorBase.h" #include "VectorConstView.h" #include "VectorView.h" #include DiagonalMatrix& DiagonalMatrix::operator*=(const DiagonalMatrix& rhs) { assert(columns() == rhs.rows()); // length of new diagonal size_t n = std::min(row_, rhs.col_); size_t n1 = data_.size(); size_t n2 = rhs.data_.size(); assert(n==n1 || (n>n1 && n>n2) || (nn1) { assert(n>n2); Vector tmp(n, 0); if (n1 <= n2) { VectorView view(tmp, 0, n1); view = data_; view.mul(VectorConstView(rhs.data_, 0, n1)); } else { VectorView view(tmp, 0, n2); view = VectorConstView(data_, 0, n2); view.mul(rhs.data_); } data_ = std::move(tmp); } else { assert(n < n1); assert(n == n2); Vector tmp(rhs.data_); tmp.mul(VectorConstView(data_, 0, n)); data_ = std::move(tmp); } col_ = rhs.col_; assert(data_.size() == n); return *this; } DiagonalMatrix operator*(const DiagonalMatrix& lhs, const DiagonalMatrix& rhs) { assert(lhs.columns() == rhs.rows()); DiagonalMatrix res(lhs.rows(), rhs.columns()); size_t n = std::min(res.rows(), res.columns()); for (size_t i=0; i
• ## trunk/yat/utility/DiagonalMatrix.h

 r3655 /* Copyright (C) 2017 Peter Johansson Copyright (C) 2017, 2021 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat */ double& operator()(size_t i); /** \brief Multiplication and assign operator Same as doing *this = *this * rhs. \since New in yat 0.20 */ DiagonalMatrix& operator*=(const DiagonalMatrix& rhs); /** \brief Add and assign operator Elementwise addition of the diagnonal elements. \since New in yat 0.20 */ DiagonalMatrix& operator+=(const DiagonalMatrix& rhs); /** \brief Subtract and assign operator Elementwise addition of the diagnonal elements. \since New in yat 0.20 */ DiagonalMatrix& operator-=(const DiagonalMatrix& rhs); private: Vector data_;
Note: See TracChangeset for help on using the changeset viewer.