This is the mail archive of the gsl-discuss@sourceware.org mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: increment a single element of matrix/vector


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]