From 75336d039d5720c188334cb05f7047695115e2db Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Thu, 20 Feb 2014 13:23:25 -0600
Subject: [PATCH] Fix stringification of FunctionIdentifier objects

---
 loopy/symbolic.py | 207 ++++++++++++++++++++++++----------------------
 1 file changed, 106 insertions(+), 101 deletions(-)

diff --git a/loopy/symbolic.py b/loopy/symbolic.py
index dcd941f71..e9912e2f6 100644
--- a/loopy/symbolic.py
+++ b/loopy/symbolic.py
@@ -60,107 +60,6 @@ import re
 import numpy as np
 
 
-# {{{ loopy-specific primitives
-
-class FunctionIdentifier(Leaf):
-    init_arg_names = ()
-
-    def __getinitargs__(self):
-        return ()
-
-    mapper_method = intern("map_loopy_function_identifier")
-
-
-class TypedCSE(CommonSubexpression):
-    def __init__(self, child, prefix=None, dtype=None):
-        CommonSubexpression.__init__(self, child, prefix)
-        self.dtype = dtype
-
-    def __getinitargs__(self):
-        return (self.child, self.dtype, self.prefix)
-
-    def get_extra_properties(self):
-        return dict(dtype=self.dtype)
-
-
-class TaggedVariable(Variable):
-    """This is an identifier with a tag, such as 'matrix$one', where
-    'one' identifies this specific use of the identifier. This mechanism
-    may then be used to address these uses--such as by prefetching only
-    accesses tagged a certain way.
-    """
-
-    init_arg_names = ("name", "tag")
-
-    def __init__(self, name, tag):
-        Variable.__init__(self, name)
-        self.tag = tag
-
-    def __getinitargs__(self):
-        return self.name, self.tag
-
-    def stringifier(self):
-        return StringifyMapper
-
-    mapper_method = intern("map_tagged_variable")
-
-
-class Reduction(AlgebraicLeaf):
-    init_arg_names = ("operation", "inames", "expr")
-
-    def __init__(self, operation, inames, expr):
-        assert isinstance(inames, tuple)
-
-        if isinstance(operation, str):
-            from loopy.library.reduction import parse_reduction_op
-            operation = parse_reduction_op(operation)
-
-        self.operation = operation
-        self.inames = inames
-        self.expr = expr
-
-    def __getinitargs__(self):
-        return (self.operation, self.inames, self.expr)
-
-    def get_hash(self):
-        return hash((self.__class__, self.operation, self.inames,
-            self.expr))
-
-    def is_equal(self, other):
-        return (other.__class__ == self.__class__
-                and other.operation == self.operation
-                and other.inames == self.inames
-                and other.expr == self.expr)
-
-    def stringifier(self):
-        return StringifyMapper
-
-    @property
-    @memoize_method
-    def inames_set(self):
-        return set(self.inames)
-
-    mapper_method = intern("map_reduction")
-
-
-class LinearSubscript(AlgebraicLeaf):
-    init_arg_names = ("aggregate", "index")
-
-    def __init__(self, aggregate, index):
-        self.aggregate = aggregate
-        self.index = index
-
-    def __getinitargs__(self):
-        return self.aggregate, self.index
-
-    def stringifier(self):
-        return StringifyMapper
-
-    mapper_method = intern("map_linear_subscript")
-
-# }}}
-
-
 # {{{ mappers with support for loopy-specific primitives
 
 class IdentityMapperMixin(object):
@@ -232,6 +131,11 @@ class StringifyMapper(StringifyMapperBase):
                     self.rec(expr.index, PREC_NONE)),
                 enclosing_prec, PREC_CALL)
 
+    def map_loopy_function_identifier(self, expr, enclosing_prec):
+        return "%s<%s>" % (
+                type(expr).__name__,
+                ", ".join(str(a) for a in expr.__getinitargs__()))
+
 
 class UnidirectionalUnifier(UnidirectionalUnifierBase):
     def map_reduction(self, expr, other, unis):
@@ -282,6 +186,107 @@ class DependencyMapper(DependencyMapperBase):
 # }}}
 
 
+# {{{ loopy-specific primitives
+
+class FunctionIdentifier(Leaf):
+    init_arg_names = ()
+
+    def stringifier(self):
+        return StringifyMapper
+
+    mapper_method = intern("map_loopy_function_identifier")
+
+
+class TypedCSE(CommonSubexpression):
+    def __init__(self, child, prefix=None, dtype=None):
+        CommonSubexpression.__init__(self, child, prefix)
+        self.dtype = dtype
+
+    def __getinitargs__(self):
+        return (self.child, self.dtype, self.prefix)
+
+    def get_extra_properties(self):
+        return dict(dtype=self.dtype)
+
+
+class TaggedVariable(Variable):
+    """This is an identifier with a tag, such as 'matrix$one', where
+    'one' identifies this specific use of the identifier. This mechanism
+    may then be used to address these uses--such as by prefetching only
+    accesses tagged a certain way.
+    """
+
+    init_arg_names = ("name", "tag")
+
+    def __init__(self, name, tag):
+        Variable.__init__(self, name)
+        self.tag = tag
+
+    def __getinitargs__(self):
+        return self.name, self.tag
+
+    def stringifier(self):
+        return StringifyMapper
+
+    mapper_method = intern("map_tagged_variable")
+
+
+class Reduction(AlgebraicLeaf):
+    init_arg_names = ("operation", "inames", "expr")
+
+    def __init__(self, operation, inames, expr):
+        assert isinstance(inames, tuple)
+
+        if isinstance(operation, str):
+            from loopy.library.reduction import parse_reduction_op
+            operation = parse_reduction_op(operation)
+
+        self.operation = operation
+        self.inames = inames
+        self.expr = expr
+
+    def __getinitargs__(self):
+        return (self.operation, self.inames, self.expr)
+
+    def get_hash(self):
+        return hash((self.__class__, self.operation, self.inames,
+            self.expr))
+
+    def is_equal(self, other):
+        return (other.__class__ == self.__class__
+                and other.operation == self.operation
+                and other.inames == self.inames
+                and other.expr == self.expr)
+
+    def stringifier(self):
+        return StringifyMapper
+
+    @property
+    @memoize_method
+    def inames_set(self):
+        return set(self.inames)
+
+    mapper_method = intern("map_reduction")
+
+
+class LinearSubscript(AlgebraicLeaf):
+    init_arg_names = ("aggregate", "index")
+
+    def __init__(self, aggregate, index):
+        self.aggregate = aggregate
+        self.index = index
+
+    def __getinitargs__(self):
+        return self.aggregate, self.index
+
+    def stringifier(self):
+        return StringifyMapper
+
+    mapper_method = intern("map_linear_subscript")
+
+# }}}
+
+
 @memoize
 def get_dependencies(expr):
     dep_mapper = DependencyMapper(composite_leaves=False)
-- 
GitLab