suanPan
operator_times.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (C) 2017-2023 Theodore Chang
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  ******************************************************************************/
17 
18 #ifndef OPERATOR_TIMES_HPP
19 #define OPERATOR_TIMES_HPP
20 
21 template<sp_d T> unique_ptr<MetaMat<T>> operator*(const T value, unique_ptr<MetaMat<T>>&& M) {
22  if(nullptr == M) return nullptr;
23 
24  M->operator*=(value);
25  return std::forward<unique_ptr<MetaMat<T>>>(M);
26 }
27 
28 template<sp_d T> unique_ptr<MetaMat<T>> operator*(const T value, const shared_ptr<MetaMat<T>>& M) {
29  if(nullptr == M) return nullptr;
30 
31  auto N = M->make_copy();
32  N->operator*=(value);
33  return N;
34 }
35 
36 template<sp_d T> Mat<T> operator*(const shared_ptr<MetaMat<T>>& M, const Mat<T>& A) { return M->operator*(A); }
37 
38 template<sp_d T> Mat<T> operator*(const unique_ptr<MetaMat<T>>& M, const Mat<T>& A) { return M->operator*(A); }
39 
40 template<sp_d T> const shared_ptr<MetaMat<T>>& operator*=(const shared_ptr<MetaMat<T>>& M, const T value) {
41  M->operator*=(value);
42  return M;
43 }
44 
45 template<sp_d T> unique_ptr<MetaMat<T>> operator+(const shared_ptr<MetaMat<T>>& A, const shared_ptr<MetaMat<T>>& B) {
46  auto M = B->make_copy();
47  M->operator+=(A);
48  return M;
49 }
50 
51 template<sp_d T> unique_ptr<MetaMat<T>> operator+(const shared_ptr<MetaMat<T>>& A, unique_ptr<MetaMat<T>>&& B) {
52  B->operator+=(A);
53  return std::forward<unique_ptr<MetaMat<T>>>(B);
54 }
55 
56 template<sp_d T> unique_ptr<MetaMat<T>> operator+(unique_ptr<MetaMat<T>>&& A, unique_ptr<MetaMat<T>>&& B) {
57  A->operator+=(std::forward<unique_ptr<MetaMat<T>>>(B));
58  return std::forward<unique_ptr<MetaMat<T>>>(A);
59 }
60 
61 template<sp_d T> const shared_ptr<MetaMat<T>>& operator+=(const shared_ptr<MetaMat<T>>& M, const shared_ptr<MetaMat<T>>& A) {
62  M->operator+=(A);
63  return M;
64 }
65 
66 template<sp_d T> const shared_ptr<MetaMat<T>>& operator+=(const shared_ptr<MetaMat<T>>& M, unique_ptr<MetaMat<T>>&& A) {
67  M->operator+=(std::forward<unique_ptr<MetaMat<T>>>(A));
68  return M;
69 }
70 
71 template<sp_d T> const unique_ptr<MetaMat<T>>& operator+=(const unique_ptr<MetaMat<T>>& M, const shared_ptr<MetaMat<T>>& A) {
72  M->operator+=(A);
73  return M;
74 }
75 
76 template<sp_d DT, sp_i IT> const unique_ptr<MetaMat<DT>>& operator+=(const unique_ptr<MetaMat<DT>>& M, const triplet_form<DT, IT>& A) {
77  M->operator+=(A);
78  return M;
79 }
80 
81 #endif // OPERATOR_TIMES_HPP
A MetaMat class that holds matrices.
Definition: MetaMat.hpp:39
Definition: triplet_form.hpp:62
const shared_ptr< MetaMat< T > > & operator*=(const shared_ptr< MetaMat< T >> &M, const T value)
Definition: operator_times.hpp:40
unique_ptr< MetaMat< T > > operator+(const shared_ptr< MetaMat< T >> &A, const shared_ptr< MetaMat< T >> &B)
Definition: operator_times.hpp:45
unique_ptr< MetaMat< T > > operator*(const T value, unique_ptr< MetaMat< T >> &&M)
Definition: operator_times.hpp:21
const shared_ptr< MetaMat< T > > & operator+=(const shared_ptr< MetaMat< T >> &M, const shared_ptr< MetaMat< T >> &A)
Definition: operator_times.hpp:61