help-gsl
[Top][All Lists]
Advanced

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

Re: [Help-gsl] Wrong result in vector from gsl_vector_alloc_col_from_mat


From: Stephan Petzchen
Subject: Re: [Help-gsl] Wrong result in vector from gsl_vector_alloc_col_from_matrix
Date: Wed, 14 Nov 2012 08:25:12 +0100

Fantastic. Thanks so much!!!!

Output is fine now.

Best,

Stephan

On Wed, Nov 14, 2012 at 8:07 AM, Peter Johansson <address@hidden> wrote:

>  On 11/14/2012 04:50 PM, Stephan Petzchen wrote:
>
> Hi Peter,
>
>  thanks for your reply.
>
>
>
>  Here is my code:
>
>  uint coffset=4;
>
>  /// 1 1 1 1 1 1 1
>  /// 2 2 2 2 2 2 2
> /// 3 3 3 3 3 3 3
> /// 4 4 4 4 4 4 4
> gsl_matrix* m=gsl_matrix_calloc(4,7);
>
>  for(int i=0;i < m->rows; i++)
>  for(int j=0;j < m->columns; j++)
>  m->data[i * m->tda + j]=i+1;
>
>  //Expected:
> /// x x x x 1 x x
> /// x x x x 2 x x
> /// x x x x 3 x x
> /// x x x x 3 x x
> gsl_vector* v = gsl_vector_alloc_col_from_matrix(m,coffset);
>
>  /// But GSL gives:
> /// x x x x 1 1 1
> /// 1 x x x x x x
> /// x x x x x x x
> /// x x x x x x x
> for(int i=0;i < v->size; i++)
>  Assert.AreEqual(m->data[i * m->tda + coffset],v->data[i]);
>
> Here is the problem. Rather than access data in 'v' directly, you should
> access the vector with function
>
> gsl_vector_const_ptr(v, i);
>
> which will take the stride into account which is 7 in this case.
>
> Hope that helps.
>
> Cheers,
> Peter
>


reply via email to

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