- Timestamp:
- Mar 10, 2024, 11:21:18 AM (7 months ago)
- Branches:
- master
- Children:
- 9398177
- Parents:
- b64d0f4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/programs/array-boundcheck-removal-stdvec.cpp
rb64d0f4 r5546f50b 3 3 forall( [M], [N], [P] ) 4 4 void matmul( array(float, M, P) & src1, 5 6 7 8 9 10 11 5 array(float, P, N) & src2, 6 array(float, M, N) & tgt ) { 7 for (i; M) for (j; N) { 8 tgt[i][j] = 0; 9 for (k; P) 10 tgt[i][j] += src1[i][k] * src2[k][j]; 11 } 12 12 } 13 13 */ … … 30 30 31 31 float f( vector<float> & a ) { 32 33 34 35 36 37 32 float result = 0; 33 for( int i = 0; i < BOUND(a.size()); i++ ) { 34 result += a.at(i); 35 // hillarious that, while writing THIS VERY DEMO, on first go, I actaully wrote it a[i] 36 } 37 return result; 38 38 } 39 39 … … 41 41 #include <iostream> 42 42 int main( int argc, char ** argv ) { 43 44 45 46 47 48 43 vector<float> v(5); 44 v.at(0) = 3.14; 45 v.at(1) = 3.14; 46 v.at(2) = 3.14; 47 v.at(3) = 3.14; 48 v.at(4) = 3.14; 49 49 50 50 float answer = f(v); 51 51 52 52 cout << "answer: " << answer << endl; 53 53 54 54 } … … 80 80 81 81 void matmul( mat & a, mat & b, mat & rslt ) { 82 83 84 85 86 87 88 89 90 91 92 93 94 95 82 size_t m = rslt.size(); 83 assert( m == a.size() ); 84 size_t p = b.size(); 85 for ( int i = 0; i < BOUND(m); i++ ) { 86 assert( p == a.at(i).size() ); 87 size_t n = rslt.at(i).size(); 88 for ( int j = 0; j < BOUND(n); j++ ) { 89 rslt.at(i).at(j) = 0.0; 90 for ( int k = 0; k < BOUND(p); k++ ) { 91 assert(b.at(k).size() == n); // asking to check it too often 92 rslt.at(i).at(j) += a.at(i).at(k) * b.at(k).at(j); 93 } 94 } 95 } 96 96 } 97 97 … … 99 99 #include <iostream> 100 100 int main( int argc, char ** argv ) { 101 102 103 104 101 mat a(5, vector<float>(6)); 102 mat b(6, vector<float>(7)); 103 mat r(5, vector<float>(7)); 104 matmul(a, b, r); 105 105 } 106 106 #endif
Note: See TracChangeset
for help on using the changeset viewer.