| 1 |
/* TableOfReal_and_SVD.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1993-2019 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 |
djmw 20021009 GPL header |
| 21 |
djmw 20031107 Added TablesOfReal_to_GSVD. |
| 22 |
djmw 20051202 Extract left/right singular vectors. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "TableOfReal_and_SVD.h" |
| 26 |
|
| 27 |
autoTableOfReal SVD_to_TableOfReal (SVD me, integer from, integer to) { |
| 28 |
try { |
| 29 |
autoMAT synthesis = SVD_synthesize (me, from, to); |
| 30 |
autoTableOfReal thee = TableOfReal_create (synthesis.nrow, synthesis.ncol); |
| 31 |
thy data.all() <<= synthesis.all(); |
| 32 |
return thee; |
| 33 |
} catch (MelderError) { |
| 34 |
Melder_throw (me, U": no TableOfReal synthesized."); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
autoSVD TableOfReal_to_SVD (TableOfReal me) { |
| 39 |
try { |
| 40 |
autoSVD thee = SVD_createFromGeneralMatrix (my data.get()); |
| 41 |
return thee; |
| 42 |
} catch (MelderError) { |
| 43 |
Melder_throw (me, U": no SVD created."); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
autoTableOfReal SVD_extractLeftSingularVectors (SVD me) { |
| 48 |
try { |
| 49 |
autoTableOfReal thee = TableOfReal_create (my numberOfRows, my numberOfColumns); |
| 50 |
thy data.all() <<= my u.all(); |
| 51 |
return thee; |
| 52 |
} catch (MelderError) { |
| 53 |
Melder_throw (me, U": left singular vector not extracted."); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
autoTableOfReal SVD_extractRightSingularVectors (SVD me) { |
| 58 |
try { |
| 59 |
autoTableOfReal thee = TableOfReal_create (my numberOfColumns, my numberOfColumns); |
| 60 |
thy data.all() <<= my v.all(); |
| 61 |
return thee; |
| 62 |
} catch (MelderError) { |
| 63 |
Melder_throw (me, U": right singular vector not extracted."); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
autoTableOfReal SVD_extractSingularValues (SVD me) { |
| 68 |
try { |
| 69 |
autoTableOfReal thee = TableOfReal_create (1, my numberOfColumns); |
| 70 |
thy data.row (1) <<= my d.all(); |
| 71 |
return thee; |
| 72 |
} catch (MelderError) { |
| 73 |
Melder_throw (me, U": singular values not extracted."); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
autoGSVD TablesOfReal_to_GSVD (TableOfReal me, TableOfReal thee) { |
| 78 |
try { |
| 79 |
Melder_require (my numberOfColumns == thy numberOfColumns, |
| 80 |
U"Both tables should have the same number of columns."); |
| 81 |
autoGSVD him = GSVD_create (my data.get(), thy data.get()); |
| 82 |
return him; |
| 83 |
} catch (MelderError) { |
| 84 |
Melder_throw (U"GSVD not constructed from TablesOfReal."); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/* End of file SVD_and_TableOfReal.cpp */ |