source: doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.cfa

Last change on this file was 80e83b6c, checked in by Peter A. Buhr <pabuhr@…>, 2 weeks ago

last proofread array chapter

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <fstream.hfa>
2#include <array.hfa>
3
4extern "C" { // don't mangle the function name `sum`
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20forall( [M], [N], [P] )
21void mul(
22
23 array(float, M, N) & res,
24 array(float, M, P) & lhs,
25 array(float, P, N) & rhs ) {
26 for ( i; M )
27
28 for ( j; N ) {
29
30 res[i, j] = 0.0;
31 for ( k; P )
32
33 @res[i, j] +=@
34 @lhs[i, k] *@
35 @rhs[k, j];@
36 }
37}
38
39
40
41
42
43
44
45} // extern "C"
46
47#ifdef RUNIT
48
49forall( [R], [C] )
50static void zero( array(float, R, C) & mat ) {
51 for ( i; R ) for ( j; C )
52 mat[i,j] = 0.0;
53}
54
55forall( [R], [C] )
56static void fill( array(float, R, C) & mat ) {
57 for ( i; R ) for ( j; C )
58 mat[i,j] = 1.0 * (i + 1) + 0.1 * (j+1);
59}
60
61forall( [R], [C] )
62static void print( array(float, R, C) & mat ) {
63 for ( i; R ) {
64 for ( j; C ) sout | wd(2, mat[i, j]) | sep | nonl;
65 sout | nl;
66 }
67}
68
69#define EXPSZ_M 2
70#define EXPSZ_N 3
71#define EXPSZ_P 4
72
73
74int main() {
75 array( float, EXPSZ_M, EXPSZ_N ) res; zero( res );
76 array( float, EXPSZ_M, EXPSZ_P ) lhs; fill( lhs );
77 array( float, EXPSZ_P, EXPSZ_N ) rhs; fill( rhs );
78 mul( res, lhs, rhs );
79 print(lhs);
80 sout | "*";
81 print(rhs);
82 sout | "=";
83 print(res);
84}
85
86
87
88#endif
Note: See TracBrowser for help on using the repository browser.