[Gretl-devel] Re: bug with "const" in function

2024-02-02 Thread Sven Schreiber

Am 02.02.2024 um 15:12 schrieb Allin Cottrell:


Right, but that happens automatically within any given gretl process, 
regardless of whether any series, or list of series, is passed to the 
called function. As a trivial illustration:



In the MPI context the dataset (if present) is not automatically 
passed between distinct gretl processes, but this is ensured by the 
--send-data option for a mpi block. Another trivial illustration:


Aha! That's very interesting, I wasn't aware of it, because I thought it 
would go against the idea of function encapsulation. But very useful 
here, so I don't need any workaround, it seems.
There's one gotcha to note here. If you don't need to pass the entire 
dataset in the MPI context you can use --send-data=L, where L is a 
list of series, BUT this won't work if L contains just const. That's 
because inter-process transfer of data is done using a gdt or gdtb 
file, and "const" is not explicitly represented in such a file. Trying 
to save a gdt[b] file containing no series other than const will fail 
with the message "No data to save!". It's fine if L contains just a 
single series, but it can't be series 0. 

That's OK.
You could insert "list L = index" before the mpi block above, and make 
the option --send-data=L.
I guess a "genr index" would also be needed, because not every existing 
dataset has the index series. But it's not really needed anyway.


Anyway, the behavior you found with exists() is clearly wrong, and I'm 
satisfied that a proper fix can be engineered: we'll give the called 
function a copy of const under the parameter name rather then doing 
the "shift and rename" thing. That should be in git quite soon.



OK, good.

sven
___
Gretl-devel mailing list -- gretl-devel@gretlml.univpm.it
To unsubscribe send an email to gretl-devel-le...@gretlml.univpm.it
Website: 
https://gretlml.univpm.it/postorius/lists/gretl-devel.gretlml.univpm.it/


[Gretl-devel] Re: bug with "const" in function

2024-02-02 Thread Allin Cottrell

On Fri, 2 Feb 2024, Sven Schreiber wrote:


Am 02.02.2024 um 01:42 schrieb Allin Cottrell:


However, that treatment of the "const" modifier cannot work when 
the series passed is the one named "const" (with ID number 0). 
That series is supposed to be automatically available at all 
levels of function execution,


Well, but only if the dataset context is passed on to the called 
function, right?


Right, but that happens automatically within any given gretl 
process, regardless of whether any series, or list of series, is 
passed to the called function. As a trivial illustration:



function void f (void)
   print const
   smpl
end function

nulldata 8
setobs 4 2016:1
f()


In the MPI context the dataset (if present) is not automatically 
passed between distinct gretl processes, but this is ensured by the 
--send-data option for a mpi block. Another trivial illustration:



function void f (void)
   printf "process %d\n", $mpirank
   print const
   smpl
end function

nulldata 8
setobs 4 2016:1
mpi --send-functions --send-data
   f()
end mpi --np=2


There's one gotcha to note here. If you don't need to pass the 
entire dataset in the MPI context you can use --send-data=L, where L 
is a list of series, BUT this won't work if L contains just const. 
That's because inter-process transfer of data is done using a gdt or 
gdtb file, and "const" is not explicitly represented in such a file. 
Trying to save a gdt[b] file containing no series other than const 
will fail with the message "No data to save!". It's fine if L 
contains just a single series, but it can't be series 0. You could 
insert "list L = index" before the mpi block above, and make the 
option --send-data=L.


Anyway, the behavior you found with exists() is clearly wrong, and 
I'm satisfied that a proper fix can be engineered: we'll give the 
called function a copy of const under the parameter name rather then 
doing the "shift and rename" thing. That should be in git quite 
soon.


Allin
___
Gretl-devel mailing list -- gretl-devel@gretlml.univpm.it
To unsubscribe send an email to gretl-devel-le...@gretlml.univpm.it
Website: 
https://gretlml.univpm.it/postorius/lists/gretl-devel.gretlml.univpm.it/


[Gretl-devel] Re: bug with "const" in function

2024-02-02 Thread Sven Schreiber

Am 02.02.2024 um 01:42 schrieb Allin Cottrell:


However, that treatment of the "const" modifier cannot work when the 
series passed is the one named "const" (with ID number 0). That series 
is supposed to be automatically available at all levels of function 
execution,


Well, but only if the dataset context is passed on to the called 
function, right? Otherwise no series is available inside, not even 
"const" (ID 0). This is the background of what I'm trying to achieve, 
with a little bit of borderline hacking. I'm working with MPI and 
(sometimes, not always in my general meta function) need to pass on the 
dataset context. And I thought the safest way is to use the series that 
always exists, namely "const".




This issue hasn't been reported before, which is not surprising since 
passing series 0 as an argument is in general pointless, since it's 
already available everywhere and is of no interest other than as the 
intercept in a regression. I think I see a way of making it harmless 
but I need to do some more testing before I'm sure.


Thanks. Again, the interest here is not the "const" series per se, but 
the idea is to "piggyback" the dataset context on an arbitrarily chosen 
series. But I think I can work around this particular problem; for 
example, two hackish pieces of syntax that work instead of the passed 
arg "const" are:


1) "(dataset)[1]" - assumes at least one other series, which is OK; not 
that "dataset[1]" didn't work


2) "deflist(const)[1]" - uglier, but also works

(More background explanation: I first tried to use a gretl list that is 
of more direct interest, but the problem was that this doesn't work in 
the also covered case that no dataset is present. That is, I can use the 
function arg specification 'series s[null]' and the null default also 
works without an active dataset, but 'list L[null]' yields an error 
then. I know this is because of the special behavior of lists, which 
always exist even when "null-ed" or omitted. But that's causing a 
problem here, hence my workaround with "const".)


If it's too dangerous to accommodate the passing of just "const" (and 
since usually there isn't much point in it), perhaps it's better to just 
ban it? Or perhaps ban the combination of passing "const" to a function 
that uses the const modifier for its arg?


thanks

sven
___
Gretl-devel mailing list -- gretl-devel@gretlml.univpm.it
To unsubscribe send an email to gretl-devel-le...@gretlml.univpm.it
Website: 
https://gretlml.univpm.it/postorius/lists/gretl-devel.gretlml.univpm.it/


[Gretl-devel] Re: bug with "const" in function

2024-02-01 Thread Allin Cottrell

On Thu, 1 Feb 2024, Sven Schreiber wrote:

this is a bug that is probably triggered only in unusual circumstances, but 
it happened to me in a kind-of real world function development scenario:



function void serc (const series s) # the 'const' here is important
    if exists(s)
    print "to be"
    else
    eval typename(s)
    print "or not to be"
    endif
end function

open denmark
print "call 1"
serc(LRM)

print "call 2"
serc(const)    # "const" is a series ID 0 in all datasets

# -> produces "null" and "or not to be", as if "s" inside
# the function didn't exist



This behavior has been there "forever" (or more precisely, ever 
since the "const" modifier for hansl function arguments has been 
supported).


It's quite an interesting problem. When a series is given as a 
function argument without the "const" modifier, gretl gives the 
function a copy of the incoming series, under the name given by the 
function parameter. But when the "const" flag is given, the series 
in question is shifted from the function-execution level of the 
caller to that of the callee, and is renamed using the parameter 
name -- and then these changes are reverted when the function exits.


However, that treatment of the "const" modifier cannot work when the 
series passed is the one named "const" (with ID number 0). That 
series is supposed to be automatically available at all levels of 
function execution, and renaming it would make in unavailable under 
its proper name inside the function -- a real bug.


This issue hasn't been reported before, which is not surprising 
since passing series 0 as an argument is in general pointless, since 
it's already available everywhere and is of no interest other than 
as the intercept in a regression. I think I see a way of making it 
harmless but I need to do some more testing before I'm sure.


Allin___
Gretl-devel mailing list -- gretl-devel@gretlml.univpm.it
To unsubscribe send an email to gretl-devel-le...@gretlml.univpm.it
Website: 
https://gretlml.univpm.it/postorius/lists/gretl-devel.gretlml.univpm.it/