Exemple #1
0
    def __init__(self, domain, shape=(), count=None):
        Terminal.__init__(self)
        counted_init(self, count=count, countedclass=Constant)

        self._ufl_domain = as_domain(domain)
        self._ufl_shape = shape

        # Repr string is build in such way, that reconstruction
        # with eval() is possible
        self._repr = "Constant({}, {}, {})".format(repr(self._ufl_domain),
                                                   repr(self._ufl_shape),
                                                   repr(self._count))
Exemple #2
0
    def __new__(cls, indices):
        if not isinstance(indices, tuple):
            error("Expecting a tuple of indices.")

        if all(isinstance(ind, FixedIndex) for ind in indices):
            # Cache multiindices consisting of purely fixed indices
            # (aka flyweight pattern)
            key = tuple(ind._value for ind in indices)
            self = MultiIndex._cache.get(key)
            if self is not None:
                return self
            self = Terminal.__new__(cls)
            MultiIndex._cache[key] = self
        else:
            # Create a new object if we have any free indices (too
            # many combinations to cache)
            if not all(isinstance(ind, IndexBase) for ind in indices):
                error("Expecting only Index and FixedIndex objects.")
            self = Terminal.__new__(cls)

        # Initialize here instead of in __init__ to avoid overwriting
        # self._indices from cached objects
        self._init(indices)
        return self
Exemple #3
0
    def __new__(cls, indices):
        if not isinstance(indices, tuple):
            error("Expecting a tuple of indices.")

        if all(isinstance(ind, FixedIndex) for ind in indices):
            # Cache multiindices consisting of purely fixed indices
            # (aka flyweight pattern)
            key = tuple(ind._value for ind in indices)
            self = MultiIndex._cache.get(key)
            if self is not None:
                return self
            self = Terminal.__new__(cls)
            MultiIndex._cache[key] = self
        else:
            # Create a new object if we have any free indices (too
            # many combinations to cache)
            if not all(isinstance(ind, IndexBase) for ind in indices):
                error("Expecting only Index and FixedIndex objects.")
            self = Terminal.__new__(cls)

        # Initialize here instead of in __init__ to avoid overwriting
        # self._indices from cached objects
        self._init(indices)
        return self
Exemple #4
0
 def __init__(self, domain):
     Terminal.__init__(self)
     self._domain = as_domain(domain)
Exemple #5
0
 def __init__(self, count=None):
     Terminal.__init__(self)
     counted_init(self, count, Label)
Exemple #6
0
 def __init__(self, domain):
     Terminal.__init__(self)
     self._domain = as_domain(domain)
Exemple #7
0
 def _init(self, indices):
     Terminal.__init__(self)
     self._indices = indices
Exemple #8
0
 def __init__(self):
     Terminal.__init__(self)
Exemple #9
0
 def __init__(self, count=None):
     Terminal.__init__(self)
     counted_init(self, count, Label)
Exemple #10
0
 def __init__(self):
     Terminal.__init__(self)
Exemple #11
0
 def _init(self, indices):
     Terminal.__init__(self)
     self._indices = indices