@@ -149,8 +149,6 @@ See also: @code{make-ra}
149149 (loop (+ k 1)))))))))
150150 (make-ra-root (%%ra-root oldra) dims (- ref (ra-offset 0 dims))))))))
151151
152- ; FIXME Depends on traversal order of ra-for-each.
153-
154152(define (ra->list ra)
155153 "
156154Return a nested list of the elements of array @var{ra}. For example, if @var{ra} is a
@@ -160,32 +158,28 @@ list contains a list for each of the rows of @var{ra}; and so on.
160158See also: @code{as-ra}
161159"
162160 (let* ((ra (ra-check ra))
163- (rank (%%ra-rank ra)))
164- (cond
165- ((zero? rank) (ra-ref ra))
166- (else
167- (let ((ra (apply ra-reverse ra (iota rank))))
168- (match (vector-ref (%%ra-dims ra) (- rank 1))
169- (($ <dim> klen klo kstep)
170- (let loop-rank ((ra ra))
171- (cond
172- ((= 1 (%%ra-rank ra))
173- (if (> klen 20)
174- (ra-fold xcons '() ra)
175- (let loop-dim ((l '()) (i klo))
176- (if (> i (dim-hi klen klo))
177- l
178- (loop-dim (cons (ra-ref ra i) l) (+ i 1))))))
179- (else
180- (let ((l '()))
181- (ra-slice-for-each 1 (lambda (x) (set! l (cons (loop-rank x) l))) ra)
182- l)))))))))))
183-
184- ; Similar to (@ (newra) ra-for-each-slice-1) - since we cannot unroll. It
185- ; might be cheaper to go Fortran order (building the index lists back to front);
186- ; should try that. C order and set-cdr! is how oldra does it.
187- ; This function is provided for compatibility with oldra; generally we shouldn't
188- ; be building index lists.
161+ (rank (%%ra-rank ra))
162+ (ra (apply ra-reverse ra (iota rank))))
163+ (if (zero? rank)
164+ (ra-ref ra)
165+ (match (vector-ref (%%ra-dims ra) (- rank 1))
166+ (($ <dim> klen klo _)
167+ (let loop-rank ((ra ra))
168+ (if (= 1 (%%ra-rank ra))
169+ (if (> klen 20)
170+ (ra-fold xcons '() ra)
171+ (let loop-dim ((l '()) (i klo))
172+ (if (> i (dim-hi klen klo))
173+ l
174+ (loop-dim (cons (ra-ref ra i) l) (+ i 1)))))
175+ (let ((l '()))
176+ (ra-slice-for-each-in-order 1 (lambda (x) (set! l (cons (loop-rank x) l))) ra)
177+ l))))))))
178+
179+ ; Based on (@ (newra) ra-for-each-slice-2) - we cannot unroll. It might be cheaper to
180+ ; go Fortran order (building the index lists back to front); should try that. C order
181+ ; and set-cdr! is how oldra does it. This function is provided for compatibility with
182+ ; oldra; generally we shouldn't be building index lists.
189183
190184(define (ra-index-map! ra op)
191185 "
@@ -204,30 +198,26 @@ x @result{} #%2:2:3(((0 0) (0 1) (0 2)) ((1 0) (1 1) (1 2)))
204198
205199See also: @code{ra-iota} @code{ra-i}
206200"
207- (let* ((kk (ra-rank ra))
208- (ii (make-list kk))
209- (los lens ((@ (newra map) ra-slice-for-each-check) kk ra)))
210- (if (= kk 0)
211- (ra-set! ra (apply op ii))
212- (let loop-rank ((k 0) (ra ra) (endi ii))
213- (let* ((lo (vector-ref los k))
214- (end (+ lo (vector-ref lens k))))
215- (if (= (+ 1 k) kk)
216- (let loop-dim ((i lo))
217- (if (= i end)
218- (set-car! endi lo)
219- (begin
220- (set-car! endi i)
221- (ra-set! ra (apply op ii) i)
222- (loop-dim (+ i 1)))))
223- (let loop-dim ((i lo))
224- (if (= i end)
225- (set-car! endi lo)
226- (begin
227- (set-car! endi i)
228- (loop-rank (+ k 1) (ra-slice ra i) (cdr endi))
229- (loop-dim (+ i 1)))))))))
230- ra))
201+ (let* ((frame (ra-check ra))
202+ (ii (make-list (%%ra-rank frame)))
203+ (dims (%%ra-dims frame))
204+ (ra (make-ra-root (%%ra-root frame) #() (ra-offset frame))))
205+ (let loop-rank ((k 0) (endi ii))
206+ (if (null? endi)
207+ ((%%ra-vset! ra) (%%ra-root ra) (%%ra-zero ra) (apply op ii))
208+ (match (vector-ref dims k)
209+ (($ <dim> len lo step)
210+ (let loop-dim ((i 0))
211+ (if (= i len)
212+ (begin
213+ (set-car! endi lo)
214+ (%%ra-zero-set! ra (- (%%ra-zero ra) (* step len))))
215+ (begin
216+ (set-car! endi (+ i lo))
217+ (loop-rank (+ k 1) (cdr endi))
218+ (%%ra-zero-set! ra (+ (%%ra-zero ra) step))
219+ (loop-dim (+ i 1)))))))))
220+ frame))
231221
232222
233223; ----------------
0 commit comments