def __init__(self, spatial_dim, var_shape, var_free_indices, var_index_dimensions, cache=None): Transformer.__init__(self) ufl_assert(all(isinstance(i, Index) for i in var_free_indices), \ "Expecting Index objects.") ufl_assert(all(isinstance(i, Index) for i in var_index_dimensions.keys()), \ "Expecting Index objects.") self._spatial_dim = spatial_dim self._var_shape = var_shape self._var_free_indices = var_free_indices self._var_index_dimensions = dict(var_index_dimensions) #if self._var_free_indices: # warning("TODO: Free indices in differentiation variable may be buggy!") self._cache = {} if cache is None else cache
def _debug_visit(self, o): "Debugging hook, enable this by renaming to 'visit'." r = Transformer.visit(self, o) f, df = r if not f is o: debug("In ForwardAD.visit, didn't get back o:") debug(" o: %s" % str(o)) debug(" f: %s" % str(f)) debug(" df: %s" % str(df)) fi_diff = set(f.free_indices()) ^ set(df.free_indices()) if fi_diff: debug("In ForwardAD.visit, got free indices diff:") debug(" o: %s" % str(o)) debug(" f: %s" % str(f)) debug(" df: %s" % str(df)) debug(" f.fi(): %s" % lstr(f.free_indices())) debug(" df.fi(): %s" % lstr(df.free_indices())) debug(" fi_diff: %s" % str(fi_diff)) return r
def _cache_visit(self, o): "Cache hook, disable this by renaming to something else than 'visit'." #debug("Visiting object of type %s." % type(o).__name__) # TODO: This doesn't work, why? # NB! Cache added in after copying from Transformer c = self._cache.get(o) if c is not None: return c # Reuse default visit function r = Transformer.visit(self, o) if (c is not None): if r[0].free_indices() != c[0].free_indices(): print "=" * 70 print "=== f: Difference between cache and recomputed indices:" print str(c[0].free_indices()) print str(r[0].free_indices()) print "=" * 70 if r[1].free_indices() != c[1].free_indices(): print "=" * 70 print "=== df: Difference between cache and recomputed indices:" print str(c[1].free_indices()) print str(r[1].free_indices()) print "=" * 70 if (r != c): print "=" * 70 print "=== Difference between cache and recomputed:" print str(c[0]) print str(c[1]) print "-" * 40 print str(r[0]) print str(r[1]) print "=" * 70 # NB! Cache added in after copying from Transformer self._cache[o] = r return r
def _cache_visit(self, o): "Cache hook, disable this by renaming to something else than 'visit'." #debug("Visiting object of type %s." % type(o).__name__) # TODO: This doesn't work, why? # NB! Cache added in after copying from Transformer c = self._cache.get(o) if c is not None: return c # Reuse default visit function r = Transformer.visit(self, o) if (c is not None): if r[0].free_indices() != c[0].free_indices(): print "="*70 print "=== f: Difference between cache and recomputed indices:" print str(c[0].free_indices()) print str(r[0].free_indices()) print "="*70 if r[1].free_indices() != c[1].free_indices(): print "="*70 print "=== df: Difference between cache and recomputed indices:" print str(c[1].free_indices()) print str(r[1].free_indices()) print "="*70 if (r != c): print "="*70 print "=== Difference between cache and recomputed:" print str(c[0]) print str(c[1]) print "-"*40 print str(r[0]) print str(r[1]) print "="*70 # NB! Cache added in after copying from Transformer self._cache[o] = r return r
def __init__(self, arguments): Transformer.__init__(self) self._want = set(arguments)
def __init__(self, default_degree, element_replace_map): Transformer.__init__(self) self.default_degree = default_degree self.element_replace_map = element_replace_map
def __init__(self, arguments): Transformer.__init__(self) self.arguments = tuple(arguments) self.empty = tuple(None for arg in arguments)
def __init__(self, require_restriction): Transformer.__init__(self) self.current_restriction = None self.require_restriction = require_restriction
def __init__(self): Transformer.__init__(self) self._empty = frozenset()
def __init__(self, argument_names=None, coefficient_names=None): Transformer.__init__(self) self.argument_names = argument_names self.coefficient_names = coefficient_names