On Fri, 30 Apr 2021, Allin Cottrell wrote:
Good idea; I think this could be useful in a number of contexts.
I'm reluctant to mess with git master when we're about to release, but in a
local branch I've tried adding a libgretl function to this effect (diff
against master attached).
Ahh, thanks. I agree that this should not be for the imminent release: I
just wanted to share the idea before I forget about it.
Two small comments:
(1) I've named my built-in function inset() rather than any().
Fine by me, any() was a provisional placeholder anyway; inset() is a
better name IMO. Actually, as Artur noted (see below), there is an any()
function in Matlab which, however, does something different, so maybe
calling the present function "any()" would be a little confusing to people
who come to hansl form a Matlab background.
(2) I've switched the order of the arguments: it seems to me a
little more
intuitive to call
inset(S, whatever)
where S is the "set" and "whatever" is the object to be assessed in
term of
membership of the set (scalar, series or matrix).
Funny, I find it more intuitive to have it the other way around, in the
same way as you write $x \in S$ (using TeX notation). I guess it's a
matter of personal taste.
One further point: hansl has no concept of "set" as such;
the doc for such a
function would have to make clear that the "S" argument is a matrix standing
in for a set (with numeric elements only). Ideally, therefore, S would be a
vector with no repeated elements.
But my inset(), like your any(), is permissive on that point. An arbitrary
matrix will be accepted: the row/column structure is ignored and repeated
elements are tolerated but will just slow things down.
Yes. An if one wanted to avoid unnecessary comparison, you always have
uniq(vec(S)).
On Sat, 1 May 2021, Artur T. wrote:
Below I added another case which is, however, not supported, as
matrices are
not supported by the meta-type 'numeric' (yet?): array of matrices.
[...]
elif typeof(X) == 6 # untested
matrix ret = array(nelem(X))
loop i=1..nelem(X)
matrix m = X[i]
# matrix
scalar r = rows(m)
scalar c = cols(m)
matrix rtmp = maxr(vec(m) .= vec(A)')
ret[i] = mshape(rtmp, r, c)
endloop
Heh; or we could go for the garatuitously showoff-ish way
elif typeof(X) == 6 # untested
matrix ret = array(nelem(X))
loop i=1..nelem(X)
ret[i] = any(X[i], A)
endloop
I guess that Jack had Matlab's function name in mind:
https://www.mathworks.com/help/matlab/ref/any.html
Ah, I wasn't even aware of it; anyway, inset() is fine as far as I'm
concerned (also: see above)
True, the term 'set' is a bit misleading here. Suppose at
some point in
future, gretl supports a set, the naming of this inset() function may confuse
people as it's not really about a set of values.
We already have the following functions:
- inlist()
- inbundle()
- instring()
- instrings()
Following this list, a candidate name may be innumeric() or innum().
Uhm, no, sorry, I find this quite ugly :D
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------