Debian Codegraph @

fon/Matrix.h

raw symbols SCIP
1 #cxx . . $ `<file>/fon/Matrix.h`/ifndef _Matrix_h_
2 #define _Matrix_h_cxx . . $ `fon/Matrix.h:2:9`!
3 /* Matrix.h
4 *
5 * Copyright (C) 1992-2005,2007-2019,2022,2024 Paul Boersma
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "SampledXY.h"cxx . . $ `<file>/fon/SampledXY.h`/
22 #include "Graphics.h"cxx . . $ `<file>/sys/Graphics.h`/
23 #include "../stat/Table.h"cxx . . $ `<file>/stat/Table.h`/
24 #include "../stat/TableOfReal.h"cxx . . $ `<file>/stat/TableOfReal.h`/
25 Thing_declarecxx . . $ Interpreter# (Interpreter);
26
27 #include "Matrix_def.h"cxx . . $ `<file>/fon/Matrix_def.h`/
28
29 #if 0
30 template <typename T, typename... Args>
31 autoSomeThing <T> Thing_create (Args ... args) {
32 autoSomeThing <T> me (new T); // this `new` has to set classInfo
33 my T::init (args...);
34 return me;
35 }
36
37 template <typename... ArgumentTypes>
38 autoMatrix CreateMatrix (ArgumentTypes... arguments) {
39 try {
40 autoMatrix me = Thing_new (Matrix);
41 Matrix_init (me.get(), arguments...);
42 return me;
43 } catch (MelderError) {
44 Melder_throw (U"Matrix object not created.");
45 }
46 }
47 #endif
48
49 void Matrix_initcxx . . $ Matrix_init(9dd6c49f9830a091).
50 (Matrixcxx . . $ Matrix# me, double xmin, double xmax, integercxx . . $ integer# nx, double dx, double x1,
51 double ymin, double ymax, integercxx . . $ integer# ny, double dy, double y1);
52
53 autoMatrixcxx . . $ autoMatrix# Matrix_createcxx . . $ Matrix_create(494a3ae9ff7e3b60).
54 (double xmin, double xmax, integercxx . . $ integer# nx, double dx, double x1,
55 double ymin, double ymax, integercxx . . $ integer# ny, double dy, double y1);
56 /*
57 Function:
58 return a new empty Matrix.
59 Preconditions:
60 xmin <= xmax;
61 ymin <= ymax;
62 nx >= 1;
63 ny >= 1;
64 dx > 0.0;
65 dy > 0.0;
66 Postconditions:
67 result -> xmin == xmin;
68 result -> xmax == xmax;
69 result -> ymin == ymin;
70 result -> ymax == ymax;
71 result -> nx == nx;
72 result -> ny == ny;
73 result -> dx == dx;
74 result -> dy == dy;
75 result -> x1 == x1;
76 result -> y1 == y1;
77 result -> z [1..ny] [1..nx] == 0.0;
78 */
79
80 autoMatrixcxx . . $ autoMatrix# Matrix_createSimplecxx . . $ Matrix_createSimple(1d1e893fc69cdb2f). (integercxx . . $ integer# numberOfRows, integercxx . . $ integer# numberOfColumns);
81 /*
82 Function:
83 return a new empty Matrix.
84 Preconditions:
85 numberOfRows >= 1;
86 numberOfColumns >= 1;
87 Postconditions:
88 result -> xmin == 0.5;
89 result -> xmax == numberOfColumns + 0.5;
90 result -> ymin == 0.5;
91 result -> ymax == numberOfRows + 0.5;
92 result -> nx == numberOfColumns;
93 result -> ny == numberOfRows;
94 result -> dx == 1.0;
95 result -> dy == 1.0;
96 result -> x1 == 1.0;
97 result -> y1 == 1.0;
98 result -> z [1..ny] [1..nx] == 0.0;
99 */
100
101 /* An implemented method
102
103 void structMatrix :: v1_writeText (MelderFile file);
104 writes a Matrix as text to `file`.
105 A sample of the format follows:
106 0 5000 1 2 ! xmin xmax ymin ymax
107 8193 2 ! nx ny
108 0.61035156 1 ! dx dy
109 0 1 ! x1 y1
110 5.1e-8 ! 0 1
111 5 ! 0.61035156 1
112 -3.556473 ! 1.2207031 1
113 ...
114 90000000 ! 4998.7793 2
115 3.1415927 ! 4999.3896 2
116 -5.735668e35 ! 5000 2
117 The data lines (all lines after the fourth) contain: my z [iy, ix], x, y.
118 things written after the "!" are mere comments:
119 you cannot use them to change the meaning or order of the data.
120 */
121
122 integercxx . . $ integer# Matrix_getWindowSamplesXcxx . . $ Matrix_getWindowSamplesX(c738979be11bd51a). (constMatrixcxx . . $ constMatrix# me,
123 double xmin, double xmax,
124 integercxx . . $ integer# *out_ixmin, integercxx . . $ integer# *out_ixmax);
125 /*
126 Function:
127 return the number of samples with x values in [xmin, xmax].
128 Put the first of these samples in ixmin.
129 Put the last of these samples in ixmax.
130 Postconditions:
131 *out_ixmin >= 1;
132 *out_ixmax <= my nx;
133 if (result != 0) *out_ixmin <= *out_ixmax; else *out_ixmin > *out_ixmax;
134 if (result != 0) result == *out_ixmax - *out_ixmin + 1;
135 */
136
137 double Matrix_getValueAtXYcxx . . $ Matrix_getValueAtXY(4f551d6141f3d8be). (constMatrixcxx . . $ constMatrix# me, double x, double y);
138 /*
139 Linear interpolation between matrix points,
140 constant extrapolation in cells on the edge,
141 undefined outside the union of the unit squares around the points.
142 */
143
144 double Matrix_getSumcxx . . $ Matrix_getSum(97cb7fd1b392c56c). (constMatrixcxx . . $ constMatrix# me);
145 double Matrix_getNormcxx . . $ Matrix_getNorm(97cb7fd1b392c56c). (constMatrixcxx . . $ constMatrix# me);
146
147 double Matrix_columnToXcxx . . $ Matrix_columnToX(89d6d8659270b8b7). (constMatrixcxx . . $ constMatrix# me, double column);
148 // return my x1 + (column - 1) * my dx
149
150 double Matrix_rowToYcxx . . $ Matrix_rowToY(89d6d8659270b8b7). (constMatrixcxx . . $ constMatrix# me, double row);
151 // return my y1 + (row - 1) * my dy
152
153 double Matrix_xToColumncxx . . $ Matrix_xToColumn(89d6d8659270b8b7). (constMatrixcxx . . $ constMatrix# me, double x);
154 // return (x - xmin) / my dx + 1
155
156 integercxx . . $ integer# Matrix_xToLowColumncxx . . $ Matrix_xToLowColumn(abc7fd41e68a8362). (constMatrixcxx . . $ constMatrix# me, double x);
157 // return Melder_ifloor (Matrix_xToColumn (me, x))
158
159 integercxx . . $ integer# Matrix_xToHighColumncxx . . $ Matrix_xToHighColumn(abc7fd41e68a8362). (constMatrixcxx . . $ constMatrix# me, double x);
160 // return Melder_iceiling (Matrix_xToColumn (me, x))
161
162 integercxx . . $ integer# Matrix_xToNearestColumncxx . . $ Matrix_xToNearestColumn(abc7fd41e68a8362). (constMatrixcxx . . $ constMatrix# me, double x);
163 // return Melder_iround (Matrix_xToColumn (me, x))
164
165 double Matrix_yToRowcxx . . $ Matrix_yToRow(89d6d8659270b8b7). (constMatrixcxx . . $ constMatrix# me, double y);
166 // return (y - ymin) / my dy + 1
167
168 integercxx . . $ integer# Matrix_yToLowRowcxx . . $ Matrix_yToLowRow(abc7fd41e68a8362). (constMatrixcxx . . $ constMatrix# me, double y);
169 // return Melder_ifloor (Matrix_yToRow (me, y))
170
171 integercxx . . $ integer# Matrix_yToHighRowcxx . . $ Matrix_yToHighRow(abc7fd41e68a8362). (constMatrixcxx . . $ constMatrix# me, double x);
172 // return Melder_iceiling (Matrix_yToRow (me, y))
173
174 integercxx . . $ integer# Matrix_yToNearestRowcxx . . $ Matrix_yToNearestRow(abc7fd41e68a8362). (constMatrixcxx . . $ constMatrix# me, double y);
175 // return Melder_iround (Matrix_yToRow (me, y))
176
177 integercxx . . $ integer# Matrix_getWindowSamplesYcxx . . $ Matrix_getWindowSamplesY(c738979be11bd51a). (constMatrixcxx . . $ constMatrix# me,
178 double ymin, double ymax,
179 integercxx . . $ integer# *out_iymin, integercxx . . $ integer# *out_iymax
180 );
181
182 integercxx . . $ integer# Matrix_getWindowExtremacxx . . $ Matrix_getWindowExtrema(d50591dd897af896). (constMatrixcxx . . $ constMatrix# me,
183 integercxx . . $ integer# ixmin, integercxx . . $ integer# ixmax,
184 integercxx . . $ integer# iymin, integercxx . . $ integer# iymax,
185 double *out_minimum, double *out_maximum
186 );
187 /*
188 Function:
189 compute the minimum and maximum values of my z over all samples inside [ixmin, ixmax] * [iymin, iymax].
190 Arguments:
191 if ixmin = 0, start at first column; if ixmax = 0, end at last column (same for iymin and iymax).
192 Return value:
193 the number of samples inside the window.
194 Postconditions:
195 if result == 0, *minimum and *maximum are not changed;
196 */
197
198 void Matrix_formulacxx . . $ Matrix_formula(3b405620ba9cc26e). (mutableMatrixcxx . . $ mutableMatrix# me, conststring32cxx . . $ conststring32# expression, Interpretercxx . . $ Interpreter# interpreter, mutableMatrixcxx . . $ mutableMatrix# target);
199 /*
200 Arguments:
201 "me" is the Matrix referred to as "self" or with "nx" etc. in the expression
202 "target" is the Matrix whose elements will change according to:
203 FOR row FROM 1 TO my ny
204 FOR col FROM 1 TO my nx
205 target -> z [row, col] = expression
206 ENDFOR
207 ENDFOR
208 "expression" is the text to be compiled and interpreted.
209 If "target" is null, the result will go to "me"; otherwise, to "target".
210 Return value:
211 0 in case of failure, otherwise 1.
212 */
213 void Matrix_formula_partcxx . . $ Matrix_formula_part(bf805b81a4f35360). (mutableMatrixcxx . . $ mutableMatrix# me, double xmin, double xmax, double ymin, double ymax,
214 conststring32cxx . . $ conststring32# expression, Interpretercxx . . $ Interpreter# interpreter, mutableMatrixcxx . . $ mutableMatrix# target);
215
216 /***** Graphics routines. *****/
217 /*
218 All of these routines show the samples of a Matrix whose x and y values
219 are inside the window [xmin, xmax] * [ymin, ymax].
220 The scaling of the values of these samples is determined by "minimum" and "maximum".
221 All of these functions can perform automatic windowing and scaling:
222 if xmax <= xmin, the window in the x direction will be set to [my xmin, my xmax];
223 if ymax <= ymin, the window in the y direction will be set to [my ymin, my ymax];
224 if maximum <= minimum, the windowing (scaling) in the z direction will be determined
225 by the minimum and maximum values of the samples inside the window.
226 */
227
228 void Matrix_drawRowscxx . . $ Matrix_drawRows(13c691ba74eecb49). (constMatrixcxx . . $ constMatrix# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax,
229 double minimum, double maximum);
230 /*
231 Every row is plotted as a function of x,
232 with straight lines connecting the sample points.
233 The rows are stacked from bottom to top.
234 */
235
236 void Matrix_drawOneContourcxx . . $ Matrix_drawOneContour(4bd2e7f7122f098e). (constMatrixcxx . . $ constMatrix# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax,
237 double height);
238
239 void Matrix_drawContourscxx . . $ Matrix_drawContours(13c691ba74eecb49). (constMatrixcxx . . $ constMatrix# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax,
240 double minimum, double maximum);
241 /* A contour altitude plot with curves at multiple heights. */
242
243 void Matrix_paintContourscxx . . $ Matrix_paintContours(13c691ba74eecb49). (constMatrixcxx . . $ constMatrix# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax,
244 double minimum, double maximum);
245 /* A contour plot with multiple shades of grey and white (low) and black (high) paint. */
246
247 void Matrix_paintImagecxx . . $ Matrix_paintImage(13c691ba74eecb49). (constMatrixcxx . . $ constMatrix# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax,
248 double minimum, double maximum);
249 /*
250 Two-dimensional interpolation of greys.
251 The larger the value of the sample, the darker the greys.
252 */
253
254 void Matrix_paintCellscxx . . $ Matrix_paintCells(13c691ba74eecb49). (constMatrixcxx . . $ constMatrix# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax,
255 double minimum, double maximum);
256 /*
257 Every sample is drawn as a grey rectangle.
258 The larger the value of the sample, the darker the rectangle.
259 */
260
261 void Matrix_paintSurfacecxx . . $ Matrix_paintSurface(6c96d4ad7475663a). (constMatrixcxx . . $ constMatrix# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax,
262 double minimum, double maximum, double elevation, double azimuth);
263 /*
264 3D surface plot. Every space between adjacent four samples is drawn as a tetragon filled with a grey value.
265 'elevation' may be 30 degrees, 'azimuth' may be 45 degrees.
266 */
267
268 void Matrix_playMoviecxx . . $ Matrix_playMovie(ad98f60fa3ff4b33). (constMatrixcxx . . $ constMatrix# me, Graphicscxx . . $ Graphics# g);
269
270 autoMatrixcxx . . $ autoMatrix# Matrix_readFromRawTextFilecxx . . $ Matrix_readFromRawTextFile(b105b5e8b59bae72). (MelderFilecxx . . $ MelderFile# file);
271 autoMatrixcxx . . $ autoMatrix# Matrix_readAPcxx . . $ Matrix_readAP(b105b5e8b59bae72). (MelderFilecxx . . $ MelderFile# file);
272 autoMatrixcxx . . $ autoMatrix# Matrix_appendRowscxx . . $ Matrix_appendRows(5457e1f9fe5f88f2). (constMatrixcxx . . $ constMatrix# me, constMatrixcxx . . $ constMatrix# thee, ClassInfocxx . . $ ClassInfo# klas);
273
274 void Matrix_eigencxx . . $ Matrix_eigen(9b4cf8088353fad6). (constMatrixcxx . . $ constMatrix# me, autoMatrixcxx . . $ autoMatrix# *eigenvectors, autoMatrixcxx . . $ autoMatrix# *eigenvalues);
275 autoMatrixcxx . . $ autoMatrix# Matrix_powercxx . . $ Matrix_power(ebeb66750e34f7d0). (constMatrixcxx . . $ constMatrix# me, integercxx . . $ integer# power);
276
277 void Matrix_scaleAbsoluteExtremumcxx . . $ Matrix_scaleAbsoluteExtremum(fed8a1cea6a7ff47). (mutableMatrixcxx . . $ mutableMatrix# me, double scale);
278
279 autoMatrixcxx . . $ autoMatrix# Table_to_Matrixcxx . . $ Table_to_Matrix(1b807057cd138548). (Tablecxx . . $ Table# me);
280 void Matrix_writeToMatrixTextFilecxx . . $ Matrix_writeToMatrixTextFile(fa97fc07ac21ec34). (constMatrixcxx . . $ constMatrix# me, MelderFilecxx . . $ MelderFile# file);
281 void Matrix_writeToHeaderlessSpreadsheetFilecxx . . $ Matrix_writeToHeaderlessSpreadsheetFile(fa97fc07ac21ec34). (constMatrixcxx . . $ constMatrix# me, MelderFilecxx . . $ MelderFile# file);
282
283 autoMatrixcxx . . $ autoMatrix# TableOfReal_to_Matrixcxx . . $ TableOfReal_to_Matrix(85875ba68b0cb4ac). (constTableOfRealcxx . . $ constTableOfReal# me);
284 autoTableOfRealcxx . . $ autoTableOfReal# Matrix_to_TableOfRealcxx . . $ Matrix_to_TableOfReal(1898bb61d2e5c140). (constMatrixcxx . . $ constMatrix# me);
285
286 /* End of file Matrix.h */
287 #endif