| 1 | /* Eigen_def.h |
| 2 | * |
| 3 | * Copyright (C) 1993-2018, 2026 David Weenink |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | Eigen represents the eigenvalues and eigenvectors of a square matrix. |
| 21 | For a general square matrix some of the eigenvalues will be complex numbers |
| 22 | and also some of the eigenvectors will be complex vectors. |
| 23 | Most matrices we use are symmetric, which means that the |
| 24 | eigenvalues and eigenvectors are real numbers. |
| 25 | For these cases we don't need the imaginary parts: |
| 26 | we don't read and write them. |
| 27 | */ |
| 28 | |
| 29 | #define ooSTRUCTcxx . . $ `dwsys/Eigen_def.h:29:9`! Eigen |
| 30 | oo_DEFINE_CLASScxx . . $ `sys/oo.h:176:9`! (Eigen, Daata) |
| 31 | |
| 32 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (numberOfEigenvalues) |
| 33 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (dimension) |
| 34 | oo_VECcxx . . $ `sys/oo.h:74:9`! (eigenvalues, numberOfEigenvalues) |
| 35 | oo_MATcxx . . $ `sys/oo.h:82:9`! (eigenvectors, numberOfEigenvalues, dimension) |
| 36 | |
| 37 | #if oo_READINGcxx . . $ `sys/oo.h:235:9`! |
| 38 | oo_VERSION_UNTIL (1) |
| 39 | onlyReals = true; |
| 40 | oo_VERSION_ELSE |
| 41 | oo_BOOLEAN (onlyReals) |
| 42 | if (! onlyReals) { |
| 43 | oo_VEC (eigenvalues_im, numberOfEigenvalues) |
| 44 | oo_MAT (eigenvectors_im, numberOfEigenvalues, dimension) |
| 45 | } |
| 46 | oo_VERSION_END |
| 47 | #else |
| 48 | oo_BOOLEANcxx . . $ `sys/oo.h:105:9`! (onlyReals) // convenience |
| 49 | #if oo_WRITINGcxx . . $ `sys/oo.h:238:9`! || oo_COMPARINGcxx . . $ `sys/oo.h:233:9`! |
| 50 | if (! onlyReals) { |
| 51 | oo_VEC (eigenvalues_im, numberOfEigenvalues) |
| 52 | oo_MAT (eigenvectors_im, numberOfEigenvalues, dimension) |
| 53 | } |
| 54 | #else |
| 55 | oo_VECcxx . . $ `sys/oo.h:74:9`! (eigenvalues_im, numberOfEigenvalues) |
| 56 | oo_MATcxx . . $ `sys/oo.h:82:9`! (eigenvectors_im, numberOfEigenvalues, dimension) |
| 57 | #endif |
| 58 | #endif |
| 59 | |
| 60 | oo_END_CLASScxx . . $ `sys/oo.h:186:9`! (Eigen) |
| 61 | |
| 62 | #undef ooSTRUCTcxx . . $ `dwsys/Eigen_def.h:29:9`! |
| 63 | |
| 64 | #define ooSTRUCTcxx . . $ `dwsys/Eigen_def.h:64:9`! Eigen2 |
| 65 | oo_DEFINE_CLASScxx . . $ `sys/oo.h:176:9`! (Eigen2, Daata) |
| 66 | |
| 67 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (numberOfEigenvalues) |
| 68 | oo_INTEGERcxx . . $ `sys/oo.h:45:9`! (dimension) |
| 69 | |
| 70 | #if oo_READINGcxx . . $ `sys/oo.h:235:9`! |
| 71 | oo_VERSION_UNTIL (1) |
| 72 | /* |
| 73 | Convert the real vector and matrix in the file to complex. |
| 74 | */ |
| 75 | autoVEC evals = raw_VEC (numberOfEigenvalues); |
| 76 | autoMAT evecs = raw_MAT (numberOfEigenvalues, dimension); |
| 77 | #if oo_READING_BINARY |
| 78 | evals = vector_readBinary_r64 (numberOfEigenvalues, _filePointer_); |
| 79 | evecs = matrix_readBinary_r64 (numberOfEigenvalues, dimension, _filePointer_); |
| 80 | #else |
| 81 | evals = vector_readText_r64 (numberOfEigenvalues, _textSource_, "eigenvalues"); |
| 82 | evecs = matrix_readText_r64 (numberOfEigenvalues, dimension, _textSource_, "eigenvectors"); |
| 83 | #endif |
| 84 | for (integer i = 1; i <= numberOfEigenvalues; i ++) { |
| 85 | eigenvalues [i] .real (evals [i]); |
| 86 | for (integer j = 1; j <= dimension; j ++) |
| 87 | eigenvectors [i] [j] .real (evecs [i] [j]); |
| 88 | } |
| 89 | onlyReals = true; |
| 90 | oo_VERSION_ELSE |
| 91 | oo_COMPVEC (eigenvalues, numberOfEigenvalues) |
| 92 | oo_COMPMAT (eigenvectors, numberOfEigenvalues, dimension) |
| 93 | oo_BOOLEAN (onlyReals) // commodity |
| 94 | oo_VERSION_END |
| 95 | #else |
| 96 | oo_COMPVECcxx . . $ `sys/oo.h:79:9`! (eigenvalues, numberOfEigenvalues) |
| 97 | oo_COMPMATcxx . . $ `sys/oo.h:86:9`! (eigenvectors, numberOfEigenvalues, dimension) |
| 98 | oo_BOOLEANcxx . . $ `sys/oo.h:105:9`! (onlyReals) // commodity |
| 99 | #endif |
| 100 | |
| 101 | oo_END_CLASScxx . . $ `sys/oo.h:186:9`! (Eigen2) |
| 102 | #undef ooSTRUCTcxx . . $ `dwsys/Eigen_def.h:64:9`! |
| 103 | |
| 104 | /* End of file Eigen_def.h */ |