help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] How GSL decide the stride of a gsl_vector


From: John D Lamb
Subject: Re: [Help-gsl] How GSL decide the stride of a gsl_vector
Date: Sun, 16 Feb 2014 20:56:52 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

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

[Prev in Thread] Current Thread [Next in Thread]