00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include<gslwrap/vector_double.h>
00018 #include<gslwrap/vector_float.h>
00019
00020 #define type_is_float
00021 #ifdef type_is
00022 #define type_is_double
00023 #endif
00024
00025 namespace gsl
00026 {
00027
00028
00029 vector_float_view
00030 vector_float::create_vector_view( const gsl_vector_float_view &other )
00031 {
00032 vector_float view;
00033 view.gsldata = (gsl_vector_float*)malloc(sizeof(gsl_vector_float));
00034 *(view.gslobj()) = other.vector;
00035 view.gslobj()->owner = 0;
00036 return view;
00037 }
00038
00039 void
00040 vector_float::resize(size_t n)
00041 {
00042 if (gsldata)
00043 {
00044 if (n==size())
00045 return;
00046 if (!gsldata->owner)
00047 {
00048 cout << "vector_float::resize ERROR can't resize a vector view" << endl;
00049 exit(-1);
00050
00051 }
00052 free();
00053 }
00054 alloc(n);
00055 }
00056
00057 void
00058 vector_float::copy(const vector_float& other)
00059 {
00060 resize(other.size());
00061 gsl_vector_float_memcpy (gsldata,other.gsldata);
00062 }
00063
00064 bool
00065 vector_float::operator==(const vector_float& other) const
00066 {
00067 if (size() != other.size())
00068 return false;
00069 for (int i=0;i<size(); i++)
00070 {
00071 if (this->operator[](i) != other[i])
00072 return false;
00073 }
00074 return true;
00075 }
00076
00077 vector_float_view
00078 vector_float::subvector (size_t offset, size_t n)
00079 {
00080 gsl_vector_float_view view = gsl_vector_float_subvector (gsldata, offset, n);
00081 return vector_float_view::create_vector_view(view);
00082 }
00083
00084
00085 const vector_float_view
00086 vector_float::subvector (size_t offset, size_t n) const
00087 {
00088 gsl_vector_float_view view = gsl_vector_float_subvector (gsldata, offset, n);
00089 return vector_float_view::create_vector_view(view);
00090 }
00091
00092
00093 float vector_float::sum() const
00094 {
00095 int i;
00096 float sum = 0;
00097
00098 for ( i = 0; i < size(); i++ )
00099 {
00100 sum += gsl_vector_float_get(gsldata, i);
00101 }
00102
00103 return( sum );
00104 }
00105
00106 double
00107 vector_float::norm2() const
00108 {
00109 vector t=*this;
00110 return gsl_blas_dnrm2(t.gslobj());
00111 }
00112
00113 ostream&
00114 operator<< ( ostream& os, const vector_float & vect )
00115 {
00116 os.setf( ios::fixed);
00117 for (int i=0;i<vect.size();i++)
00118 {
00119 os << vect[i] << endl;
00120 }
00121 return os;
00122 }
00123
00124
00125
00126
00127
00128
00129 void
00130 vector_float_view::init(const vector_float& other)
00131 {
00132 free();
00133 gsldata = (gsl_vector_float*)malloc(sizeof(gsl_vector_float));
00134 *gsldata = *(other.gslobj());
00135 gsldata->owner = 0;
00136 }
00137
00138 }