~ubuntu-branches/ubuntu/saucy/rheolef/saucy

« back to all changes in this revision

Viewing changes to skit/ptst2/vec_expr_tst.cc

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Saramito
  • Date: 2011-03-23 11:14:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110323111426-cjvhey7lxt6077ty
Tags: 5.93-1
* New upstream release (minor changes):
  - some extra warning message deleted in heap_allocator
  - graphic output with mayavi2 fixed
  - add doc refman in .info and .pdf format

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
19
///
20
20
/// =========================================================================
21
 
#include "rheolef/vec_expr.h"
22
 
#include "rheolef/parstream.h"
 
21
#include "rheolef/vec_expr_ops.h"
 
22
#include "rheolef/diststream.h"
 
23
#include "rheolef/pretty_name.h"
23
24
using namespace rheolef;
24
25
using namespace std;
25
26
 
 
27
template <class Iterator>
 
28
void
 
29
check_iterator_access_raw (Iterator iter, size_t n) {
 
30
  warning_macro ("iter: expr.size="<<n);
 
31
  for (size_t i = 0; i < n; i++, iter++) {
 
32
    warning_macro ("iter: expr["<<i<<"] = "<<*iter);
 
33
  }
 
34
}
 
35
template <class Expr>
 
36
void
 
37
check_iterator_access (Expr e) {
 
38
  check_iterator_access_raw (e.begin(), e.size());
 
39
}  
 
40
template <class Expr>
 
41
void
 
42
check_subscript_access (Expr e) {
 
43
  warning_macro ("sub: expr.size="<<e.size());
 
44
  for (typename Expr::size_type i = 0, n = e.size(); i < n; i++) {
 
45
    warning_macro ("sub: expr["<<i<<"] = "<< e[i]);
 
46
  }
 
47
}
26
48
struct phi : unary_function<Float,Float> {
27
49
  Float operator() (const Float& x) { return 2*x; }
28
50
};
29
51
int main(int argc, char**argv) {
30
 
    environment parallel(argc, argv);
 
52
    environment distributed(argc, argv);
31
53
    size_t n = (argc < 2) ? 5 : atoi(argv[1]);
32
 
    vec<Float> x(n, 2.);
33
 
    vec<Float> y(n, 3.);
 
54
    vec<Float> x(n, 2.5);
 
55
    vec<Float> y(n, 4.);
34
56
 
35
57
    // set size and then assign:
36
58
    vec<Float> z(n); 
37
 
    z = 2.*x - y;
38
 
    pcout << "z = " << z.par_size() << endl;
39
 
    z.put (pcout);
 
59
    z = 2*x - y;
 
60
    dcout << "z = 2*x-y : z.dis_size = " << z.dis_size() << endl;
 
61
    z.put_values (dcout);
40
62
    
41
63
    // size is zero and then assign:
42
64
    vec<Float> z1; 
43
 
    z1 = 2.*x - y;
44
 
    pcout << "z1 = " << z1.par_size() << endl;
45
 
    z1.put (pcout);
 
65
    z1 = 2*x - y;
 
66
    dcout << "z1.dis_size = " << z1.dis_size() << endl;
 
67
    z1.put_values (dcout);
46
68
    
47
69
    // copy cstor:
48
 
    vec<Float> z2 = 2.*x - y;
49
 
    pcout << "z2 = " << z2.par_size() << endl;
50
 
    z2.put (pcout);
 
70
    vec<Float> z2 = 2*x - y;
 
71
    dcout << "z2.dis_size = " << z2.dis_size() << endl;
 
72
    z2.put_values (dcout);
 
73
 
 
74
    check_iterator_access  (x+y);
 
75
    check_subscript_access (x+y);
 
76
 
 
77
    // dot with expression (lazy evaluation)
 
78
    dcout << "dot(x, z) = " << dot(x, z) << endl;
 
79
    dcout << "dot(x, 2*x-y) = " << dot(x, 2*x - y) << endl;
 
80
    dcout << "dot(2*x-y, x) = " << dot(2*x-y, x) << endl;
 
81
    dcout << "dot(3*x-y, 2*x-y) = " << dot(3*x-y, 2*x-y) << endl;
51
82
 
52
83
#ifdef TO_CLEAN    
53
 
    // set bad size and then assign:
 
84
    // set bad size and then assign: it may exit(1)
54
85
    vec<Float> z3(n+1); 
55
86
    z3 = 2*x - y;
56
 
    pcout << "z3 = " << z3.size() << endl;
57
 
    z3.put (pcout);
 
87
    dcout << "z3 = " << z3.size() << endl;
 
88
    z3.put_values (dcout);
58
89
#endif // TO_CLEAN    
59
90
}