ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.2k stars 142 forks source link

SRFI 231: specialized-array-reshape issues #986

Closed gambiteer closed 2 months ago

gambiteer commented 2 months ago

The first is correct:

heine:~/programs/chibi-scheme> chibi-scheme 
> (import (srfi 231))
> (specialized-array-reshape (array-sample (array-copy (make-array (make-interval '#(3 4)) list)) '#(2 1)) (make-interval'#(8)))
ERROR: can't reshape
    #<Array 140652817941600>
    #<Interval 140652813848640>

This should work:

> (specialized-array-reshape (array-sample (array-copy (make-array (make-interval '#(3 4)) list)) '#(2 1)) (make-interval'#(8)) #t)
ERROR: assertion failed
    (and (mutable-array? destination) (array? source) (interval= dest-domain source-domain))
    (destination #<Array 140652812854464>)
    (source #<Array 140652812792992>)
    (dest-domain #<Interval 140652812196256>)
    (source-domain #<Interval 140652812567712>)

This fails, too. It's probably just another place where empty arrays need be treated specially:

> (specialized-array-reshape (make-specialized-array (make-interval '#(1 2 0 4))) (make-interval '#(2 0 4)))
ERROR in lp on line 461 of file /usr/local/chibi//share/chibi/srfi/231/base.scm: divide by zero
gambiteer commented 2 months ago

And this should return foo:

> (array->list*
  (specialized-array-reshape           ;; Reshape to a zero-dimensional array
   (array-extract                      ;; Restrict to the first element
    (make-specialized-array-from-data  ;; The basic one-dimensional array
     (vector 'foo 'bar 'baz))
    (make-interval '#(1)))
   (make-interval '#())))
ERROR in interval-lower-bound on line 80 of file /usr/local/chibi//share/chibi/srfi/231/base.scm: vector-ref: index out of range
    #()
    0
ashinn commented 2 months ago

Handled the empty/zero cases, looks like I just never properly implemented the copy-on-failure path.