@@ -57,6 +57,7 @@ namespace QuantLib {
5757 Matrix (const Matrix&);
5858 Matrix (Matrix&&) noexcept ;
5959 Matrix (std::initializer_list<std::initializer_list<Real>>);
60+ ~Matrix () = default ;
6061
6162 Matrix& operator =(const Matrix&);
6263 Matrix& operator =(Matrix&&) noexcept ;
@@ -152,16 +153,35 @@ namespace QuantLib {
152153 /* ! \relates Matrix */
153154 Matrix operator +(const Matrix&, const Matrix&);
154155 /* ! \relates Matrix */
156+ Matrix operator +(const Matrix&, Matrix&&);
157+ /* ! \relates Matrix */
158+ Matrix operator +(Matrix&&, const Matrix&);
159+ /* ! \relates Matrix */
160+ Matrix operator +(Matrix&&, Matrix&&);
161+ /* ! \relates Matrix */
155162 Matrix operator -(const Matrix&);
156163 /* ! \relates Matrix */
164+ Matrix operator -(Matrix&&);
165+ /* ! \relates Matrix */
157166 Matrix operator -(const Matrix&, const Matrix&);
158167 /* ! \relates Matrix */
168+ Matrix operator -(const Matrix&, Matrix&&);
169+ /* ! \relates Matrix */
170+ Matrix operator -(Matrix&&, const Matrix&);
171+ /* ! \relates Matrix */
172+ Matrix operator -(Matrix&&, Matrix&&);
173+ /* ! \relates Matrix */
159174 Matrix operator *(const Matrix&, Real);
160175 /* ! \relates Matrix */
176+ Matrix operator *(Matrix&&, Real);
177+ /* ! \relates Matrix */
161178 Matrix operator *(Real, const Matrix&);
162179 /* ! \relates Matrix */
180+ Matrix operator *(Real, Matrix&&);
181+ /* ! \relates Matrix */
163182 Matrix operator /(const Matrix&, Real);
164-
183+ /* ! \relates Matrix */
184+ Matrix operator /(Matrix&&, Real);
165185
166186 // vectorial products
167187
@@ -513,12 +533,50 @@ namespace QuantLib {
513533 return temp;
514534 }
515535
536+ inline Matrix operator +(const Matrix& m1, Matrix&& m2) {
537+ QL_REQUIRE (m1.rows () == m2.rows () &&
538+ m1.columns () == m2.columns (),
539+ " matrices with different sizes (" <<
540+ m1.rows () << " x" << m1.columns () << " , " <<
541+ m2.rows () << " x" << m2.columns () << " ) cannot be "
542+ " added" );
543+ std::transform (m1.begin (), m1.end (), m2.begin (), m2.begin (), std::plus<>());
544+ return std::move (m2);
545+ }
546+
547+ inline Matrix operator +(Matrix&& m1, const Matrix& m2) {
548+ QL_REQUIRE (m1.rows () == m2.rows () &&
549+ m1.columns () == m2.columns (),
550+ " matrices with different sizes (" <<
551+ m1.rows () << " x" << m1.columns () << " , " <<
552+ m2.rows () << " x" << m2.columns () << " ) cannot be "
553+ " added" );
554+ std::transform (m1.begin (), m1.end (), m2.begin (), m1.begin (), std::plus<>());
555+ return std::move (m1);
556+ }
557+
558+ inline Matrix operator +(Matrix&& m1, Matrix&& m2) {
559+ QL_REQUIRE (m1.rows () == m2.rows () &&
560+ m1.columns () == m2.columns (),
561+ " matrices with different sizes (" <<
562+ m1.rows () << " x" << m1.columns () << " , " <<
563+ m2.rows () << " x" << m2.columns () << " ) cannot be "
564+ " added" );
565+ std::transform (m1.begin (), m1.end (), m2.begin (), m1.begin (), std::plus<>());
566+ return std::move (m1);
567+ }
568+
516569 inline Matrix operator -(const Matrix& m1) {
517570 Matrix temp (m1.rows (), m1.columns ());
518571 std::transform (m1.begin (), m1.end (), temp.begin (), std::negate<>());
519572 return temp;
520573 }
521574
575+ inline Matrix operator -(Matrix&& m1) {
576+ std::transform (m1.begin (), m1.end (), m1.begin (), std::negate<>());
577+ return std::move (m1);
578+ }
579+
522580 inline Matrix operator -(const Matrix& m1, const Matrix& m2) {
523581 QL_REQUIRE (m1.rows () == m2.rows () &&
524582 m1.columns () == m2.columns (),
@@ -531,24 +589,72 @@ namespace QuantLib {
531589 return temp;
532590 }
533591
592+ inline Matrix operator -(const Matrix& m1, Matrix&& m2) {
593+ QL_REQUIRE (m1.rows () == m2.rows () &&
594+ m1.columns () == m2.columns (),
595+ " matrices with different sizes (" <<
596+ m1.rows () << " x" << m1.columns () << " , " <<
597+ m2.rows () << " x" << m2.columns () << " ) cannot be "
598+ " subtracted" );
599+ std::transform (m1.begin (), m1.end (), m2.begin (), m2.begin (), std::minus<>());
600+ return std::move (m2);
601+ }
602+
603+ inline Matrix operator -(Matrix&& m1, const Matrix& m2) {
604+ QL_REQUIRE (m1.rows () == m2.rows () &&
605+ m1.columns () == m2.columns (),
606+ " matrices with different sizes (" <<
607+ m1.rows () << " x" << m1.columns () << " , " <<
608+ m2.rows () << " x" << m2.columns () << " ) cannot be "
609+ " subtracted" );
610+ std::transform (m1.begin (), m1.end (), m2.begin (), m1.begin (), std::minus<>());
611+ return std::move (m1);
612+ }
613+
614+ inline Matrix operator -(Matrix&& m1, Matrix&& m2) {
615+ QL_REQUIRE (m1.rows () == m2.rows () &&
616+ m1.columns () == m2.columns (),
617+ " matrices with different sizes (" <<
618+ m1.rows () << " x" << m1.columns () << " , " <<
619+ m2.rows () << " x" << m2.columns () << " ) cannot be "
620+ " subtracted" );
621+ std::transform (m1.begin (), m1.end (), m2.begin (), m1.begin (), std::minus<>());
622+ return std::move (m1);
623+ }
624+
534625 inline Matrix operator *(const Matrix& m, Real x) {
535626 Matrix temp (m.rows (),m.columns ());
536627 std::transform (m.begin (), m.end (), temp.begin (), [=](Real y) -> Real { return y * x; });
537628 return temp;
538629 }
539630
631+ inline Matrix operator *(Matrix&& m, Real x) {
632+ std::transform (m.begin (), m.end (), m.begin (), [=](Real y) -> Real { return y * x; });
633+ return std::move (m);
634+ }
635+
540636 inline Matrix operator *(Real x, const Matrix& m) {
541637 Matrix temp (m.rows (),m.columns ());
542638 std::transform (m.begin (), m.end (), temp.begin (), [=](Real y) -> Real { return x * y; });
543639 return temp;
544640 }
545641
642+ inline Matrix operator *(Real x, Matrix&& m) {
643+ std::transform (m.begin (), m.end (), m.begin (), [=](Real y) -> Real { return x * y; });
644+ return std::move (m);
645+ }
646+
546647 inline Matrix operator /(const Matrix& m, Real x) {
547648 Matrix temp (m.rows (),m.columns ());
548649 std::transform (m.begin (), m.end (), temp.begin (), [=](Real y) -> Real { return y / x; });
549650 return temp;
550651 }
551652
653+ inline Matrix operator /(Matrix&& m, Real x) {
654+ std::transform (m.begin (), m.end (), m.begin (), [=](Real y) -> Real { return y / x; });
655+ return std::move (m);
656+ }
657+
552658 inline Array operator *(const Array& v, const Matrix& m) {
553659 QL_REQUIRE (v.size () == m.rows (),
554660 " vectors and matrices with different sizes ("
0 commit comments