Loading...
Searching...
No Matches
multiplication.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25// ========================================================================== //
26// LINEAR ALGEBRA PACKAGE //
27// //
28// Functions for basic linear algebra computations. //
29// ========================================================================== //
30// INFO //
31// ========================================================================== //
32// Author : Alessandro Alaia //
33// Data : Sept 26, 2014 //
34// Version : v2.0 //
35// //
36// All rights reserved. //
37// ========================================================================== //
38# ifndef __BITPIT_MULTIPLICATION_HPP__
39# define __BITPIT_MULTIPLICATION_HPP__
40
41// ========================================================================== //
42// INCLUDES //
43// ========================================================================== //
44
45// Standard template library
46# include <vector>
47# include <cmath>
48# include <array>
49# include <iostream>
50
51# include "bitpit_operators.hpp"
52
53# include "matrix_utilities.hpp"
54
55namespace bitpit{
56
60namespace linearalgebra{
61
62template <class T>
63void matmul( // Matrix multiplication with a constant
64 T , // (input) 1st input scalar
65 const std::vector< std::vector< T > > &, // (input) 2nd input matrix
66 std::vector< std::vector< T > > & // (input/output) output matrix
67);
68
69template <class T, size_t m, size_t n>
70void matmul( // Matrix multiplication with a constant
71 T , // (input) 1st input scalar
72 const std::array< std::array< T, n >, m > &, // (input) 2nd input matrix
73 std::array< std::array< T, n >, m > & // (input/output) output matrix
74);
75
76template <class T>
77void matmul( // Matrix multiplication with a constant
78 const std::vector< std::vector< T > > &, // (input) 1st input matrix
79 T , // (input) 2nd input scalar
80 std::vector< std::vector< T > > & // (input/output) output matrix
81);
82
83template <class T, size_t m, size_t n>
84void matmul( // Matrix multiplication with a constant
85 const std::array< std::array< T, n >, m > &, // (input) 1st input matrix
86 T , // (input) 2nd input scalar
87 std::array< std::array< T, n >, m > & // (input/output) output matrix
88);
89
90template <class T>
91void matmul( // Matrix multiplication with a vector
92 const std::vector< T > &, // (input) 1st input vector
93 const std::vector< std::vector< T > > &, // (input) 2nd input matrix
94 std::vector< T > & // (input/output) output vector
95);
96
97template <class T, size_t m, size_t n>
98void matmul( // Matrix multiplication with a vector
99 const std::array< T, m > &, // (input) 1st input vector
100 const std::array< std::array < T, n >, m > &, // (input) 2nd input matrix
101 std::array< T, n > & // (input/output) output vector
102);
103
104template <class T>
105void matmul( // Matrix multiplication with a vector
106 const std::vector< std::vector< T > > &, // (input) 1st input matrix
107 const std::vector< T > &, // (input) 2nd input vector
108 std::vector< T > & // (input/output) output vector
109);
110
111template <class T, size_t m, size_t n>
112void matmul( // Matrix multiplication with a vector
113 const std::array< std::array < T, n >, m > &, // (input) 1st input matrix
114 const std::array< T, n > &, // (input) 2nd input vector
115 std::array< T, m > & // (input/output) output vector
116);
117
118template <class T>
119void matmul( // Matrix multiplication
120 const std::vector< std::vector< T > > &, // (input) 1st input matrix
121 const std::vector< std::vector< T > > &, // (input) 2nd input matrix
122 std::vector< std::vector< T > > & // (input/output) output matrix
123);
124
125template <class T, size_t m, size_t n, size_t l>
126void matmul( // Matrix multiplication
127 const std::array< std::array< T, n >, m > &, // (input) 1st input matrix
128 const std::array< std::array< T, l >, n > &, // (input) 2nd input matrix
129 std::array< std::array< T, l >, m > & // (input/output) output matrix
130);
131
132template <class T, size_t d1, size_t d2, size_t d3>
133std::array< std::array<T, d2> , d1> matmul(
134 const std::array< std::array<T, d3>, d1> &,
135 const std::array< std::array<T, d2>, d3> &
136);
137
138template <class T>
139std::vector< std::vector<T> > matmul(
140 const std::vector< std::vector<T> > &,
141 const std::vector< std::vector<T> > &
142);
143
144template <class T>
145std::vector< std::vector<T> > matmulDiag(
146 const std::vector<T> &,
147 const std::vector< std::vector<T> > &
148);
149
150template <class T>
151std::vector< std::vector<T> > matmulDiag(
152 const std::vector< std::vector<T> > &,
153 const std::vector<T> &
154);
155
156template <class T, size_t d1, size_t d2>
157std::array< std::array<T, d2> , d1> matmulDiag(
158 const std::array<T, d1> &,
159 const std::array< std::array<T, d2>, d1> &
160);
161
162template <class T, size_t d1, size_t d2>
163std::array< std::array<T, d2> , d1> matmulDiag(
164 const std::array< std::array<T, d2>, d1> & ,
165 const std::array<T, d2> &
166);
167
168// Matrix Vector Multiplication ------------------------------------------------------ //
169template <class T>
170std::vector<T> matmul(
171 const std::vector< std::vector<T>> &,
172 const std::vector<T> &
173);
174
175template <class T, size_t d1, size_t d2>
176std::array<T, d1> matmul(
177 const std::array< std::array<T, d2>, d1> &,
178 const std::array<T, d2> &
179);
180
181// Operator Tensor_Product ------------------------------------------------------------ //
182template <class T>
183std::vector<std::vector<T>> tensorProduct(
184 std::vector<T> const &,
185 std::vector<T> const &
186);
187
188template <class T, size_t n, size_t m>
189std::array<std::array<T,m>, n> tensorProduct(
190 std::array<T, n> const &,
191 std::array<T, m> const &
192);
193
194}
195
196}
197
198// =================================================================================== //
199// TEMPLATES //
200// =================================================================================== //
201# include "multiplication.tpp"
202
203# endif
std::vector< std::vector< T > > tensorProduct(std::vector< T > const &, std::vector< T > const &)
void matmul(T, const std::vector< std::vector< T > > &, std::vector< std::vector< T > > &)
std::vector< std::vector< T > > matmulDiag(const std::vector< T > &, const std::vector< std::vector< T > > &)
--- layout: doxygen_footer ---