mirror of
https://gitlab.com/scemama/irpf90.git
synced 2025-01-03 01:55:42 +01:00
Vitali reduction working
This commit is contained in:
parent
1c9b661b49
commit
aaebcf8025
128
src/irpf90.py
128
src/irpf90.py
@ -54,92 +54,96 @@ def main():
|
|||||||
|
|
||||||
comm_world = Irpy_comm_world()
|
comm_world = Irpy_comm_world()
|
||||||
|
|
||||||
|
|
||||||
if command_line.do_graph:
|
if command_line.do_graph:
|
||||||
# Create a dot reprenstion of the dependency graph.
|
# Create a dot reprenstion of the dependency graph.
|
||||||
# Merge inside a subgraph the Entity provided together
|
# Merge inside a subgraph the Entity provided together
|
||||||
|
|
||||||
|
def print_full_diagram(l_entity):
|
||||||
|
|
||||||
|
l_entity_not_leaf= [e for e in l_entity if e.needs]
|
||||||
|
print 'digraph Full { '
|
||||||
|
for e in l_entity_not_leaf:
|
||||||
|
print ' %s -> { %s } ' % (e.name, ' '.join(e.needs))
|
||||||
|
print '}'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def print_subgraph(l_tuple,name,color):
|
||||||
|
for i,s in enumerate(l_tuple):
|
||||||
|
print ' subgraph cluster_%s_%s {' % (name,i)
|
||||||
|
print ' %s ' % ' '.join(s)
|
||||||
|
print ' color = %s ' % color
|
||||||
|
print ' }'
|
||||||
|
|
||||||
comm_world.t_filename_parsed_text # Initialize entity need. Dirty I know.
|
comm_world.t_filename_parsed_text # Initialize entity need. Dirty I know.
|
||||||
|
|
||||||
from util import l_dummy_entity, split_l_set
|
|
||||||
#print len(comm_world.d_entity)
|
|
||||||
#print sum(len(i.needs) for i in comm_world.d_entity.values())
|
|
||||||
#print l_dummy_entity(comm_world.d_entity)
|
|
||||||
#print len(l_dummy_entity(comm_world.d_entity))
|
|
||||||
#print sum(len(i) for i in l_dummy_entity(comm_world.d_entity))
|
|
||||||
|
|
||||||
|
print 'digraph Compact { '
|
||||||
|
print ' graph [ordering="out" splines=true overlap=false];'
|
||||||
|
|
||||||
l_main_usr = set([entity for entity in comm_world.d_entity.values() if entity.is_main])
|
l_main_usr = set([entity for entity in comm_world.d_entity.values() if entity.is_main])
|
||||||
l_main_head_usr = set([entity for entity in l_main_usr if entity.others_entity_name])
|
l_main_head_usr = set([entity for entity in l_main_usr if entity.others_entity_name])
|
||||||
l_main_atomic_usr = l_main_usr - l_main_head_usr
|
l_set_main_head_name = [ set([e.name]+e.others_entity_name) for e in l_main_head_usr]
|
||||||
|
|
||||||
print 'digraph Full { '
|
print_subgraph(l_set_main_head_name,'usr',color='blue')
|
||||||
for e in comm_world.d_entity.values():
|
|
||||||
if e.needs:
|
|
||||||
print ' %s -> { %s } ' % (e.name, ' '.join(e.needs))
|
|
||||||
|
|
||||||
print '}'
|
|
||||||
print ''
|
|
||||||
|
|
||||||
print 'digraph Small { '
|
from util import l_dummy_entity
|
||||||
print ' graph [ordering="out"];'
|
|
||||||
for e in l_main_head_usr:
|
|
||||||
print ' subgraph cluster%s {' % e.name
|
|
||||||
print ' %s ' % ' '.join([e.name] + e.others_entity_name)
|
|
||||||
print ' }'
|
|
||||||
|
|
||||||
|
l_set_dummy_name= l_dummy_entity(comm_world.d_entity)
|
||||||
|
print_subgraph(l_set_dummy_name,'dummy',color='red')
|
||||||
|
|
||||||
|
#~=~=~=~=
|
||||||
l_set_dummy_name= l_dummy_entity(comm_world.d_entity)
|
# Create List Node Uniq
|
||||||
for i,s in enumerate(l_set_dummy_name):
|
#~=~=~=~=
|
||||||
print ' subgraph cluster%s {' % i
|
|
||||||
print ' %s ' % ' '.join(s)
|
|
||||||
print ' color = blue'
|
|
||||||
print ' }'
|
|
||||||
|
|
||||||
|
from util import split_l_set, flatten
|
||||||
# We do exactly like the multi-provider.
|
|
||||||
l_main_dummy_name, s_exculde_dummy_name = split_l_set(l_set_dummy_name)
|
l_main_dummy_name, s_exculde_dummy_name = split_l_set(l_set_dummy_name)
|
||||||
from util import flatten
|
l_name_dummy_name_flatten = flatten(l_set_dummy_name)
|
||||||
l_dummy_name = flatten(l_set_dummy_name)
|
|
||||||
l_main_head_dummy = [comm_world.d_entity[name] for name in l_main_dummy_name]
|
l_main_head_dummy = set([comm_world.d_entity[name] for name in l_name_dummy_name_flatten])
|
||||||
|
s_exculde_dummy = set([comm_world.d_entity[name] for name in s_exculde_dummy_name])
|
||||||
|
|
||||||
|
l_node_uniq = (l_main_usr | l_main_head_dummy) - s_exculde_dummy
|
||||||
|
|
||||||
|
|
||||||
|
#~=~=~=~=
|
||||||
|
# Create All edge
|
||||||
|
#~=~=~=~=
|
||||||
|
# We need to remove the spurious edge caused by the the dummy multiples providers
|
||||||
|
d_need = dict()
|
||||||
|
for e in l_node_uniq:
|
||||||
|
d_need[e.name] = set(e.needs)
|
||||||
|
|
||||||
|
|
||||||
# Optimisation
|
#~=~=~=~=
|
||||||
# 1) We merge the depency of multiple-provider. All entity into a multiple provider are the same.
|
# Create All edge
|
||||||
# 2) For the automatic one, we draw only the arrow for one parent.
|
#~=~=~=~=
|
||||||
|
# Draw the eddge
|
||||||
|
# If a arrow if arriving into Multipliple provider and if it is bold this mean it use all the entity inside it.
|
||||||
|
|
||||||
for e in (e for e in l_main_atomic_usr if e.needs and e.name not in l_dummy_name):
|
from util import uniquify
|
||||||
needs_filter = set(e.needs) - s_exculde_dummy_name
|
l_set_multiple = uniquify(l_set_dummy_name + l_set_main_head_name)
|
||||||
if set(e.needs) != needs_filter:
|
|
||||||
needs_filter = set(e.needs) - s_exculde_dummy_name
|
|
||||||
for s in needs_filter:
|
|
||||||
if s in l_dummy_name:
|
|
||||||
print ' %s -> { %s } [color=blue, penwidth=2]' % (e.name, s)
|
|
||||||
|
|
||||||
else:
|
l_name_usr = [e.name for e in l_main_head_usr]
|
||||||
print ' %s -> { %s }' % (e.name, s)
|
for source,l_target in d_need.items():
|
||||||
else:
|
|
||||||
print ' %s -> { %s }' % (e.name, ' ; '.join(e.needs))
|
|
||||||
|
|
||||||
for e in (e for e in l_main_head_usr if e.needs and e.name not in l_dummy_name):
|
if source in l_name_usr:
|
||||||
needs_filter = set(e.needs) - s_exculde_dummy_name
|
color = 'blue'
|
||||||
if set(e.needs) != needs_filter:
|
elif source in l_name_dummy_name_flatten:
|
||||||
needs_filter = set(e.needs) - s_exculde_dummy_name
|
color = 'red'
|
||||||
for s in needs_filter:
|
else:
|
||||||
if s in l_dummy_name:
|
color = 'black'
|
||||||
print ' %s -> { %s } [color=blue, penwidth=2]' % (e.name, s)
|
|
||||||
|
|
||||||
else:
|
for s in l_set_multiple:
|
||||||
print ' %s -> { %s } [penwidth=2]' % (e.name, s)
|
if s.issubset(l_target):
|
||||||
else:
|
print ' %s -> %s [color="%s", penwidth=2]' %(source,sorted(s).pop(), color)
|
||||||
print ' %s -> { %s } [penwidth=2]' % (e.name, ' ; '.join(e.needs))
|
l_target = l_target - s
|
||||||
|
|
||||||
for e in (e for e in l_main_head_dummy if e.needs):
|
if l_target:
|
||||||
print ' %s -> { %s } [color=blue, penwidth=2]' % (e.name, ' ; '.join(e.needs))
|
print ' %s -> { %s } [color="%s"]'% (source,' '.join(l_target), color)
|
||||||
|
|
||||||
print '}'
|
print ' }'
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -566,35 +566,14 @@ def build_needs(parsed_text, subroutines, stuple, variables):
|
|||||||
# Needs_by
|
# Needs_by
|
||||||
# ~#~#~#~#~#
|
# ~#~#~#~#~#
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
d_needed_by = defaultdict(list)
|
d_needed_by = defaultdict(list)
|
||||||
|
for var in variables.values():
|
||||||
d_needed_by2 = defaultdict(list)
|
|
||||||
|
|
||||||
for v in variables:
|
|
||||||
var = variables[v]
|
|
||||||
for x in var.needs:
|
for x in var.needs:
|
||||||
d_needed_by2[x].append(var.name)
|
d_needed_by[x].append(var.name)
|
||||||
|
|
||||||
|
|
||||||
for v in variables:
|
|
||||||
main = variables[v].same_as
|
|
||||||
if main != v:
|
|
||||||
d_needed_by[v] = d_needed_by[main]
|
|
||||||
|
|
||||||
for v in variables:
|
|
||||||
var = variables[v]
|
|
||||||
if var.is_main:
|
|
||||||
for x in var.needs:
|
|
||||||
d_needed_by[x].append(var.same_as)
|
|
||||||
|
|
||||||
from util import mangled
|
|
||||||
for v in d_needed_by:
|
for v in d_needed_by:
|
||||||
d_needed_by[v] = uniquify(d_needed_by[v])
|
variables[v].needed_by = uniquify(d_needed_by[v])
|
||||||
d_needed_by2[v] = uniquify(d_needed_by2[v])
|
|
||||||
|
|
||||||
for v in d_needed_by:
|
|
||||||
variables[v].needed_by = d_needed_by2[v]
|
|
||||||
variables[v].needed_by2 = d_needed_by2[v]
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
from command_line import command_line
|
from command_line import command_line
|
||||||
|
14
src/util.py
14
src/util.py
@ -243,8 +243,16 @@ def check_output(*popenargs, **kwargs):
|
|||||||
|
|
||||||
def uniquify(l,sort=False):
|
def uniquify(l,sort=False):
|
||||||
# (Iter, bool) -> List[Any]
|
# (Iter, bool) -> List[Any]
|
||||||
'''Uniquify a immutable iterable. Don't preserve the order'''
|
'''Uniquify a immutable iterable. Don't preserve the order. Or maybe.'''
|
||||||
r = list(set(l))
|
|
||||||
|
|
||||||
|
#Be carefull that element in Iter can be unshable.
|
||||||
|
try:
|
||||||
|
r = list(set(l))
|
||||||
|
except TypeError:
|
||||||
|
used = list()
|
||||||
|
r = [x for x in l if x not in used and (used.append(x) or True)]
|
||||||
|
|
||||||
if not sort:
|
if not sort:
|
||||||
return r
|
return r
|
||||||
else:
|
else:
|
||||||
@ -329,8 +337,6 @@ def l_dummy_entity(d_entity):
|
|||||||
l_dummy = [set([i,j]) for i,j in l_candidate_botom if d_entity[i].needed_by == d_entity[j].needed_by]
|
l_dummy = [set([i,j]) for i,j in l_candidate_botom if d_entity[i].needed_by == d_entity[j].needed_by]
|
||||||
|
|
||||||
return che_merge(l_dummy)
|
return che_merge(l_dummy)
|
||||||
l_merge = che_merge(l_dummy)
|
|
||||||
return [l_set for l_set in l_merge if all(d_entity[e].is_main for e in l_set)]
|
|
||||||
|
|
||||||
def split_l_set(l_set_org):
|
def split_l_set(l_set_org):
|
||||||
#(List[set] -> (List, Set)
|
#(List[set] -> (List, Set)
|
||||||
|
Loading…
Reference in New Issue
Block a user