source: doc/theses/mike_brooks_MMath/programs/hello-md.cfa @ 382467f

ast-experimental
Last change on this file since 382467f was a5e2682, checked in by Michael Brooks <mlbrooks@…>, 2 years ago

Improve new-array subscripting to cover missing cases.

Missing cases include acknowledging a[0] and a[1] as required uses; therefore, give them
special overloads. Add comments to explain why.

Missing cases include test coverage of these overloads (where tests actually fail when an overload
is missing). Perhaps surprisingly, you need to use a lot of features at the same time for the need
for several overloads to obtain; make test coverage go there.

Also, switch thesis's demo of mutidimensional transposing/slicing to use (improved) libcfa ar
(pseudo-)trait, in place of former ix trait. Therefore, also port this demo to new array
syntax. (No changes to thesis discussion around this demo yet; these are still pending.) All
in, cause this thesis demo to be runnable again.

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[bbf6a180]1#include "array.hfa"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[a5e2682]34
35
36
37
38
39
40forall( [N] )
[bbf6a180]41void print1d_cstyle( array(float, N) & c );
42
[a5e2682]43forall( [N], C & | ar( C, float, N ) )
[bbf6a180]44void print1d( C & c );
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[a5e2682]60forall( [N] )
[bbf6a180]61void print1d_cstyle( array(float, N) & c ) {
[a5e2682]62    for( i; N ) {
[bbf6a180]63        printf("%.1f  ", c[i]);
64    }
65    printf("\n");
66}
67
68
69
70
71
72
73
74
75
76
77
78
79
[a5e2682]80forall( [N], C & | ar( C, float, N ) )
[bbf6a180]81void print1d( C & c ) {
[a5e2682]82    for( i; N ) {
[bbf6a180]83        printf("%.1f  ", c[i]);
84    }
85    printf("\n");
86}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
[a5e2682]101void fill( array(float, 5, 7) & a ) {
[bbf6a180]102    for ( i; (ptrdiff_t) 5 ) {
103        for ( j; 7 ) {
[a5e2682]104            a[i,j] = 1.0 * i + 0.1 * j;
105            printf("%.1f  ", a[i,j]);
[bbf6a180]106        }
107        printf("\n");
108    }
109    printf("\n");
110}
111
112int main() {
113
114
115
116
117
118
119
[a5e2682]120array( float, 5, 7 ) a;
[bbf6a180]121fill(a);
122/*
1230.0  0.1  0.2  0.3  0.4  0.5  0.6 
1241.0  1.1  1.2  1.3  1.4  1.5  1.6 
1252.0  2.1  2.2  2.3  2.4  2.5  2.6 
1263.0  3.1  3.2  3.3  3.4  3.5  3.6 
1274.0  4.1  4.2  4.3  4.4  4.5  4.6
128*/
129   
130
131
132
133
134
135
136
137
138
139
140print1d_cstyle( a[ 2 ] );  // 2.0  2.1  2.2  2.3  2.4  2.5  2.6
141
142
143
144
145print1d( a[ 2 ] );  // 2.0  2.1  2.2  2.3  2.4  2.5  2.6
146
147
148
149
[a5e2682]150print1d( a[ 2, all ] );  // 2.0  2.1  2.2  2.3  2.4  2.5  2.6
151print1d( a[ all, 3 ] );  // 0.3  1.3  2.3  3.3  4.3
[bbf6a180]152
153
154
[a5e2682]155print1d_cstyle( a[ 2, all ] );
[bbf6a180]156
157
158
159
160
161
162
[a5e2682]163#ifdef SHOW_ERROR_1
[bbf6a180]164
[a5e2682]165print1d_cstyle( a[ all, 2 ] );  // bad
[bbf6a180]166
167#endif
168
169}
170
171
172
Note: See TracBrowser for help on using the repository browser.