~ubuntu-branches/ubuntu/utopic/blitz++/utopic

« back to all changes in this revision

Viewing changes to blitz/generate/genmatbops.cpp

  • Committer: Package Import Robot
  • Author(s): Christophe Trophime
  • Date: 2012-07-06 09:15:30 UTC
  • mfrom: (11.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20120706091530-vzrb8zf0vpbf8tp9
Tags: 1:0.10-1
* New upstream release
  Closes: #679407
* debian/rules:
  - update for new release
  - add override_dh_auto_test target
  - regenerate configure and Makefile.am
* debian/control:
  - add libtool, automake to BuildDepends
* debian/libblitz-doc.install
  - modify path for html files
* remove uneeded patches
* add examples.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
#include <iostream>
3
 
#include <fstream>
4
 
#include "optuple2.h"
5
 
 
6
 
int main()
7
 
{
8
 
    std::cout << "Generating <matbops.h>" << std::endl;
9
 
 
10
 
    OperandTuple2 operands(2);
11
 
 
12
 
    std::ofstream ofs("../matbops.h");
13
 
    ofs << "// Generated source file.  Do not edit." << std::endl;
14
 
    ofs << "// Created by: " << __FILE__ << " " << __DATE__ 
15
 
        << " " << __TIME__ << std::endl << std::endl;
16
 
 
17
 
    ofs << "#ifndef BZ_MATBOPS_H" << std::endl
18
 
        << "#define BZ_MATBOPS_H" << std::endl
19
 
        << std::endl << "BZ_NAMESPACE(blitz)" << std::endl << std::endl
20
 
        << "#ifndef BZ_MATEXPR_H" << std::endl
21
 
        << " #error <blitz/matbops.h> must be included via <blitz/matexpr.h>" 
22
 
        << std::endl << "#endif" << std::endl << std::endl;
23
 
 
24
 
    struct {
25
 
        const char* opSymbol;
26
 
        bool        nonIntOperands;
27
 
        bool        complexOperands;
28
 
        const char* opApplicName;
29
 
        const char* comment;
30
 
    } ops[] = {
31
 
     { "+",  true,  true,  "_bz_Add",            "Addition Operators" },
32
 
     { "-",  true,  true,  "_bz_Subtract",       "Subtraction Operators" },
33
 
     { "*",  true,  true,  "_bz_Multiply",       "Multiplication Operators" },
34
 
     { "/",  true,  true,  "_bz_Divide",         "Division Operators" },
35
 
     { "%",  false, false, "_bz_Mod",            "Modulus Operators" },
36
 
     { "^",  false, false, "_bz_BitwiseXOR",     "Bitwise XOR Operators" },
37
 
     { "&",  false, false, "_bz_BitwiseAnd",     "Bitwise And Operators" },
38
 
     { "|",  false, false, "_bz_BitwiseOr",      "Bitwise Or Operators" },
39
 
     { ">>", false, false, "_bz_ShiftRight",     "Shift right Operators" },
40
 
     { "<<", false, false, "_bz_ShiftLeft",      "Shift left Operators" },
41
 
     { ">",  true,  false, "_bz_Greater",        "Greater-than Operators" },
42
 
     { "<",  true,  false, "_bz_Less",           "Less-than Operators" },
43
 
     { ">=", true,  false, "_bz_GreaterOrEqual", "Greater or equal (>=) operators" },
44
 
     { "<=", true,  false, "_bz_LessOrEqual",    "Less or equal (<=) operators" },
45
 
     { "==", true,  true,  "_bz_Equal",          "Equality operators" },
46
 
     { "!=", true,  true,  "_bz_NotEqual",       "Not-equal operators" },
47
 
     { "&&", false, false, "_bz_LogicalAnd",     "Logical AND operators" },
48
 
     { "||", false, false, "_bz_LogicalOr",      "Logical OR operators" },
49
 
     { "min", false, false, "_bz_Min",      "Minimum Operators" },
50
 
     { "max", false, false, "_bz_Max",      "Maximum Operators" }
51
 
    };
52
 
 
53
 
    for (int i=0; i < 20; ++i)
54
 
    {
55
 
    ofs << "/****************************************************************************" << std::endl
56
 
        << " * " << ops[i].comment << std::endl
57
 
        << " ****************************************************************************/" << std::endl;
58
 
 
59
 
    operands.reset();
60
 
 
61
 
    do {
62
 
        if (ops[i].nonIntOperands == false)
63
 
        {
64
 
            if ((operands[0].isScalar() && !operands[0].isInteger())
65
 
             || (operands[1].isScalar() && !operands[1].isInteger()))
66
 
                continue;
67
 
        }
68
 
 
69
 
        // Matrix<P_numtype1> + _bz_MatExpr<P_expr2>
70
 
 
71
 
        if (operands.anyComplex())
72
 
            ofs << "#ifdef BZ_HAVE_COMPLEX" << std::endl;
73
 
 
74
 
        ofs << std::endl << "// ";
75
 
        operands[0].printName(ofs);
76
 
        ofs << " " << ops[i].opSymbol << " ";
77
 
        operands[1].printName(ofs);
78
 
        ofs << std::endl;
79
 
 
80
 
        operands.printTemplates(ofs);
81
 
        ofs << std::endl << "inline" << std::endl;
82
 
 
83
 
        // _bz_MatExpr<_bz_MatExprOp<MatRef<T_numtype1>,
84
 
        //     _bz_MatExpr<T_expr2>, _bz_Add<T_numtype1,typename T_expr2::T_numtype> > >
85
 
        ofs << "_bz_MatExpr<_bz_MatExprOp<";
86
 
        operands.printIterators(ofs, 1);
87
 
        ofs << "," << std::endl << "      " << ops[i].opApplicName << "<";
88
 
        operands[0].printNumtype(ofs);
89
 
        ofs << ", ";    
90
 
        operands[1].printNumtype(ofs);
91
 
        ofs << " > > >" << std::endl;
92
 
     
93
 
        // operator+(const Matrix<T_numtype1>& d1, _bz_MatExpr<T_expr2> d2)
94
 
                                if (ops[i].opSymbol[0] == 'm') 
95
 
                                        ofs << ops[i].opSymbol << "(";
96
 
                                else
97
 
                ofs << "operator" << ops[i].opSymbol << "(";
98
 
        operands.printArgumentList(ofs, 1);
99
 
        ofs << ")" << std::endl << "{" << std::endl;
100
 
 
101
 
        // typedef _bz_MatExprOp<MatRef<T_numtype1>,
102
 
        // _bz_MatExpr<T_expr2>, _bz_Add<T_numtype1,typename T_expr2::T_numtype> > T_expr;
103
 
        ofs << "    typedef _bz_MatExprOp<";
104
 
        operands.printIterators(ofs, 1);
105
 
        ofs << ", " << std::endl << "      " << ops[i].opApplicName << "<";
106
 
        operands[0].printNumtype(ofs);
107
 
        ofs << ", ";
108
 
        operands[1].printNumtype(ofs);
109
 
        ofs << "> > T_expr;" << std::endl << std::endl;
110
 
 
111
 
        // return _bz_MatExpr<T_expr>(T_expr(a.begin(), b));
112
 
        ofs << "    return _bz_MatExpr<T_expr>(T_expr(";
113
 
        operands.printInitializationList(ofs,1);
114
 
        ofs << "));" << std::endl << "}" << std::endl;
115
 
 
116
 
        if (operands.anyComplex())
117
 
            ofs << "#endif // BZ_HAVE_COMPLEX" << std::endl << std::endl;
118
 
 
119
 
    } while (++operands);
120
 
    
121
 
    }
122
 
 
123
 
    ofs << std::endl << "BZ_NAMESPACE_END" << std::endl << std::endl
124
 
        << "#endif // BZ_MATBOPS_H" << std::endl;
125
 
 
126
 
   std::cout << operands.numSpecializations() << " operators written." << std::endl;
127
 
}
128