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: Klaus Huthmacher
Subject: Re: [Help-gsl] How GSL decide the stride of a gsl_vector
Date: Mon, 17 Feb 2014 09:10:32 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130922 Icedove/17.0.9

Hi Shikai Luo,

I agree with the previous mail from John D Lamb, use C++11 whenever possible.

I appended a minimal example for some usage of gsl stuff, e.g. using unique_ptr, STL, etc.

Best wishes,

    Klaus.


On 16.02.2014 21:56, John D Lamb wrote:
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.


Attachment: mb.cpp
Description: Text Data

Attachment: huthmacher.vcf
Description: Vcard


reply via email to

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