Debian Codegraph @

%3a25/list.scm

raw symbols SCIP
1 ;;; An identity matrix.
2
3 (define i_4
4 (let* ((i (make-array
5 (shape 0 4 0 4)
6 0))
7 (d (share-array i
8 (shape 0 4)
9 (lambda (k)
10 (values k k)))))
11 (do ((k 0 (+ k 1))) ((= k 4))
12 (array-set! d k 1))
13 i))
14
15 (past "i_4")
16
17 (or (array-equal? i_4
18 (tabulate-array
19 (shape 0 4 0 4)
20 (lambda (j k)
21 (if (= j k) 1 0))))
22 (error "failed to build i_4"))
23
24 (past "i_4 vs tabulate-array")
25
26 (or (array-equal? i_4
27 (array
28 (shape 0 4 0 4)
29 1 0 0 0
30 0 1 0 0
31 0 0 1 0
32 0 0 0 1))
33 (error "failed to array i_4"))
34
35 (past "i_4 vs array")
36
37 (or (array-equal? (share-array
38 i_4
39 (shape 0 4)
40 (lambda (k)
41 (values k k)))
42 (share-array
43 (array (shape) 1)
44 (shape 0 4)
45 (lambda (k)
46 (values))))
47 (error "failed to share diagonal of i_4 or cell of 1"))
48
49 (past "i_4 diagonal")
50
51 (or (array-equal? (share-array
52 i_4
53 (shape 0 4)
54 (lambda (k)
55 (values (- 3 k) k)))
56 (share-array
57 (array (shape) 0)
58 (shape 0 4)
59 (lambda (k)
60 (values))))
61 (error "failed to share codiagonal of i_4 or cell of 0"))
62
63 (past "i_4 codiagonal")
64
65 (or (array-equal? (share-array
66 i_4
67 (shape 0 2 0 2)
68 (lambda (j k)
69 (values (* 3 j) (* 3 k))))
70 (share-array
71 i_4
72 (shape 0 2 0 2)
73 (lambda (j k)
74 (values (+ j 1) (+ k 1)))))
75 (error "failed to share corners or center of i_4"))
76
77 (past "i_4 corners and center")
78
79 (or (array-equal? i_4 (transpose i_4))
80 (error "failed to transpose i_4"))
81
82 (past "i_4 transpose")
83
84 ;;; Try a three dimensional transpose. This will also exercise matrix
85 ;;; multiplication.
86
87 (define threed123
88 (array (shape 0 1 0 2 0 3)
89 'a 'b 'c
90 'd 'e 'f))
91
92 (past "threed123")
93
94 (define threed312
95 (array (shape 0 3 0 1 0 2)
96 'a 'd
97 'b 'e
98 'c 'f))
99
100 (past "threed312")
101
102 (define rot231 (list 1 2 0))
103 ;; 0 1 0
104 ;; 0 0 1
105 ;; 1 0 0
106
107 (or (array-equal? threed123
108 (apply transpose threed312 rot231))
109 (error "failed to transpose three dimensions"))
110
111 (past "threed123 transpose")
112
113 ;;; The frivolous board game exercises share of share of share.
114
115 ;;; A three dimensional chess board with two phases: piece and colour
116 ;;; of piece. Think of pieces in a cube with height, width and depth,
117 ;;; and piece colours in a parallel cube. We put pink jays around and
118 ;;; grey crows inside the board proper. Later we put in a blue rook.
119
120 (define board
121 (tabulate-array
122 (shape -1 9 -1 9 -1 9 0 2)
123 (lambda (t u v w)
124 (case w
125 ((0) (if (and (< -1 u 8)
126 (< -1 v 8)
127 (< -1 t 8))
128 'crow
129 'jay))
130 ((1) (if (and (< -1 u 8)
131 (< -1 v 8)
132 (< -1 t 8))
133 'grey
134 'pink))))))
135
136 (past "board")
137
138 ;;; A cylinder with height 4, width 4, depth 6, both phases, centered
139 ;;; inside the board. Top left front corner is at 0 0 0 of cylinder but
140 ;;; 2 2 1 of board.
141
142 (define board-cylinder
143 (share-array
144 board
145 (shape 0 4 0 4 0 6 0 2)
146 (lambda (t u v w)
147 (values (+ t 2) (+ u 2) (+ v 1) w))))
148
149 (past "board-cylinder")
150
151 ;;; The center cube with side 2 of the cylinder, hence of the board,
152 ;;; with both phases. Top left corner is 0 0 0 of center but 1 1 2
153 ;;; of cylinder and 3 3 3 of board.
154
155 (define board-center
156 (share-array
157 board-cylinder
158 (shape 0 2 0 2 0 2 0 2)
159 (lambda (t u v w)
160 (values (+ t 1) (+ u 1) (+ v 2) w))))
161
162 (past "board-center")
163
164 ;;; Front face of center cube, in two dimensions plus phase. Top left
165 ;;; corner is 0 0 of face but 0 0 0 of center and 1 1 2 of cylinder
166 ;;; 3 3 3 of board.
167
168 (define board-face
169 (share-array
170 board-center
171 (shape 0 2 0 2 0 2)
172 (lambda (t u w)
173 (values t u 0 w))))
174
175 (past "board-face")
176
177 ;;; Left side of face in three dimensions plus phase. Top is 0 0 0 of
178 ;;; pillar but 0 0 of face and 0 0 0 of center and 1 1 2 of cylinder
179 ;;; and 3 3 3 of board. Bottom is 1 0 0 of pillar but 1 0 of face and
180 ;;; 1 0 0 of center and 2 1 2 of cylinder and 4 3 3 of board.
181
182 (define board-pillar
183 (share-array
184 board-face
185 (shape 0 2 0 1 0 1 0 2)
186 (lambda (t u v w)
187 (values t 0 w))))
188
189 (past "board-pillar")
190
191 ;;; Pillar upside down. Now top 0 0 0 is 1 0 of face and 1 0 0 of center
192 ;;; and 2 1 2 of cylinder and 4 3 3 of board.
193
194 (define board-reverse-pillar
195 (share-array
196 board-pillar
197 (shape 0 2 0 1 0 1 0 2)
198 (lambda (t u v w)
199 (values (- 1 t) u v w))))
200
201 (past "board-reverse-pillar")
202
203 ;;; Bottom of pillar.
204
205 (define board-cubicle
206 (share-array
207 board-pillar
208 (shape 0 2)
209 (lambda (w)
210 (values 1 0 0 w))))
211
212 (past "board-cubicle")
213
214 ;;; Top of upside down pair.
215
216 (define board-reverse-cubicle
217 (share-array
218 board-reverse-pillar
219 (shape 0 2)
220 (lambda (w)
221 (values 0 0 0 w))))
222
223 (past "board-reverse-cubicle")
224
225 ;;; Piece phase of cubicle.
226
227 (define board-piece
228 (share-array
229 board-cubicle
230 (shape)
231 (lambda ()
232 (values 0))))
233
234 (past "board-piece")
235
236 ;;; Colour phase of the other cubicle that is actually the same cubicle.
237
238 (define board-colour
239 (share-array
240 board-reverse-cubicle
241 (shape)
242 (lambda ()
243 (values 1))))
244
245 (past "board-colour")
246
247 ;;; Put a blue rook at the bottom of the pillar and at the top of the
248 ;;; upside pillar.
249
250 (array-set! board-piece 'rook)
251 (array-set! board-colour 'blue)
252
253 (past "array-set! to board-piece and board-colour")
254
255 ;;; Build the same chess position directly.
256
257 (define board-two
258 (tabulate-array
259 (shape -1 9 -1 9 -1 9 0 2)
260 (lambda (t u v w)
261 (if (and (= t 4) (= u 3) (= v 3))
262 (case w
263 ((0) 'rook)
264 ((1) 'blue))
265 (case w
266 ((0) (if (and (< -1 u 8)
267 (< -1 v 8)
268 (< -1 t 8))
269 'crow
270 'jay))
271 ((1) (if (and (< -1 u 8)
272 (< -1 v 8)
273 (< -1 t 8))
274 'grey
275 'pink)))))))
276
277 (past "board-two")
278
279 (or (array-equal? board board-two)
280 (error "failed in three dimensional chess"))
281
282 (past "board vs board-two")
283
284 ;;; Permute the dimensions of the chess board in two different ways.
285 ;;; The transpose also exercises matrix multiplication.
286
287 (define board-three
288 (share-array
289 board-two
290 (shape 0 2 -1 9 -1 9 -1 9)
291 (lambda (w t u v)
292 (values t u v w))))
293
294 (past "board-three")
295
296 (or (array-equal? board-three
297 (transpose board-two 3 0 1 2))
298 ;; 0 0 0 1
299 ;; 1 0 0 0
300 ;; 0 1 0 0
301 ;; 0 0 1 0
302 (error "failed to permute chess board dimensions"))
303
304 (past "board-three vs transpose of board-two")
305
306 (or (array-equal? (share-array
307 board-two
308 (shape -1 9 0 2 -1 9 -1 9)
309 (lambda (t w u v)
310 (values t u v w)))
311 (transpose board-two 0 3 1 2))
312 ;; 1 0 0 0
313 ;; 0 0 0 1
314 ;; 0 1 0 0
315 ;; 0 0 1 0
316 (error "failed to permute chess board dimensions another way"))
317
318 (past "board-two versus transpose of board-two")
319
320 ;;; Just see that empty share does not crash. No index is valid. Just by
321 ;;; the way. There is nothing to be done with it.
322
323 (define board-nothing
324 (share-array
325 board
326 (shape 0 3 1 1 0 3)
327 (lambda (t u v)
328 (values 0 0 0))))
329
330 (or (array-equal? board-nothing (array (array-shape board-nothing)))
331 (error "board-nothing failed"))
332
333 (past "board-nothing")
334
335 ;;; ---
336
337 (or (array-equal? (tabulate-array (shape 4 8 2 5 0 1) *)
338 (tabulate-array! (shape 4 8 2 5 0 1)
339 (lambda (v)
340 (* (vector-ref v 0)
341 (vector-ref v 1)
342 (vector-ref v 2)))
343 (vector * * *)))
344 (error "tabulate-array! with vector failed"))
345
346 (past "tabulate-array! with vector")
347
348 (or (array-equal? (tabulate-array (shape 4 8 2 5 0 1) *)
349 (let ((index (share-array (make-array (shape 0 2 0 3))
350 (shape 0 3)
351 (lambda (k) (values 1 k)))))
352 (tabulate-array! (shape 4 8 2 5 0 1)
353 (lambda (a)
354 (* (array-ref a 0)
355 (array-ref a 1)
356 (array-ref a 2)))
357 index)))
358 (error "tabulate-array! with array failed"))
359
360 (past "tabulate-array! with array")
361
362 ;;; Sum of constants
363
364 (or (array-equal?
365 (array-map
366 +
367 (share-array (array (shape) 0) (shape 1 2 1 4) (lambda _ (values)))
368 (share-array (array (shape) 1) (shape 1 2 1 4) (lambda _ (values)))
369 (share-array (array (shape) 2) (shape 1 2 1 4) (lambda _ (values))))
370 (array (shape 1 2 1 4) 3 3 3))
371 (error "failed to map constants to their constant sum"))
372
373 (past "array-map sum")
374
375 ;;; Multiplication table
376
377 (define four-by-four
378 (array (shape 0 4 0 4)
379 0 0 0 0
380 0 1 2 3
381 0 2 4 6
382 0 3 6 9))
383
384 (past "four-by-four")
385
386 (or (array-equal? four-by-four (tabulate-array (shape 0 4 0 4) *))
387 (error "failed to tabulate four by four"))
388
389 (past "four-by-four vs tabulate-array")
390
391 (or (array-equal?
392 four-by-four
393 (let ((table (make-array (shape 0 4 0 4) 19101)))
394 (array-retabulate! table (array-shape table) *)
395 table))
396 (error "failed to retabulate four by four simply"))
397
398 (past "four-by-four vs array-retabulate!")
399
400 (or (array-equal?
401 four-by-four
402 (let ((table (make-array (shape 0 4 0 4) 19101)))
403 (array-retabulate!
404 table
405 (shape 1 2 1 4)
406 (lambda (v)
407 (* (vector-ref v 0) (vector-ref v 1)))
408 (vector - -))
409 (array-retabulate!
410 table
411 (shape 2 4 0 4)
412 (lambda (a)
413 (* (array-ref a (vector 0)) (array-ref a (vector 1))))
414 (make-array (shape 0 2)))
415 (array-set! table 0 0 0)
416 (array-set! table (vector 0 1) 0)
417 (array-set! table (array (shape 0 2) 0 2) 0)
418 (shape-for-each
419 (shape 0 1 3 4)
420 (lambda (v)
421 (array-set! table v (vector-ref v 0)))
422 (vector - -))
423 (let ((arr (share-array
424 table
425 (shape 1 2 0 1 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8)
426 (lambda (r k . _)
427 (values r k)))))
428 (array-retabulate! arr (array-shape arr) *))
429 table))
430 (error "failed to retabulate four by four in a hard way"))
431
432 (past "four-by-four vs array-retabulate! on parts")
433
434 ;;; An argument was missing in a call in arlib when
435 ;;; shape-for-each was called without an index object.
436
437 (or (let ((em '()))
438 (shape-for-each
439 (shape 0 2 -2 0 0 1)
440 (lambda (u v w)
441 (set! em (cons (list u v w) em))))
442 (equal? (reverse em) '((0 -2 0) (0 -1 0) (1 -2 0) (1 -1 0))))
443 (error "shape-for-each without index object"))
444
445 (past "shape-for-each without index object")
446
447
448 ;;; Exercise share-array/index!
449
450 (or (let ((arr (tabulate-array (shape 2 4 3 5 4 7) *)))
451 (array-equal? (share-array/index!
452 arr
453 (array-shape arr)
454 (lambda (v) v)
455 (vector * * *))
456 arr))
457 (error "share-array/index! with identity and vector failed"))
458
459 (past "share-array/index! with identity and vector")
460
461 (or (let ((arr (tabulate-array (shape 2 4 3 5 4 7) *))
462 (ind (share-array (make-array (shape 0 2 0 3))
463 (shape 0 3)
464 (lambda (k) (values 1 k)))))
465 (array-equal? (share-array/index!
466 arr
467 (array-shape arr)
468 (lambda (a) a) ind)
469 arr))
470 (error "share-array/index! with identity and array failed"))
471
472 (past "share-array/index! with identity and array")
473
474 (or (let ((arr (tabulate-array (shape 3 5 4 5 4 7) *))
475 (in (vector * *))
476 (out (array (shape 0 3) 4 * *)))
477 (array-equal? (share-array/index!
478 arr
479 (shape 4 5 4 7)
480 (lambda (in)
481 (array-set! out 1 (vector-ref in 0))
482 (array-set! out 2 (vector-ref in 1))
483 out)
484 in)
485 (share-array
486 arr
487 (shape 4 5 4 7)
488 (lambda (j k)
489 (values 4 j k)))))
490 (error "share-array/index! with vector in array out failed"))
491
492 (past "share-array/index! with vector in array out")
493
494 (or (let ((arr (tabulate-array (shape 3 5 4 5 4 7) *))
495 (in (array (shape 0 2) * *))
496 (out (vector 4 * *)))
497 (array-equal? (share-array/index!
498 arr
499 (shape 4 5 4 7)
500 (lambda (in)
501 (vector-set! out 1 (array-ref in 0))
502 (vector-set! out 2 (array-ref in 1))
503 out)
504 in)
505 (share-array
506 arr
507 (shape 4 5 4 7)
508 (lambda (j k)
509 (values 4 j k)))))
510 (error "share-array/index! with array in vector out failed"))
511
512 (past "share-array/index! with array in vector out")
513
514 (let ((x (array (shape 2 4 3 5 4 5 5 7 6 8)
515 10 11 12 13
516 20 21 22 23
517 30 31 32 33
518 40 41 42 43)))
519 (or (array-equal? (share-array/origin x 3 3 3 3 3)
520 (array-append 0 (array (shape 3 3
521 3 5
522 3 4
523 3 5
524 3 5))
525 x))
526 (error "share-array/origin against empty array-append failed"))
527 (or (array-equal? (share-array/origin x 3 3 3 3 3)
528 (array-append 3 (array (shape 3 5
529 3 5
530 3 4
531 3 3
532 3 5))
533 x))
534 (error "share-array/origin against empty array-append failed")))
535
536 (past "share-array/origin against empty array-append")
537
538 (let ((a* (make-array (shape 4 6 7 9 100 101) 'a))
539 (b* (make-array (shape 3 6 7 8 200 201) 'b))
540 (c* (make-array (shape 0 1 2 4 300 301) 'c)))
541 (or (array-equal? (array-append 1 (array-append 0 a* c*) b* b* b*)
542 (apply array (shape 4 7 7 12 100 101)
543 '(a a b b b
544 a a b b b
545 c c b b b)))
546 (error "array-append failed")))
547
548 (past "array-append")
549
550 (let ((a* (make-array (shape 4 6 7 9 100 101) 'a))
551 (b* (make-array (shape 3 6 7 8 200 201) 'b))
552 (c* (make-array (shape 0 1 2 4 300 301) 'c)))
553 (or (array-equal? (array-append 1 a* (transpose c* 1 0 2)
554 (array-append 0 (transpose b* 1 0 2)
555 (transpose b* 1 0 2)))
556 (apply array (shape 4 6 7 13 100 101)
557 '(a a c b b b
558 a a c b b b)))
559 (error "array-append with transpose failed")))
560
561 (past "array-append with transpose")
562
563 ;;; Check that share-array/index! agrees with share-array.
564
565 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
566 (or (array-equal? m (share-array m (shape 1 3 1 3) values))
567 (error "share-array identity failed"))
568 (or (array-equal? m (share-array/index!
569 m (shape 1 3 1 3)
570 (lambda (x) x)
571 (vector * *)))
572 (error "share-array/index! identity with vector failed"))
573 (or (array-equal? m (share-array/index!
574 m (shape 1 3 1 3)
575 (lambda (x) x)
576 (make-array (shape 0 2))))
577 (error "share-array/index! identity with actor failed")))
578
579 (past "share-array/index! identity")
580
581 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
582 (or (array-equal? (share-array
583 m (shape 1 3)
584 (lambda (r)
585 (values r 1)))
586 (share-array/index!
587 m (shape 1 3)
588 (lambda (x)
589 (vector (vector-ref x 0) 1))
590 (vector *)))
591 (error "share-array/index! 1-d column failed")))
592
593 (past "share-array/index! 1-d column")
594
595 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
596 (or (array-equal? (share-array
597 m (shape 1 3 1 3)
598 (lambda (r k)
599 (values r 1)))
600 (share-array/index!
601 m (shape 1 3 1 3)
602 (lambda (x)
603 (vector (vector-ref x 0) 1))
604 (vector * *)))
605 (error "share-array/index! 2-d column failed")))
606
607 (past "share-array/index! 2-d column")
608
609 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
610 (or (array-equal? (share-array
611 m (shape 1 3)
612 (lambda (k)
613 (values 1 k)))
614 (share-array/index!
615 m (shape 1 3)
616 (lambda (x)
617 (vector 1 (vector-ref x 0)))
618 (vector *)))
619 (error "share-array/index! 1-d row failed")))
620
621 (past "share-array/index! 1-d row")
622
623 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
624 (or (array-equal? (share-array
625 m (shape 1 2 1 3)
626 (lambda (r k)
627 (values 1 k)))
628 (share-array/index!
629 m (shape 1 2 1 3)
630 (lambda (x)
631 (vector 1 (vector-ref x 1)))
632 (vector * *)))
633 (error "share-array/index! 2-d row failed")))
634
635 (past "share-array/index! 2-d row")
636
637 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
638 (or (array-equal? (share-array
639 m (shape 1 3)
640 (lambda (r)
641 (values r r)))
642 (share-array/index!
643 m (shape 1 3)
644 (lambda (x)
645 (vector (vector-ref x 0) (vector-ref x 0)))
646 (vector *)))
647 (error "share-array/index! diagonal failed")))
648
649 (past "share-array/index! diagonal")
650
651 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
652 (or (array-equal? (share-array
653 m (shape)
654 (lambda ()
655 (values 1 2)))
656 (share-array/index!
657 m (shape)
658 (lambda (x)
659 (vector 1 2))
660 (vector)))
661 (error "share-array/index! 0-d corner failed")))
662
663 (past "share-array/index! 0-d corner")
664
665 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
666 (or (array-equal? (share-array
667 m (shape 1 2)
668 (lambda (_)
669 (values 1 2)))
670 (share-array/index!
671 m (shape 1 2)
672 (lambda (x)
673 (vector 1 2))
674 (vector *)))
675 (error "share-array/index! 1-d corner failed")))
676
677 (past "share-array/index! 1-d corner")
678
679 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
680 (or (array-equal? (share-array
681 m (shape 1 2 1 2)
682 (lambda (r k)
683 (values 1 2)))
684 (share-array/index!
685 m (shape 1 2 1 2)
686 (lambda (x)
687 (vector 1 2))
688 (vector * *)))
689 (error "share-array/index! 2-d corner failed")))
690
691 (past "share-array/index! 2-d corner")
692
693 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
694 (or (array-equal? (share-array/prefix m 1)
695 (share-array/index!
696 m (shape 1 3)
697 (lambda (x)
698 (vector 1 (vector-ref x 0)))
699 (vector *)))
700 (error "share-array/index! with prefix 1 failed")))
701
702 (past "share-array/{prefix,index!} 1")
703
704 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
705 (or (array-equal? (share-array/prefix m (vector 1))
706 (share-array/index!
707 m (shape 1 3)
708 (lambda (x)
709 (vector 1 (vector-ref x 0)))
710 (vector *)))
711 (error "share-array/prefix with vector failed")))
712
713 (past "share-array/prefix with vector")
714
715 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
716 (or (array-equal? (share-array/prefix m 2)
717 (share-array/index!
718 m (shape 1 3)
719 (lambda (x)
720 (vector 2 (vector-ref x 0)))
721 (vector *)))
722 (error "share-array/index! with prefix 2 failed")))
723
724 (past "share-array/{prefix,index!} 2")
725
726 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
727 (or (array-equal? (share-array/prefix m (array (shape 0 1) 2))
728 (share-array/index!
729 m (shape 1 3)
730 (lambda (x)
731 (vector 2 (vector-ref x 0)))
732 (vector *)))
733 (error "share-array/prefix with array failed")))
734
735 (past "share-array/prefix with array")
736
737 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
738 (or (array-equal? (share-array/prefix m)
739 (share-array/index!
740 m (shape 1 3 1 3)
741 (lambda (x) x)
742 (vector * *)))
743 (error "share-array/index! with empty prefix failed")))
744
745 (past "share-array/{prefix,index!} e")
746
747 (let ((m (array (shape 1 3 1 3) 'a 'b 'c 'd)))
748 (or (array-equal? (share-array/prefix m 1 2)
749 (share-array/index!
750 m (shape)
751 (lambda (x)
752 (vector 1 2))
753 (vector)))
754 (error "share-array/index! with prefix 1 2 failed")))
755
756 (past "share-array/{prefix,index!} 1 2")
757
758 ;;; Uh oh.
759
760 (let* ((hape (tabulate-array
761 (shape 0 57 0 2)
762 (lambda (r k)
763 (case k
764 ((0) r)
765 ((1) (case r
766 ((0) (+ r 2))
767 ((56) (+ r 4))
768 (else (+ r 1))))))))
769 (tape (tabulate-array
770 (shape 0 34 0 2)
771 (lambda (r k)
772 (case k
773 ((0) (+ r 23))
774 ((1) (case r
775 ((33) (+ r 27))
776 (else (+ r 24))))))))
777 (long (make-vector 57 *))
778 (shot (make-vector 34 *))
779 (huge (tabulate-array!
780 hape
781 (lambda (ix) (vector-ref '#(a b) (vector-ref ix 0)))
782 long))
783 (tiny0 (share-array/index!
784 huge
785 tape
786 (begin
787 (do ((k 0 (+ k 1)))
788 ((= k 23))
789 (vector-set! long k k))
790 (lambda (ix)
791 (do ((k 23 (+ k 1)))
792 ((= k 57))
793 (vector-set! long k (vector-ref ix (- k 23))))
794 long))
795 shot))
796 (tiny1 (share-array/index!
797 huge
798 tape
799 (begin
800 (vector-set! long 0 1)
801 (do ((k 1 (+ k 1)))
802 ((= k 23))
803 (vector-set! long k k))
804 (lambda (ix)
805 (do ((k 23 (+ k 1)))
806 ((= k 57))
807 (vector-set! long k (vector-ref ix (- k 23))))
808 long))
809 shot)))
810 (or (and (equal? (array->vector huge) '#(a a a a b b b b))
811 (equal? (array->vector tiny0) '#(a a a a))
812 (equal? (array->vector tiny1) '#(b b b b)))
813 (error "share-array/index! failed huge or tiny contents"))
814 (or (array-equal? huge
815 (share-array/index!
816 (array (shape 4 6) 'a 'b)
817 hape
818 (lambda (ix)
819 (vector-ref '#(#(4) #(5)) (vector-ref ix 0)))
820 long))
821 (error "share-array/index! failed huge"))
822 (or (array-equal? tiny0
823 (share-array/index!
824 (array (shape 6 7) 'a)
825 tape
826 (lambda (ix) '#(6))
827 shot))
828 (error "share-array/index! failed tiny0"))
829 (or (array-equal? tiny1
830 (share-array/index!
831 (array (shape 6 7 8 9) 'b)
832 tape
833 (lambda (ix) '#(6 8))
834 shot))
835 (error "share-array/index! failed tiny1")))
836
837 (past "share-array/index! huge as tiny")