@@ -79,40 +79,41 @@ def single_morph_output(
7979 rw_pos + idx , (f"squeeze a{ idx } " , sq_dict [f"a{ idx } " ])
8080 )
8181 mr_copy = dict (morph_results_list )
82- func_function = None
83- if "function" in mr_copy :
84- func_function = mr_copy .pop ("function" )
85- if "funcxy" in mr_copy :
86- fxy_dict = mr_copy .pop ("funcxy" )
87- rw_pos = list (mr_copy .keys ()).index ("Rw" )
88- morph_results_list = list (mr_copy .items ())
89- for idx , key in enumerate (fxy_dict ):
90- morph_results_list .insert (
91- rw_pos + idx , (f"funcxy { key } " , fxy_dict [key ])
92- )
93- mr_copy = dict (morph_results_list )
94- elif "funcy" in mr_copy :
95- fy_dict = mr_copy .pop ("funcy" )
96- rw_pos = list (mr_copy .keys ()).index ("Rw" )
97- morph_results_list = list (mr_copy .items ())
98- for idx , key in enumerate (fy_dict ):
99- morph_results_list .insert (
100- rw_pos + idx , (f"funcy { key } " , fy_dict [key ])
101- )
102- mr_copy = dict (morph_results_list )
82+
83+ # Handle special inputs (functional remove)
84+ func_dicts = {
85+ "funcxy" : [None , None ],
86+ "funcx" : [None , None ],
87+ "funcy" : [None , None ],
88+ }
89+ for func in func_dicts .keys ():
90+ if f"{ func } _function" in mr_copy :
91+ func_dicts [func ][0 ] = mr_copy .pop (f"{ func } _function" )
92+ if func in mr_copy :
93+ func_dicts [func ][1 ] = mr_copy .pop (func )
94+ rw_pos = list (mr_copy .keys ()).index ("Rw" )
95+ morph_results_list = list (mr_copy .items ())
96+ for idx , key in enumerate (func_dicts [func ][1 ]):
97+ morph_results_list .insert (
98+ rw_pos + idx , (f"{ func } { key } " , func_dicts [func ][1 ][key ])
99+ )
100+ mr_copy = dict (morph_results_list )
101+
103102 # Normal inputs
104103 morphs_out += "\n " .join (
105104 f"# { key } = { mr_copy [key ]:.6f} " for key in mr_copy .keys ()
106105 )
107- # Special inputs (functional)
108- if func_function is not None :
109- morphs_in += '# function =\n """\n '
110- f_code , _ = inspect .getsourcelines (func_function )
111- n_leading = len (f_code [0 ]) - len (f_code [0 ].lstrip ())
112- for idx , f_line in enumerate (f_code ):
113- f_code [idx ] = f_line [n_leading :]
114- morphs_in += "" .join (f_code )
115- morphs_in += '"""\n '
106+
107+ # Handle special inputs (functional add)
108+ for func in func_dicts .keys ():
109+ if func_dicts [func ][0 ] is not None :
110+ morphs_in += f'# { func } function =\n """\n '
111+ f_code , _ = inspect .getsourcelines (func_dicts [func ][0 ])
112+ n_leading = len (f_code [0 ]) - len (f_code [0 ].lstrip ())
113+ for idx , f_line in enumerate (f_code ):
114+ f_code [idx ] = f_line [n_leading :]
115+ morphs_in += "" .join (f_code )
116+ morphs_in += '"""\n '
116117
117118 # Printing to terminal
118119 if stdout_flag :
0 commit comments