Re: Is this a bug in 'read-vector?
Raymond Toy <[email protected]>
| Newsgroups | gmane.lisp.cmucl.general |
|---|---|
| Message-ID | <[email protected]> |
>>>>> "Jeffrey" == Jeffrey Cunningham <[email protected]> writes: Jeffrey> I have been trying to read large binary files of floating point data Jeffrey> using CMUCL (19c). I thought I would have to do it using some form of Jeffrey> FFI and went to comp.lang.lisp for help getting that working. I Jeffrey> succeeded. But Duane Rettig at Allegro suggested it would be easier to Jeffrey> use 'read-vector. So I tried that as follows: Jeffrey> (let ((vec (make-array 10 :element-type 'double-float))) Jeffrey> (with-open-file (os "d10.bin") Jeffrey> (read-vector vec os) Jeffrey> (print vec))) Jeffrey> where "d10.bin" is a double-float binary file containing 10 Jeffrey> elements. When I try to read the file it produces the following error: Jeffrey> Type-error in KERNEL::OBJECT-NOT-DOUBLE-FLOAT-ERROR-HANDLER: Jeffrey> #\Null is not of type DOUBLE-FLOAT First, thanks for entering a ticket for cmucl on this issue! Second, I've looked a bit more. The ticket has my response, but in a nutshell, CMUCL has two versions of read-vector. The version you used is EXT:READ-VECTOR and has the bug. But if you (require 'simple-streams), and use this (note the :class arg): (let ((vec (make-array 10 :element-type 'double-float))) (with-open-file (os "d10.bin" :class 'stream:file-simple-stream) (stream:read-vector vec os) (print vec))) everything works as you expect. I think we should make EXT:READ-VECTOR work the same as STREAM:READ-VECTOR, especially since EXT:READ-VECTOR is significantly faster (order of magnitude or more) than STREAM:READ-VECTOR. Ray