make utils and test code python2 compliant
							parent
							
								
									83cbcd0bea
								
							
						
					
					
						commit
						52da4580fb
					
				|  | @ -4,8 +4,12 @@ Author: Jing Wu and Frank Dellaert | |||
| """ | ||||
| # pylint: disable=invalid-name | ||||
| 
 | ||||
| import io | ||||
| import sys | ||||
| if sys.version_info.major >= 3: | ||||
|     from io import StringIO | ||||
| else: | ||||
|     from cStringIO import StringIO | ||||
| 
 | ||||
| import unittest | ||||
| from datetime import datetime | ||||
| 
 | ||||
|  | @ -40,7 +44,7 @@ class TestOptimizeComet(GtsamTestCase): | |||
|             graph, initial, self.params) | ||||
| 
 | ||||
|         # setup output capture | ||||
|         self.capturedOutput = io.StringIO() | ||||
|         self.capturedOutput = StringIO() | ||||
|         sys.stdout = self.capturedOutput | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|  | @ -51,7 +55,7 @@ class TestOptimizeComet(GtsamTestCase): | |||
|         """Test with a simple hook.""" | ||||
| 
 | ||||
|         # Provide a hook that just prints | ||||
|         def hook(_, error: float): | ||||
|         def hook(_, error): | ||||
|             print(error) | ||||
| 
 | ||||
|         # Only thing we require from optimizer is an iterate method | ||||
|  | @ -75,7 +79,7 @@ class TestOptimizeComet(GtsamTestCase): | |||
|                        + str(time.hour)+":"+str(time.minute)+":"+str(time.second)) | ||||
| 
 | ||||
|         # I want to do some comet thing here | ||||
|         def hook(optimizer, error: float): | ||||
|         def hook(optimizer, error): | ||||
|             comet.log_metric("Karcher error", | ||||
|                              error, optimizer.iterations()) | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,15 +4,11 @@ Author: Jing Wu and Frank Dellaert | |||
| """ | ||||
| # pylint: disable=invalid-name | ||||
| 
 | ||||
| from typing import TypeVar | ||||
| 
 | ||||
| from gtsam import NonlinearOptimizer, NonlinearOptimizerParams | ||||
| import gtsam | ||||
| 
 | ||||
| T = TypeVar('T') | ||||
| 
 | ||||
| 
 | ||||
| def optimize(optimizer: T, check_convergence, hook): | ||||
| def optimize(optimizer, check_convergence, hook): | ||||
|     """ Given an optimizer and a convergence check, iterate until convergence. | ||||
|         After each iteration, hook(optimizer, error) is called. | ||||
|         After the function, use values and errors to get the result. | ||||
|  | @ -36,8 +32,8 @@ def optimize(optimizer: T, check_convergence, hook): | |||
|         current_error = new_error | ||||
| 
 | ||||
| 
 | ||||
| def gtsam_optimize(optimizer: NonlinearOptimizer, | ||||
|                    params: NonlinearOptimizerParams, | ||||
| def gtsam_optimize(optimizer, | ||||
|                    params, | ||||
|                    hook): | ||||
|     """ Given an optimizer and params, iterate until convergence. | ||||
|         After each iteration, hook(optimizer) is called. | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue