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: Rhys Ulerich <rhys dot ulerich at gmail dot com>
- Cc: "gsl-discuss at sourceware dot org" <gsl-discuss at sourceware dot org>
- Date: Tue, 28 Jan 2014 14:26:25 -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> <52E71EC5 dot 800 at colorado dot edu> <52E816F8 dot 9050405 at colorado dot edu> <CAKDqugRbqu-jsBTpzQ-rKFXXnZyp6sUqf2LVgU8M9p-SawxKjw at mail dot gmail dot com>
On 01/28/2014 02:16 PM, Rhys Ulerich wrote:
*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.
Yes sorry I didn't see the * the first time I read that
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
Hmm ok you convinced me, I'll reverse those last few commits