Debian Codegraph @

%3a25/ix-ctor.scm

raw symbols SCIP
1 (define (array-ref a . xs)
2 (or (array:array? a)
3 (error "not an array"))
4 (let ((shape (array:shape a)))
5 (if (null? xs)
6 (array:check-indices "array-ref" xs shape)
7 (let ((x (car xs)))
8 (if (vector? x)
9 (array:check-index-vector "array-ref" x shape)
10 (if (integer? x)
11 (array:check-indices "array-ref" xs shape)
12 (if (array:array? x)
13 (array:check-index-actor "array-ref" x shape)
14 (error "not an index object"))))))
15 (vector-ref
16 (array:vector a)
17 (if (null? xs)
18 (vector-ref (array:index a) 0)
19 (let ((x (car xs)))
20 (if (vector? x)
21 (array:index/vector
22 (quotient (vector-length shape) 2)
23 (array:index a)
24 x)
25 (if (integer? x)
26 (array:vector-index (array:index a) xs)
27 (if (array:array? x)
28 (array:index/array
29 (quotient (vector-length shape) 2)
30 (array:index a)
31 (array:vector x)
32 (array:index x))
33 (error "array-ref: bad index object")))))))))
34
35 (define (array-set! a x . xs)
36 (or (array:array? a)
37 (error "array-set!: not an array"))
38 (let ((shape (array:shape a)))
39 (if (null? xs)
40 (array:check-indices "array-set!" '() shape)
41 (if (vector? x)
42 (array:check-index-vector "array-set!" x shape)
43 (if (integer? x)
44 (array:check-indices.o "array-set!" (cons x xs) shape)
45 (if (array:array? x)
46 (array:check-index-actor "array-set!" x shape)
47 (error "not an index object")))))
48 (if (null? xs)
49 (vector-set! (array:vector a) (vector-ref (array:index a) 0) x)
50 (if (vector? x)
51 (vector-set! (array:vector a)
52 (array:index/vector
53 (quotient (vector-length shape) 2)
54 (array:index a)
55 x)
56 (car xs))
57 (if (integer? x)
58 (let ((v (array:vector a))
59 (i (array:index a))
60 (r (quotient (vector-length shape) 2)))
61 (do ((sum (* (vector-ref i 0) x)
62 (+ sum (* (vector-ref i k) (car ks))))
63 (ks xs (cdr ks))
64 (k 1 (+ k 1)))
65 ((= k r)
66 (vector-set! v (+ sum (vector-ref i k)) (car ks)))))
67 (if (array:array? x)
68 (vector-set! (array:vector a)
69 (array:index/array
70 (quotient (vector-length shape) 2)
71 (array:index a)
72 (array:vector x)
73 (array:index x))
74 (car xs))
75 (error (string-append
76 "array-set!: bad index object: "
77 (array:thing->string x)))))))))