00001
00011 #ifndef _BASIC_FUNCTIONS_BASSO_H_
00012 #define _BASIC_FUNCTIONS_BASSO_H_
00013
00014 #include "basso.h"
00015
00016 namespace basso {
00017
00018
00019
00027 Numeric norm( const nArray &a, int type=2 )
00028 {
00029 switch ( type )
00030 {
00031 case 0:
00032 return vect_norminf(a);
00033
00034 case 1:
00035 return vect_norm1(a);
00036
00037 case 2:
00038 return vect_norm2(a);
00039
00040 default:
00041 WarningMessage("norm","unknown norm type, returning L2 norm");
00042 return vect_norm2(a);
00043 }
00044 }
00045
00054 Numeric normalize( nArray &a, int type=2 )
00055 {
00056 Numeric n=norm(a,type);
00057 for ( int i=0; i<a.size(); ++i )
00058 a[i] = a[i] / n;
00059 return n;
00060 }
00061
00063 void cross_prod( const nArray &a, const nArray &b, nArray &c )
00064 {
00065 #ifdef ALLOW_DYNAMIC_RESIZE
00066 if ( vect_size(c)!=3 )
00067 resize( c, 3 );
00068 #elif EXPLICIT_BOUNDS_CHECK
00069 if ( vect_size(c)<3 || vect_size(a)<3 || vect_size(b)<3 )
00070 WarningMessage("cross_product","invalid size of vectors, must be of dimension 3");
00071 #endif
00072 c[0]=a[1]*b[2]-a[2]*b[1];
00073 c[1]=a[2]*b[0]-a[0]*b[2];
00074 c[2]=a[0]*b[1]-a[1]*b[0];
00075 }
00076
00084 void outer_prod ( const nArray &a, const nArray &b, nMatrix &c, Numeric alpha=1.0 )
00085 {
00086 #ifdef ALLOW_DYNAMIC_RESIZE
00087 if ( mat_nrows(c)!=vect_size(a) || mat_ncols(c)!=vect_size(b) )
00088 resize( c, a.size(), b.size() );
00089 #elif EXPLICIT_BOUNDS_CHECK
00090 if ( mat_nrows(c)!=vect_size(a) || mat_ncols(c)!=vect_size(b) )
00091 WarningMessage("outer_product","incompatible dimensions");
00092 #endif
00093 for ( int i=0; i<vect_size(a); ++i )
00094 for ( int j=0; j<vect_size(b); ++j )
00095 c(i,j)=alpha*a[i]*b[j];
00096 }
00097
00098
00099 }
00100
00101 #endif