~ubuntu-branches/ubuntu/vivid/ffc/vivid

« back to all changes in this revision

Viewing changes to ffc/quadrature/symbol.py

  • Committer: Package Import Robot
  • Author(s): Johannes Ring
  • Date: 2014-01-10 13:56:45 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20140110135645-4ozcd71y1oggj44z
Tags: 1.3.0-1
* New upstream release.
* debian/watch: Update URL for move to Bitbucket.
* debian/docs: README -> README.rst and remove TODO.
* debian/control:
  - Add python-numpy to Build-Depends.
  - Replace python-all with python-all-dev in Build-Depends.
  - Add ${shlibs:Depends} to Depends.
  - Change to Architecture: any.
  - Bump Standards-Version to 3.9.5 (no changes needed).
* debian/rules: Call dh_numpy in override_dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
class Symbol(Expr):
36
36
    __slots__ = ("v", "base_expr", "base_op", "exp", "cond")
37
 
    def __init__(self, variable, symbol_type, base_expr=None, base_op=0, expo=None, cond=()):
 
37
    def __init__(self, variable, symbol_type, base_expr=None, base_op=0):
38
38
        """Initialise a Symbols object, it derives from Expr and contains
39
39
        the additional variables:
40
40
 
57
57
        # ops = base_expr.ops() + base_ops = 2 + 1 = 3
58
58
        self.base_expr = base_expr
59
59
        self.base_op = base_op
60
 
        self.exp = expo
61
 
        self.cond = cond
62
60
 
63
61
        # If type of the base_expr is lower than the given symbol_type change type.
64
62
        # TODO: Should we raise an error here? Or simply require that one
69
67
        # Compute the representation now, such that we can use it directly
70
68
        # in the __eq__ and __ne__ methods (improves performance a bit, but
71
69
        # only when objects are cached).
72
 
        if self.base_expr and self.exp is None:
 
70
        if self.base_expr:# and self.exp is None:
73
71
            self._repr = "Symbol('%s', %s, %s, %d)" % (self.v, type_to_string[self.t],\
74
72
                         self.base_expr._repr, self.base_op)
75
 
        elif self.base_expr:
76
 
            self._repr = "Symbol('%s', %s, %s, %d, %s)" % (self.v, type_to_string[self.t],\
77
 
                         self.base_expr._repr, self.base_op, self.exp)
78
 
        elif self.cond:
79
 
            self._repr = "Symbol('%s', %s, %s, %d, %s, %s)" % (self.v, type_to_string[self.t],\
80
 
                          self.base_expr, self.base_op, self.exp, self.cond)
81
73
        else:
82
74
            self._repr = "Symbol('%s', %s)" % (self.v, type_to_string[self.t])
83
75
 
87
79
    # Print functions.
88
80
    def __str__(self):
89
81
        "Simple string representation which will appear in the generated code."
90
 
        if self.base_expr is None:
91
 
            if self.cond == ():
92
 
                return self.v
93
 
            else:
94
 
                if len(self.cond) == 2:
95
 
                    return self.cond[1](str(self.cond[0]))
96
 
                return format["grouping"]("".join([str(c) for c in self.cond]))
97
 
        elif self.exp is None:
98
 
            return self.v(str(self.base_expr))
99
 
        return self.v(str(self.base_expr), self.exp)
 
82
#        print "sym str: ", self.v
 
83
        return self.v
100
84
 
101
85
    # Binary operators.
102
86
    def __add__(self, other):
232
216
        # for the base (sin(2*x + 1)) --> 2 + 1.
233
217
        if self.base_expr:
234
218
            return self.base_op + self.base_expr.ops()
235
 
        elif self.cond:
236
 
            if len(self.cond) == 2:
237
 
                return self.base_op + self.cond[0].ops() + 1
238
 
            return self.base_op + self.cond[0].ops() + self.cond[2].ops() + 1
239
219
        return self.base_op
240
220
 
241
221
from floatvalue import FloatValue