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

Merge bodge:src/islpy

parents 69022fcd 9183f686
No related branches found
No related tags found
No related merge requests found
......@@ -129,30 +129,6 @@ EXPR_CLASSES = tuple(cls for cls in ALL_CLASSES
if "Aff" in cls.__name__ or "Polynomial" in cls.__name__)
def _runs_in_integer_set(s, max_int=None):
if not s:
return
if max_int is None:
max_int = max(s)
i = 0
while i < max_int:
if i in s:
start = i
i += 1
while i < max_int and i in s:
i += 1
end = i
yield (start, end-start)
else:
i += 1
def _add_functionality():
# {{{ Context
......@@ -1209,100 +1185,4 @@ def align_two(obj1, obj2, across_dim_types=False):
return (obj1, obj2)
# {{{ performance tweak for dim_{min,max}: project first
class TooManyInteractingDims(Exception):
pass
def _find_aff_dims(aff, dim_types_and_gen_dim_types):
result = []
for dt, gen_dt in dim_types_and_gen_dim_types:
for i in range(aff.dim(dt)):
if not aff.get_coefficient_val(dt, i).is_zero():
result.append((gen_dt, i))
result = set(result)
for i in range(aff.dim(dim_type.div)):
result.update(_find_aff_dims(aff.get_div(i)))
return result
def _transitive_closure(graph_dict):
pass
def _find_noninteracting_dims(obj, dt, idx, other_dt, stop_at=6):
if isinstance(obj, BasicSet):
basics = [obj]
elif isinstance(obj, Set):
basics = obj.get_basic_sets()
else:
raise TypeError("unsupported arg type '%s'" % type(obj))
connections = []
for bs in basics:
for c in bs.get_constraints():
conn = _find_aff_dims(
c.get_aff(),
[(dim_type.param, dim_type.param), (dim_type.in_, dim_type.set)])
if len(conn) > 1:
connections.append(conn)
interacting = set([(dt, idx)])
while True:
changed_something = False
# Compute the connected component near (dt, idx) by fixed point iteration
for conn in connections:
prev_len = len(interacting)
overlap = interacting & conn
if overlap:
interacting.update(conn)
if len(interacting) != prev_len:
changed_something = True
if len(interacting) >= stop_at:
raise TooManyInteractingDims()
if not changed_something:
break
return set(range(obj.dim(other_dt))) - set(
idx for dt, idx in interacting
if dt == other_dt)
def _eliminate_noninteracting(obj, dt, idx, other_dt):
try:
nonint = _find_noninteracting_dims(obj, dt, idx, other_dt)
except TooManyInteractingDims:
return obj
for first, n in _runs_in_integer_set(nonint):
obj = obj.eliminate(other_dt, first, n)
return obj
def dim_min_with_elimination(obj, idx):
obj_elim = _eliminate_noninteracting(obj, dim_type.out, idx, dim_type.param)
return obj_elim.dim_min(idx)
def dim_max_with_elimination(obj, idx):
obj_elim = _eliminate_noninteracting(obj, dim_type.out, idx, dim_type.param)
return obj_elim.dim_max(idx)
# }}}
# vim: foldmethod=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