• API Main Page
  • Documentation
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

src/linalg.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2010 by Matthias Ihrke                                  *
00003  *   ihrke@nld.ds.mpg.de
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   aint with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00031 #ifndef LINALG_H
00032 # define LINALG_H
00033 #include "definitions.h"
00034 #include "array.h"
00035 #include <gsl/gsl_matrix.h>
00036 
00049 #define matrix_CHECK( flag, m )                                                 \
00050   if( (m)==NULL ){                                                                  \
00051      errprintf("got NULL as matrix\n");                                         \
00052      flag=FALSE;                                                                        \
00053   } else if(!( (m)->ndim==2 && (m)->dtype==DOUBLE )){                       \
00054      char *dts="";                                                                      \
00055      array_DTYPESTRING( dts, m->dtype );                                        \
00056      errprintf("not a matrix, ndim=%i, dtype=%s\n", m->ndim, dts ); \
00057      flag=FALSE;                                                                        \
00058   } else { flag=TRUE; } 
00059 
00072 #define matrix_CHECKSQR( flag, m )                                                  \
00073   if(!( (m)->ndim==2 && (m)->dtype==DOUBLE )){                                  \
00074      char *dts="";                                                                          \
00075      array_DTYPESTRING( dts, (m)->dtype );                                          \
00076      errprintf("not a matrix, ndim=%i, dtype=%s\n", (m)->ndim, dts );       \
00077      flag=FALSE;                                                                            \
00078   } else if( (m)->size[0]!=(m)->size[1] ) {                                     \
00079      errprintf("Matrix is not square, got (%i,%i)\n",(m)->size[0],(m)->size[1]); \
00080      flag=FALSE;                                                                            \
00081   } else { flag=TRUE; }                                                             
00082 
00089 #define mat_IDX( m, i, j )                              \
00090   array_INDEX2( m, double, i, j )
00091 
00098 #define vec_IDX( v, i )                                 \
00099   array_INDEX1( v, double, i )
00100 
00113 #define vector_CHECK( flag, v )                                                     \
00114   if( (v)==NULL ){                                                                      \
00115      errprintf("got NULL as vector\n");                                             \
00116      flag=FALSE;                                                                            \
00117   } else if(!( (v)->ndim==1 && (v)->dtype==DOUBLE ) ){                      \
00118      char *dts="";                                                                          \
00119      array_DTYPESTRING( dts, v->dtype );                                            \
00120      errprintf("not a vector, ndim=%i, dtype=%s\n", v->ndim, dts );     \
00121      flag=FALSE;                                                                            \
00122   } else { flag=TRUE; }                                                             
00123 
00124 
00125 #ifdef __cplusplus
00126 extern "C" {
00127 #endif
00128 
00129   /* -------------- FUNCTIONS ---------------- */
00130   gsl_matrix* matrix_to_gsl( Array *in, bool alloc );
00131 
00132   Array* matrix_get_col( Array *m, int col );
00133   Array* matrix_get_row( Array *m, int row, bool alloc );
00134   
00135   Array* matrix_mult( const Array *m1, const Array *m2 );
00136   Array* matrix_transpose( Array *m, bool alloc );
00137 
00138   Array* matrix_mean( Array *a, int dim );
00139   Array* matrix_pca( Array *X, Array **var, bool alloc );
00140 
00141 
00142 #ifdef __cplusplus
00143 }
00144 #endif
00145 
00146 #endif /* LINALG_H */

Generated on Fri Jun 25 2010 14:10:19 for libeegtools by  doxygen 1.7.0