On Friday 06 July 2007 03:54:08 Allin Cottrell wrote:
On Wed, 4 Jul 2007, Ignacio Diaz-Emparanza wrote:
> If you want to use a matrix in a function pakage, the matrix
> need to be declared previously...
I have just put in place a new Windows snapshot which should
have better error-reporting for user-defined functions.
As for the issue of "matrix needs to be declared previously",
there are two cases:
A. The matrix argument is direct or by-value, of type "matrix".
In this case it is indeed an error if you type a name to which
there corresponds no pre-existing matrix. This error should now
be flagged properly.
OK, this is an input matrix and needs to be known previously. I think Gretl
works well in this case.
B. The matrix argument is indirect or by-reference, of type
"matrix *". In this case, if you type a name, and no matrix
exists of that name, a new "null matrix" [in fact, a 1 x 1 matrix
with value 0] will be created automatically and supplied as the
argument in question.
The point is that in case B it's plausible that the function is
not interested in the original content of the matrix. but is
rather offering to re-size and fill the matrix with something that
might be of interest to the caller. (Obviously, if you as the
writer of a function package actually expect valid incoming
information in such an indirect matrix argument, you'll have to
check for this.)
This is exactly the case. My function is not interested in the original
content of the matrix, but does some calculations to fill it.
The problem is that the behaviour in Linux is correct, but in Windows, the
original matrix must be previously declared.
I've taken another look at the code, and I don't see anything
relevant that should differ between Linux and Windows -- though.
of course, I could have missed some weird subtlety!
I tried now with the current Windows snaphot and the problem is there.
The function that originated this naive "matrixdec" package was
function matrixdec (series Y, matrix *inreg)
series yl = Y(-1)
return series yl
I am writing this small package because my real function is very complicated.
But I am reproducing the problem perfectly with this small package. The
matrix "inreg" is computed internally in my real package and its value should
be assigned to the matrix name the user provides in the dialog box. In this
small matrixdec package I am not assigning internally a value to the matrix,
but this is not a problem (I can run it perfectly in Linux).
To run the package in Linux I open a time series data file (data3-6, for
example) and select "/File/Function Files/On local machine" and
select "matrixdec". In the dialog box I put, for example, Ct in the series
field, blabla (or whatever you want) in the matrix "inreg" field, and any
name (dC) in the return field. Clicking on "ok" the series with the first lag
of Ct is computed (I know it is silly, but serves as an example). The main
window normally it is not automatically refreshed so you can
select "/Data/Refresh window" to see the new created series dC.
If I follow the same steps in Windows, when I click on the "ok" button in the
dialog box I obtain the error "Unspecified error".
I do not obtain the error if, before executing the function, I open a gretl
console and run the command "matrix blabla".
DEPARTAMENTO DE ECONOMÍA APLICADA III (ECONOMETRÍA Y ESTADÍSTICA)
Avda. Lehendakari Aguirre, 83 | 48015 BILBAO
T.: +34 946013732 | F.: +34 946013754