Main Page | Modules | Class List | File List | Class Members | File Members

mat_gen.h

Go to the documentation of this file.
00001 
00014 /* This library is free software; you can redistribute it and/or
00015    modify it under the terms of the GNU Lesser General Public
00016    License as published by the Free Software Foundation; either
00017    version 2.1 of the License, or (at your option) any later version.
00018 
00019    This library is distributed in the hope that it will be useful,
00020    but WITHOUT ANY WARRANTY; without even the implied warranty of
00021    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022    Lesser General Public License for more details.
00023 
00024    You should have received a copy of the GNU Lesser General Public
00025    License along with this library; if not, write to the Free Software
00026    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 */
00028 
00029 #ifndef _GAN_MAT_GEN_H
00030 #define _GAN_MAT_GEN_H
00031 
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <stdarg.h>
00035 #include <gandalf/common/misc_defs.h>
00036 #include <gandalf/common/misc_error.h>
00037 #include <gandalf/linalg/linalg_defs.h>
00038 
00039 #ifdef __cplusplus
00040 extern "C" {
00041 #endif
00042 
00058 struct Gan_SquMatrix;
00059 
00061 typedef struct Gan_Matrix
00062 {
00063    /* row and column dimensions of matrix */
00064    unsigned long rows, cols;
00065 
00066    /* data array containing matrix elements */
00067    double *data;
00068 
00069    /* allocated size of matrix (number of double's) */
00070    size_t data_size;
00071 
00072    /* flag indicating whether matrix data was dynamically allocated */
00073    Gan_Bool data_alloc;
00074 
00075    /* flag indicating whether matrix structure was dynamically allocated */
00076    Gan_Bool struct_alloc;
00077 } Gan_Matrix;
00078 
00079 #define GAN_MATRIX_STRUCT_DEFINED
00080 
00081 #include <gandalf/linalg/vec_gen.h>
00082 #include <gandalf/linalg/mat_square.h>
00083 
00084  void gan_mat_free ( Gan_Matrix *A );
00085  Gan_Matrix *gan_mat_set_dims ( Gan_Matrix *A,
00086                                unsigned long rows, unsigned long cols );
00087  Gan_Matrix *gan_mat_fill_va ( Gan_Matrix *A,
00088                               unsigned long rows, unsigned long cols, ... );
00089  Gan_Matrix *gan_mat_fill_vap ( Gan_Matrix *A,
00090                                unsigned long rows, unsigned long cols,
00091                                va_list *aptr );
00092  Gan_Matrix *gan_mat_fill_const_q ( Gan_Matrix *A,
00093                                    unsigned long rows, unsigned long cols,
00094                                    double value );
00095  Gan_Bool gan_mat_read_va ( const Gan_Matrix *A,
00096                            unsigned long rows, unsigned long cols, ... );
00097  Gan_Matrix *gan_mat_copy_q ( const Gan_Matrix *A, Gan_Matrix *B );
00098  Gan_Matrix *gan_mat_scale_q ( Gan_Matrix *A, double a, Gan_Matrix *B );
00099  Gan_Matrix *gan_mat_divide_q ( Gan_Matrix *A, double a, Gan_Matrix *B );
00100  Gan_Matrix *gan_mat_tpose_q ( Gan_Matrix *A, Gan_Matrix *B );
00101  Gan_Matrix *gan_mat_insertsym ( Gan_Matrix *A,
00102                                 unsigned long rA, unsigned long cA,
00103                                 const struct Gan_SquMatrix *B,
00104                                 unsigned long rB, unsigned long cB,
00105                                 unsigned long rows , unsigned long cols );
00106  Gan_Bool gan_mat_is_zero ( Gan_Matrix *A );
00107  void gan_mat_free_va ( Gan_Matrix *A, ... );
00108  Gan_Matrix *gan_mat_extract_q ( const Gan_Matrix *A,
00109                                 unsigned long r0,   unsigned long c0,
00110                                 unsigned long rows, unsigned long cols,
00111                                 Gan_Matrix *B );
00112  double gan_mat_sumsqr ( const Gan_Matrix *A );
00113  double gan_mat_Fnorm ( const Gan_Matrix *A );
00114  Gan_Matrix *gan_mat_invert_q ( const Gan_Matrix *A, Gan_Matrix *B );
00115  Gan_Bool gan_mat_fprint ( FILE *fp, const Gan_Matrix *A, const char *prefix,
00116                           unsigned indent, const char *fmt );
00117  Gan_Matrix *gan_mat_fscanf_q ( FILE *fp, Gan_Matrix *A,
00118                                char *prefix, int prefix_len );
00119  Gan_Bool gan_mat_fwrite ( FILE *fp, const Gan_Matrix *A, gan_uint32 magic_number );
00120  Gan_Matrix *gan_mat_fread_q ( FILE *fp, Gan_Matrix *A,
00121                               gan_uint32 *magic_number );
00122 
00123 #define Gan_SquMatrix struct Gan_SquMatrix
00124 
00138  Gan_Matrix *gan_mat_alloc ( unsigned long rows, unsigned long cols );
00139 
00151  Gan_Matrix *gan_mat_form ( Gan_Matrix *A,
00152                            unsigned long rows, unsigned long cols );
00153 
00168  Gan_Matrix *gan_mat_form_data ( Gan_Matrix *A,
00169                                 unsigned long rows, unsigned long cols,
00170                                 double *data, size_t data_size );
00171 
00187  Gan_Bool gan_mat_set_el ( Gan_Matrix *A, unsigned i, unsigned j, double value);
00188 
00194  double gan_mat_get_el ( const Gan_Matrix *A, unsigned i, unsigned j );
00195 
00202  Gan_Bool gan_mat_inc_el ( Gan_Matrix *A, unsigned i, unsigned j, double value);
00203 
00210  Gan_Bool gan_mat_dec_el ( Gan_Matrix *A, unsigned i, unsigned j, double value);
00211 
00228  Gan_Bool gan_mat_print ( const Gan_Matrix *A,
00229                          const char *prefix, int indent, const char *fmt );
00230 
00252  Gan_Matrix *gan_mat_fill_const_s ( unsigned long rows, unsigned long cols,
00253                                    double value );
00254 
00265  Gan_Matrix *gan_mat_fill_zero_q ( Gan_Matrix *A,
00266                                   unsigned long rows, unsigned long cols );
00267 
00279  Gan_Matrix *gan_mat_fill_zero_s ( unsigned long rows, unsigned cols );
00280 
00295  Gan_Matrix *gan_mat_copy_s ( const Gan_Matrix *A );
00296 
00311  Gan_Matrix *gan_mat_scale_s ( Gan_Matrix *A, double a );
00312 
00318  Gan_Matrix *gan_mat_scale_i ( Gan_Matrix *A, double a );
00319 
00325  Gan_Matrix *gan_mat_divide_s ( Gan_Matrix *A, double a );
00326 
00332  Gan_Matrix *gan_mat_divide_i ( Gan_Matrix *A, double a );
00333 
00339  Gan_Matrix *gan_mat_negate_q ( Gan_Matrix *A, Gan_Matrix *B );
00340 
00346  Gan_Matrix *gan_mat_negate_s ( Gan_Matrix *A );
00347 
00353  Gan_Matrix *gan_mat_negate_i ( Gan_Matrix *A );
00354 
00369  Gan_Matrix *gan_mat_tpose_s ( Gan_Matrix *A );
00370 
00377  Gan_Matrix *gan_mat_tpose_i ( Gan_Matrix *A );
00378 
00394  Gan_Matrix *gan_mat_add_q ( Gan_Matrix *A, Gan_Matrix *B, Gan_Matrix *C );
00395 
00402  Gan_Matrix *gan_mat_add_s ( Gan_Matrix *A, Gan_Matrix *B );
00403 
00410  Gan_Matrix *gan_mat_add_i1 ( Gan_Matrix *A, Gan_Matrix *B );
00411 
00418  Gan_Matrix *gan_mat_add_i2 ( Gan_Matrix *A, Gan_Matrix *B );
00419 
00426  Gan_Matrix *gan_mat_increment ( Gan_Matrix *A, Gan_Matrix *B );
00427 
00434  Gan_Matrix *gan_mat_addT_q ( Gan_Matrix *A, Gan_Matrix *B, Gan_Matrix *C );
00435 
00442  Gan_Matrix *gan_mat_addT_s ( Gan_Matrix *A, Gan_Matrix *B );
00443 
00450  Gan_Matrix *gan_mat_incrementT ( Gan_Matrix *A, Gan_Matrix *B );
00451 
00459  Gan_SquMatrix *gan_mat_add_sym_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00460                                    Gan_SquMatrix *C );
00461 
00469  Gan_SquMatrix *gan_mat_add_sym_s ( const Gan_Matrix *A, Gan_Matrix *B );
00470 
00478  Gan_SquMatrix *gan_mat_addT_sym_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00479                                     Gan_SquMatrix *C );
00480 
00488  Gan_SquMatrix *gan_mat_addT_sym_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00489 
00497  Gan_SquMatrix *gan_matT_add_sym_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00498                                     Gan_SquMatrix *C );
00499 
00507  Gan_SquMatrix *gan_matT_add_sym_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00508 
00516  Gan_SquMatrix *gan_matT_addT_sym_q ( Gan_Matrix *A, Gan_Matrix *B,
00517                                      Gan_SquMatrix *C );
00518 
00526  Gan_SquMatrix *gan_matT_addT_sym_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00527 
00534  Gan_SquMatrix *gan_mat_saddT_sym_q ( const Gan_Matrix *A, const Gan_SquMatrix *B );
00535 
00542  Gan_SquMatrix *gan_mat_saddT_sym_s ( const Gan_Matrix *A );
00543 
00550  Gan_SquMatrix *gan_matT_sadd_sym_q ( const Gan_Matrix *A, Gan_SquMatrix *B );
00551 
00558  Gan_SquMatrix *gan_matT_sadd_sym_s ( const Gan_Matrix *A );
00559 
00575  Gan_Matrix *gan_mat_sub_q ( Gan_Matrix *A, Gan_Matrix *B, Gan_Matrix *C );
00576 
00583  Gan_Matrix *gan_mat_sub_s ( Gan_Matrix *A, Gan_Matrix *B );
00584 
00591  Gan_Matrix *gan_mat_sub_i1 ( Gan_Matrix *A, Gan_Matrix *B );
00592 
00599  Gan_Matrix *gan_mat_sub_i2 ( Gan_Matrix *A, Gan_Matrix *B );
00600 
00607  Gan_Matrix *gan_mat_decrement ( Gan_Matrix *A, Gan_Matrix *B );
00608 
00615  Gan_Matrix *gan_mat_subT_q ( Gan_Matrix *A, Gan_Matrix *B,
00616                              Gan_Matrix *C );
00617 
00624  Gan_Matrix *gan_mat_subT_s ( Gan_Matrix *A, Gan_Matrix *B );
00625 
00632  Gan_Matrix *gan_mat_decrementT ( Gan_Matrix *A, Gan_Matrix *B );
00633 
00649  Gan_Vector *gan_mat_multv_q ( const Gan_Matrix *A, const Gan_Vector *x,
00650                               Gan_Vector *y );
00651 
00658  Gan_Vector *gan_mat_multv_s ( const Gan_Matrix *A, const Gan_Vector *x );
00659 
00666  Gan_Vector *gan_matT_multv_q ( const Gan_Matrix *A, const Gan_Vector *x,
00667                                Gan_Vector *y );
00668 
00675  Gan_Vector *gan_matT_multv_s ( const Gan_Matrix *A, const Gan_Vector *x );
00676 
00692  Gan_Matrix *gan_mat_rmult_q ( const Gan_Matrix *A, const Gan_Matrix *B, Gan_Matrix *C );
00693 
00700  Gan_Matrix *gan_mat_rmult_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00701 
00708  Gan_Matrix *gan_mat_rmultT_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00709                                Gan_Matrix *C );
00710 
00717  Gan_Matrix *gan_mat_rmultT_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00718 
00725  Gan_Matrix *gan_matT_rmult_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00726                                Gan_Matrix *C );
00727 
00734  Gan_Matrix *gan_matT_rmult_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00735 
00742  Gan_Matrix *gan_matT_rmultT_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00743                                 Gan_Matrix *C );
00744 
00751  Gan_Matrix *gan_matT_rmultT_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00752 
00760  Gan_SquMatrix *gan_mat_rmult_sym_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00761                                      Gan_SquMatrix *C );
00762 
00770  Gan_SquMatrix *gan_mat_rmult_sym_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00771 
00779  Gan_SquMatrix *gan_mat_rmultT_sym_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00780                                       Gan_SquMatrix *C );
00781 
00789  Gan_SquMatrix *gan_mat_rmultT_sym_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00790 
00798  Gan_SquMatrix *gan_matT_rmult_sym_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00799                                       Gan_SquMatrix *C );
00800 
00808  Gan_SquMatrix *gan_matT_rmult_sym_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00809 
00817  Gan_SquMatrix *gan_matT_rmultT_sym_q ( const Gan_Matrix *A, const Gan_Matrix *B,
00818                                        Gan_SquMatrix *C );
00819 
00827  Gan_SquMatrix *gan_matT_rmultT_sym_s ( const Gan_Matrix *A, const Gan_Matrix *B );
00828 
00835  Gan_SquMatrix *gan_mat_srmultT_q ( const Gan_Matrix *A, const Gan_SquMatrix *B );
00836 
00843  Gan_SquMatrix *gan_mat_srmultT_s ( const Gan_Matrix *A );
00844 
00851  Gan_SquMatrix *gan_mat_slmultT_q ( const Gan_Matrix *A, Gan_SquMatrix *B );
00852 
00859  Gan_SquMatrix *gan_mat_slmultT_s ( const Gan_Matrix *A );
00860 
00883  Gan_Matrix *gan_mat_invert_s ( const Gan_Matrix *A );
00884 
00902  Gan_Bool gan_mat_same_dims ( const Gan_Matrix *A, const Gan_Matrix *B );
00903 
00922  Gan_Matrix *gan_mat_insert ( Gan_Matrix *A, unsigned long rA, unsigned long cA,
00923                              const Gan_Matrix *B,
00924                              unsigned long rB,   unsigned long cB,
00925                              unsigned long rows, unsigned long cols );
00926 
00936  Gan_Matrix *gan_mat_insertT ( Gan_Matrix *A,
00937                               unsigned long rA, unsigned long cA,
00938                               const Gan_Matrix *B,
00939                               unsigned long rB,   unsigned long cB,
00940                               unsigned long rows, unsigned long cols );
00941 
00949  Gan_Matrix *gan_mat_insertv ( Gan_Matrix *A,
00950                               unsigned long rA, unsigned long cA,
00951                               const Gan_Vector *x, unsigned long rx,
00952                               unsigned long rows );
00953 
00964  Gan_Matrix *gan_mat_insertvT ( Gan_Matrix *A,
00965                                unsigned long rA, unsigned long cA,
00966                                const Gan_Vector *x, unsigned long rx,
00967                                unsigned long cols );
00968 
00984  Gan_Bool gan_mat_test_dims ( const Gan_Matrix *A, unsigned long rows,
00985                                             unsigned long cols );
00986 
01002  size_t gan_mat_data_size ( unsigned long rows, unsigned long cols );
01003 
01028  Gan_Matrix *gan_mat_extract_s ( const Gan_Matrix *A,
01029                                 unsigned long r0,   unsigned long c0,
01030                                 unsigned long rows, unsigned long cols );
01031 
01054  Gan_Matrix *gan_mat_fscanf_s ( FILE *fp, const char *prefix, int prefix_len );
01055 
01066  Gan_Matrix *gan_mat_fread_s ( FILE *fp, gan_uint32 *magic_number );
01067 
01072 #undef Gan_SquMatrix
01073 
01074 /* not user functions */
01075  Gan_Matrix *gan_mat_form_gen ( Gan_Matrix *A,
01076                                unsigned long rows, unsigned long cols,
01077                                double *data, size_t data_size );
01078  Gan_Bool gan_mat_realloc_gen ( Gan_Matrix *A,
01079                                unsigned long rows, unsigned long cols );
01080  Gan_Matrix *gan_mat_add_gen ( Gan_Matrix *A, Gan_TposeFlag A_tr,
01081                               Gan_Matrix *B, Gan_TposeFlag B_tr,
01082                               Gan_Matrix *C );
01083  struct Gan_SquMatrix *gan_mat_add_sym_gen ( const Gan_Matrix *A, Gan_TposeFlag A_tr,
01084                                             const Gan_Matrix *B, Gan_TposeFlag B_tr,
01085                                             struct Gan_SquMatrix *C );
01086  Gan_Matrix *gan_mat_sub_gen ( Gan_Matrix *A, Gan_TposeFlag A_tr,
01087                               Gan_Matrix *B, Gan_TposeFlag B_tr,
01088                               Gan_Matrix *C );
01089  Gan_Vector *gan_mat_multv_gen ( const Gan_Matrix *A, Gan_TposeFlag A_tr,
01090                                 const Gan_Vector *x, Gan_Vector *y );
01091  Gan_Matrix *gan_mat_rmult_gen ( const Gan_Matrix *A, Gan_TposeFlag A_tr,
01092                                 const Gan_Matrix *B, Gan_TposeFlag B_tr,
01093                                 Gan_Matrix *C );
01094  struct Gan_SquMatrix *gan_mat_rmult_sym_gen (const Gan_Matrix *A, Gan_TposeFlag A_tr,
01095                                              const Gan_Matrix *B, Gan_TposeFlag B_tr,
01096                                              struct Gan_SquMatrix *C );
01097  Gan_Matrix *gan_mat_insert_gen ( Gan_Matrix *A,
01098                                  unsigned long rA, unsigned long cA,
01099                                  const Gan_Matrix *B, Gan_TposeFlag B_tr,
01100                                  unsigned long rB, unsigned long cB,
01101                                  unsigned long rows , unsigned long cols );
01102  Gan_Matrix *gan_mat_insertv_gen ( Gan_Matrix *A,
01103                                   unsigned long rA, unsigned long cA,
01104                                   const struct Gan_Vector *x, Gan_TposeFlag x_tr,
01105                                   unsigned long rx, unsigned long size );
01106 
01107 #ifndef NDEBUG
01108  void gan_mat_db ( const Gan_Matrix *A ); /* for use in a debugger */
01109 #endif
01110 
01111 #define gan_mat_realloc(A,rows,cols) gan_mat_realloc_gen(A,rows,cols)
01112 
01125 #ifdef __cplusplus
01126 }
01127 #endif
01128 
01129 #endif /* #ifndef _GAN_MAT_GEN_H */

Generated on Fri Mar 17 12:44:47 2006 by  doxygen 1.3.9.1