one-line if conditions
by Sven Schreiber
Hi,
sorry, here's again one of my crazy syntactic sugar ideas: I think it
would be nice if hansl had a more concise way of writing a basic
if-endif block, where the thing to be executed is just a single line.
In other languages, this would be (AFAIK):
C:
if (<condition>) <execution> ;
Bash:
if <condition> ; then <execution> fi
Python:
if <condition> : <execution>
So "every" language has such convenient one-liners (OK, it seems Matlab
doesn't have it). I know hansl has the ternary expression (<condition> ?
<resultTRUE> : <resultFALSE>), but this always has an else branch in it.
Don't know whether using : or ; would be better for hansl in this
context. Perhaps a new keyword "iffi" could be used to signal this
construct to gretl / to the parser.
Obviously extremely non-urgent, but for a while I've had the feeling
that hansl code is quite a bit longer than it would have to be.
thanks
sven
1 year, 11 months
from time to $time ?
by Sven Schreiber
Hello once more,
as explained in section 10.1 of the user guide, there are few special
expressions that produce series and that are somewhat at odds with the
usual hansl syntax, for historical path-dependent reasons. One is
"time", which can either be used as "genr time" (not "series time",
which as per standard syntax produces a new series full of missings); or
it can be used in assignments such as "series x = time", even when
'time' wasn't previously defined or created.
Wouldn't it be more consistent to have a dollar accessor $time instead?
This would be just like the change from 'pi' to '$pi' in the past.
Pragmatically, "time" should stay for compatibility, but I believe $time
should be preferred.
thanks
sven
1 year, 11 months
eval and matrix right division (/)
by Sven Schreiber
Hi, there is a disconnect here somehow:
<console>
? m = ones(4,3)
? div = {1, 0.2, 5}
? X = m / div
Ungültiges Argument # = invalid arg
? eval m/ div
0,23810
0,23810
0,23810
0,23810
</console>
Given that as per the doc X should solve X*div = m, and div has dim 1x3,
m has dim 4x3, X having dim 4x1 seems OK. But obviously the result is
wrong and it's clear that in linear algebra terms there is no solution.
So what is eval doing there?
thanks
sven
1 year, 11 months
print, range, and bundles
by Sven Schreiber
Hi, another small glitch when stuff is inside a bundle:
<hansl>
m = seq(1,10)' - 0.1
bundle bb = _(m)
print m --range=1:5 # works
print bb.m --range=1:5 # range is ignored
</hansl>
thanks
sven
1 year, 11 months
different degrees of lazy evaluation
by Sven Schreiber
Hi, sometimes I was under the impression that hansl supports lazy
evaluation of boolean expressions, and sometimes I thought that no, it
doesn't. And turns out I was right because it seems to depend. Consider
this:
<hansl>
clear # neither a nor b exist
eval 1==2 && a==b # lazy works, FALSE no matter what a or b
eval 1==1 || a==b # lazy fails, even though it's always TRUE
</hansl>
For me a frequent use case for the OR case is a function argument check
with a null default, something like:
if !exists(s) || s==""
So of the string argument s was passed into the function as 'null' the
first part is TRUE, but gretl still goes on to check s=="" and then
complains that s isn't defined.
I think it would be good to have lazy evaluation also in the OR case. Or
--to make it less confusing-- ban it entirely, also for the AND case,
although I'm not in favor of that.
I can think of some subtleties concerning NA values and lazy boolean
evaluations, but then again, we already have it partly, so it doesn't
seem to be so problematic.
cheers
sven
1 year, 11 months
--decr option for index loops
by Sven Schreiber
Hi,
the mentioned option (recently introduced in 2022b according to the
changelog) doesn't seem to be documented yet.
(If anybody is wondering, here's an example:
loop i = 10..1 --decr
print i
endloop
)
thanks
sven
1 year, 11 months
more specific error matrix for eigen()?
by Sven Schreiber
Hi,
in lib/src/gretl_matrix.c inside the real_gretl_dgeev function on line
9797 I'm seeing:
if (gretl_is_null_matrix(A) || A->rows != A->cols) {
*err = E_INVARG;
return NULL;
leading to the user-level generic error message "invalid argument" for
example for non-square matrix input into the eigen() function.
Do we have some error other than E_INVARG that we could use here to
yield something a little more informative?
thanks
sven
1 year, 11 months
small issue with error message for 'genseries' with bundle
by Sven Schreiber
Hi,
consider this example:
<hansl>
open denmark
bundle b = _(y=LRM)
list L = const
L += genseries("L", b.y)
</hansl>
This rightly gives an error, since genseries tries to create a series
"L", where the identifier "L" is already occupied by the defined list
before. But the error message is a little opaque: "variable number -1
out of bounds".
Of course, the return value -1 just signals an error. And if this wrong
construction is executed without the bundle sauce on top of it, then
gretl also says "object type list not acceptable in this context", which
is informative. But: in the example above this additional message is not
printed out, just the out of bounds reply.
Not very important, I know, but I stumbled over it in real code.
thanks
sven
1 year, 11 months
MPI problems because of complex numbers?
by Sven Schreiber
Hi,
I have been struggling with a function of mine that uses MPI and gave me
mysterious errors only in some cases (always hard to debug MPI stuff on
Windows anyway). But I think I may have found some indication of what's
going on, consider this:
<hansl>
mpi --send-functions
switch = 5
if switch == 2
m = ones(2) # works
elif switch == 3
m = eigen(mnormal(3,3)) # fails
elif switch == 4
m = mnormal(3,3) # works (in isolation)
m = eigen(m) # fails with this
elif switch == 5
m = complex(zeros(5), ones(5)) # fails
endif
if $mpirank==0
print m
endif
# and everything works if the following is commented out
mpireduce(&m, vcat) # same with "vcat" in quotes
end mpi --np=2
</hansl>
It seems to me that mpireduce() cannot handle the new complex-valued
matrices. If that hypothesis is correct, is it because the gretlmpi.exe
program that is shipped with gretl on Windows wasn't updated when the
new complex number handling was introduced? Or is it because the
mpi-related stuff simply wasn't adjusted in the source? Or some other
reason? In any case, it would be very interesting, of course, if it
works on Linux.
This is with the Dec 22nd snapshot on Windows 10. MPI in general is
working fine here (see the working examples in the code above).
thanks
sven
1 year, 11 months
problem with advanced regls (Lasso) use
by Sven Schreiber
Hi,
I want to run the Lasso with gretl's recent regls addon as a helper
function for another algorithm, not as a main application. Also, it's
inside a matrix-based specialized function, so I can't use the official
regls() function which AFAIK only works with series and lists, not with
matrices. (So I would request the feature that the standard regls()
function accept matrix input; perhaps this issue came up before.)
So I've tried to use the "hidden" internal function _regls() (note the
underscore) that I found in the hansl code of regls. In the addon's
code, it seems to take two matrices and a bundle as input. The following
attempt to imitate this failed, however:
<hansl>
include regls.gfn
matrix X = mnormal(200,5)
matrix Y = mnormal(200)
bundle reglsret = _(xvalidate=FALSE, estimator="LASSO", lfrac=0.2,
stdize=FALSE)
err = _regls(X, Y, reglsret) # use internal function for matrix stuff
</hansl>
I get an error message "datatypes not conformable".
Can such an approach be made to work?
thanks
sven
1 year, 11 months