Debian Codegraph @

contrib/ms-sbvar/utilities_dw/include/dw_matrix.h

raw
1 /*
2 * Copyright (C) 1996-2011 Daniel Waggoner
3 *
4 * This free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * It is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * If you did not received a copy of the GNU General Public License
15 * with this software, see <http://www.gnu.org/licenses/>.
16 */
17
18 /********************************************************************************
19 VECTORS AND MATRICES
20 A TVector is an array of floating points together with the dimension of the
21 vector. A TVector implementation can contain additional information. An
22 instance of TVector must be created with calls to CreateVector() and freed with
23 calls to FreeVector(). The following macros must be defined.
24
25 DimV(x) - x : TVector
26 Returns: int containing the dimension.
27
28 ElementV(x,i) - x : TVector
29 i : integer
30 Returns: L-value PRECISION containing the ith element. The
31 index i is zero-based.
32
33 pElementV(x) - x : TVector
34 Returns: pointer to 0th element of the array storing the vector.
35
36 A TMatrix is an array of floating points together with the number of rows and
37 columns in the matrix. If the storage type (row or column major) is variable,
38 then it also must be stored. A TMatrix implementation can contain additional
39 information. A instance of TMatrix must be created with CreateMatrix() and freed
40 with FreeMatrix(). The following macros must be defined.
41
42 RowM(x) - x : TMatrix
43 Returns: int containing the number of rows.
44
45 ColM(x) - x : TMatrix
46 Returns: int containing the number of columns.
47
48 ElementM(x,i,j) - x : TVector
49 i : int
50 j : int
51 Returns: L-value PRECISION containing the element in the ith
52 row and jth column. The indexes i and j are zero
53 based.
54
55 pElementM(x) - x : TMatrix
56 Returns: pointer to 0th element of the array storing the
57 matrix.
58
59 MajorForm(x) - x : TMatrix
60 Returns: 0 if data stored in row major format and 1 if data
61 stored in column major format. The data is in row
62 major format if
63
64 ElementM(x,i,j) = pElementM(x)[i*ColM(x)+j]
65
66 and is in column major format if
67
68 ElementM(x,i,j) = pElementM(x)[i+j*RowM(x)]
69
70 SetMajorForm(x,i) - Sets the MajorForm of the TMatrix x to the int i. The value
71 of i must be either 0 or 1. If the implementation allows
72 for only one type, then this can be defined to be blank.
73 For this reason, it is important that the user be careful in
74 using this macro since it may not have an effect in all
75 implementations. It is always permissible to assign the
76 value of an existing TMatrix, as in
77
78 SetMajorForm(x,MajorForm(y));
79
80 but in all other cases, it is important to check, via a call
81 to MajorForm(), that the MajorForm has actually been set.
82
83
84 The precision (float or double) is controlled by the define PRECISION
85 contained in the file prcsn.h.
86
87
88 PERMUTATION MATRICES
89 For 0 <= i,j <= m-1, let (i,j) denote the transposition which interchanges i
90 and j leaves the other elements fixed. Let P(i,j) denote the m x m matrix
91 obtained from the m x m identitiy matrix by interchanging the ith and jth rows,
92 which for the identity matrix is equivalent to interchanging the ith and jth
93 columns. If p is a permutation of {0,...,m-1} and is equal to the product of
94 transpositions
95
96 (i1,j1)*(i2,j2)*...*(iq,jq)
97
98 then the permutation matrix associated with the permutation p is
99
100 P = P(i1,j1)*P(i2,j2)*...*P(iq,jq)
101
102 Note that our convention is that
103
104 (i1,j1)*(i2,j2)(k) = (i1,j1)((i2,j2)(k))
105
106 Thus (1,2)(2,3) is the permutation that sends 1 to 2, 2 to 3, and 3 to 1. Note
107 that multiplication on the left by a permutation matrix P associated with the
108 permutation p permutes the rows by p. Multiplication on the right permutes the
109 columns by the inverse of p.
110
111 A TPermutation is an integer array together with the length of the array and
112 the number of array elements actually used. A TPermutation implementation can
113 contain additional information. A instance of TPermutation must be created
114 with CreatePermutation() and freed with FreePermutation(). The following
115 macros must be defined.
116
117 DimP(x) - x : TPermutation
118 Returns: int containing the dimension.
119
120 UseP(x) - x : TPermutation
121 Returns: L-value int containing the number of array elements
122 used. This macro can also be used to set this number.
123 It must be the case that 0 <= UseP(x) <= DimP(x).
124
125 ElementP(x,i) - x : TPermutation
126 i : int
127 Returns: L-value int containing the ith element. The index i
128 is zero-based. It must be case that i < UseP(x) and
129
130 i <= ElementP(x,i) < DimP(x).
131
132 pElementP(x) - x : TPermutation
133 Returns: pointer to 0th element of the array storing the
134 permutation.
135
136 The representation as a product of transpositions used by TPermutation
137
138 (0,ElementP(x,0))*...*(UseP(x)-1,ElementP(x,UseP(x)-1)
139
140 In order to have a unique representation, we require that
141
142 UseP(x) - 1 < ElementP(x,UseP(x) - 1)
143
144 *******************************************************************************/
145
146 /*******************************************************************************
147 Some thoughts on vector and matrix implementation:
148
149 1) Because vectors are one dimensional and matrices are two dimensional,
150 they should have different implementations for reasons of efficiency.
151
152 2) Can one get efficiency from more general n-dimensional matrix
153 representations?
154
155 3) Should the types be encoded as a pointer to a structure or as a pointer
156 to a float or double with the dimension and other infomation hidden.
157
158 4) There must be an efficient Element() operator. If (1) is followed, there
159 must be efficient ElementV() and ElementM() operators. These operators
160 must be able to return L-values and so probably need to implemented as
161 macros. This has the disadvantage that ElementM() will have side effects
162 that must be avoided.
163
164 5) There must be an efficient Dim() operator. If (1) is followed, there
165 should be efficient DimV(), RowM(), ColM() operators, probably
166 implemented as macros.
167
168 6) Should there be a flag to represent special matrices. For instance,
169 diagonal, upper triangular, lower triagular, and symmetric. If the
170 decision is made to include such a flag, then a decision must be made
171 on the storage of special matrices. In particular, should special
172 matrices use a compressed storage, or should they use the general
173 storage technique. If they use the general storage technique, should
174 the full matrix be stored, or should the redundant elements be left
175 undefined. This has implications for the ElementM() operator.
176
177 7) Should a decision be made to always encode matrices as column major, or
178 should there be a flag to determine whether the matrix is encoded as
179 column major or row major. This gives added flexibility, but adds an
180 extra cost to all matrix functions. For complex functions which already
181 check size, this cost is small, but for functions such as ElementM(),
182 the cost may not be so small. One solution would to be to add the
183 operators ElementM_R() and ElementM_C(), which would retrieve the orginal
184 efficiency in ElementM(), but would put a burden on the user to ensure
185 that the right operator was called.
186
187 8) Many routines will have the form Y = fnct(X, Z1, Z2, ...), where X and Y
188 are pointers to the same type. The characteristics (usually size) of X
189 depends on the Z's. For this reason, X is allowed to be a null pointer.
190 This allows the routine to create and return a pointer with the proper
191 characteristics. On the other hand, errors occur in the routine, then
192 a null pointer is returned. There is a potential for memory leaks. The
193 following syntax must be avoided: X = fnct(X, Z1, Z2, ... ). If X is null
194 or no errors occur, then no harm will result, but if X is not null and an
195 error occurs then a memory leak will exist. This type of construct must
196 be avoided. Similarly, the following construct must be avoided:
197
198 X = fnct2(fnct1(...), ...)
199
200 If fnct1() returns a non-null pointer but fnct2 exits because of an error,
201 then a memory leak will exist. The proper construct in this case is
202 fnct1(X = fnct1(...), ...)
203
204 ********************************************************************************/
205
206 #ifndef __MATRIX__
207 #define __MATRIX__
208
209 #include "prcsn.h"
210 #include <stdio.h>
211
212 #ifdef __cplusplus
213 extern "C"
214 {
215 #endif
216
217 /******************************************************************************/
218 /********************************* Data Types *********************************/
219 /******************************************************************************/
220 /*
221 The default is TZ_COLUMN_MAJOR. To use one of the other type, it must be passed
222 via the compiler -- generally -d TYPE
223 */
224 #if !defined(STANDARD_COLUMN_MAJOR) && !defined(STANDARD_ROW_MAJOR) && !defined(STRUCTURED_COLUMN_MAJOR) && !defined(STRUCTURED_ROW_MAJOR) && !defined(STRUCTURED_MAJOR_FORM) \
225 && !defined(LEGACY_ROW_MAJOR) && !defined(TZ_COLUMN_MAJOR) && !defined(CHECK_MACRO_CALLS)
226
227 #define TZ_COLUMN_MAJOR
228
229 #endif
230
231 #define COLUMN_MAJOR 1
232 #define ROW_MAJOR 0
233
234 typedef int *TPermutation;
235 #define UseP(y) (((int*)(y))[-1])
236 #define DimP(y) (((int*)(y))[-2])
237 #define pElementP(y) (y)
238 #define ElementP(y,i) ((y)[(i)])
239
240 /*----------------------------------------------------------------------------*/
241 #if defined CHECK_MACRO_CALLS
242 typedef PRECISION *TVector;
243 typedef PRECISION **TMatrix;
244 typedef int *TPermutation;
245
246 int DimV(TVector x);
247 PRECISION ElementV(TVector x, int i);
248 PRECISION* pElementV(TVector x);
249
250 int RowM(TMatrix x);
251 int ColM(TMatrix x);
252 PRECISION ElementM(TMatrix x, int i, int j);
253 PRECISION* pElementM(TMatrix x);
254
255 int DimP(TPermutation x);
256 int UseP(TPermutation x);
257 int ElementP(TPermutation y, int i);
258 int* pElementP(TPermutation y);
259 #endif
260 /*----------------------------------------------------------------------------*/
261 #if (defined(STANDARD_COLUMN_MAJOR) || defined(STANDARD_ROW_MAJOR))
262 // Data types
263 typedef struct
264 {
265 int dim;
266 PRECISION x[1];
267 } TVectorStructure;
268 typedef TVectorStructure *TVector;
269
270 typedef struct
271 {
272 int row;
273 int col;
274 PRECISION x[1];
275 } TMatrixStructure;
276 typedef TMatrixStructure* TMatrix;
277
278 // Element access macros
279 #define DimV(y) ((y)->dim)
280 #define pElementV(y) ((y)->x)
281 #define ElementV(y,i) ((y)->x[(i)])
282
283 #define RowM(y) ((y)->row)
284 #define ColM(y) ((y)->col)
285 #define pElementM(y) ((y)->x)
286 #if defined STANDARD_COLUMN_MAJOR
287 #define ElementM(y,i,j) ((y)->x[(i)+(j)*((y)->row)])
288 #else
289 #define ElementM(y,i,j) ((y)->x[(i)*((y)->col)+(j)])
290 #endif
291
292 // Major form macros
293 #define SetMajorForm(x,i)
294 #if defined STANDARD_COLUMN_MAJOR
295 #define MajorForm(x) COLUMN_MAJOR
296 #else
297 #define MajorForm(x) ROW_MAJOR
298 #endif
299
300 #endif
301 /*----------------------------------------------------------------------------*/
302 #if (defined(STRUCTURED_COLUMN_MAJOR) || defined(STRUCTURED_ROW_MAJOR) || defined(STRUCTURED_MAJOR_FORM))
303 // Data types
304 typedef struct
305 {
306 int dim;
307 PRECISION *x;
308 } TVectorStructure;
309 typedef TVectorStructure *TVector;
310
311 typedef struct
312 {
313 int row;
314 int col;
315 #if (defined(STRUCTURED_MAJOR_FORM))
316 int major;
317 #endif
318 PRECISION *x;
319 } TMatrixStructure;
320 typedef TMatrixStructure* TMatrix;
321
322 // Element access macros
323 #define DimV(y) ((y)->dim)
324 #define pElementV(y) ((y)->x)
325 #define ElementV(y,i) ((y)->x[(i)])
326
327 #define RowM(y) ((y)->row)
328 #define ColM(y) ((y)->col)
329 #define pElementM(y) ((y)->x)
330 #if defined STRUCTURED_COLUMN_MAJOR
331 #define ElementM(y,i,j) ((y)->x[(i)+(j)*((y)->row)])
332 #elif defined STRUCTURED_ROW_MAJOR
333 #define ElementM(y,i,j) ((y)->x[(i)*((y)->col)+(j)])
334 #elif defined STRUCTURED_MAJOR_FORM
335 #define ElementM(y,i,j) ((y)->x[(y)->major ? (i)+(j)*((y)->row) : (i)*((y)->col)+(j)])
336 #endif
337
338 // Major form macros
339 #if defined STRUCTURED_COLUMN_MAJOR
340 #define MajorForm(x) COLUMN_MAJOR
341 #define SetMajorForm(x,i)
342 #elif defined STRUCTURED_ROW_MAJOR
343 #define MajorForm(x) ROW_MAJOR
344 #define SetMajorForm(x,i)
345 #elif defined STRUCTURED_MAJOR_FORM
346 #define SetMajorForm(x,i) ((x)->major=(i))
347 #define MajorForm(x) ((x)->major)
348 #endif
349
350 #endif
351 /*----------------------------------------------------------------------------*/
352 #if defined LEGACY_ROW_MAJOR
353 // Data types
354 typedef PRECISION *TVector;
355 typedef PRECISION **TMatrix;
356
357 // Element access macros
358 #define DimV(y) (((int*)(y))[-1])
359 #define pElementV(y) (y)
360 #define ElementV(y,i) ((y)[(i)])
361
362 #define RowM(y) (((int*)(y))[-2])
363 #define ColM(y) (((int*)(y))[-1])
364 #define pElementM(y) ((y)[0])
365 #define ElementM(y,i,j) ((y)[(i)][(j)])
366
367 // Legacy element access
368 #define V_DIM(x) (((int*)(x))[-1])
369 #define M_ROW(x) (((int*)(x))[-2])
370 #define M_COL(x) (((int*)(x))[-1])
371 #define P_USE(x) UseP(x)
372 #define P_DIM(x) DimP(x)
373
374 // Major form macros
375 #define SetMajorForm(x,i)
376 #define MajorForm(x) ROW_MAJOR
377
378 #endif
379 /*----------------------------------------------------------------------------*/
380 #if defined TZ_COLUMN_MAJOR
381
382 /* In prcsn.h, PRECISION must be defined to be double */
383 #if PRECISION_SIZE != 8
384 precision size must be 8
385 #endif
386
387 // Defines
388 #include "tzmatlab.h"
389
390 // Data types
391 typedef TSdvector* TVector;
392 typedef TSdmatrix* TMatrix;
393
394 // Element access macros
395 #define DimV(y) ((y)->n)
396 #define pElementV(y) ((y)->v)
397 #define ElementV(y,i) ((y)->v[(i)])
398
399 #define RowM(y) ((y)->nrows)
400 #define ColM(y) ((y)->ncols)
401 #define pElementM(y) ((y)->M)
402 #define ElementM(y,i,j) ((y)->M[(i)+(j)*((y)->nrows)])
403
404 // Major form macros
405 #define SetMajorForm(x,i)
406 #define MajorForm(x) COLUMN_MAJOR
407
408 #endif
409 /*----------------------------------------------------------------------------*/
410 /******************************************************************************/
411 /******************************************************************************/
412
413 /* Allocation/Deallocation Routines */
414 TVector CreateVector(int m);
415 TMatrix CreateMatrix(int m, int n);
416 void FreeVector(TVector x);
417 void FreeMatrix(TMatrix X);
418
419 /* Initialization Routines */
420 TVector InitializeVector(TVector x, PRECISION c);
421 TMatrix InitializeMatrix(TMatrix X, PRECISION c);
422
423 /* Assignment Routines */
424 TVector EquateVector(TVector x, TVector y);
425 TMatrix EquateMatrix(TMatrix X, TMatrix Y);
426 TMatrix Transpose(TMatrix X, TMatrix Y);
427 TMatrix IdentityMatrix(TMatrix X, int m);
428 TMatrix ZeroMatrix(TMatrix X, int m, int n);
429 TMatrix DiagonalMatrix(TMatrix X, TVector y);
430 TVector MinusV(TVector x, TVector y);
431 TMatrix MinusM(TMatrix X, TMatrix Y);
432 TVector AbsV(TVector x, TVector y);
433 TMatrix AbsM(TMatrix X, TMatrix Y);
434 TMatrix SubMatrix(TMatrix X, TMatrix Y, int brow, int bcol, int rows, int cols);
435 TVector SubVector(TVector x, TVector y, int b, int d);
436 TMatrix InsertSubMatrix(TMatrix X, TMatrix Y, int brow_X, int bcol_X, int brow_Y, int bcol_Y, int rows, int cols);
437 TMatrix InsertColumnVector(TMatrix X, TVector y, int col);
438 TMatrix InsertRowVector(TMatrix X, TVector y, int row);
439 TVector ColumnVector(TVector x, TMatrix Y, int col);
440 TVector RowVector(TVector x, TMatrix Y, int row);
441 TMatrix ColumnMatrix(TMatrix X, TVector y);
442 TMatrix RowMatrix(TMatrix X, TVector y);
443
444 //=== Addition Routines ===
445 TVector AddVV(TVector x, TVector y, TVector z);
446 TMatrix AddMM(TMatrix X, TMatrix Y, TMatrix Z);
447 TVector SubtractVV(TVector x, TVector y, TVector z);
448 TMatrix SubtractMM(TMatrix X, TMatrix Y, TMatrix Z);
449
450 //=== Multiplication Routines ===
451 TVector ProductSV(TVector x, PRECISION s, TVector y);
452 #define ProductVS(x,y,s) ProductSV(x,s,y)
453 TMatrix ProductSM(TMatrix X, PRECISION s, TMatrix Y);
454 #define ProductMS(X,Y,s) ProductSM(X,s,Y)
455 TVector ProductVM(TVector x, TVector y, TMatrix Z);
456 TVector ProductMV(TVector x, TMatrix Y, TVector z);
457 TMatrix ProductMM(TMatrix X, TMatrix Y, TMatrix Z);
458 TMatrix ProductMU(TMatrix X, TMatrix Y, TMatrix Z);
459 TMatrix ProductML(TMatrix X, TMatrix Y, TMatrix Z);
460 TMatrix ProductUM(TMatrix X, TMatrix Y, TMatrix Z);
461 TMatrix ProductLM(TMatrix X, TMatrix Y, TMatrix Z);
462 TVector ProductInverseVM(TVector x, TVector y, TMatrix Z);
463 TMatrix ProductInverseMM(TMatrix X, TMatrix Y, TMatrix Z);
464 TVector ProductInverseVU(TVector x, TVector y, TMatrix Z);
465 TMatrix ProductInverseMU(TMatrix X, TMatrix Y, TMatrix Z);
466 TVector ProductInverseVL(TVector x, TVector y, TMatrix Z);
467 TMatrix ProductInverseML(TMatrix X, TMatrix Y, TMatrix Z);
468 TVector InverseProductMV(TVector x, TMatrix Y, TVector z);
469 TMatrix InverseProductMM(TMatrix X, TMatrix Y, TMatrix Z);
470 TVector InverseProductUV(TVector x, TMatrix Y, TVector z);
471 TMatrix InverseProductUM(TMatrix X, TMatrix Y, TMatrix Z);
472 TVector InverseProductLV(TVector x, TMatrix Y, TVector z);
473 TMatrix InverseProductLM(TMatrix X, TMatrix Y, TMatrix Z);
474 TMatrix TransposeProductMM(TMatrix X, TMatrix Y, TMatrix Z);
475 #define TransposeProductMV(x,Y,z) ProductVM(x,z,Y)
476 TMatrix ProductTransposeMM(TMatrix X, TMatrix Y, TMatrix Z);
477 #define ProductTransposeVM(x,y,Z) ProductMV(x,Z,y)
478
479 //=== Updating ===
480 TVector LinearCombinationV(TVector x, PRECISION a, TVector y, PRECISION b, TVector z);
481 TMatrix LinearCombinationM(TMatrix X, PRECISION a, TMatrix Y, PRECISION b, TMatrix Z);
482 #define UpdateV(a,x,b,y) LinearCombinationV(x,a,x,b,y)
483 #define UpdateM(a,X,b,Y) LinearCombinationM(X,a,X,b,Y)
484 TMatrix UpdateProductMM(PRECISION a, TMatrix X, PRECISION b, TMatrix Y, TMatrix Z);
485 TVector UpdateProductMV(PRECISION a, TVector x, PRECISION b, TMatrix Y, TVector z);
486 TVector UpdateProductVM(PRECISION a, TVector x, PRECISION b, TVector y, TMatrix Z);
487
488 /* Matrix Inverse Routines */
489 TMatrix Inverse_LU(TMatrix X, TMatrix Y);
490 TMatrix Inverse_SVD(TMatrix X, TMatrix Y);
491 TMatrix Inverse_Cholesky(TMatrix X, TMatrix Y);
492 TMatrix Inverse_UT(TMatrix X, TMatrix Y);
493 TMatrix Inverse_LT(TMatrix X, TMatrix Y);
494 TMatrix GeneralizedInverse(TMatrix X, TMatrix Y);
495
496 /* Matrix Decompositions */
497 int SVD(TMatrix U, TVector d, TMatrix V, TMatrix A);
498 int QR(TMatrix Q, TMatrix R, TMatrix X);
499
500 int GeneralizedSchur_Real(TMatrix S, TMatrix T, TMatrix Q, TMatrix Z, TMatrix A, TMatrix B,
501 TVector alpha_r, TVector alpha_i, TVector beta); ;
502 int ReorderGeneralizedSchur_Real(TMatrix SS, TMatrix TT, TMatrix QQ, TMatrix ZZ, TMatrix S, TMatrix T, TMatrix Q,
503 TMatrix Z, int *select, TVector alpha_r, TVector alpha_i, TVector beta);
504 int SortGeneralizedSchur_Real(TMatrix SS, TMatrix TT, TMatrix QQ, TMatrix ZZ, TMatrix S, TMatrix T, TMatrix Q,
505 TMatrix Z, TVector alpha_r, TVector alpha_i, TVector beta, int descend);
506
507 TMatrix CholeskyUT(TMatrix T, TMatrix X);
508 TMatrix CholeskyLT(TMatrix T, TMatrix X);
509
510 int LU(TPermutation P, TMatrix X, TMatrix A);
511 TVector LU_SolveCol(TVector x, TVector y, TMatrix LU, TPermutation P);
512 TVector LU_SolveRow(TVector x, TVector y, TMatrix LU, TPermutation P);
513
514 int Eigenvalues(TVector Re, TVector Im, TMatrix X);
515 int Eigen(TVector ReVal, TVector ImVal, TMatrix ReVec, TMatrix ImVec, TMatrix X);
516
517 TMatrix MatrixSquareRoot(TMatrix X, TMatrix Y);
518
519 /* Complex Routines */
520 int ComplexProductMM(TMatrix ReX, TMatrix ImX, TMatrix ReY, TMatrix ImY, TMatrix ReZ, TMatrix ImZ);
521
522 /* Miscellaneous Routines */
523 PRECISION Norm(TVector x);
524 PRECISION MatrixNormEuclidean(TMatrix X);
525 PRECISION MatrixNorm(TMatrix X);
526 PRECISION DotProduct(TVector x, TVector y);
527 PRECISION InnerProduct(TVector x, TVector y, TMatrix S);
528 TMatrix OuterProduct(TMatrix X, TVector y, TVector z);
529 PRECISION Trace(TMatrix X);
530 TVector CrossProduct_LU(TVector x, TMatrix Y);
531 PRECISION Determinant_LU(TMatrix X);
532 PRECISION LogAbsDeterminant_LU(TMatrix X);
533 int Rank_SVD(TMatrix X);
534 TMatrix NullSpace(TMatrix Y);
535 TMatrix ForceSymmetric(TMatrix X);
536
537 /* Kronecker Routines */
538 TVector Vec(TVector x, TMatrix Y);
539 TMatrix ReshapeV(TMatrix X, TVector y, int rows, int cols);
540 TMatrix KroneckerProduct(TMatrix X, TMatrix Y, TMatrix Z);
541
542 /* Input - Output Routines */
543 int dw_PrintVector(FILE *f, TVector x, const char *format);
544 int dw_PrintMatrix(FILE *f, TMatrix X, const char *format);
545 int dw_ReadMatrix(FILE *f, TMatrix X);
546 int dw_ReadVector(FILE *f, TVector x);
547 int OutVectorFloat(FILE *f, TVector x);
548 int OutMatrixFloat(FILE *f, TMatrix X);
549 int OutVectorDouble(FILE *f, TVector x);
550 int OutMatrixDouble(FILE *f, TMatrix X);
551 TVector InVector(FILE *f, TVector x);
552 TMatrix InMatrix(FILE *f, TMatrix X);
553
554 /* Permutations */
555 TPermutation CreatePermutation(int m);
556 void FreePermutation(TPermutation X);
557 TPermutation InitializePermutation(TPermutation X, int *p, int m);
558 int* ExtractPermutation(int *p, TPermutation X);
559 TPermutation TranspositionPermutation(TPermutation X, int i, int j, int m);
560 TPermutation EquatePermutation(TPermutation X, TPermutation Y);
561 TMatrix PermutationMatrix(TMatrix X, TPermutation Y);
562 TMatrix ProductPM(TMatrix X, TPermutation Y, TMatrix Z);
563 TMatrix ProductMP(TMatrix X, TMatrix Y, TPermutation Z);
564 TVector ProductPV(TVector x, TPermutation Y, TVector z);
565 TVector ProductVP(TVector x, TVector y, TPermutation Z);
566 TMatrix TransposeProductPM(TMatrix X, TPermutation Y, TMatrix Z);
567 #define TransposeProductPV(x,Y,z) ProductVP(x,z,Y)
568 TMatrix ProductTransposeMP(TMatrix X, TMatrix Y, TPermutation Z);
569 #define ProductTransposeVP(x,y,Z) ProductPV(x,Z,y)
570 void PrintPermutation(FILE *f, TPermutation);
571
572 /****** Old Style Syntax ******
573 //====== Error Routines ======
574 #define MatrixError(err) Error(err)
575 #define ClearMatrixError() ClearError()
576 #define GetMatrixError() GetError()
577 #define SetMatrixErrorVerbose(err) SetVerboseErrors(err)
578 #define SetMatrixErrorTerminate(err) SetTerminalErrors(err)
579
580 //#define Inverse(X,Y) Inverse_LU(X,Y)
581 //#define TransposeProduct(X,Y,Z) TransposeProductMM(X,Y,Z)
582 //#define ProductTranspose(X,Y,Z) ProductTransposeMM(X,Y,Z)
583 //#define InverseProduct(X,Y,Z) InverseProductMM(X,Y,Z)
584 //#define ProductInverse(X,Y,Z) ProductInverseMM(X,Y,Z)
585 //#define VectorProductInverse(x,y,Z) ProductInverseVM(x,y,Z)
586 //#define ERROR(i) MatrixError(i)
587
588 // int Cholesky_U(TMatrix T, TMatrix X) X = T'* T (T upper triangular)
589 // int Cholesky_L(TMatrix T, TMatrix X) X = T * T' (T lower triangular)
590 // int SingularValueDecomposition(TMatrix U, TVector d, TMatrix V, TMatrix A) A = U * Diagonal(d) * V'
591 // int* QR_RPivot(TMatrix R, TMatrix X);
592 // int* QR_QRPivot(TMatrix Q, TMatrix R, TMatrix X);
593 // InitializePermutationFromIntArray(TPermutation X, int *p, int m);
594 **/
595
596 #ifdef __cplusplus
597 }
598 #endif
599
600 #endif