@@ -200,9 +200,8 @@ def _handle_negation_ANY(visitor, node, arg):
200
200
201
201
202
202
_exit_node_handlers [NegationExpression ] = {
203
+ None : _handle_negation_ANY ,
203
204
(_CONSTANT ,): _handle_negation_constant ,
204
- (_LINEAR ,): _handle_negation_ANY ,
205
- (_GENERAL ,): _handle_negation_ANY ,
206
205
}
207
206
208
207
#
@@ -211,20 +210,18 @@ def _handle_negation_ANY(visitor, node, arg):
211
210
212
211
213
212
def _handle_product_constant_constant (visitor , node , arg1 , arg2 ):
214
- _ , arg1 = arg1
215
- _ , arg2 = arg2
216
- ans = arg1 * arg2
213
+ ans = arg1 [1 ] * arg2 [1 ]
217
214
if ans != ans :
218
- if not arg1 or not arg2 :
215
+ if not arg1 [ 1 ] or not arg2 [ 1 ] :
219
216
deprecation_warning (
220
- f"Encountered { str (arg1 )} *{ str (arg2 )} in expression tree. "
217
+ f"Encountered { str (arg1 [ 1 ] )} *{ str (arg2 [ 1 ] )} in expression tree. "
221
218
"Mapping the NaN result to 0 for compatibility "
222
219
"with the lp_v1 writer. In the future, this NaN "
223
220
"will be preserved/emitted to comply with IEEE-754." ,
224
221
version = '6.6.0' ,
225
222
)
226
- return _ , 0
227
- return _ , arg1 * arg2
223
+ return _CONSTANT , 0
224
+ return _CONSTANT , ans
228
225
229
226
230
227
def _handle_product_constant_ANY (visitor , node , arg1 , arg2 ):
@@ -276,15 +273,12 @@ def _handle_product_nonlinear(visitor, node, arg1, arg2):
276
273
277
274
278
275
_exit_node_handlers [ProductExpression ] = {
276
+ None : _handle_product_nonlinear ,
279
277
(_CONSTANT , _CONSTANT ): _handle_product_constant_constant ,
280
278
(_CONSTANT , _LINEAR ): _handle_product_constant_ANY ,
281
279
(_CONSTANT , _GENERAL ): _handle_product_constant_ANY ,
282
280
(_LINEAR , _CONSTANT ): _handle_product_ANY_constant ,
283
- (_LINEAR , _LINEAR ): _handle_product_nonlinear ,
284
- (_LINEAR , _GENERAL ): _handle_product_nonlinear ,
285
281
(_GENERAL , _CONSTANT ): _handle_product_ANY_constant ,
286
- (_GENERAL , _LINEAR ): _handle_product_nonlinear ,
287
- (_GENERAL , _GENERAL ): _handle_product_nonlinear ,
288
282
}
289
283
_exit_node_handlers [MonomialTermExpression ] = _exit_node_handlers [ProductExpression ]
290
284
@@ -309,24 +303,18 @@ def _handle_division_nonlinear(visitor, node, arg1, arg2):
309
303
310
304
311
305
_exit_node_handlers [DivisionExpression ] = {
306
+ None : _handle_division_nonlinear ,
312
307
(_CONSTANT , _CONSTANT ): _handle_division_constant_constant ,
313
- (_CONSTANT , _LINEAR ): _handle_division_nonlinear ,
314
- (_CONSTANT , _GENERAL ): _handle_division_nonlinear ,
315
308
(_LINEAR , _CONSTANT ): _handle_division_ANY_constant ,
316
- (_LINEAR , _LINEAR ): _handle_division_nonlinear ,
317
- (_LINEAR , _GENERAL ): _handle_division_nonlinear ,
318
309
(_GENERAL , _CONSTANT ): _handle_division_ANY_constant ,
319
- (_GENERAL , _LINEAR ): _handle_division_nonlinear ,
320
- (_GENERAL , _GENERAL ): _handle_division_nonlinear ,
321
310
}
322
311
323
312
#
324
313
# EXPONENTIATION handlers
325
314
#
326
315
327
316
328
- def _handle_pow_constant_constant (visitor , node , * args ):
329
- arg1 , arg2 = args
317
+ def _handle_pow_constant_constant (visitor , node , arg1 , arg2 ):
330
318
ans = apply_node_operation (node , (arg1 [1 ], arg2 [1 ]))
331
319
if ans .__class__ in native_complex_types :
332
320
ans = complex_number_error (ans , visitor , node )
@@ -358,15 +346,10 @@ def _handle_pow_nonlinear(visitor, node, arg1, arg2):
358
346
359
347
360
348
_exit_node_handlers [PowExpression ] = {
349
+ None : _handle_pow_nonlinear ,
361
350
(_CONSTANT , _CONSTANT ): _handle_pow_constant_constant ,
362
- (_CONSTANT , _LINEAR ): _handle_pow_nonlinear ,
363
- (_CONSTANT , _GENERAL ): _handle_pow_nonlinear ,
364
351
(_LINEAR , _CONSTANT ): _handle_pow_ANY_constant ,
365
- (_LINEAR , _LINEAR ): _handle_pow_nonlinear ,
366
- (_LINEAR , _GENERAL ): _handle_pow_nonlinear ,
367
352
(_GENERAL , _CONSTANT ): _handle_pow_ANY_constant ,
368
- (_GENERAL , _LINEAR ): _handle_pow_nonlinear ,
369
- (_GENERAL , _GENERAL ): _handle_pow_nonlinear ,
370
353
}
371
354
372
355
#
@@ -389,9 +372,8 @@ def _handle_unary_nonlinear(visitor, node, arg):
389
372
390
373
391
374
_exit_node_handlers [UnaryFunctionExpression ] = {
375
+ None : _handle_unary_nonlinear ,
392
376
(_CONSTANT ,): _handle_unary_constant ,
393
- (_LINEAR ,): _handle_unary_nonlinear ,
394
- (_GENERAL ,): _handle_unary_nonlinear ,
395
377
}
396
378
_exit_node_handlers [AbsExpression ] = _exit_node_handlers [UnaryFunctionExpression ]
397
379
@@ -414,9 +396,8 @@ def _handle_named_ANY(visitor, node, arg1):
414
396
415
397
416
398
_exit_node_handlers [Expression ] = {
399
+ None : _handle_named_ANY ,
417
400
(_CONSTANT ,): _handle_named_constant ,
418
- (_LINEAR ,): _handle_named_ANY ,
419
- (_GENERAL ,): _handle_named_ANY ,
420
401
}
421
402
422
403
#
@@ -449,12 +430,7 @@ def _handle_expr_if_nonlinear(visitor, node, arg1, arg2, arg3):
449
430
return _GENERAL , ans
450
431
451
432
452
- _exit_node_handlers [Expr_ifExpression ] = {
453
- (i , j , k ): _handle_expr_if_nonlinear
454
- for i in (_LINEAR , _GENERAL )
455
- for j in (_CONSTANT , _LINEAR , _GENERAL )
456
- for k in (_CONSTANT , _LINEAR , _GENERAL )
457
- }
433
+ _exit_node_handlers [Expr_ifExpression ] = {None : _handle_expr_if_nonlinear }
458
434
for j in (_CONSTANT , _LINEAR , _GENERAL ):
459
435
for k in (_CONSTANT , _LINEAR , _GENERAL ):
460
436
_exit_node_handlers [Expr_ifExpression ][_CONSTANT , j , k ] = _handle_expr_if_const
@@ -487,11 +463,9 @@ def _handle_equality_general(visitor, node, arg1, arg2):
487
463
488
464
489
465
_exit_node_handlers [EqualityExpression ] = {
490
- (i , j ): _handle_equality_general
491
- for i in (_CONSTANT , _LINEAR , _GENERAL )
492
- for j in (_CONSTANT , _LINEAR , _GENERAL )
466
+ None : _handle_equality_general ,
467
+ (_CONSTANT , _CONSTANT ): _handle_equality_const ,
493
468
}
494
- _exit_node_handlers [EqualityExpression ][_CONSTANT , _CONSTANT ] = _handle_equality_const
495
469
496
470
497
471
def _handle_inequality_const (visitor , node , arg1 , arg2 ):
@@ -517,13 +491,9 @@ def _handle_inequality_general(visitor, node, arg1, arg2):
517
491
518
492
519
493
_exit_node_handlers [InequalityExpression ] = {
520
- (i , j ): _handle_inequality_general
521
- for i in (_CONSTANT , _LINEAR , _GENERAL )
522
- for j in (_CONSTANT , _LINEAR , _GENERAL )
494
+ None : _handle_inequality_general ,
495
+ (_CONSTANT , _CONSTANT ): _handle_inequality_const ,
523
496
}
524
- _exit_node_handlers [InequalityExpression ][
525
- _CONSTANT , _CONSTANT
526
- ] = _handle_inequality_const
527
497
528
498
529
499
def _handle_ranged_const (visitor , node , arg1 , arg2 , arg3 ):
@@ -554,14 +524,9 @@ def _handle_ranged_general(visitor, node, arg1, arg2, arg3):
554
524
555
525
556
526
_exit_node_handlers [RangedExpression ] = {
557
- (i , j , k ): _handle_ranged_general
558
- for i in (_CONSTANT , _LINEAR , _GENERAL )
559
- for j in (_CONSTANT , _LINEAR , _GENERAL )
560
- for k in (_CONSTANT , _LINEAR , _GENERAL )
527
+ None : _handle_ranged_general ,
528
+ (_CONSTANT , _CONSTANT , _CONSTANT ): _handle_ranged_const ,
561
529
}
562
- _exit_node_handlers [RangedExpression ][
563
- _CONSTANT , _CONSTANT , _CONSTANT
564
- ] = _handle_ranged_const
565
530
566
531
567
532
class LinearBeforeChildDispatcher (BeforeChildDispatcher ):
@@ -754,7 +719,10 @@ def _initialize_exit_node_dispatcher(exit_handlers):
754
719
exit_dispatcher = {}
755
720
for cls , handlers in exit_handlers .items ():
756
721
for args , fcn in handlers .items ():
757
- exit_dispatcher [(cls , * args )] = fcn
722
+ if args is None :
723
+ exit_dispatcher [cls ] = fcn
724
+ else :
725
+ exit_dispatcher [(cls , * args )] = fcn
758
726
return exit_dispatcher
759
727
760
728
0 commit comments