~ubuntu-branches/ubuntu/trusty/ffc/trusty

« back to all changes in this revision

Viewing changes to ffc/quadrature/symbol.py

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2010-09-02 11:50:35 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100902115035-ifepqvpkveaa0sjw
Tags: 0.9.4-1
* New upstream release.
* Bump Standards-Version (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from expr import Expr
20
20
 
21
21
class Symbol(Expr):
22
 
    __slots__ = ("v", "base_expr", "base_op", "exp")
23
 
    def __init__(self, variable, symbol_type, base_expr=None, base_op=0):
 
22
    __slots__ = ("v", "base_expr", "base_op", "exp", "cond")
 
23
    def __init__(self, variable, symbol_type, base_expr=None, base_op=0, cond=()):
24
24
        """Initialise a Symbols object, it derives from Expr and contains
25
25
        the additional variables:
26
26
 
44
44
        self.base_expr = base_expr
45
45
        self.base_op = base_op
46
46
        self.exp = None
 
47
        self.cond = cond
47
48
 
48
49
        # If type of the base_expr is lower than the given symbol_type change type.
49
50
        # TODO: Should we raise an error here? Or simply require that one
56
57
        # only when objects are cached).
57
58
        if self.base_expr:
58
59
            self._repr = "Symbol('%s', %s, %s, %d)" % (self.v, type_to_string[self.t], self.base_expr._repr, self.base_op)
 
60
        elif self.cond:
 
61
            self._repr = "Symbol('%s', %s, %s, %d, %s)" % (self.v, type_to_string[self.t], self.base_expr, self.base_op, self.cond)
59
62
        else:
60
63
            self._repr = "Symbol('%s', %s)" % (self.v, type_to_string[self.t])
61
64
 
66
69
    def __str__(self):
67
70
        "Simple string representation which will appear in the generated code."
68
71
        if self.base_expr is None:
69
 
            return self.v
 
72
            if self.cond == ():
 
73
                return self.v
 
74
            else:
 
75
                return "".join([str(c) for c in self.cond])
70
76
        elif self.exp is None:
71
77
            return self.v(str(self.base_expr))
72
78
        return self.v(str(self.base_expr), self.exp)
205
211
        # for the base (sin(2*x + 1)) --> 2 + 1.
206
212
        if self.base_expr:
207
213
            return self.base_op + self.base_expr.ops()
 
214
        elif self.cond:
 
215
            return self.base_op + self.cond[0].ops() + self.cond[2].ops() + 1
208
216
        return self.base_op
209
217
 
210
218
from floatvalue import FloatValue