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: Rhys Ulerich <rhys dot ulerich at gmail dot com>
- To: Patrick Alken <patrick dot alken at colorado dot edu>
- Cc: gsl-discuss at sourceware dot org
- Date: Tue, 28 Jan 2014 15:16:09 -0600
- 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> <52E71EC5 dot 800 at colorado dot edu> <52E816F8 dot 9050405 at colorado dot edu>
>>>> *gsl_vector_ptr(v, i) += x
>> *(gsl_vector_ptr(v, i)) += x;
Why the extra parens? They hurt nothing, but the former statement
without them works just fine for me. Unless I'm mistaken, the
function application happens before the dereference. And the
dereference is much, much higher than anything like += or *= that the
user might want.
>> This could lead to trouble so its probably better to have a function
>> which does range checking, etc.
There is range checking in gsl_vector_ptr, so long as someone doesn't
start doing pointer arithmetic on its result.
Lastly, the pointer-based solution is nicely general: *(i > j ?
gsl_vector_ptr(v, i) : gsl_vector_ptr(j)) += 1
- Rhys