@@ -2422,18 +2422,18 @@ def interconnect(
2422
2422
elif not found_system :
2423
2423
raise ValueError ("could not find signal %s" % sname )
2424
2424
else :
2425
- # TODO: refactor code to remove duplication
2426
2425
if isinstance (connection , list ):
2427
2426
# Passed a list => create input map
2428
2427
dprint (f" detected input list" )
2429
- new_inplist . append ([])
2428
+ signal_list = []
2430
2429
for spec in connection :
2431
2430
isys , indices , gain = _parse_spec (syslist , spec , 'input' )
2432
2431
for isig in indices :
2433
- new_inplist [- 1 ].append ((isys , isig , gain ))
2434
- dprint (f" adding input { (isys , isig , gain )} " )
2432
+ signal_list .append ((isys , isig , gain ))
2433
+ dprint (f" adding input { (isys , isig , gain )} to list" )
2434
+ new_inplist .append (signal_list )
2435
2435
else :
2436
- # Passed a single single => single input
2436
+ # Passed a single signal name => add individual input(s)
2437
2437
isys , indices , gain = _parse_spec (syslist , connection , 'input' )
2438
2438
for isig in indices :
2439
2439
new_inplist .append ((isys , isig , gain ))
@@ -2503,39 +2503,15 @@ def interconnect(
2503
2503
elif not found_system :
2504
2504
raise ValueError ("could not find signal %s" % sname )
2505
2505
else :
2506
- # TODO: refactor code to remove duplication
2507
- if isinstance (connection , list ):
2508
- # Passed a list => create input map
2509
- dprint (f" detected output list" )
2510
- new_outlist .append ([])
2511
- for spec in connection :
2512
- try :
2513
- # First trying looking in the output signals
2514
- osys , indices , gain = _parse_spec (
2515
- syslist , spec , 'output' )
2516
- for osig in indices :
2517
- dprint (f" adding output { (osys , osig , gain )} " )
2518
- new_outlist [- 1 ].append ((osys , osig , gain ))
2519
- except ValueError :
2520
- # If not, see if we can find it in inputs
2521
- isys , indices , gain = _parse_spec (
2522
- syslist , spec , 'input or output' ,
2523
- dictname = 'input_index' )
2524
- for isig in indices :
2525
- # Use string form to allow searching input list
2526
- dprint (f" adding input { (isys , isig , gain )} " )
2527
- new_outlist [- 1 ].append (
2528
- (syslist [isys ].name ,
2529
- syslist [isys ].input_labels [isig ], gain ))
2530
- else :
2531
- spec = connection
2506
+ # Utility function to find named output or input signal
2507
+ def _find_output_or_input_signal (spec ):
2508
+ signal_list = []
2532
2509
try :
2533
2510
# First trying looking in the output signals
2534
- osys , indices , gain = _parse_spec (
2535
- syslist , spec , 'output' )
2511
+ osys , indices , gain = _parse_spec (syslist , spec , 'output' )
2536
2512
for osig in indices :
2537
- dprint (f" adding output { (osys , osig , gain )} " )
2538
- new_outlist .append ((osys , osig , gain ))
2513
+ dprint (f" adding output { (osys , osig , gain )} " )
2514
+ signal_list .append ((osys , osig , gain ))
2539
2515
except ValueError :
2540
2516
# If not, see if we can find it in inputs
2541
2517
isys , indices , gain = _parse_spec (
@@ -2544,9 +2520,21 @@ def interconnect(
2544
2520
for isig in indices :
2545
2521
# Use string form to allow searching input list
2546
2522
dprint (f" adding input { (isys , isig , gain )} " )
2547
- new_outlist .append (
2523
+ signal_list .append (
2548
2524
(syslist [isys ].name ,
2549
2525
syslist [isys ].input_labels [isig ], gain ))
2526
+ return signal_list
2527
+
2528
+ if isinstance (connection , list ):
2529
+ # Passed a list => create input map
2530
+ dprint (f" detected output list" )
2531
+ signal_list = []
2532
+ for spec in connection :
2533
+ signal_list += _find_output_or_input_signal (spec )
2534
+ new_outlist .append (signal_list )
2535
+ else :
2536
+ new_outlist += _find_output_or_input_signal (connection )
2537
+
2550
2538
outlist , outputs = new_outlist , new_outputs
2551
2539
dprint (f" { outlist = } \n { outputs = } " )
2552
2540
0 commit comments