spLib
Loading...
Searching...
No Matches
matrix.h
Go to the documentation of this file.
1
4#ifndef SPLIB_MATRIX_H
5#define SPLIB_MATRIX_H
6
7#include <sp/vector.h>
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#if (defined(SP_USE_VECTOR_LINEAR_ALGEBRA_ENGINE) && !defined(SP_USE_MATRIX_LINEAR_ALGEBRA_ENGINE))
14#define SP_USE_MATRIX_LINEAR_ALGEBRA_ENGINE
15#endif
16
34 /*----@addtogroup matrixGroup----*/
35
36typedef struct _spSMatrix *spSMatrix;
37typedef struct _spLMatrix *spLMatrix;
38typedef struct _spFMatrix *spFMatrix;
39typedef struct _spDMatrix *spDMatrix;
40
47struct _spSMatrix {
50 long row;
53 long col;
57 short **data;
62 short **imag;
63
64#ifdef SP_USE_MATRIX_ENGINE
65 spPlugin *plugin;
66 void *instance;
67 spBool locked;
68#ifdef SP_USE_MATRIX_LINEAR_ALGEBRA_ENGINE
69 spLinearAlgebraPluginList la_plugin_list;
70 spLinearAlgebraPluginList la_current_list;
71 unsigned long la_status_mask;
72#endif
73#endif
74};
75
82struct _spLMatrix {
85 long row;
88 long col;
92 long **data;
97 long **imag;
98
99#ifdef SP_USE_MATRIX_ENGINE
100 spPlugin *plugin;
101 void *instance;
102 spBool locked;
103#ifdef SP_USE_MATRIX_LINEAR_ALGEBRA_ENGINE
104 spLinearAlgebraPluginList la_plugin_list;
105 spLinearAlgebraPluginList la_current_list;
106 unsigned long la_status_mask;
107#endif
108#endif
109};
110
117struct _spFMatrix {
120 long row;
123 long col;
127 float **data;
132 float **imag;
133
134#ifdef SP_USE_MATRIX_ENGINE
135 spPlugin *plugin;
136 void *instance;
137 spBool locked;
138#ifdef SP_USE_MATRIX_LINEAR_ALGEBRA_ENGINE
139 spLinearAlgebraPluginList la_plugin_list;
140 spLinearAlgebraPluginList la_current_list;
141 unsigned long la_status_mask;
142#endif
143#endif
144};
145
152struct _spDMatrix {
155 long row;
158 long col;
162 double **data;
167 double **imag;
168
169#ifdef SP_USE_MATRIX_ENGINE
170 spPlugin *plugin;
171 void *instance;
172 spBool locked;
173#ifdef SP_USE_MATRIX_LINEAR_ALGEBRA_ENGINE
174 spLinearAlgebraPluginList la_plugin_list;
175 spLinearAlgebraPluginList la_current_list;
176 unsigned long la_status_mask;
177#endif
178#endif
179};
180
181typedef struct _spSMatrices {
182 long num_matrix;
183 spSMatrix *matrix;
184} *spSMatrices;
185
186typedef struct _spLMatrices {
187 long num_matrix;
188 spLMatrix *matrix;
189} *spLMatrices;
190
191typedef struct _spFMatrices {
192 long num_matrix;
193 spFMatrix *matrix;
194} *spFMatrices;
195
196typedef struct _spDMatrices {
197 long num_matrix;
198 spDMatrix *matrix;
199} *spDMatrices;
200
201 /*----@addtogroup matrixGroup----*/
202
203#define SMatrix spSMatrix
204#define LMatrix spLMatrix
205#define FMatrix spFMatrix
206#define DMatrix spDMatrix
207#define _SMatrix _spSMatrix
208#define _LMatrix _spLMatrix
209#define _FMatrix _spFMatrix
210#define _DMatrix _spDMatrix
211
212#define SMatrices spSMatrices
213#define LMatrices spLMatrices
214#define FMatrices spFMatrices
215#define DMatrices spDMatrices
216#define _SMatrices _spSMatrices
217#define _LMatrices _spLMatrices
218#define _FMatrices _spFMatrices
219#define _DMatrices _spDMatrices
220
221#if defined(MACOS)
222#pragma import on
223#endif
224
225extern spSMatrix xsmalloc(long row, long col);
226extern spLMatrix xlmalloc(long row, long col);
227extern spFMatrix xfmalloc(long row, long col);
228extern spDMatrix xdmalloc(long row, long col);
229extern void xsmfree(spSMatrix matrix);
230extern void xlmfree(spLMatrix matrix);
231extern void xfmfree(spFMatrix matrix);
232extern void xdmfree(spDMatrix matrix);
233
234extern void smialloc(spSMatrix x);
235extern void lmialloc(spLMatrix x);
236extern void fmialloc(spFMatrix x);
237extern void dmialloc(spDMatrix x);
238extern void smifree(spSMatrix x);
239extern void lmifree(spLMatrix x);
240extern void fmifree(spFMatrix x);
241extern void dmifree(spDMatrix x);
242
243extern spSMatrix xsmrialloc(long row, long col);
244extern spLMatrix xlmrialloc(long row, long col);
245extern spFMatrix xfmrialloc(long row, long col);
246extern spDMatrix xdmrialloc(long row, long col);
247
248extern spSMatrices xsmsalloc(long num);
249extern spLMatrices xlmsalloc(long num);
250extern spFMatrices xfmsalloc(long num);
251extern spDMatrices xdmsalloc(long num);
252extern void xsmsfree(spSMatrices xs);
253extern void xlmsfree(spLMatrices xs);
254extern void xfmsfree(spFMatrices xs);
255extern void xdmsfree(spDMatrices xs);
256
257extern void smset(spSMatrix matrix, short **data, long row, long col);
258extern void lmset(spLMatrix matrix, long **data, long row, long col);
259extern void fmset(spFMatrix matrix, float **data, long row, long col);
260extern void dmset(spDMatrix matrix, double **data, long row, long col);
261
262extern void smreal(spSMatrix x);
263extern void lmreal(spLMatrix x);
264extern void fmreal(spFMatrix x);
265extern void dmreal(spDMatrix x);
266extern void smimag(spSMatrix x);
267extern void lmimag(spLMatrix x);
268extern void fmimag(spFMatrix x);
269extern void dmimag(spDMatrix x);
270extern void smconj(spSMatrix x);
271extern void lmconj(spLMatrix x);
272extern void fmconj(spFMatrix x);
273extern void dmconj(spDMatrix x);
274extern void smriswap(spSMatrix x);
275extern void lmriswap(spLMatrix x);
276extern void fmriswap(spFMatrix x);
277extern void dmriswap(spDMatrix x);
278
279extern void smcopy(spSMatrix y, spSMatrix x);
280extern void lmcopy(spLMatrix y, spLMatrix x);
281extern void fmcopy(spFMatrix y, spFMatrix x);
282extern void dmcopy(spDMatrix y, spDMatrix x);
283extern spSMatrix xsmclone(spSMatrix x);
284extern spLMatrix xlmclone(spLMatrix x);
285extern spFMatrix xfmclone(spFMatrix x);
286extern spDMatrix xdmclone(spDMatrix x);
287
288extern spSMatrix xsmnums(long row, long col, short value);
289extern spLMatrix xlmnums(long row, long col, long value);
290extern spFMatrix xfmnums(long row, long col, float value);
291extern spDMatrix xdmnums(long row, long col, double value);
292extern void smnums(spSMatrix mat, long row, long col, short value);
293extern void lmnums(spLMatrix mat, long row, long col, long value);
294extern void fmnums(spFMatrix mat, long row, long col, float value);
295extern void dmnums(spDMatrix mat, long row, long col, double value);
296extern void sminums(spSMatrix mat, long row, long col, short value);
297extern void lminums(spLMatrix mat, long row, long col, long value);
298extern void fminums(spFMatrix mat, long row, long col, float value);
299extern void dminums(spDMatrix mat, long row, long col, double value);
300extern spSMatrix xsmrinums(long row, long col, short value);
301extern spLMatrix xlmrinums(long row, long col, long value);
302extern spFMatrix xfmrinums(long row, long col, float value);
303extern spDMatrix xdmrinums(long row, long col, double value);
304
305extern void smeye(spSMatrix mat);
306extern void lmeye(spLMatrix mat);
307extern void fmeye(spFMatrix mat);
308extern void dmeye(spDMatrix mat);
309extern spSMatrix xsmeye(long row, long col);
310extern spLMatrix xlmeye(long row, long col);
311extern spFMatrix xfmeye(long row, long col);
312extern spDMatrix xdmeye(long row, long col);
313
314extern spFMatrix xfmpascal(long n);
315extern spDMatrix xdmpascal(long n);
316
317extern spSMatrix xsminitrow(long nrow, long j, long incr, long n);
318extern spLMatrix xlminitrow(long nrow, long j, long incr, long n);
319extern spFMatrix xfminitrow(long nrow, float j, float incr, float n);
320extern spDMatrix xdminitrow(long nrow, double j, double incr, double n);
321extern spSMatrix xsminitcol(long ncol, long j, long incr, long n);
322extern spLMatrix xlminitcol(long ncol, long j, long incr, long n);
323extern spFMatrix xfminitcol(long ncol, float j, float incr, float n);
324extern spDMatrix xdminitcol(long ncol, double j, double incr, double n);
325
326extern void smeraserow(spSMatrix mat, long row, long offset, long length, spBool inv);
327extern void lmeraserow(spLMatrix mat, long row, long offset, long length, spBool inv);
328extern void fmeraserow(spFMatrix mat, long row, long offset, long length, spBool inv);
329extern void dmeraserow(spDMatrix mat, long row, long offset, long length, spBool inv);
330extern spSMatrix xsmeraserow(spSMatrix mat, long row, long offset, long length, spBool inv);
331extern spLMatrix xlmeraserow(spLMatrix mat, long row, long offset, long length, spBool inv);
332extern spFMatrix xfmeraserow(spFMatrix mat, long row, long offset, long length, spBool inv);
333extern spDMatrix xdmeraserow(spDMatrix mat, long row, long offset, long length, spBool inv);
334extern void smerasecol(spSMatrix mat, long col, long offset, long length, spBool inv);
335extern void lmerasecol(spLMatrix mat, long col, long offset, long length, spBool inv);
336extern void fmerasecol(spFMatrix mat, long col, long offset, long length, spBool inv);
337extern void dmerasecol(spDMatrix mat, long col, long offset, long length, spBool inv);
338extern spSMatrix xsmerasecol(spSMatrix mat, long col, long offset, long length, spBool inv);
339extern spLMatrix xlmerasecol(spLMatrix mat, long col, long offset, long length, spBool inv);
340extern spFMatrix xfmerasecol(spFMatrix mat, long col, long offset, long length, spBool inv);
341extern spDMatrix xdmerasecol(spDMatrix mat, long col, long offset, long length, spBool inv);
342
343extern long smcutrowto(spSMatrix mat, long row, long offset, long length, spSVector vec, long vec_offset, int overlap);
344extern long smcutrow(spSMatrix mat, long row, long offset, long length, spSVector vec);
345extern spSVector xsmcutrow(spSMatrix mat, long row, long offset, long length);
346extern long lmcutrowto(spLMatrix mat, long row, long offset, long length, spLVector vec, long vec_offset, int overlap);
347extern long lmcutrow(spLMatrix mat, long row, long offset, long length, spLVector vec);
348extern spLVector xlmcutrow(spLMatrix mat, long row, long offset, long length);
349extern long fmcutrowto(spFMatrix mat, long row, long offset, long length, spFVector vec, long vec_offset, int overlap);
350extern long fmcutrow(spFMatrix mat, long row, long offset, long length, spFVector vec);
351extern spFVector xfmcutrow(spFMatrix mat, long row, long offset, long length);
352extern long dmcutrowto(spDMatrix mat, long row, long offset, long length, spDVector vec, long vec_offset, int overlap);
353extern long dmcutrow(spDMatrix mat, long row, long offset, long length, spDVector vec);
354extern spDVector xdmcutrow(spDMatrix mat, long row, long offset, long length);
355extern long smcutcolto(spSMatrix mat, long col, long offset, long length, spSVector vec, long vec_offset, int overlap);
356extern long smcutcol(spSMatrix mat, long col, long offset, long length, spSVector vec);
357extern spSVector xsmcutcol(spSMatrix mat, long col, long offset, long length);
358extern long lmcutcolto(spLMatrix mat, long col, long offset, long length, spLVector vec, long vec_offset, int overlap);
359extern long lmcutcol(spLMatrix mat, long col, long offset, long length, spLVector vec);
360extern spLVector xlmcutcol(spLMatrix mat, long col, long offset, long length);
361extern long fmcutcolto(spFMatrix mat, long col, long offset, long length, spFVector vec, long vec_offset, int overlap);
362extern long fmcutcol(spFMatrix mat, long col, long offset, long length, spFVector vec);
363extern spFVector xfmcutcol(spFMatrix mat, long col, long offset, long length);
364extern long dmcutcolto(spDMatrix mat, long col, long offset, long length, spDVector vec, long vec_offset, int overlap);
365extern long dmcutcol(spDMatrix mat, long col, long offset, long length, spDVector vec);
366extern spDVector xdmcutcol(spDMatrix mat, long col, long offset, long length);
367
368extern long smpasterowfrom(spSMatrix mat, long row, long offset, long length,
369 spSVector vec, long vec_offset, int overlap);
370extern long smpasterow(spSMatrix mat, long row, spSVector vec, long offset, long length, int overlap);
371extern long lmpasterowfrom(spLMatrix mat, long row, long offset, long length,
372 spLVector vec, long vec_offset, int overlap);
373extern long lmpasterow(spLMatrix mat, long row, spLVector vec, long offset, long length, int overlap);
374extern long fmpasterowfrom(spFMatrix mat, long row, long offset, long length,
375 spFVector vec, long vec_offset, int overlap);
376extern long fmpasterow(spFMatrix mat, long row, spFVector vec, long offset, long length, int overlap);
377extern long dmpasterowfrom(spDMatrix mat, long row, long offset, long length,
378 spDVector vec, long vec_offset, int overlap);
379extern long dmpasterow(spDMatrix mat, long row, spDVector vec, long offset, long length, int overlap);
380extern long smpastecolfrom(spSMatrix mat, long col, long offset, long length,
381 spSVector vec, long vec_offset, int overlap);
382extern long smpastecol(spSMatrix mat, long col, spSVector vec, long offset, long length, int overlap);
383extern long lmpastecolfrom(spLMatrix mat, long col, long offset, long length,
384 spLVector vec, long vec_offset, int overlap);
385extern long lmpastecol(spLMatrix mat, long col, spLVector vec, long offset, long length, int overlap);
386extern long fmpastecolfrom(spFMatrix mat, long col, long offset, long length,
387 spFVector vec, long vec_offset, int overlap);
388extern long fmpastecol(spFMatrix mat, long col, spFVector vec, long offset, long length, int overlap);
389extern long dmpastecolfrom(spDMatrix mat, long col, long offset, long length,
390 spDVector vec, long vec_offset, int overlap);
391extern long dmpastecol(spDMatrix mat, long col, spDVector vec, long offset, long length, int overlap);
392
393extern long smpastematfrom(spSMatrix matto, long rowto, long colto, long rowlength, long collength,
394 spSMatrix matfrom, long rowfrom, long colfrom, int overlap);
395extern long smpastemat(spSMatrix matto, long rowto, long colto, spSMatrix matfrom,
396 long rowlength, long collength, int overlap);
397extern long lmpastematfrom(spLMatrix matto, long rowto, long colto, long rowlength, long collength,
398 spLMatrix matfrom, long rowfrom, long colfrom, int overlap);
399extern long lmpastemat(spLMatrix matto, long rowto, long colto, spLMatrix matfrom,
400 long rowlength, long collength, int overlap);
401extern long fmpastematfrom(spFMatrix matto, long rowto, long colto, long rowlength, long collength,
402 spFMatrix matfrom, long rowfrom, long colfrom, int overlap);
403extern long fmpastemat(spFMatrix matto, long rowto, long colto, spFMatrix matfrom,
404 long rowlength, long collength, int overlap);
405extern long dmpastematfrom(spDMatrix matto, long rowto, long colto, long rowlength, long collength,
406 spDMatrix matfrom, long rowfrom, long colfrom, int overlap);
407extern long dmpastemat(spDMatrix matto, long rowto, long colto, spDMatrix matfrom,
408 long rowlength, long collength, int overlap);
409
410extern long smpastematrowfrom(spSMatrix matto, long rowto, long offset, long length,
411 spSMatrix matfrom, long rowfrom, long offsetfrom, int overlap);
412extern long smpastematrow(spSMatrix matto, long rowto, spSMatrix matfrom, long rowfrom,
413 long offset, long length, int overlap);
414extern long smpastematcolfrom(spSMatrix matto, long colto, long offset, long length,
415 spSMatrix matfrom, long colfrom, long offsetfrom, int overlap);
416extern long smpastematcol(spSMatrix matto, long colto, spSMatrix matfrom, long colfrom,
417 long offset, long length, int overlap);
418extern long lmpastematrowfrom(spLMatrix matto, long rowto, long offset, long length,
419 spLMatrix matfrom, long rowfrom, long offsetfrom, int overlap);
420extern long lmpastematrow(spLMatrix matto, long rowto, spLMatrix matfrom, long rowfrom,
421 long offset, long length, int overlap);
422extern long lmpastematcolfrom(spLMatrix matto, long colto, long offset, long length,
423 spLMatrix matfrom, long colfrom, long offsetfrom, int overlap);
424extern long lmpastematcol(spLMatrix matto, long colto, spLMatrix matfrom, long colfrom,
425 long offset, long length, int overlap);
426extern long fmpastematrowfrom(spFMatrix matto, long rowto, long offset, long length,
427 spFMatrix matfrom, long rowfrom, long offsetfrom, int overlap);
428extern long fmpastematrow(spFMatrix matto, long rowto, spFMatrix matfrom, long rowfrom,
429 long offset, long length, int overlap);
430extern long fmpastematcolfrom(spFMatrix matto, long colto, long offset, long length,
431 spFMatrix matfrom, long colfrom, long offsetfrom, int overlap);
432extern long fmpastematcol(spFMatrix matto, long colto, spFMatrix matfrom, long colfrom,
433 long offset, long length, int overlap);
434extern long dmpastematrowfrom(spDMatrix matto, long rowto, long offset, long length,
435 spDMatrix matfrom, long rowfrom, long offsetfrom, int overlap);
436extern long dmpastematrow(spDMatrix matto, long rowto, spDMatrix matfrom, long rowfrom,
437 long offset, long length, int overlap);
438extern long dmpastematcolfrom(spDMatrix matto, long colto, long offset, long length,
439 spDMatrix matfrom, long colfrom, long offsetfrom, int overlap);
440extern long dmpastematcol(spDMatrix matto, long colto, spDMatrix matfrom, long colfrom,
441 long offset, long length, int overlap);
442
443/* extract vector in row direction */
444extern spSVector xsmrextract(spSMatrix mat, spLVector colidx);
445extern spLVector xlmrextract(spLMatrix mat, spLVector colidx);
446extern spFVector xfmrextract(spFMatrix mat, spLVector colidx);
447extern spDVector xdmrextract(spDMatrix mat, spLVector colidx);
448/* extract vector in column direction */
449extern spSVector xsmcextract(spSMatrix mat, spLVector rowidx);
450extern spLVector xlmcextract(spLMatrix mat, spLVector rowidx);
451extern spFVector xfmcextract(spFMatrix mat, spLVector rowidx);
452extern spDVector xdmcextract(spDMatrix mat, spLVector rowidx);
453
454extern spSMatrix xsmextractrows(spSMatrix mat, spLVector rowidx);
455extern spLMatrix xlmextractrows(spLMatrix mat, spLVector rowidx);
456extern spFMatrix xfmextractrows(spFMatrix mat, spLVector rowidx);
457extern spDMatrix xdmextractrows(spDMatrix mat, spLVector rowidx);
458extern spSMatrix xsmextractcols(spSMatrix mat, spLVector colidx);
459extern spLMatrix xlmextractcols(spLMatrix mat, spLVector colidx);
460extern spFMatrix xfmextractcols(spFMatrix mat, spLVector colidx);
461extern spDMatrix xdmextractcols(spDMatrix mat, spLVector colidx);
462
463extern spSMatrix xsmextractrowscols(spSMatrix mat, spLVector rowidx, spLVector colidx);
464extern spLMatrix xlmextractrowscols(spLMatrix mat, spLVector rowidx, spLVector colidx);
465extern spFMatrix xfmextractrowscols(spFMatrix mat, spLVector rowidx, spLVector colidx);
466extern spDMatrix xdmextractrowscols(spDMatrix mat, spLVector rowidx, spLVector colidx);
467
468extern void smabs(spSMatrix mat);
469extern void lmabs(spLMatrix mat);
470extern void fmabs(spFMatrix mat);
471extern void dmabs(spDMatrix mat);
472extern spSMatrix xsmabs(spSMatrix mat);
473extern spLMatrix xlmabs(spLMatrix mat);
474extern spFMatrix xfmabs(spFMatrix mat);
475extern spDMatrix xdmabs(spDMatrix mat);
476
477extern spLVector xsmrmax(spSMatrix mat);
478extern spLVector xlmrmax(spLMatrix mat);
479extern spLVector xfmrmax(spFMatrix mat);
480extern spLVector xdmrmax(spDMatrix mat);
481extern spLVector xsmrmin(spSMatrix mat);
482extern spLVector xlmrmin(spLMatrix mat);
483extern spLVector xfmrmin(spFMatrix mat);
484extern spLVector xdmrmin(spDMatrix mat);
485extern spLVector xsmcmax(spSMatrix mat);
486extern spLVector xlmcmax(spLMatrix mat);
487extern spLVector xfmcmax(spFMatrix mat);
488extern spLVector xdmcmax(spDMatrix mat);
489extern spLVector xsmcmin(spSMatrix mat);
490extern spLVector xlmcmin(spLMatrix mat);
491extern spLVector xfmcmin(spFMatrix mat);
492extern spLVector xdmcmin(spDMatrix mat);
493extern short smmin(spSMatrix mat, long *row, long *col);
494extern long lmmin(spLMatrix mat, long *row, long *col);
495extern float fmmin(spFMatrix mat, long *row, long *col);
496extern double dmmin(spDMatrix mat, long *row, long *col);
497extern short smmax(spSMatrix mat, long *row, long *col);
498extern long lmmax(spLMatrix mat, long *row, long *col);
499extern float fmmax(spFMatrix mat, long *row, long *col);
500extern double dmmax(spDMatrix mat, long *row, long *col);
501
502extern spSMatrix xsmcrop(spSMatrix mat, long row_offset, long row_length, long col_offset, long col_length);
503extern spLMatrix xlmcrop(spLMatrix mat, long row_offset, long row_length, long col_offset, long col_length);
504extern spFMatrix xfmcrop(spFMatrix mat, long row_offset, long row_length, long col_offset, long col_length);
505extern spDMatrix xdmcrop(spDMatrix mat, long row_offset, long row_length, long col_offset, long col_length);
506
507extern spSMatrix xsmhcat(spSMatrix a, spSMatrix b);
508extern spSMatrix xsmvcat(spSMatrix a, spSMatrix b);
509extern spLMatrix xlmhcat(spLMatrix a, spLMatrix b);
510extern spLMatrix xlmvcat(spLMatrix a, spLMatrix b);
511extern spFMatrix xfmhcat(spFMatrix a, spFMatrix b);
512extern spFMatrix xfmvcat(spFMatrix a, spFMatrix b);
513extern spDMatrix xdmhcat(spDMatrix a, spDMatrix b);
514extern spDMatrix xdmvcat(spDMatrix a, spDMatrix b);
515
516extern void smshiftrow(spSMatrix x, long shift);
517extern void smshiftcol(spSMatrix x, long shift);
518extern void lmshiftrow(spLMatrix x, long shift);
519extern void lmshiftcol(spLMatrix x, long shift);
520extern void fmshiftrow(spFMatrix x, long shift);
521extern void fmshiftcol(spFMatrix x, long shift);
522extern void dmshiftrow(spDMatrix x, long shift);
523extern void dmshiftcol(spDMatrix x, long shift);
524
525extern spSVector xsvdiag(spSMatrix A);
526extern spLVector xlvdiag(spLMatrix A);
527extern spFVector xfvdiag(spFMatrix A);
528extern spDVector xdvdiag(spDMatrix A);
529/* supdiag: superdiagonal (shift > 0), subdialognal (shift < 0), or diagonal (shift = 0) */
530extern spSVector xsvsupdiag(spSMatrix A, long shift);
531extern spLVector xlvsupdiag(spLMatrix A, long shift);
532extern spFVector xfvsupdiag(spFMatrix A, long shift);
533extern spDVector xdvsupdiag(spDMatrix A, long shift);
534extern void smdiag(spSMatrix A);
535extern void lmdiag(spLMatrix A);
536extern void fmdiag(spFMatrix A);
537extern void dmdiag(spDMatrix A);
538extern void smsupdiag(spSMatrix A, long shift);
539extern void lmsupdiag(spLMatrix A, long shift);
540extern void fmsupdiag(spFMatrix A, long shift);
541extern void dmsupdiag(spDMatrix A, long shift);
542extern spSMatrix xsmdiag(spSMatrix A);
543extern spLMatrix xlmdiag(spLMatrix A);
544extern spFMatrix xfmdiag(spFMatrix A);
545extern spDMatrix xdmdiag(spDMatrix A);
546extern spSMatrix xsmsupdiag(spSMatrix A, long shift);
547extern spLMatrix xlmsupdiag(spLMatrix A, long shift);
548extern spFMatrix xfmsupdiag(spFMatrix A, long shift);
549extern spDMatrix xdmsupdiag(spDMatrix A, long shift);
550extern spSMatrix xsmmakediag(spSVector d);
551extern spLMatrix xlmmakediag(spLVector d);
552extern spFMatrix xfmmakediag(spFVector d);
553extern spDMatrix xdmmakediag(spDVector d);
554extern spSMatrix xsmmakesupdiag(spSVector d, long shift);
555extern spLMatrix xlmmakesupdiag(spLVector d, long shift);
556extern spFMatrix xfmmakesupdiag(spFVector d, long shift);
557extern spDMatrix xdmmakesupdiag(spDVector d, long shift);
558/* make permutation matrix */
559extern spSMatrix xsmmakeperm(spLVector index);
560extern spLMatrix xlmmakeperm(spLVector index);
561extern spFMatrix xfmmakeperm(spLVector index);
562extern spDMatrix xdmmakeperm(spLVector index);
563
564extern spBool smtranspose(spSMatrix A);
565extern spSMatrix xsmtranspose(spSMatrix A);
566extern spBool smconjtranspose(spSMatrix A);
567extern spSMatrix xsmconjtranspose(spSMatrix A);
568extern spBool lmtranspose(spLMatrix A);
569extern spLMatrix xlmtranspose(spLMatrix A);
570extern spBool lmconjtranspose(spLMatrix A);
571extern spLMatrix xlmconjtranspose(spLMatrix A);
572extern spBool fmtranspose(spFMatrix A);
573extern spFMatrix xfmtranspose(spFMatrix A);
574extern spBool fmconjtranspose(spFMatrix A);
575extern spFMatrix xfmconjtranspose(spFMatrix A);
576extern spBool dmtranspose(spDMatrix A);
577extern spDMatrix xdmtranspose(spDMatrix A);
578extern spBool dmconjtranspose(spDMatrix A);
579extern spDMatrix xdmconjtranspose(spDMatrix A);
580
581extern void dmscoper(spDMatrix x, const char *op, double t);
582extern spDMatrix xdmscoper(spDMatrix x, const char *op, double t);
583
584extern spBool dmbalance(spDMatrix A /* input/output */, spDMatrix D /* outputA=inv(D)*A*D */);
585extern spDMatrix xdmbalance(spDMatrix A, spDMatrix *xoD /* outputA=inv(D)*A*D */);
586
587/*
588 * functions for householder matrix
589 * x --> v (normalized householder vector)
590 * H = eye(n) - 2 * v * v'; (H: householder matrix)
591 * H * x --> [x(0)*x0weight, 0, 0, ...];
592 * dvhouse return: x0weight
593 * complex vector/matrix is supported
594 */
595extern double dvhouse(spDVector x);
596extern spDVector xdvhouse(spDVector x,
597 double *x0weight /* output weight for x(0) (conversion result of x(0)) */);
598extern spBool dmhouse(spDMatrix H /* output householder matrix */,
599 spDVector v /* input hyperplane normal vector */);
600extern spDMatrix xdmhouse(/* output householder matrix */
601 spDVector v /* input hyperplane normal vector */);
602
603extern spBool dmhess(spDMatrix A /* input/output */, spDMatrix P /* inputA=P*outputA*P' */);
604extern spDMatrix xdmhess(spDMatrix A, spDMatrix *xoP /* A=P*output*P' */);
605
606extern spBool dmbidiag(spDMatrix A /* input/output */, spDMatrix U, spDMatrix V); /* inputA = U*outputA*V'. U and V can be NODATA */
607extern spDMatrix xdmbidiag(spDMatrix A, spDMatrix *xoU, spDMatrix *xoV); /* inputA = U*outputA*V'. xoU and xoV can be NULL, must be freed */
608
609/* functions for QR decomposition */
610/* complex matrix is now supported (0.9.4+) */
611extern spBool dmqr(spDMatrix A, spDMatrix Q, spDMatrix R);
612/* double shift QR algorithm. accepts complex matrix */
613extern spDVector xdmeigdsqr(spDMatrix A, long max_iteration /* 0: no limit */, double tolerance,
614 spDVectors *xoeigvecs /* can be NULL, must be freed */);
615
616extern spBool dmsvdbidiag(spDMatrix B /* input: bidiagonal matrix, output: SVD diagonal matrix. size = [M, N] */,
617 long max_iteration, double tolerance,
618 spDMatrix oU /* size = [M, M] */, spDMatrix oV /* size = [N, N] */); /* inputB = oU * outputB * oV' */
619extern spBool dmsvd(spDMatrix A /* output: SVD diagonal matrix. size = [M, N] */, long max_iteration, double tolerance,
620 spDMatrix oU /* size = [M, M] */, spDMatrix oV /* size = [N, N] */); /* inputA = oU * outputA * oV' */
621extern spDMatrix xdmsvd(spDMatrix A /* size = [M, N] */, long max_iteration, double tolerance,
622 spDMatrix *xoU /* size = [M, M] */, spDMatrix *xoV /* size = [N, N] */); /* A = xoU * diag(output) * xoV' */
623
624/* functions for Cholesky decomposition */
625/* complex matrix is supported */
626extern spBool dmchol(spDMatrix C/* size: (A->row, A->row) */, spDMatrix A, spBool lower);
627extern spDMatrix xdmchol(spDMatrix A, spBool lower);
628extern spBool dmcholinv(spDMatrix Ainv, spDMatrix C, spBool lower);
629extern spDMatrix xdmcholinv(spDMatrix C, spBool lower);
630extern spBool dvcholsolve(spDVector x, spDMatrix C, spDVector b, spBool lower);
631extern spDVector xdvcholsolve(spDMatrix C, spDVector b, spBool lower);
632
633/* functions for LU decomposition */
634/* complex matrix is mostly supported (use dmlucplx or xdmlucplx for complex input matrix A) */
635extern spBool dmlu(spDMatrix A, spLVector *xoindex /* can be NULL, must be freed */, double *det); /* det (determinant) can be NULL */
636/* real LU decomposition with buffer (no memory allocation in this function) */
637extern spBool dmluwb(spDMatrix A, spDVector weightbuf/* length: A->row (= A->col) */,
638 spLVector index/* length: A->row (= A->col) */, double *det); /* det (determinant) can be NULL */
639extern spDMatrix xdmlu(spDMatrix A, spLVector *xoindex /* can be NULL, must be freed */, double *det); /* det (determinant) can be NULL */
640extern spBool dmlucplx(spDMatrix A, spLVector *xoindex /* can be NULL, must be freed */, double *detr, double *deti); /* detr and deti (determinant) can be NULL */
641/* complex LU decomposition with buffer (no memory allocation in this function) */
642extern spBool dmlucplxwb(spDMatrix A, spDVector weightbuf/* length: A->row (= A->col) */,
643 spLVector index/* length: A->row (= A->col) */,
644 double *detr, double *deti); /* detr and deti (determinant) can be NULL */
645extern spDMatrix xdmlucplx(spDMatrix A, spLVector *xoindex /* can be NULL, must be freed */, double *detr, double *deti); /* detr and deti (determinant) can be NULL */
646extern spBool dmluupper(spDMatrix U /* output */, spDMatrix LU, spLVector index);
647extern spBool dmlulower(spDMatrix L /* output */, spDMatrix LU, spLVector index);
648extern spBool dmlupermlower(spDMatrix L1 /* output */, spDMatrix LU, spLVector index);
649extern spDMatrix xdmluupper(spDMatrix LU, spLVector index);
650extern spDMatrix xdmlulower(spDMatrix LU, spLVector index);
651extern spDMatrix xdmlupermlower(spDMatrix LU, spLVector index);
652extern spDMatrix xdmludiag(spDMatrix LU, spLVector index);
653extern spBool dmluinv(spDMatrix Ainv, spDMatrix LU, spLVector index);
654extern spDMatrix xdmluinv(spDMatrix LU, spLVector index);
655extern spBool dvlusolve(spDVector x, spDMatrix LU, spLVector index, spDVector b);
656extern spDVector xdvlusolve(spDMatrix LU, spLVector index, spDVector b);
657
658extern spDMatrix xdminv(spDMatrix A);
659extern spDVector xdvmldivide(spDMatrix A, spDVector b);
660
661extern spBool dmtimes(spDMatrix C/* size: (A->row, A->col) */, spDMatrix A, spDMatrix B);
662extern spDMatrix xdmtimes(spDMatrix A, spDMatrix B);
663extern spBool dvmvtimes(spDVector y, spDMatrix A, spDVector x/* column vector */);
664extern spDVector xdvmvtimes(spDMatrix A, spDVector x/* column vector */);
665extern spBool dvvmtimes(spDVector y/* row vector */, spDVector x/* row vector */, spDMatrix A);
666extern spDVector xdvvmtimes(spDVector x/* row vector */, spDMatrix A);
667extern spBool dmvvtimes(spDMatrix C/* size: (a->length, b->length) */, spDVector a/* column vector */, spDVector b/* row vector */);
668extern spDMatrix xdmvvtimes(spDVector a/* column vector */, spDVector b/* row vector */);
669
670extern double dmfrobnorm(spDMatrix A);
671extern double dminftynorm(spDMatrix A);
672extern double dmonenorm(spDMatrix A);
673extern double dmtwonorm(spDMatrix A);
674/* p == -1: infinity norm, p == 0: frobenius norm, p == 1: 1-norm, p == 2: 2-norm */
675extern double dmnorm(spDMatrix A, long p);
676
677extern double dmcondp(spDMatrix A, long p);
678extern double dmcond(spDMatrix A);
679
680extern double dmrank(spDMatrix A, double tolerance);
681
682extern spDMatrix xdmcompan(spDVector u, double tolerance,
683 long *onum_leading_zero /* can be NULL */, long *onum_trailing_zero /* can be NULL */);
684extern spDVector xdvrootscompan(spDMatrix C /* must be companion matrix */, long num_leading_zero, long num_trailing_zero);
685extern spDVector xdvroots(spDVector u, double tolerance);
686
687#if defined(MACOS)
688#pragma import off
689#endif
690
691#define smextractrow(mat, k, vec) smcutrow(mat, (long)(k), 0, mat->col, vec)
692#define lmextractrow(mat, k, vec) lmcutrow(mat, (long)(k), 0, mat->col, vec)
693#define fmextractrow(mat, k, vec) fmcutrow(mat, (long)(k), 0, mat->col, vec)
694#define dmextractrow(mat, k, vec) dmcutrow(mat, (long)(k), 0, mat->col, vec)
695#define smextractcol(mat, k, vec) smcutcol(mat, (long)(k), 0, mat->row, vec)
696#define lmextractcol(mat, k, vec) lmcutcol(mat, (long)(k), 0, mat->row, vec)
697#define fmextractcol(mat, k, vec) fmcutcol(mat, (long)(k), 0, mat->row, vec)
698#define dmextractcol(mat, k, vec) dmcutcol(mat, (long)(k), 0, mat->row, vec)
699
700#define xsmextractrow(mat, k) xsmcutrow(mat, (long)(k), 0, mat->col)
701#define xlmextractrow(mat, k) xlmcutrow(mat, (long)(k), 0, mat->col)
702#define xfmextractrow(mat, k) xfmcutrow(mat, (long)(k), 0, mat->col)
703#define xdmextractrow(mat, k) xdmcutrow(mat, (long)(k), 0, mat->col)
704#define xsmextractcol(mat, k) xsmcutcol(mat, (long)(k), 0, mat->row)
705#define xlmextractcol(mat, k) xlmcutcol(mat, (long)(k), 0, mat->row)
706#define xfmextractcol(mat, k) xfmcutcol(mat, (long)(k), 0, mat->row)
707#define xdmextractcol(mat, k) xdmcutcol(mat, (long)(k), 0, mat->row)
708
709/* copy vector to matrix row */
710#define smcopyrow(mat, k, vec) smpasterowfrom(mat, (long)(k), 0, vec->length, vec, 0, 0)
711#define lmcopyrow(mat, k, vec) lmpasterowfrom(mat, (long)(k), 0, vec->length, vec, 0, 0)
712#define fmcopyrow(mat, k, vec) fmpasterowfrom(mat, (long)(k), 0, vec->length, vec, 0, 0)
713#define dmcopyrow(mat, k, vec) dmpasterowfrom(mat, (long)(k), 0, vec->length, vec, 0, 0)
714/* copy vector to matrix column */
715#define smcopycol(mat, k, vec) smpastecolfrom(mat, (long)(k), 0, vec->length, vec, 0, 0)
716#define lmcopycol(mat, k, vec) lmpastecolfrom(mat, (long)(k), 0, vec->length, vec, 0, 0)
717#define fmcopycol(mat, k, vec) fmpastecolfrom(mat, (long)(k), 0, vec->length, vec, 0, 0)
718#define dmcopycol(mat, k, vec) dmpastecolfrom(mat, (long)(k), 0, vec->length, vec, 0, 0)
719
720/* copy matrix to particular position of matrix */
721#define smcopyto(matto, rowto, colto, matfrom) smpastematfrom(matto, rowto, colto, 0, 0, matfrom, 0, 0, 0)
722#define lmcopyto(matto, rowto, colto, matfrom) lmpastematfrom(matto, rowto, colto, 0, 0, matfrom, 0, 0, 0)
723#define fmcopyto(matto, rowto, colto, matfrom) fmpastematfrom(matto, rowto, colto, 0, 0, matfrom, 0, 0, 0)
724#define dmcopyto(matto, rowto, colto, matfrom) dmpastematfrom(matto, rowto, colto, 0, 0, matfrom, 0, 0, 0)
725
726#define smcopymatrow(matto, rowto, matfrom, rowfrom) smpastematrowfrom(matto, rowto, 0, matfrom->col, matfrom, rowfrom, 0, 0)
727#define smcopymatcol(matto, colto, matfrom, colfrom) smpastematcolfrom(matto, colto, 0, matfrom->row, matfrom, colfrom, 0, 0)
728#define lmcopymatrow(matto, rowto, matfrom, rowfrom) lmpastematrowfrom(matto, rowto, 0, matfrom->col, matfrom, rowfrom, 0, 0)
729#define lmcopymatcol(matto, colto, matfrom, colfrom) lmpastematcolfrom(matto, colto, 0, matfrom->row, matfrom, colfrom, 0, 0)
730#define fmcopymatrow(matto, rowto, matfrom, rowfrom) fmpastematrowfrom(matto, rowto, 0, matfrom->col, matfrom, rowfrom, 0, 0)
731#define fmcopymatcol(matto, colto, matfrom, colfrom) fmpastematcolfrom(matto, colto, 0, matfrom->row, matfrom, colfrom, 0, 0)
732#define dmcopymatrow(matto, rowto, matfrom, rowfrom) dmpastematrowfrom(matto, rowto, 0, matfrom->col, matfrom, rowfrom, 0, 0)
733#define dmcopymatcol(matto, colto, matfrom, colfrom) dmpastematcolfrom(matto, colto, 0, matfrom->row, matfrom, colfrom, 0, 0)
734
735#define xsmzeros(row, col) xsmnums(row, col, 0)
736#define xlmzeros(row, col) xlmnums(row, col, 0)
737#define xfmzeros(row, col) xfmnums(row, col, 0.0f)
738#define xdmzeros(row, col) xdmnums(row, col, 0.0)
739#define xsmones(row, col) xsmnums(row, col, 1)
740#define xlmones(row, col) xlmnums(row, col, 1)
741#define xfmones(row, col) xlmnums(row, col, 1.0f)
742#define xdmones(row, col) xdmnums(row, col, 1.0)
743
744#define smzeros(mat, row, col) smnums(mat, row, col, 0)
745#define lmzeros(mat, row, col) lmnums(mat, row, col, 0)
746#define fmzeros(mat, row, col) fmnums(mat, row, col, 0.0f)
747#define dmzeros(mat, row, col) dmnums(mat, row, col, 0.0)
748#define smones(mat, row, col) smnums(mat, row, col, 1)
749#define lmones(mat, row, col) lmnums(mat, row, col, 1)
750#define fmones(mat, row, col) fmnums(mat, row, col, 1.0f)
751#define dmones(mat, row, col) dmnums(mat, row, col, 1.0)
752
753#define smizeros(mat, row, col) sminums(mat, row, col, 0)
754#define lmizeros(mat, row, col) lminums(mat, row, col, 0)
755#define fmizeros(mat, row, col) fminums(mat, row, col, 0.0f)
756#define dmizeros(mat, row, col) dminums(mat, row, col, 0.0)
757#define smiones(mat, row, col) sminums(mat, row, col, 1)
758#define lmiones(mat, row, col) lminums(mat, row, col, 1)
759#define fmiones(mat, row, col) fminums(mat, row, col, 1.0f)
760#define dmiones(mat, row, col) dminums(mat, row, col, 1.0)
761
762#define xsmrizeros(row, col) xsmrinums(row, col, 0)
763#define xlmrizeros(row, col) xlmrinums(row, col, 0)
764#define xfmrizeros(row, col) xfmrinums(row, col, 0.0f)
765#define xdmrizeros(row, col) xdmrinums(row, col, 0.0)
766#define xsmriones(row, col) xsmrinums(row, col, 1)
767#define xlmriones(row, col) xlmrinums(row, col, 1)
768#define xfmriones(row, col) xfmrinums(row, col, 1.0f)
769#define xdmriones(row, col) xdmrinums(row, col, 1.0)
770
771#define xsmnull() xsmalloc(0, 0)
772#define xlmnull() xlmalloc(0, 0)
773#define xfmnull() xfmalloc(0, 0)
774#define xdmnull() xdmalloc(0, 0)
775
776#define msset(xs, index, x) {(xs)->matrix[index]=(x);}
777#define smsset msset
778#define lmsset msset
779#define fmsset msset
780#define dmsset msset
781
782/* for backwards compatibility */
783typedef spSMatrix SMATRIX;
784typedef spLMatrix LMATRIX;
785typedef spFMatrix FMATRIX;
786typedef spDMatrix DMATRIX;
787
788typedef spSMatrices SMATRICES;
789typedef spLMatrices LMATRICES;
790typedef spFMatrices FMATRICES;
791typedef spDMatrices DMATRICES;
792
793#define xdmmin dmmin
794#define xdmmax dmmax
795
796#define xdvmtimes xdvmvtimes
797
798#ifdef __cplusplus
799} /* Close scope of 'extern "C"' declaration */
800#endif
801
802#endif /* SPLIB_MATRIX_H */
int spBool
Matrix type that contains the elements of double type.
Definition matrix.h:152
double ** imag
Definition matrix.h:167
long row
Definition matrix.h:155
long col
Definition matrix.h:158
double ** data
Definition matrix.h:162
Vector type that contains the elements of double type.
Definition vector.h:248
Matrix type that contains the elements of float type.
Definition matrix.h:117
float ** data
Definition matrix.h:127
long row
Definition matrix.h:120
long col
Definition matrix.h:123
float ** imag
Definition matrix.h:132
Vector type that contains the elements of float type.
Definition vector.h:214
Matrix type that contains the elements of long type.
Definition matrix.h:82
long ** data
Definition matrix.h:92
long row
Definition matrix.h:85
long col
Definition matrix.h:88
long ** imag
Definition matrix.h:97
Vector type that contains the elements of long type.
Definition vector.h:180
Matrix type that contains the elements of short type.
Definition matrix.h:47
short ** imag
Definition matrix.h:62
short ** data
Definition matrix.h:57
long row
Definition matrix.h:50
long col
Definition matrix.h:53
Vector type that contains the elements of short type.
Definition vector.h:146