<s> """<STR_LIT>""" <EOL> import scipy as _sp <EOL> from collections import OrderedDict as _odict <EOL> class PrintableList ( list ) : <EOL> def __str__ ( self ) : <EOL> horizontal_rule = '<STR_LIT:->' * <NUM_LIT> <EOL> lines = [ horizontal_rule ] <EOL> self . sort ( ) <EOL> for i , item in enumerate ( self ) : <EOL> lines . append ( '<STR_LIT>' . format ( i + <NUM_LIT:1> , item ) ) <EOL> lines . append ( horizontal_rule ) <EOL> return '<STR_LIT:\n>' . join ( lines ) <EOL> class ObjectContainer ( dict ) : <EOL> r"""<STR_LIT>""" <EOL> def __call__ ( self , name = None ) : <EOL> if self == { } : <EOL> return [ ] <EOL> if name is None : <EOL> objs = [ item for item in self . keys ( ) ] <EOL> if self [ objs [ <NUM_LIT:0> ] ] . _isa ( '<STR_LIT>' ) : <EOL> objs = [ self [ objs [ <NUM_LIT:0> ] ] ] <EOL> else : <EOL> if type ( name ) is not list : <EOL> name = [ name ] <EOL> objs = [ self [ item ] for item in name ] <EOL> if objs [ <NUM_LIT:0> ] . _isa ( '<STR_LIT>' ) : <EOL> objs = objs [ <NUM_LIT:0> ] <EOL> return objs <EOL> class PrintableDict ( _odict ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . _header = '<STR_LIT:value>' <EOL> if '<STR_LIT>' in kwargs : <EOL> self . _header = kwargs . pop ( '<STR_LIT>' ) <EOL> super ( ) . __init__ ( * args , ** kwargs ) <EOL> def __repr__ ( self ) : <EOL> text = dict ( self ) . __str__ ( ) <EOL> return text <EOL> def __str__ ( self ) : <EOL> horizontal_rule = '<STR_LIT:->' * <NUM_LIT> <EOL> lines = [ horizontal_rule ] <EOL> lines . append ( '<STR_LIT>' . format ( '<STR_LIT:key>' , self . _header ) ) <EOL> lines . append ( horizontal_rule ) <EOL> for item in list ( self . keys ( ) ) : <EOL> lines . append ( '<STR_LIT>' . format ( item , self [ item ] ) ) <EOL> lines . append ( horizontal_rule ) <EOL> return '<STR_LIT:\n>' . join ( lines ) <EOL> class HealthDict ( PrintableDict ) : <EOL> r"""<STR_LIT>""" <EOL> def __init__ ( self , header = '<STR_LIT:status>' , ** kwargs ) : <EOL> super ( ) . __init__ ( header = header , ** kwargs ) <EOL> def _get_health ( self ) : <EOL> health = True <EOL> for item in list ( self . keys ( ) ) : <EOL> if self [ item ] != [ ] : <EOL> health = False <EOL> return health <EOL> health = property ( fget = _get_health ) <EOL> class SetLocations ( ) : <EOL> @ staticmethod <EOL> def add ( obj , element , locations ) : <EOL> net = obj . _net <EOL> element = obj . _parse_element ( element , single = True ) <EOL> locations = obj . _parse_locations ( locations ) <EOL> if obj . _isa ( '<STR_LIT>' ) : <EOL> boss = obj . parent_phase <EOL> objs = boss . _physics <EOL> elif obj . _isa ( '<STR_LIT>' ) : <EOL> boss = obj . _net <EOL> objs = net . _geometries <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> temp = _sp . zeros ( net . _count ( element = element ) , dtype = int ) <EOL> for item in objs : <EOL> inds = boss . _get_indices ( element = element , labels = item . name ) <EOL> temp [ inds ] += <NUM_LIT:1> <EOL> temp [ locations ] += <NUM_LIT:1> <EOL> if _sp . any ( temp [ locations ] > <NUM_LIT:1> ) : <EOL> raise Exception ( '<STR_LIT>' + element + '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> new_len = obj . _count ( element = element ) + _sp . size ( locations ) <EOL> obj . update ( { element + '<STR_LIT>' : _sp . ones ( ( new_len , ) , dtype = bool ) } ) <EOL> inds_orig = net . _get_indices ( element = element , labels = obj . name ) <EOL> if element + '<STR_LIT:.>' + obj . name not in net . keys ( ) : <EOL> net [ element + '<STR_LIT:.>' + obj . name ] = False <EOL> net [ element + '<STR_LIT:.>' + obj . name ] [ locations ] = True <EOL> inds_new = net . _get_indices ( element = element , labels = obj . name ) <EOL> if obj . _isa ( '<STR_LIT>' ) : <EOL> phase = obj . parent_phase <EOL> if element + '<STR_LIT:.>' + obj . name not in phase . keys ( ) : <EOL> phase [ element + '<STR_LIT:.>' + obj . name ] = False <EOL> phase [ element + '<STR_LIT:.>' + obj . name ] [ locations ] = True <EOL> labels = obj . labels ( ) <EOL> labels . remove ( element + '<STR_LIT>' ) <EOL> for item in labels : <EOL> if item . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] == element : <EOL> net [ element + '<STR_LIT:.>' + '<STR_LIT:blank>' ] = False <EOL> net [ element + '<STR_LIT:.>' + '<STR_LIT:blank>' ] [ inds_orig ] = obj [ item ] <EOL> obj [ item ] = net [ element + '<STR_LIT:.>' + '<STR_LIT:blank>' ] [ inds_new ] <EOL> net . pop ( element + '<STR_LIT:.>' + '<STR_LIT:blank>' , None ) <EOL> @ staticmethod <EOL> def drop ( obj , element , locations ) : <EOL> net = obj . _net <EOL> element = obj . _parse_element ( element , single = True ) <EOL> locations = obj . _parse_locations ( locations ) <EOL> obj_inds = net . _map ( element = element , <EOL> locations = locations , <EOL> target = obj ) <EOL> keep = ~ obj . _tomask ( locations = obj_inds , element = element ) <EOL> for item in list ( obj . keys ( ) ) : <EOL> if item . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] == element : <EOL> temp = obj [ item ] [ keep ] <EOL> obj . update ( { item : temp } ) <EOL> net [ element + '<STR_LIT:.>' + obj . name ] [ locations ] = False <EOL> if obj . _isa ( '<STR_LIT>' ) : <EOL> phase = obj . parent_phase <EOL> phase [ element + '<STR_LIT:.>' + obj . name ] [ locations ] = False </s>
