#include <iostream>
#include <ginac/ginac.h>
#include "SyFi.h"
#include "ginac_tools.h"
Go to the source code of this file.
Functions | |
ex | pickExpression (int i) |
int | main (int argc, char **argv) |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 48 of file flop_counter.cpp.
References SyFi::ExStats::adds, SyFi::count_ops(), test::e, demos::simple::f, SyFi::ExStats::flops, swig::from(), SyFi::ExStats::functions, SyFi::ExStats::muls, pickExpression(), and SyFi::ExStats::pows.
00049 { 00050 bool verbose = false; // turn this off for the unit tests 00051 if(argc>1 && argv[1][0] == 'v') verbose = true; 00052 00053 int from = 0; 00054 int to = 10; 00055 for(int i=from; i<to; i++) 00056 { 00057 // pick an expression to test 00058 ex e = pickExpression(i); 00059 ex f = e*e; 00060 00061 ExStats es = count_ops(e); 00062 ExStats fs = count_ops(f); 00063 00064 if(verbose) cout << "Flops in e = " << e << endl; 00065 else cout << "Flops in e " << endl; 00066 cout << " adds: " << es.adds << endl; 00067 cout << " muls: " << es.muls << endl; 00068 cout << " pows: " << es.pows << endl; 00069 cout << " funs: " << es.functions << endl; 00070 cout << " flops: " << es.flops << endl; 00071 cout << endl; 00072 if(verbose) cout << "Flops in f = " << f << endl; 00073 else cout << "Flops in f " << endl; 00074 cout << " adds: " << fs.adds << endl; 00075 cout << " muls: " << fs.muls << endl; 00076 cout << " pows: " << fs.pows << endl; 00077 cout << " funs: " << fs.functions << endl; 00078 cout << " flops: " << fs.flops << endl; 00079 cout << endl; 00080 } 00081 00082 return 0; 00083 }
ex pickExpression | ( | int | i | ) |
Definition at line 16 of file flop_counter.cpp.
References test::e, SyFi::get_symbol(), SyFi::x, SyFi::y, and SyFi::z.
Referenced by main().
00017 { 00018 ex x = get_symbol("x"); 00019 ex y = get_symbol("y"); 00020 ex z = get_symbol("z"); 00021 00022 ex e; 00023 switch(i) 00024 { 00025 case 0: e = 1; break; 00026 case 1: e = x; break; 00027 case 2: e = x+y; break; 00028 case 3: e = x+y+z; break; 00029 case 4: e = x*y; break; 00030 case 5: e = x*y*z; break; 00031 case 6: e = x*x*y*y*z*z; break; 00032 case 7: e = x*x*x*y*y*y*z*z*z; break; 00033 case 8: 00034 e = power(x,3)*power(y,2) + power(x,2) + x*y*y; 00035 break; 00036 case 9: 00037 e = power(x,3)*power(y,2) + power(x,2) + x*y*y; 00038 e = power(e, e) + e; 00039 break; 00040 // add more tests with a new case here, and update the iteration limit in main 00041 default: 00042 e = 0; 00043 } 00044 return e; 00045 }