[GSLL-devel] making copy-to working in clisp+grid: fix to element-type
Liam Healy
lhealy at common-lisp.net
Thu Dec 26 01:07:53 UTC 2013
Your solution is not a good one, because if a general array is passed to
copy-to it will cause an error if all the elements are not the same type as
the first one. For example, (copy-to #(1.0d0 1)) will behave incorrectly.
By the way, your example with #(1d0 2d0) fails on SBCL as well, and should
fail everywhere because #( ) is making a general (T) array. It is
unfortunate that CLISP apparently does not have specialized arrays, but the
proper solution is to use a different function.
The correct solution when copying from a general array is to explicitly
specify the element-type. This capability is provided by the function #'copy
(copy #(1d0 2d0) :grid-type 'grid:foreign-array :element-type 'double-float)
The function #'copy-to is provided merely as a convenient shortcut to using
#'copy which works in many situations. The solution to your problem is to
use copy with explicit element-type instead of copy-to. After debating
whether to eliminate copy-to, I have added another optional argument,
element-type, that defaults to *default-element-type*, and this should fix
your problem. However, it is meant only as a convenience for interactive
code, it should really not be put into files relying on the default value
specials which may be changed. So I have also removed its use in GSLL
itself. This change is untested and made in 86671c4ef057, which is in the
multiple-systems branch and will be merged into master soon.
I have added antik-devel to this email because this an Antik issue and has
nothing to do with GSLL.
On Fri, Jan 4, 2013 at 10:39 AM, Mirko Vukovic <mirko.vukovic at gmail.com>wrote:
> The following works in sbcl+grid:
>
> (copy-to (make-array 2 :element-type 'double-float :initial-contents
> '(1.0d0 2.0d0)) 'grid:foreign-array)
>
> But it does not work in clisp+grid.
>
> The root cause lies in the function grid/array.lisp/element-type. It uses
> `(array-element-type grid)'.
>
> But this can present a problem. Quoting hyperspec:
>
> (Because of *array* <http://26_glo_a.htm#array> *upgrading*, this *type
> specifier* <http://26_glo_t.htm#type_specifier> can in some cases denote
> a *supertype* <http://26_glo_s.htm#supertype> of the *expressed array
> element type* <http://26_glo_e.htm#expressed_array_element_type> of the
> *array*.)
>
> In CLISP, array-element-type returns `T' when passed #(1d0 2d0)
>
> It returns T even when passed a simple array:
>
> (array-element-type (make-array 2 :element-type 'double-float
> :initial-contents
> '(1.0d0 2.0d0)
> :adjustable nil
> :fill-pointer nil
> :displaced-to nil) )
>
> The proposed fix is
>
> (defmethod element-type ((grid array))
> (type-of (row-major-aref grid 0))
> #+skip(array-element-type grid))
>
> Now copy-to works in clisp as well.
>
> Mirko
>
>
>
> _______________________________________________
> GSLL-devel mailing list
> GSLL-devel at common-lisp.net
> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/gsll-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/gsll-devel/attachments/20131225/0b3f3f0e/attachment.html>
More information about the gsll-devel
mailing list