Loading...
Searching...
No Matches
matrix_utilities.cpp
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#include "bitpit_common.hpp"
26
27#include "matrix_utilities.hpp"
28
29namespace bitpit {
30
31namespace linearalgebra {
32
48int linearIndexColMajor(int row, int col, int nRows, int nCols)
49{
50 BITPIT_UNUSED(nCols);
51
52 return row + col * nRows;
53}
54
65int linearIndexRowMajor(int row, int col, int nRows, int nCols)
66{
67 BITPIT_UNUSED(nRows);
68
69 return row * nCols + col;
70}
71
87int linearIndexColMajorSymmetric(int row, int col, int nRows, int nCols, char uplo)
88{
89 assert(uplo == 'L' || uplo == 'U');
90
91 if ((uplo == 'U' && col < row) || (uplo == 'L' && col > row)) {
92 return linearIndexColMajor(col, row, nRows, nCols);
93 } else {
94 return linearIndexColMajor(row, col, nRows, nCols);
95 }
96}
97
113int linearIndexRowMajorSymmetric(int row, int col, int nRows, int nCols, char uplo)
114{
115 assert(uplo == 'L' || uplo == 'U');
116
117 if ((uplo == 'U' && col < row) || (uplo == 'L' && col > row)) {
118 return linearIndexRowMajor(col, row, nRows, nCols);
119 } else {
120 return linearIndexRowMajor(row, col, nRows, nCols);
121 }
122}
123
128}
129
130}
#define BITPIT_UNUSED(variable)
Definition compiler.hpp:63
int linearIndexRowMajor(int row, int col, int nRows, int nCols)
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)
--- layout: doxygen_footer ---