]> gitweb.factorcode.org Git - factor.git/blob - extra/arrays/shaped/shaped-tests.factor
Switch to https urls
[factor.git] / extra / arrays / shaped / shaped-tests.factor
1 ! Copyright (C) 2012 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays.shaped kernel math sequences tools.test ;
4
5 { t } [
6     { 5 5 } increasing
7     {
8         { 0 1 2 3 4 }
9         { 5 6 7 8 9 }
10         { 10 11 12 13 14 }
11         { 15 16 17 18 19 }
12         { 20 21 22 23 24 }
13     } >shaped-array =
14 ] unit-test
15
16 { { 5 5 } } [
17     {
18         { 0 1 2 3 4 }
19         { 5 6 7 8 9 }
20         { 10 11 12 13 14 }
21         { 15 16 17 18 19 }
22         { 20 21 22 23 24 }
23     } >shaped-array shape>>
24 ] unit-test
25
26 { { 5 5 } } [
27     {
28         { 0 1 2 3 4 }
29         { 5 6 7 8 9 }
30         { 10 11 12 13 14 }
31         { 15 16 17 18 19 }
32         { 20 21 22 23 24 }
33     } >shaped-array shape
34 ] unit-test
35
36 { sa{ 1 } } [ { } ones ] unit-test
37 { sa{ 1 } } [ { 1 } ones ] unit-test
38
39 { sa{ 0 } } [ { } zeros ] unit-test
40 { sa{ 0 } } [ { 1 } zeros ] unit-test
41
42 ! Error on 0, negative shapes
43
44 {
45     sa{ { 1 3 3 } { 4 1 3 } { 4 4 1 } }
46 } [
47     { 3 3 } 2 strict-lower
48     [ drop 3 ] map-strict-upper
49     [ drop 1 ] map-diagonal
50     [ sq ] map-strict-lower
51 ] unit-test
52
53
54 [ 15 <iota> { 3 5 1 } reshape ] must-not-fail