import sys sys.path.append("python/need_not_convert") from SurfStatCoord2Ind import * import surfstat_wrap as sw import numpy as np import pytest sw.matlab_init_surfstat() def dummy_test(coord, surf): try: # wrap matlab functions Wrapped_ind = sw.matlab_SurfStatCoord2Ind(coord, surf) except: pytest.skip("Original MATLAB code does not work with these inputs.") Python_ind = py_SurfStatCoord2Ind(coord, surf) # compare matlab-python outputs testout = np.allclose(Wrapped_ind, Python_ind, rtol=1e-05, equal_nan=True) assert testout #### Test 1 def test_surf_coord(): # coord is 2D array, surf['coord'] is 2D array m = np.random.randint(1, 100) n = np.random.randint(1, 100)
import sys sys.path.append("python") import numpy as np import pytest from SurfStatLinMod import py_SurfStatLinMod import surfstat_wrap as sw from term import Term surfstat_eng = sw.matlab_init_surfstat() def dummy_test(Y, model, surf=None): py_slm = py_SurfStatLinMod(Y, model, surf=surf) mat_slm = sw.matlab_SurfStatLinMod(Y, model, surf=surf) for k in set.union(set(py_slm.keys()), set(mat_slm.keys())): assert k in mat_slm, "'%s' missing from MATLAB slm." % k assert k in py_slm, "'%s' missing from Python slm." % k if k not in ['df', 'dr']: assert mat_slm[k].shape == py_slm[k].shape, \ "Different shape: %s" % k assert np.allclose(mat_slm[k], py_slm[k]), "Not equal: %s" % k # 2D inputs --- square matrices def test_2d_square_matrices(): n = np.random.randint(10, 100) A = np.random.rand(n, n)