Created
August 4, 2016 15:03
-
-
Save YaronBlinder/aebb38bb6de95b937728b721fc94005b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import decorator | |
class RuntimeInsertionManager(object): | |
def insert_with_args(self, *args, **dargs): | |
@decorator.decorator | |
def _wrapper(wrapped, *_args, **_dargs): | |
if hasattr(self, 'callback'): | |
return self.callback(wrapped, _args, _dargs, args, dargs) | |
return wrapped(*_args, **_dargs) | |
return _wrapper | |
MANAGER = RuntimeInsertionMananger() | |
mimic = MANAGER.insert_with_args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rt_insert import MANAGER | |
from calculateSC_ported import calculateSC_ported | |
try: | |
import matlab.engine as engine | |
except ImportError: | |
try: | |
from oct2py import octave as engine | |
except ImportError: | |
raise ImportError("Found neither 'matlab.engine' nor 'oct2py'") | |
engine.addpath('./') | |
def callback(func, func_args, func_dargs, dec_args, dec_dargs): | |
mfunc_name = dec_args[0] | |
mfunc_result = getattr(engine, mfunc_name)(*func_args) | |
local_result = func(*func_args, **func_dargs) | |
assert np.allclose(mfunc_result, local_result) | |
return local_result | |
MANAGER.callback = callback | |
TEST_CASES = [(True, False, 5), (False, True, 5), (True, True, 5), (True, True, 7)] | |
def test_calculateSC_ported(): | |
for temporal_correlation, spatial_correlation, window_size in TEST_CASES: | |
yield calculateSC_ported, temporal_correlation, spatial_correlation, window_size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment