This is the mail archive of the
gsl-discuss@sourceware.org
mailing list for the GSL project.
Re: increment a single element of matrix/vector
- From: Patrick Alken <patrick dot alken at Colorado dot EDU>
- To: "gsl-discuss at sourceware dot org" <gsl-discuss at sourceware dot org>
- Date: Mon, 27 Jan 2014 20:06:45 -0700
- Subject: Re: increment a single element of matrix/vector
- Authentication-results: sourceware.org; auth=none
- References: <52E6EFF3 dot 1000808 at colorado dot edu> <CAKDqugSbjFausECoC3Bm_JdYtOK9VwuG_nkOKtqk4A_e+Cb0Bw at mail dot gmail dot com> <CAKDqugRJE8PbH8FTvzhi3LudALpopcsSq14aa1K-Rs5pXY36Gg at mail dot gmail dot com>
On 01/27/2014 07:14 PM, Rhys Ulerich wrote:
>> *gsl_vector_ptr(v, i) += x
>
> Of course, make sure warnings about expressions without side effects
> are turned on. Otherwise it may be a long debugging session before
> you discover a
>
> gsl_vector_ptr(v, i) += x
>
> mistake for integer-like types.
>
> - Rhys
>
Nice find - unfortunately since it returns a pointer to the element, you
need to do:
*(gsl_vector_ptr(v, i)) += x;
This could lead to trouble so its probably better to have a function
which does range checking, etc. I'll think a little more on a good way
to do this.
Thanks,
Patrick