Loading...
Searching...
No Matches
matrix_utilities.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_MATRIX_UTILITIES_HPP__
39# define __BITPIT_MATRIX_UTILITIES_HPP__
40
41// ========================================================================== //
42// INCLUDES //
43// ========================================================================== //
44
45// Standard template library
46# include <vector>
47# include <cassert>
48# include <cmath>
49# include <array>
50# include <iostream>
51
52# include "bitpit_operators.hpp"
53
54namespace bitpit{
55
59namespace linearalgebra{
60
61// Generic routines --------------------------------------------------------- //
62template <class T>
63void display( // Display matrix in nicely formatted output
64 std::ostream &, // (input/output) handle to output stream
65 std::vector< std::vector< T > > & // (input) matrix to be displayed
66);
67
68template <class T, size_t m, size_t n>
69void display( // Display matrix in nicely formatted output
70 std::ostream &, // (input/output) handle to output stream
71 std::array< std::array< T, n >, m > & // (input) matrix to be displayed
72);
73
74template <class T>
75void displayColMajor( // Display matrix in nicely formatted output
76 std::ostream &out, // (input/output) handle to output stream
77 T *A, // (input) matrix to be displayed
78 int nRows, // (input) number of rows
79 int nCols // (input) number of columns
80);
81
82template <class T>
83void displayRowMajor( // Display matrix in nicely formatted output
84 std::ostream &out, // (input/output) handle to output stream
85 T *A, // (input) matrix to be displayed
86 int nRows, // (input) number of rows
87 int nCols // (input) number of columns
88);
89
90template <class T>
91void displayColMajorSymmetric( // Display matrix in nicely formatted output
92 std::ostream &out, // (input/output) handle to output stream
93 T *A, // (input) matrix to be displayed
94 int nRows, // (input) number of rows
95 int nCols, // (input) number of columns
96 char uplo // (input) upper or lower portion of the matrix
97);
98
99template <class T>
100void displayRowMajorSymmetric( // Display matrix in nicely formatted output
101 std::ostream &out, // (input/output) handle to output stream
102 T *A, // (input) matrix to be displayed
103 int nRows, // (input) number of rows
104 int nCols, // (input) number of columns
105 char uplo // (input) upper or lower portion of the matrix
106);
107
108// Auxiliary routines --------------------------------------------------------- //
109template <class T>
110void complement( // Complement extraction
111 int , // (input) complement 1st index
112 int , // (input) complement 2nd index
113 std::vector< std::vector< T > > &, // (input) input matrix
114 std::vector< std::vector< T > > & // (input/output) (i,j) complement
115);
116
117template <class T, size_t m, size_t n>
118void complement( // Complement extraction
119 int , // (input) complement 1st index
120 int , // (input) complement 2nd index
121 std::array< std::array< T, n >, m > &, // (input) input matrix
122 std::array< std::array<T, n-1>, m-1> & // (input/output) (i,j) complement
123);
124
126 int row, // (input) row
127 int col, // (input) column
128 int nRows, // (input) number of rows
129 int nCols // (input) number of columns
130);
131
133 int row, // (input) row
134 int col, // (input) column
135 int nRows, // (input) number of rows
136 int nCols // (input) number of columns
137);
138
140 int row, // (input) row
141 int col, // (input) column
142 int nRows, // (input) number of rows
143 int nCols, // (input) number of columns
144 char uplo // (input) upper or lower portion of the matrix
145
146);
147
149 int row, // (input) row
150 int col, // (input) column
151 int nRows, // (input) number of rows
152 int nCols, // (input) number of columns
153 char uplo // (input) upper or lower portion of the matrix
154);
155
156// Matrix Basic templates --------------------------------------------------- //
157template <class T>
158void zeros( // Initialize an m-by-n matrix of zeros
159 std::vector< std::vector < T > > &, // (input/output) matrix
160 int , // (input) number of rows
161 int // (input) number of columns
162);
163
164template <class T, size_t m, size_t n>
165void zeros( // Initialize an m-by-n matrix of zeros
166 std::array< std::array < T, n >, m > & // (input/output) matrix
167);
168
169template <class T>
170void ones( // Initialize an m-by-n matrix of ones
171 std::vector< std::vector < T > > &, // (input/output) matrix
172 int , // (input) number of rows
173 int // (input) number of columns
174);
175
176template <class T, size_t m, size_t n>
177void ones( // Initialize an m-by-n matrix of ones
178 std::array< std::array < T, n >, m > & // (input/output) matrix
179);
180
181template <class T>
182void eye( // Initialize and m-by-n identity matrix
183 std::vector< std::vector < T > > &, // (input/output) matrix
184 int , // (input) number of rows
185 int // (input) number of columns
186);
187
188template <class T, size_t m, size_t n>
189void eye( // Initialize and m-by-n identity matrix
190 std::array< std::array < T, n >, m > & // (input/output) matrix
191);
192
193// Matrix determinant ------------------------------------------------------- //
194template <class T>
195T det( // Matrix determinant
196 std::vector< std::vector< T > > & // (input) input matrix
197);
198
199template <class T>
200T det( // Dummy function for recursive calls to det()
201 std::array< std::array < T, 1 >, 1 > & // (input) input matrix
202);
203
204template <class T, size_t m, size_t n>
205T det( // Matrix determinant
206 std::array< std::array < T, n >, m > & // (input) input matrix
207);
208
209}
210
211}
212
213// =================================================================================== //
214// TEMPLATES //
215// =================================================================================== //
216# include "matrix_utilities.tpp"
217
218# endif
int linearIndexRowMajor(int row, int col, int nRows, int nCols)
void complement(int, int, std::vector< std::vector< T > > &, std::vector< std::vector< T > > &)
int linearIndexColMajorSymmetric(int row, int col, int nRows, int nCols, char uplo)
int linearIndexRowMajorSymmetric(int row, int col, int nRows, int nCols, char uplo)
int linearIndexColMajor(int row, int col, int nRows, int nCols)
void displayColMajorSymmetric(std::ostream &out, T *A, int nRows, int nCols, char uplo)
void displayColMajor(std::ostream &out, T *A, int nRows, int nCols)
void display(std::ostream &, std::vector< std::vector< T > > &)
void displayRowMajorSymmetric(std::ostream &out, T *A, int nRows, int nCols, char uplo)
void displayRowMajor(std::ostream &out, T *A, int nRows, int nCols)
T det(std::vector< std::vector< T > > &)
void zeros(std::vector< std::vector< T > > &, int, int)
void ones(std::vector< std::vector< T > > &, int, int)
void eye(std::vector< std::vector< T > > &, int, int)
--- layout: doxygen_footer ---