suanPan
operator_times.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (C) 2017-2024 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
21template<sp_d T> op_add<T> operator+(const shared_ptr<MetaMat<T>>& A, const shared_ptr<MetaMat<T>>& B) { return op_add<T>(A, B); }
22
23template<sp_d T> op_scale<T> operator*(const T value, const shared_ptr<MetaMat<T>>& M) { return op_scale<T>(value, M); }
24
25template<sp_d T> op_scale<T> operator*(const T value, op_add<T>&& M) { return op_scale<T>(value, std::forward<op_add<T>>(M)); }
26
27template<sp_d T> const shared_ptr<MetaMat<T>>& operator+=(const shared_ptr<MetaMat<T>>& M, const op_scale<T>& A) {
28 M->operator+=(A);
29 return M;
30}
31
32template<sp_d T> const unique_ptr<MetaMat<T>>& operator+=(const unique_ptr<MetaMat<T>>& M, const op_scale<T>& A) {
33 M->operator+=(A);
34 return M;
35}
36
37template<sp_d T> unique_ptr<MetaMat<T>> operator*(const T value, unique_ptr<MetaMat<T>>&& M) {
38 if(nullptr == M) return nullptr;
39
40 M->operator*=(value);
41 return std::forward<unique_ptr<MetaMat<T>>>(M);
42}
43
44//template<sp_d T> unique_ptr<MetaMat<T>> operator*(const T value, const shared_ptr<MetaMat<T>>& M) {
45// if(nullptr == M) return nullptr;
46//
47// auto N = M->make_copy();
48// N->operator*=(value);
49// return N;
50//}
51
52template<sp_d T> Mat<T> operator*(const shared_ptr<MetaMat<T>>& M, const Mat<T>& A) { return M->operator*(A); }
53
54template<sp_d T> Mat<T> operator*(const unique_ptr<MetaMat<T>>& M, const Mat<T>& A) { return M->operator*(A); }
55
56template<sp_d T> const shared_ptr<MetaMat<T>>& operator*=(const shared_ptr<MetaMat<T>>& M, const T value) {
57 M->operator*=(value);
58 return M;
59}
60
61//template<sp_d T> unique_ptr<MetaMat<T>> operator+(const shared_ptr<MetaMat<T>>& A, const shared_ptr<MetaMat<T>>& B) {
62// auto M = B->make_copy();
63// M->operator+=(A);
64// return M;
65//}
66
67template<sp_d T> unique_ptr<MetaMat<T>> operator+(const shared_ptr<MetaMat<T>>& A, unique_ptr<MetaMat<T>>&& B) {
68 B->operator+=(A);
69 return std::forward<unique_ptr<MetaMat<T>>>(B);
70}
71
72template<sp_d T> unique_ptr<MetaMat<T>> operator+(unique_ptr<MetaMat<T>>&& A, unique_ptr<MetaMat<T>>&& B) {
73 A->operator+=(std::forward<unique_ptr<MetaMat<T>>>(B));
74 return std::forward<unique_ptr<MetaMat<T>>>(A);
75}
76
77template<sp_d T> const shared_ptr<MetaMat<T>>& operator+=(const shared_ptr<MetaMat<T>>& M, const shared_ptr<MetaMat<T>>& A) {
78 M->operator+=(A);
79 return M;
80}
81
82template<sp_d T> const shared_ptr<MetaMat<T>>& operator+=(const shared_ptr<MetaMat<T>>& M, unique_ptr<MetaMat<T>>&& A) {
83 M->operator+=(std::forward<unique_ptr<MetaMat<T>>>(A));
84 return M;
85}
86
87template<sp_d T> const unique_ptr<MetaMat<T>>& operator+=(const unique_ptr<MetaMat<T>>& M, const shared_ptr<MetaMat<T>>& A) {
88 M->operator+=(A);
89 return M;
90}
91
92template<sp_d DT, sp_i IT> const unique_ptr<MetaMat<DT>>& operator+=(const unique_ptr<MetaMat<DT>>& M, const triplet_form<DT, IT>& A) {
93 M->operator+=(A);
94 return M;
95}
96
97#endif // OPERATOR_TIMES_HPP
A MetaMat class that holds matrices.
Definition: MetaMat.hpp:72
Definition: MetaMat.hpp:41
Definition: MetaMat.hpp:56
Definition: triplet_form.hpp:62
op_scale< T > operator*(const T value, const shared_ptr< MetaMat< T > > &M)
Definition: operator_times.hpp:23
const shared_ptr< MetaMat< T > > & operator*=(const shared_ptr< MetaMat< T > > &M, const T value)
Definition: operator_times.hpp:56
const shared_ptr< MetaMat< T > > & operator+=(const shared_ptr< MetaMat< T > > &M, const op_scale< T > &A)
Definition: operator_times.hpp:27
op_add< T > operator+(const shared_ptr< MetaMat< T > > &A, const shared_ptr< MetaMat< T > > &B)
Definition: operator_times.hpp:21