| 1 | /************************************************************************* |
| 2 | * * |
| 3 | * Vega FEM Simulation Library Version 3.1 * |
| 4 | * * |
| 5 | * "matrix" library , Copyright (C) 2007 CMU, 2009 MIT * |
| 6 | * All rights reserved. * |
| 7 | * * |
| 8 | * Code author: Jernej Barbic * |
| 9 | * http://www.jernejbarbic.com/code * |
| 10 | * Research: Jernej Barbic, Doug L. James, Jovan Popovic * |
| 11 | * Funding: NSF, Link Foundation, Singapore-MIT GAMBIT Game Lab * |
| 12 | * * |
| 13 | * This library is free software; you can redistribute it and/or * |
| 14 | * modify it under the terms of the BSD-style license that is * |
| 15 | * included with this library in the file LICENSE.txt * |
| 16 | * * |
| 17 | * This library is distributed in the hope that it will be useful, * |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file * |
| 20 | * LICENSE.TXT for more details. * |
| 21 | * * |
| 22 | *************************************************************************/ |
| 23 | |
| 24 | #include <math.h> |
| 25 | #include "matrix.h" |
| 26 | #include "matrixIO.h" |
| 27 | #include "matrixExp.h" |
| 28 | |
| 29 | template<class real> |
| 30 | Matrix<real>::Matrix(const char * filename) |
| 31 | { |
| 32 | if (ReadMatrixFromDisk(filename, &m, &n, &data) != 0) |
| 33 | { |
| 34 | printf("Error loading matrix from %s.\n", filename); |
| 35 | throw 1; |
| 36 | } |
| 37 | freeDataInDestructor = true; |
| 38 | } |
| 39 | |
| 40 | template<class real> |
| 41 | Matrix<real>::Matrix(int m_, int n_, const real * data_, |
| 42 | bool makeInternalDataCopy, bool freeDataInDestructor_): |
| 43 | m(m_), n(n_), freeDataInDestructor(freeDataInDestructor_) |
| 44 | { |
| 45 | if (makeInternalDataCopy) |
| 46 | { |
| 47 | data = (real*) malloc (sizeof(real) * m * n); |
| 48 | memcpy(data, data_, sizeof(real) * m * n); |
| 49 | } |
| 50 | else |
| 51 | data = (real*)data_; |
| 52 | } |
| 53 | |
| 54 | template<class real> |
| 55 | Matrix<real>::Matrix (int m_, int n_, bool freeDataInDestructor_): |
| 56 | m(m_), n(n_), freeDataInDestructor(freeDataInDestructor_) |
| 57 | { |
| 58 | data = (real*) calloc (m * n, sizeof(real)); |
| 59 | } |
| 60 | |
| 61 | template<class real> |
| 62 | Matrix<real>::Matrix (int m_, int n_, real constEntry, bool freeDataInDestructor_): |
| 63 | m(m_), n(n_), freeDataInDestructor(freeDataInDestructor_) |
| 64 | { |
| 65 | data = (real*) malloc (sizeof(real) * m * n); |
| 66 | for(int i=0; i<m*n; i++) |
| 67 | data[i] = constEntry; |
| 68 | } |
| 69 | |
| 70 | template<class real> |
| 71 | Matrix<real>::Matrix(int m_, real diagonal, |
| 72 | bool freeDataInDestructor_): |
| 73 | m(m_), n(m_), freeDataInDestructor(freeDataInDestructor_) |
| 74 | { |
| 75 | data = (real*) calloc (m*m, sizeof(real)); |
| 76 | for(int i=0; i<m; i++) |
| 77 | data[ELT(m,i,i)] = diagonal; |
| 78 | } |
| 79 | |
| 80 | template<class real> |
| 81 | Matrix<real>::Matrix (int m_, const Matrix & vec, bool freeDataInDestructor_): |
| 82 | m(m_), n(m_), freeDataInDestructor(freeDataInDestructor_) |
| 83 | { |
| 84 | if (m != vec.Getm()) |
| 85 | throw 101; |
| 86 | if (vec.Getn() != 1) |
| 87 | throw 102; |
| 88 | data = (real*) calloc (m*m, sizeof(real)); |
| 89 | for(int i=0; i<m; i++) |
| 90 | data[ELT(m,i,i)] = vec(i,0); |
| 91 | } |
| 92 | |
| 93 | template<class real> |
| 94 | Matrix<real>::Matrix(int m_, const real * diagonal, |
| 95 | bool freeDataInDestructor_): |
| 96 | m(m_), n(m_), freeDataInDestructor(freeDataInDestructor_) |
| 97 | { |
| 98 | data = (real*) calloc (m*m, sizeof(real)); |
| 99 | for(int i=0; i<m; i++) |
| 100 | data[ELT(m,i,i)] = diagonal[i]; |
| 101 | } |
| 102 | |
| 103 | template<class real> |
| 104 | Matrix<real>::Matrix(const Matrix<real> & mtx2) |
| 105 | { |
| 106 | m = mtx2.Getm(); |
| 107 | n = mtx2.Getn(); |
| 108 | data = (real*) malloc (sizeof(real) * m * n); |
| 109 | memcpy(data, mtx2.GetData(), sizeof(real) * m * n); |
| 110 | freeDataInDestructor = true; |
| 111 | } |
| 112 | |
| 113 | template<class real> |
| 114 | Matrix<real>::~Matrix() |
| 115 | { |
| 116 | if (freeDataInDestructor) |
| 117 | free(data); |
| 118 | } |
| 119 | |
| 120 | template<class real> |
| 121 | const Matrix<real> Matrix<real>::operator+ (const Matrix<real> & mtx2) const |
| 122 | { |
| 123 | if ((m != mtx2.Getm()) || (n != mtx2.Getn())) |
| 124 | { |
| 125 | printf("Matrix size mismatch in Matrix::operator+ . m = %d, n = %d, mtx2.m = %d, mtx2.n = %d\n", |
| 126 | m, n, mtx2.Getm(), mtx2.Getn()); |
| 127 | throw 1; |
| 128 | } |
| 129 | real * output = SumMatrices(m, n, data, mtx2.GetData(), (real*)NULL); |
| 130 | return Matrix<real>(m,n,output,false); |
| 131 | } |
| 132 | |
| 133 | template<class real> |
| 134 | const Matrix<real> Matrix<real>::operator- (const Matrix<real> & mtx2) const |
| 135 | { |
| 136 | if ((m != mtx2.Getm()) || (n != mtx2.Getn())) |
| 137 | { |
| 138 | printf("Matrix size mismatch in Matrix::operator- . m = %d, n = %d, mtx2.m = %d, mtx2.n = %d\n", |
| 139 | m, n, mtx2.Getm(), mtx2.Getn()); |
| 140 | throw 2; |
| 141 | } |
| 142 | real * output = SubtractMatrices(m, n, data, mtx2.GetData(), (real*)NULL); |
| 143 | return Matrix<real>(m,n,output,false); |
| 144 | } |
| 145 | |
| 146 | template<class real> |
| 147 | const Matrix<real> Matrix<real>::operator* (const Matrix<real> & mtx2) const |
| 148 | { |
| 149 | if (n != mtx2.Getm()) |
| 150 | { |
| 151 | printf("Matrix size mismatch in Matrix::operator* . m = %d, n = %d, mtx2.m = %d, mtx2.n = %d\n", |
| 152 | m, n, mtx2.Getm(), mtx2.Getn()); |
| 153 | throw 3; |
| 154 | } |
| 155 | real * output = MultiplyMatrices(m, n, mtx2.Getn(), data, mtx2.GetData(), (real*)NULL); |
| 156 | return Matrix<real>(m,mtx2.Getn(),output,false); |
| 157 | } |
| 158 | |
| 159 | // output = trans(this) * mtx2 |
| 160 | template<class real> |
| 161 | const Matrix<real> Matrix<real>::MultiplyT(const Matrix & mtx2) const |
| 162 | { |
| 163 | if (m != mtx2.Getm()) |
| 164 | { |
| 165 | printf("Matrix size mismatch in Matrix::MultiplyT . m = %d, n = %d, mtx2.m = %d, mtx2.n = %d\n", |
| 166 | m, n, mtx2.Getm(), mtx2.Getn()); |
| 167 | throw 31; |
| 168 | } |
| 169 | real * output = MultiplyMatricesT(n, m, mtx2.Getn(), data, mtx2.GetData(), (real*)NULL); |
| 170 | return Matrix<real>(n,mtx2.Getn(),output,false); |
| 171 | } |
| 172 | |
| 173 | template<class real> |
| 174 | Matrix<real> & Matrix<real>::operator= (const Matrix<real> & mtx2) |
| 175 | { |
| 176 | if ((m != mtx2.Getm()) || (n != mtx2.Getn())) |
| 177 | { |
| 178 | printf("Matrix size mismatch in Matrix::operator= . m = %d, n = %d, mtx2.m = %d, mtx2.n = %d\n", |
| 179 | m, n, mtx2.Getm(), mtx2.Getn()); |
| 180 | throw 4; |
| 181 | } |
| 182 | |
| 183 | if (this == &mtx2) // self-assignment |
| 184 | return (*this); |
| 185 | |
| 186 | memcpy(data, mtx2.GetData(), sizeof(real) * m * n); |
| 187 | return (*this); |
| 188 | } |
| 189 | |
| 190 | template<class real> |
| 191 | Matrix<real> & Matrix<real>::operator+= (const Matrix<real> & mtx2) |
| 192 | { |
| 193 | if ((m != mtx2.Getm()) || (n != mtx2.Getn())) |
| 194 | { |
| 195 | printf("Matrix size mismatch in Matrix::operator+= . m = %d, n = %d, mtx2.m = %d, mtx2.n = %d\n", |
| 196 | m, n, mtx2.Getm(), mtx2.Getn()); |
| 197 | throw 5; |
| 198 | } |
| 199 | // works fine even if self-assignment |
| 200 | SumMatrices(m, n, data, mtx2.GetData(), data); |
| 201 | return (*this); |
| 202 | } |
| 203 | |
| 204 | template<class real> |
| 205 | Matrix<real> & Matrix<real>::operator-= (const Matrix<real> & mtx2) |
| 206 | { |
| 207 | if ((m != mtx2.Getm()) || (n != mtx2.Getn())) |
| 208 | { |
| 209 | printf("Matrix size mismatch in Matrix::operator-= . m = %d, n = %d, mtx2.m = %d, mtx2.n = %d\n", |
| 210 | m, n, mtx2.Getm(), mtx2.Getn()); |
| 211 | throw 6; |
| 212 | } |
| 213 | // works fine even if self-assignment |
| 214 | SubtractMatrices(m, n, data, mtx2.GetData(), data); |
| 215 | return (*this); |
| 216 | } |
| 217 | |
| 218 | template<class real> |
| 219 | Matrix<real> & Matrix<real>::operator*= (const Matrix<real> & mtx2) |
| 220 | { |
| 221 | if ((n != mtx2.Getm()) || (n != mtx2.Getn())) |
| 222 | { |
| 223 | printf("Matrix size mismatch in Matrix::operator*= . m = %d, n = %d, mtx2.m = %d, mtx2.n = %d\n", |
| 224 | m, n, mtx2.Getm(), mtx2.Getn()); |
| 225 | throw 7; |
| 226 | } |
| 227 | // works fine even if self-assignment |
| 228 | real * buffer = MultiplyMatrices(m, n, n, data, mtx2.GetData()); |
| 229 | memcpy(data, buffer, sizeof(real) * m * n); |
| 230 | free(buffer); |
| 231 | return (*this); |
| 232 | } |
| 233 | |
| 234 | template<class real> |
| 235 | Matrix<real> & Matrix<real>::operator*= (const real alpha) |
| 236 | { |
| 237 | int mn = m * n; |
| 238 | for(int i=0; i<mn; i++) |
| 239 | data[i] *= alpha; |
| 240 | return (*this); |
| 241 | } |
| 242 | |
| 243 | template<class real> |
| 244 | real Matrix<real>::MaxAbsEntry() const |
| 245 | { |
| 246 | real maxAbsEntry = 0.0; |
| 247 | int mn = m * n; |
| 248 | for(int i=0; i<mn; i++) |
| 249 | { |
| 250 | if (fabs(data[i]) > maxAbsEntry) |
| 251 | maxAbsEntry = fabs(data[i]); |
| 252 | } |
| 253 | return maxAbsEntry; |
| 254 | } |
| 255 | |
| 256 | template<class real> |
| 257 | Matrix<real> & Matrix<real>::InPlaceTranspose() |
| 258 | { |
| 259 | InPlaceTransposeMatrix(m, n, data); |
| 260 | // swap m,n |
| 261 | int swap = m; |
| 262 | m = n; |
| 263 | n = swap; |
| 264 | return (*this); |
| 265 | } |
| 266 | |
| 267 | template<class real> |
| 268 | void Matrix<real>::Print(int numDigits) const |
| 269 | { |
| 270 | char formatString[6]; |
| 271 | if (numDigits < 0) |
| 272 | strcpy(formatString,"%G "); |
| 273 | else |
| 274 | sprintf(formatString,"%%.%df ", numDigits); |
| 275 | |
| 276 | for(int i=0; i<m; i++) |
| 277 | { |
| 278 | for(int j=0; j<n; j++) |
| 279 | printf(formatString, (*this)(i,j)); |
| 280 | printf("\n"); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | template<class real> |
| 285 | void Matrix<real>::SymmetricEigenDecomposition(Matrix<real> & Q, Matrix<real> & Lambda) |
| 286 | { |
| 287 | if (m != n) |
| 288 | { |
| 289 | printf("Matrix size mismatch in Matrix::SymmetricEigenDecomposition . m = %d, n = %d\n", m, n); |
| 290 | throw 12; |
| 291 | } |
| 292 | |
| 293 | real * QData = (real*) malloc(sizeof(real) * m * m); |
| 294 | real * LambdaData = (real*) malloc(sizeof(real) * m); |
| 295 | SymmetricMatrixEigenDecomposition(m, data, QData, LambdaData); |
| 296 | Q = Matrix<real>(m,m,QData,false); |
| 297 | Lambda = Matrix<real>(m,1,LambdaData,false); |
| 298 | } |
| 299 | |
| 300 | template<class real> |
| 301 | void Matrix<real>::SVD(Matrix<real> & U, Matrix<real> & Sigma, Matrix<real> & VT) |
| 302 | { |
| 303 | real * UData = (real*) malloc(sizeof(real) * m * MIN(m,n)); |
| 304 | real * SigmaData = (real*) malloc(sizeof(real) * MIN(m,n)); |
| 305 | real * VTData = (real*) malloc(sizeof(real) * MIN(m,n) * n); |
| 306 | MatrixSVD(m, n, data, UData, SigmaData, VTData); |
| 307 | U = Matrix<real>(m, MIN(m,n), UData, false); |
| 308 | Sigma = Matrix<real>(MIN(m,n), 1, SigmaData, false); |
| 309 | VT = Matrix<real>(MIN(m,n), n, VTData, false); |
| 310 | } |
| 311 | |
| 312 | template<class real> |
| 313 | int Matrix<real>::EigenDecomposition(Matrix<real> & EigenVectors, Matrix<real> & LambdaRe, Matrix<real> & LambdaIm) |
| 314 | { |
| 315 | if (m != n) |
| 316 | { |
| 317 | printf("Matrix size mismatch in Matrix::EigenDecomposition . m = %d, n = %d\n", m, n); |
| 318 | throw 13; |
| 319 | } |
| 320 | |
| 321 | real * EigenVectorsData = (real*) malloc(sizeof(real) * m * m); |
| 322 | real * LambdaReData = (real*) malloc(sizeof(real) * m); |
| 323 | real * LambdaImData = (real*) malloc(sizeof(real) * m); |
| 324 | int code = MatrixEigenDecomposition(m, data, |
| 325 | EigenVectorsData, LambdaReData, LambdaImData); |
| 326 | |
| 327 | EigenVectors = Matrix<real>(m,m,EigenVectorsData,false); |
| 328 | LambdaRe = Matrix<real>(m,1,LambdaReData,false); |
| 329 | LambdaIm = Matrix<real>(m,1,LambdaImData,false); |
| 330 | |
| 331 | return code; |
| 332 | } |
| 333 | |
| 334 | template<class real> |
| 335 | int Matrix<real>::LUSolve(const Matrix<real> & x, const Matrix<real> & rhs) |
| 336 | { |
| 337 | if ((Getm() != Getn()) || (Getm() != x.Getm()) || (x.Getm() != rhs.Getm()) || (x.Getn() != rhs.Getn()) ) |
| 338 | { |
| 339 | printf("Matrix size mismatch in Matrix::LUSolve .\n"); |
| 340 | throw 12; |
| 341 | } |
| 342 | |
| 343 | int exitCode = 0; |
| 344 | try |
| 345 | { |
| 346 | MatrixLUSolve(Getn(), rhs.Getn(), GetData(), x.GetData(), rhs.GetData()); |
| 347 | } |
| 348 | catch(int exceptionCode) |
| 349 | { |
| 350 | exitCode = exceptionCode; |
| 351 | } |
| 352 | |
| 353 | return exitCode; |
| 354 | } |
| 355 | |
| 356 | #ifdef USE_EXPOKIT |
| 357 | |
| 358 | template<class real> |
| 359 | void Matrix<real>::MExpv(real t, const Matrix<real> & v, Matrix<real> & w) |
| 360 | { |
| 361 | if ((Getm() != Getn()) || (Getm() != v.Getm()) || (Getm() != w.Getm()) || (v.Getn() != 1) || (w.Getn() != 1)) |
| 362 | { |
| 363 | printf("Matrix size mismatch in Matrix::MExpv .\n"); |
| 364 | throw 13; |
| 365 | } |
| 366 | |
| 367 | MatrixExpv(Getm(), GetData(), t, v.GetData(), w.GetData()); |
| 368 | } |
| 369 | |
| 370 | #else |
| 371 | |
| 372 | template<class real> |
| 373 | void Matrix<real>::MExpv(real t, const Matrix<real> & v, Matrix<real> & w) |
| 374 | { |
| 375 | printf("Error: MExpv is not enabled.\n"); |
| 376 | } |
| 377 | |
| 378 | #endif |
| 379 | |
| 380 | |
| 381 | |
| 382 | template<class real> |
| 383 | int Matrix<real>::Save(const char * filename) const |
| 384 | { |
| 385 | if (WriteMatrixToDisk(filename, m, n, data) != 0) |
| 386 | { |
| 387 | printf("Error writing matrix to %s.\n", filename); |
| 388 | return 1; |
| 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | template<class real> |
| 394 | void Matrix<real>::SetSubmatrix(int I, int J, const Matrix<real> & submatrix) |
| 395 | { |
| 396 | int subm = submatrix.Getm(); |
| 397 | int subn = submatrix.Getn(); |
| 398 | real * subdata = submatrix.GetData(); |
| 399 | |
| 400 | if ((I < 0) || (J < 0) || (I + subm > m) || (J + subn > n)) |
| 401 | { |
| 402 | printf("Error: matrix index out of bounds.\n"); |
| 403 | throw 21; |
| 404 | } |
| 405 | |
| 406 | for(int j=0; j<subn; j++) |
| 407 | for(int i=0; i<subm; i++) |
| 408 | data[ELT(m,I+i,J+j)] = subdata[ELT(subm,i,j)]; |
| 409 | } |
| 410 | |
| 411 | template<class real> |
| 412 | void Matrix<real>::RemoveColumns(int columnStart, int columnEnd) |
| 413 | { |
| 414 | // write everything to the right of columnEnd to the left |
| 415 | int stride = columnEnd - columnStart; |
| 416 | for(int column=columnEnd; column<n; column++) |
| 417 | { |
| 418 | // write column to column-stride |
| 419 | memcpy(&data[ELT(m, 0, column-stride)], &data[ELT(m, 0, column)], sizeof(double) * m); |
| 420 | } |
| 421 | |
| 422 | // free the space |
| 423 | data = (real*) realloc (data, sizeof(real) * m * (n - stride)); |
| 424 | |
| 425 | n = n - stride; |
| 426 | } |
| 427 | |
| 428 | template<class real> |
| 429 | void Matrix<real>::RemoveRows(int rowStart, int rowEnd) |
| 430 | { |
| 431 | InPlaceTransposeMatrix(m, n, data); |
| 432 | int mBuf = m; |
| 433 | m = n; |
| 434 | n = mBuf; |
| 435 | RemoveColumns(rowStart, rowEnd); |
| 436 | InPlaceTransposeMatrix(m, n, data); |
| 437 | mBuf = m; |
| 438 | m = n; |
| 439 | n = mBuf; |
| 440 | } |
| 441 | |
| 442 | template<class real> |
| 443 | void Matrix<real>::RemoveRowsColumns(int columnStart, int columnEnd) |
| 444 | { |
| 445 | RemoveColumns(columnStart, columnEnd); |
| 446 | RemoveRows(columnStart, columnEnd); |
| 447 | } |
| 448 | |
| 449 | template<class real> |
| 450 | void Matrix<real>::AppendColumns(const Matrix<real> & columns) |
| 451 | { |
| 452 | if (columns.Getm() != m) |
| 453 | { |
| 454 | printf("Error: mismatch in number of rows in AppendColumns.\n"); |
| 455 | throw 41; |
| 456 | } |
| 457 | |
| 458 | data = (real*) realloc (data, sizeof(real) * (m * (n + columns.Getn()))); |
| 459 | memcpy(&data[ELT(m, 0, n)], columns.GetData(), sizeof(real) * m * columns.Getn()); |
| 460 | n += columns.Getn(); |
| 461 | } |
| 462 | |
| 463 | template<class real> |
| 464 | void Matrix<real>::AppendRows(const Matrix<real> & rows) |
| 465 | { |
| 466 | if (rows.Getn() != n) |
| 467 | { |
| 468 | printf("Error: mismatch in number of columns in AppendRows.\n"); |
| 469 | throw 42; |
| 470 | } |
| 471 | |
| 472 | InPlaceTransposeMatrix(m, n, data); |
| 473 | int mBuf = m; |
| 474 | m = n; |
| 475 | n = mBuf; |
| 476 | Matrix<real> rowsT = Transpose(rows); |
| 477 | AppendColumns(rowsT); |
| 478 | InPlaceTransposeMatrix(m, n, data); |
| 479 | mBuf = m; |
| 480 | m = n; |
| 481 | n = mBuf; |
| 482 | } |
| 483 | |
| 484 | template<class real> |
| 485 | void Matrix<real>::AppendRowsColumns(const Matrix<real> & bottomLeftBlock, const Matrix<real> & topRightBlock, const Matrix<real> & bottomRightBlock) |
| 486 | { |
| 487 | if (topRightBlock.Getm() != m) |
| 488 | { |
| 489 | printf("Error: mismatch in AppendRowsColumns.\n"); |
| 490 | throw 43; |
| 491 | } |
| 492 | |
| 493 | if (bottomLeftBlock.Getn() != n) |
| 494 | { |
| 495 | printf("Error: mismatch in AppendRowsColumns.\n"); |
| 496 | throw 44; |
| 497 | } |
| 498 | |
| 499 | if (bottomRightBlock.Getm() != bottomLeftBlock.Getm()) |
| 500 | { |
| 501 | printf("Error: mismatch in AppendRowsColumns.\n"); |
| 502 | throw 45; |
| 503 | } |
| 504 | |
| 505 | if (bottomRightBlock.Getn() != topRightBlock.Getn()) |
| 506 | { |
| 507 | printf("Error: mismatch in AppendRowsColumns.\n"); |
| 508 | throw 46; |
| 509 | } |
| 510 | |
| 511 | AppendColumns(topRightBlock); |
| 512 | |
| 513 | Matrix<real> blockMatrix(bottomLeftBlock.Getm(), n); |
| 514 | real * blockMatrixData = blockMatrix.GetData(); |
| 515 | memcpy(blockMatrixData, bottomLeftBlock.GetData(), sizeof(real) * (bottomLeftBlock.Getm() * bottomLeftBlock.Getn())); |
| 516 | memcpy(&blockMatrixData[ELT(bottomLeftBlock.Getm(), 0, bottomLeftBlock.Getn())], bottomRightBlock.GetData(), sizeof(real) * (bottomRightBlock.Getm() * bottomRightBlock.Getn())); |
| 517 | AppendRows(blockMatrix); |
| 518 | } |
| 519 | |
| 520 | // === float === |
| 521 | template Matrix<float>::Matrix(const char * filename); |
| 522 | template Matrix<float>::Matrix(int m, int n, const float * data, |
| 523 | bool makeInternalDataCopy, bool freeDataInDestructor); |
| 524 | template Matrix<float>::Matrix(int m, int n, bool freeDataInDestructor); |
| 525 | template Matrix<float>::Matrix(int m, int n, float constEntry, bool freeDataInDestructor); |
| 526 | template Matrix<float>::Matrix(int m, float diagonal, bool freeDataInDestructor); |
| 527 | template Matrix<float>::Matrix(int m, const float * diagonal, bool freeDataInDestructor); |
| 528 | template Matrix<float>::Matrix (int m, const Matrix<float> & vec, bool freeDataInDestructor); |
| 529 | template Matrix<float>::Matrix(const Matrix<float> & mtx2); |
| 530 | template Matrix<float>::~Matrix(); |
| 531 | template const Matrix<float> Matrix<float>::operator+ (const Matrix<float> & mtx2) const; |
| 532 | template const Matrix<float> Matrix<float>::operator- (const Matrix<float> & mtx2) const; |
| 533 | template const Matrix<float> Matrix<float>::operator* (const Matrix<float> & mtx2) const; |
| 534 | template const Matrix<float> Matrix<float>::MultiplyT(const Matrix<float> & mtx2) const; |
| 535 | template Matrix<float> & Matrix<float>::operator= (const Matrix<float> & mtx2); |
| 536 | template Matrix<float> & Matrix<float>::operator+= (const Matrix<float> & mtx2); |
| 537 | template Matrix<float> & Matrix<float>::operator-= (const Matrix<float> & mtx2); |
| 538 | template Matrix<float> & Matrix<float>::operator*= (const Matrix<float> & mtx2); |
| 539 | template Matrix<float> & Matrix<float>::operator*= (const float alpha); |
| 540 | template float Matrix<float>::MaxAbsEntry() const; |
| 541 | template Matrix<float> & Matrix<float>::InPlaceTranspose(); |
| 542 | template void Matrix<float>::SymmetricEigenDecomposition(Matrix<float> & Q, Matrix<float> & Lambda); |
| 543 | template void Matrix<float>::SVD(Matrix<float> & U, Matrix<float> & Sigma, Matrix<float> & VT); |
| 544 | template int Matrix<float>::EigenDecomposition(Matrix<float> & EigenVectors, Matrix<float> & LambdaRe, Matrix<float> & LambdaIm); |
| 545 | template int Matrix<float>::LUSolve(const Matrix<float> & x, const Matrix<float> & rhs); |
| 546 | #ifdef USE_EXPOKIT |
| 547 | template void Matrix<float>::MExpv(float t, const Matrix<float> & v, Matrix<float> & w); |
| 548 | #endif |
| 549 | template void Matrix<float>::Print(int numDigits) const; |
| 550 | template int Matrix<float>::Save(const char * filename) const; |
| 551 | template void Matrix<float>::SetSubmatrix(int I, int J, const Matrix<float> & submatrix); |
| 552 | template void Matrix<float>::RemoveColumns(int columnStart, int columnEnd); |
| 553 | template void Matrix<float>::RemoveRows(int rowStart, int rowEnd); |
| 554 | template void Matrix<float>::RemoveRowsColumns(int columnStart, int columnEnd); |
| 555 | template void Matrix<float>::AppendRows(const Matrix<float> & rows); |
| 556 | template void Matrix<float>::AppendColumns(const Matrix<float> & columns); |
| 557 | template void Matrix<float>::AppendRowsColumns(const Matrix<float> & bottomLeftBlock, const Matrix<float> & topRightBlock, const Matrix<float> & bottomRightBlock); |
| 558 | |
| 559 | // === double === |
| 560 | template Matrix<double>::Matrix(const char * filename); |
| 561 | template Matrix<double>::Matrix(int m, int n, const double * data, |
| 562 | bool makeInternalDataCopy, bool freeDataInDestructor); |
| 563 | template Matrix<double>::Matrix(int m, int n, bool freeDataInDestructor); |
| 564 | template Matrix<double>::Matrix(int m, int n, double constEntry, bool freeDataInDestructor); |
| 565 | template Matrix<double>::Matrix(int m, double diagonal, bool freeDataInDestructor); |
| 566 | template Matrix<double>::Matrix(int m, const double * diagonal, bool freeDataInDestructor); |
| 567 | template Matrix<double>::Matrix (int m, const Matrix<double> & vec, bool freeDataInDestructor); |
| 568 | template Matrix<double>::Matrix(const Matrix<double> & mtx2); |
| 569 | template Matrix<double>::~Matrix(); |
| 570 | template const Matrix<double> Matrix<double>::operator+ (const Matrix<double> & mtx2) const; |
| 571 | template const Matrix<double> Matrix<double>::operator- (const Matrix<double> & mtx2) const; |
| 572 | template const Matrix<double> Matrix<double>::operator* (const Matrix<double> & mtx2) const; |
| 573 | template Matrix<double> & Matrix<double>::operator*= (const double alpha); |
| 574 | template const Matrix<double> Matrix<double>::MultiplyT(const Matrix<double> & mtx2) const; |
| 575 | template Matrix<double> & Matrix<double>::operator= (const Matrix<double> & mtx2); |
| 576 | template Matrix<double> & Matrix<double>::operator+= (const Matrix<double> & mtx2); |
| 577 | template Matrix<double> & Matrix<double>::operator-= (const Matrix<double> & mtx2); |
| 578 | template Matrix<double> & Matrix<double>::operator*= (const Matrix<double> & mtx2); |
| 579 | template double Matrix<double>::MaxAbsEntry() const; |
| 580 | template Matrix<double> & Matrix<double>::InPlaceTranspose(); |
| 581 | template void Matrix<double>::SymmetricEigenDecomposition(Matrix<double> & Q, Matrix<double> & Lambda); |
| 582 | template void Matrix<double>::SVD(Matrix<double> & U, Matrix<double> & Sigma, Matrix<double> & VT); |
| 583 | template int Matrix<double>::EigenDecomposition(Matrix<double> & EigenVectors, Matrix<double> & LambdaRe, Matrix<double> & LambdaIm); |
| 584 | template int Matrix<double>::LUSolve(const Matrix<double> & x, const Matrix<double> & rhs); |
| 585 | #ifdef USE_EXPOKIT |
| 586 | template void Matrix<double>::MExpv(double t, const Matrix<double> & v, Matrix<double> & w); |
| 587 | #endif |
| 588 | template void Matrix<double>::Print(int numDigits) const; |
| 589 | template int Matrix<double>::Save(const char * filename) const; |
| 590 | template void Matrix<double>::SetSubmatrix(int I, int J, const Matrix<double> & submatrix); |
| 591 | template void Matrix<double>::RemoveColumns(int columnStart, int columnEnd); |
| 592 | template void Matrix<double>::RemoveRows(int rowStart, int rowEnd); |
| 593 | template void Matrix<double>::RemoveRowsColumns(int columnStart, int columnEnd); |
| 594 | template void Matrix<double>::AppendRows(const Matrix<double> & rows); |
| 595 | template void Matrix<double>::AppendColumns(const Matrix<double> & columns); |
| 596 | template void Matrix<double>::AppendRowsColumns(const Matrix<double> & bottomLeftBlock, const Matrix<double> & topRightBlock, const Matrix<double> & bottomRightBlock); |
| 597 |