On Mon, Mar 2, 2026 at 1:44 PM Sven Schreiber
<sven.schreiber(a)fu-berlin.de> wrote:
Am 02.03.2026 um 19:04 schrieb Riccardo (Jack) Lucchetti:
>
> From time to time, when writing hansl code, I find myself having to
> select parts of a matrix based on some logical condition. In many
> cases, selifr/selifc do the job very well, but it's often useful to
> keep the indices of the relevant rows/columns. In this cases, it'd be
> nice to have a function vaguely like R's which(), possibly adapted to
> the matrix case. For example [...]
>
> Of course, as the example above shows, it's quite easy to code this in
> hansl, but perhaps this is one of those cases when we want to have
> this done in C for maximum efficiency. Thoughts?
>
Just for fun, below is a variation that I personally find a little more
intuitive. Now you can start your speed comparisons ;-) But seriously,
since no loops are involved or anything, would there really be a
noticeable speed gain of moving this fully to C?
OK, I've been running my stopwatch. The hansl codes shown by Jack and
Sven both run fast. Jack' s is a little faster, in my testing. But I
also tried coding it in "libgretl-C" and found that Sven's final point
is supported: the speed difference vs hansl is negligible.
I should maybe add: faster execution is not necessarily the only
reason to code some functionality in C, as a built-in gretl function,
rather than in a function package. Ease of access is also relevant.
Allin
Allin