Skip to content
Snippets Groups Projects
Commit 6301c15a authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Merge branch 'fix-non-unique-names-in-symbolgenerator' into 'master'

SymbolicAssignmentCollection: Fix name uniqueness (closes #13).

Closes #13

See merge request !27
parents 9486ad03 573f110a
No related branches found
No related tags found
1 merge request!27SymbolicAssignmentCollection: Fix name uniqueness (closes #13).
Pipeline #
...@@ -48,7 +48,14 @@ class _SymbolGenerator(object): ...@@ -48,7 +48,14 @@ class _SymbolGenerator(object):
from collections import defaultdict from collections import defaultdict
self.base_to_count = defaultdict(lambda: 0) self.base_to_count = defaultdict(lambda: 0)
def _normalize(self, base):
# Strip off any _N suffix, to avoid generating conflicting names.
import re
base = re.split("_\d+$", base)[0]
return base if base != "" else "expr"
def __call__(self, base="expr"): def __call__(self, base="expr"):
base = self._normalize(base)
count = self.base_to_count[base] count = self.base_to_count[base]
def make_id_str(base, count): def make_id_str(base, count):
......
from __future__ import division, absolute_import, print_function
__copyright__ = "Copyright (C) 2017 Matt Wala"
__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import sys
import logging
logger = logging.getLogger(__name__)
def test_symbolic_assignment_name_uniqueness():
# https://gitlab.tiker.net/inducer/sumpy/issues/13
from sumpy.assignment_collection import SymbolicAssignmentCollection
sac = SymbolicAssignmentCollection({"s_0": 1})
sac.assign_unique("s_", 1)
sac.assign_unique("s_", 1)
assert len(sac.assignments) == 3
sac = SymbolicAssignmentCollection()
sac.assign_unique("s_0", 1)
sac.assign_unique("s_", 1)
sac.assign_unique("s_", 1)
assert len(sac.assignments) == 3
# You can test individual routines by typing
# $ python test_fmm.py 'test_sumpy_fmm(cl.create_some_context)'
if __name__ == "__main__":
if len(sys.argv) > 1:
exec(sys.argv[1])
else:
from py.test.cmdline import main
main([__file__])
# vim: fdm=marker
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment