File: TableOfReal_and_Permutation.cpp

package info (click to toggle)
praat 6.4.27%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 206,060 kB
  • sloc: cpp: 1,409,811; ansic: 286,305; makefile: 946; python: 340; sh: 35
file content (74 lines) | stat: -rw-r--r-- 2,803 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* TableOfReal_and_Permutation.cpp
 *
 * Copyright (C) 2005-2022 David Weenink
 *
 * This code is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This code is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this work. If not, see <http://www.gnu.org/licenses/>.
 */

/*
 djmw 20050708
*/

#include "Index.h"
#include "TableOfReal_and_Permutation.h"
#include "TableOfReal_extensions.h"
#include "NUM2.h"

autoTableOfReal TableOfReal_Permutation_permuteRows (TableOfReal me, Permutation thee) {
	try {
		Melder_require (my numberOfRows == thy numberOfElements,
			U"The number of rows in the table and the number of elements in the Permutation should be equal.");
		autoTableOfReal him = TableOfReal_create (my numberOfRows, my numberOfColumns);

		for (integer irow = 1; irow <= thy numberOfElements; irow ++)
			TableOfReal_copyOneRowWithLabel (me, him.get(), thy p [irow], irow);
		for (integer icol = 1; icol <= my numberOfColumns; icol ++)
			TableOfReal_setColumnLabel (him.get(), icol, my columnLabels [icol].get());
		return him;
	} catch (MelderError) {
		Melder_throw (me, U": rows not permuted.");
	}
}

autoTableOfReal TableOfReal_Permutation_permuteColumns (TableOfReal me, Permutation thee) {
	try {
		Melder_require (my numberOfColumns == thy numberOfElements,
			U"The number of columns in the table and the number of elements in the Permutation should be equal.");
		autoTableOfReal him = TableOfReal_create (my numberOfRows, my numberOfColumns);

		for (integer icol = 1; icol <= thy numberOfElements; icol ++) {
			const integer fromCol = thy p [icol];
			his columnLabels [icol] = Melder_dup (my columnLabels [fromCol].get());
			for (integer irow = 1; irow <= my numberOfRows; irow ++)
				his data [irow] [icol] = my data [irow][fromCol];
		}
		for (integer irow = 1; irow <= my numberOfColumns; irow ++)
			TableOfReal_setRowLabel (him.get(), irow, my rowLabels [irow].get());
		return him;
	} catch (MelderError) {
		Melder_throw (me, U": columns not permuted.");
	}
	
}
autoPermutation TableOfReal_to_Permutation_sortRowLabels (TableOfReal me) {
	try {
		autoPermutation thee = Permutation_create (my numberOfRows, true);
		INTVECindex_inout (thy p.get(), my rowLabels.get());
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": no Permutation created.");
	}
}

/* End of file TableOfReal_and_Permutation.cpp */