On 16/02/14 16:54, Shikai Luo wrote:
I was just wondering how GSL decide the stride when I allocate memory
for a gsl_vector?

You decide the stride. If you use gsl_vector_alloc() the stride is 1. But if you use, for example gsl_vector_subvector_with_stride() you can choose a different stride.

I need to use STL generic algorithms on gsl vector and matrix, so I need
the stride to be 1,

You could try some C++ wrappers I wrote for gsl, http://ccgsl.sourceforge.net/ These cover most of gsl-1.16 except things like sorting, which STL provides. These are just headers so you could extract the files you need for gsl::vector and gsl::matrix. These are thoroughly tested and allow you to do stuff like:

using namespace std;
using namespace gsl;

vector v( 7 );
for( size_t i = 0; i < v.size(); ++i )
  v[i] = sqrt( i );

or even, with a gsl::matrix M and C++11,

for( size_t i { 0 }; i < M.size2(); ++i )
  auto col { M.col( i ) };
  for( auto e : col )
    cout << e << " ";
  cout << endl;

Note that the stride doesn’t matter here because the vector class has an iterator that works with any stride.

Alternatively, try Andrew Steiner’s
http://o2scl.sourceforge.net/
which has similar functionality.

--
John D Lamb

Reply via email to