[GSLL-devel] grid:map-n-grids does not play nice with gsll:make-interpolation
Mirko Vukovic
mirko.vukovic at gmail.com
Sun Nov 6 14:53:56 UTC 2011
On Thu, Nov 3, 2011 at 3:02 PM, Mirko Vukovic <mirko.vukovic at gmail.com>wrote:
> The following is using a a few months old GSLL and SBCL -- I do not want
> to upgrade unless absolutely necessary at this moment, because I need to
> finish a project first.
>
> Consider the following function:
>
> (defun foo (x y)
> (let ((z (grid:map-n-grids :combination-function (lambda (y)
> y)
> :sources `((,y nil)))))
> (gsll:make-interpolation gsll:+linear-interpolation+
> x z)))
>
> If I call it twice with vectors of different size on the second call
>
> (let ((x #m(1d0 2d0 3d0))
> (y #m(1d0 1d0 1d0))
> (u #m(1d0 2d0 3d0 4d0))
> (v #m(1d0 1d0 1d0 1d0)))
> (foo x y)
> (foo u v))
>
> I get an error on the second call
>
> Invalid argument; data must match size of interpolation object in interp.c
> at line 76
> [Condition of type GSLL:INVALID-ARGUMENT]
>
> It seems that `z' still somehow lives with incorrect dimensions between
> the calls.
>
> In actual use, I call foo from repl. So, before calling it, I force a
> recompile, so that it works for a new vector.
>
> Is there a more elegant workaround for this problem?
>
> Thanks,
>
> Mirko
>
I figured out the cause of the error. In the function
(defun foo (x y)
(let ((z (grid:map-n-grids :combination-function (lambda (y)
y)
:sources `((,y nil)))))
(gsll:make-interpolation gsll:+linear-interpolation+
x z)))
I was defining sources using `((,y nil)) to save myself typing. But this
expands into a (cons ... ) list.
If I do it explicitly (list (list y nil)), the problem goes away.
The underlying reason is that `list' always creates a fresh list while
`cons' does not. Thus, lisp re-used the old cons while I really needed a
new list.
Mirko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/gsll-devel/attachments/20111106/fa2ce5f3/attachment.html>
More information about the gsll-devel
mailing list