Skip to content

Instantly share code, notes, and snippets.

@YaronBlinder
Created August 4, 2016 15:03
Show Gist options
  • Save YaronBlinder/aebb38bb6de95b937728b721fc94005b to your computer and use it in GitHub Desktop.
Save YaronBlinder/aebb38bb6de95b937728b721fc94005b to your computer and use it in GitHub Desktop.
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
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