Last change
on this file since 37270 was
37270,
checked in by Ivan Raikov, 2 years ago
|
release 1.5 of srfi-4-comprehensions
|
File size:
1.4 KB
|
Line | |
---|
1 | (import scheme (chicken base) srfi-1 srfi-4 srfi-42 srfi-4-comprehensions test) |
---|
2 | |
---|
3 | (define n 20) |
---|
4 | |
---|
5 | (define xlst (list-tabulate n (lambda (x) x))) |
---|
6 | |
---|
7 | (define (to-4-dp f) |
---|
8 | (/ (round (* f 10000)) 10000)) |
---|
9 | |
---|
10 | (define (=4 n1 n2) |
---|
11 | (= (to-4-dp n1) (to-4-dp n2))) |
---|
12 | |
---|
13 | (test-group "SRFI-4 vector comprehension" |
---|
14 | |
---|
15 | (test (list->f64vector xlst) (f64vector-ec (: i 0 n) i) ) |
---|
16 | (test (list->f32vector xlst) (f32vector-ec (: i 0 n) i) ) |
---|
17 | ; (test (list->s64vector xlst) (s64vector-ec (: i 0 n) i) ) |
---|
18 | (test (list->u64vector xlst) (u64vector-ec (: i 0 n) i) ) |
---|
19 | (test (list->s32vector xlst) (s32vector-ec (: i 0 n) i) ) |
---|
20 | (test (list->u32vector xlst) (u32vector-ec (: i 0 n) i) ) |
---|
21 | (test (list->s16vector xlst) (s16vector-ec (: i 0 n) i) ) |
---|
22 | (test (list->u16vector xlst) (u16vector-ec (: i 0 n) i) ) |
---|
23 | (test (list->s8vector xlst) (s8vector-ec (: i 0 n) i) ) |
---|
24 | (test (list->u8vector xlst) (u8vector-ec (: i 0 n) i) ) |
---|
25 | |
---|
26 | ) |
---|
27 | |
---|
28 | |
---|
29 | |
---|
30 | (test-group "SRFI-4 vector fold comprehension" |
---|
31 | |
---|
32 | (let ((v (f64vector-ec (: i 0. n) (* 0.5 i)))) |
---|
33 | |
---|
34 | (test-assert (=4 617.5 (fold-ec 0. (:f64vector x (index i) v) x (lambda (x ax) (+ ax (* x x))))))) |
---|
35 | |
---|
36 | (let ((v (f32vector-ec (: i 0. n) (* 0.5 i)))) |
---|
37 | |
---|
38 | (test-assert (=4 617.5 (fold-ec 0. (:f32vector x (index i) v) x (lambda (x ax) (+ ax (* x x)))))) |
---|
39 | |
---|
40 | )) |
---|
Note: See
TracBrowser
for help on using the repository browser.