Ignore:
Timestamp:
02/25/11 17:08:41 (3 years ago)
Author:
jdsiiro
Message:

More tweaks of expression generation

  • only clone arguments to intrinsic functions if someone else holds a reference to the argument
  • avoid unnecessary call to as)numeric(_self) when generating operator expressions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_expr.py

    r3554 r3714  
    12821282        self.refCount.append(count) 
    12831283 
    1284     def test_UNREFERENCED_EXPR_CUNT(self): 
     1284    def test_UNREFERENCED_EXPR_COUNT(self): 
    12851285        generate_expression.clone_if_needed_callback = \ 
    12861286            lambda x: self.trapCloneIfNeeded(x) 
    12871287        expr1 = abs(self.model.a+self.model.a) 
    1288         self.assertEqual(len(self.refCount), 1) 
    1289         self.assertEqual( self.refCount[0], 0 ) 
     1288        self.assertEqual( self.refCount, [0] ) 
    12901289        expr2 = expr1 + self.model.a 
    1291         self.assertEqual(len(self.refCount), 2) 
    1292         self.assertEqual( self.refCount[1], 1 ) 
     1290        self.assertEqual( self.refCount, [0,1] ) 
    12931291         
    12941292 
     
    13751373 
    13761374 
     1375    def test_cloneCount_intrinsicFunction(self): 
     1376        # intrinsicFunction of a simple expression 
     1377        count = generate_intrinsic_expression.clone_counter 
     1378        expr = log(self.model.c + self.model.a) 
     1379        self.assertEqual(generate_intrinsic_expression.clone_counter, count) 
     1380 
     1381        # intrinsicFunction of a referenced expression 
     1382        count = generate_intrinsic_expression.clone_counter 
     1383        expr = self.model.c + self.model.a 
     1384        expr1 = log(expr) 
     1385        self.assertEqual(generate_intrinsic_expression.clone_counter, count+1) 
     1386 
     1387 
    13771388if __name__ == "__main__": 
    13781389   unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.