Ignore:
Timestamp:
Mar 10, 2024, 11:21:18 AM (7 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
9398177
Parents:
b64d0f4
Message:

more switch to tabs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mike_brooks_MMath/programs/array-boundcheck-removal-stdvec.cpp

    rb64d0f4 r5546f50b  
    33forall( [M], [N], [P] )
    44void matmul( array(float, M, P) & src1,
    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     }
     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        }
    1212}
    1313*/
     
    3030
    3131float f( vector<float> & a ) {
    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;
     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;
    3838}
    3939
     
    4141#include <iostream>
    4242int main( int argc, char ** argv ) {
    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;
     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;
    4949
    50     float answer = f(v);
     50        float answer = f(v);
    5151
    52     cout << "answer: " << answer << endl;
     52        cout << "answer: " << answer << endl;
    5353
    5454}
     
    8080
    8181void matmul( mat & a, mat & b, mat & rslt ) {
    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     }
     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        }
    9696}
    9797
     
    9999#include <iostream>
    100100int main( int argc, char ** argv ) {
    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);
     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);
    105105}
    106106#endif
Note: See TracChangeset for help on using the changeset viewer.