From ce545ffab9494e0c8250a8880859b6b097ed544d Mon Sep 17 00:00:00 2001 From: Vivien Maisonneuve Date: Wed, 2 Jul 2014 23:22:57 +0200 Subject: [PATCH 1/1] Implementation of Symbol.sortkey() --- pypol/domains.py | 4 ++-- pypol/linexprs.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pypol/domains.py b/pypol/domains.py index 74351fc..224ac5f 100644 --- a/pypol/domains.py +++ b/pypol/domains.py @@ -5,7 +5,7 @@ import re from . import islhelper from .islhelper import mainctx, libisl, isl_set_basic_sets -from .linexprs import Expression +from .linexprs import Expression, Symbol __all__ = [ @@ -50,7 +50,7 @@ class Domain: symbols = set() for item in iterator: symbols.update(item.symbols) - return tuple(sorted(symbols, key=lambda symbol: symbol.name)) + return tuple(sorted(symbols, key=Symbol.sortkey)) @property def polyhedra(self): diff --git a/pypol/linexprs.py b/pypol/linexprs.py index 9a1ed64..73c6b0e 100644 --- a/pypol/linexprs.py +++ b/pypol/linexprs.py @@ -61,7 +61,7 @@ class Expression: self = object().__new__(cls) self._coefficients = OrderedDict() for symbol, coefficient in sorted(coefficients, - key=lambda item: item[0].name): + key=lambda item: item[0].sortkey()): if isinstance(coefficient, Rational): coefficient = coefficient.constant if not isinstance(coefficient, numbers.Rational): @@ -380,6 +380,9 @@ class Symbol(Expression): def dimension(self): return 1 + def sortkey(self): + return self.name, + def issymbol(self): return True -- 2.20.1