41namespace linearalgebra{
57 std::vector< std::vector< T > > &A
73for (i = 0; i < m; ++i) {
74 out << A[i] << std::endl;
87template<
class T,
size_t m,
size_t n>
90 std::array<std::array<T, n>, m> &A
106for (i = 0; i < m; ++i) {
107 out << A[i] << std::endl;
129 for (
int i = 0; i < nRows; ++i) {
130 for (
int j = 0; j < nCols; ++j) {
154 for (
int i = 0; i < nRows; ++i) {
155 for (
int j = 0; j < nCols; ++j) {
176 std::ostream &out, T *A,
181 assert(uplo==
'L' || uplo==
'U');
183 for (
int i = 0; i < nRows; ++i) {
184 for (
int j = 0; j < nCols; ++j) {
211 assert(uplo==
'L' || uplo==
'U');
213 for (
int i = 0; i < nRows; ++i) {
214 for (
int j = 0; j < nCols; ++j) {
243 std::vector< std::vector< T > > &A,
244 std::vector< std::vector< T > > &B
261if (m == 0) {
return; }
263if (n == 0) {
return; }
264if ((i >= m) || (i < 0)) {
267if ((j >= n) || (j < 0)) {
277for (
int p = 0; p < m-1; ++p) {
278 B[p].resize(n-1, T{});
282for (l = 0; l < i; l++) {
283 for (k = 0; k < j; k++) {
286 for (k = j+1; k < n; k++) {
290for (l = i+1; l < m; l++) {
291 for (k = 0; k < j; k++) {
294 for (k = j+1; k < n; k++) {
295 B[l-1][k-1] = A[l][k];
311template <
class T,
size_t m,
size_t n>
315 std::array< std::array< T, n >, m > &A,
316 std::array< std::array<T, n-1>, m-1> &B
332if (m == 0) {
return; }
333if (n == 0) {
return; }
334if ((i >= (
long) m) || (i < 0)) {
337if ((j >= (
long) n) || (j < 0)) {
344for (l = 0; l < i; l++) {
345 for (k = 0; k < j; k++) {
348 for (k = j+1; k < (long) n; k++) {
352for (l = i+1; l < (long) m; l++) {
353 for (k = 0; k < j; k++) {
356 for (k = j+1; k < (long) n; k++) {
357 B[l-1][k-1] = A[l][k];
382 std::vector< std::vector < T > > &A,
400if ((m == 0) || (n == 0)) {
408for (i = 0; i < m; i++) {
409 A[i].resize(n, (T) 0.0);
410 for (j = 0; j < n; j++) {
427template <
class T,
size_t m,
size_t n>
429 std::array< std::array < T, n >, m > &A
462if ((m == 0) || (n == 0)) {
469for (i = 0; i < m; i++) {
485 std::vector< std::vector < T > > &A,
503if ((m == 0) || (n == 0)) {
504 std::cout <<
"ERROR: number of rows (columns) must be > 0!!" << std::endl;
511for (i = 0; i < m; i++) {
512 A[i].resize(n, (T) 1.0);
513 for (j = 0; j < n; j++) {
530template <
class T,
size_t m,
size_t n>
532 std::array< std::array < T, n >, m > &A
548if ((m == 0) || (n == 0)) {
555for (i = 0; i < m; i++) {
572 std::vector< std::vector < T > > &A,
582int s = std::min(m, n);
590if ((m == 0) || (n == 0)) {
598for (i = 0; i < s; i++) {
614template <
class T,
size_t m,
size_t n>
616 std::array< std::array < T, n >, m > &A
624int s = std::min(m, n);
632if ((m == 0) || (n == 0)) {
640for (i = 0; i < s; i++) {
667 std::array< std::array< T, 1 >, 1 > &A
681 std::vector< std::vector < T > > &A
691std::vector< std::vector < T > > C;
697if (m == 0) {
return(d); };
699if (n == 0) {
return(d); };
711 d = A[0][0]*A[1][1] - A[0][1]*A[1][0];
714 d = A[0][0]*A[1][1]*A[2][2] - A[0][0]*A[1][2]*A[2][1]
715 + A[0][1]*A[1][2]*A[2][0] - A[0][1]*A[1][0]*A[2][2]
716 + A[0][2]*A[1][0]*A[2][1] - A[0][2]*A[1][1]*A[2][0];
720 for (
int i = 0; i < m; i++) {
722 d +=
pow(-1.0, i) * A[0][i] *
det(C);
738template <
class T,
size_t m,
size_t n>
740 std::array< std::array < T, n >, m > &A
756if (m == 0) {
return(d); };
757if (n == 0) {
return(d); };
769 d = A[0][0]*A[1][1] - A[0][1]*A[1][0];
772 d = A[0][0]*A[1][1]*A[2][2] - A[0][0]*A[1][2]*A[2][1]
773 + A[0][1]*A[1][2]*A[2][0] - A[0][1]*A[1][0]*A[2][2]
774 + A[0][2]*A[1][0]*A[2][1] - A[0][2]*A[1][1]*A[2][0];
777 std::array< std::array < double, m-1 >, m-1 > C;
778 for (i = 0; i < m; i++) {
780 d +=
pow(-1.0, i) * A[0][i] *
det(C);
std::array< T, d > pow(std::array< T, d > &x, double p)
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)