forked from tooringanalytics/pyambiguity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm2py.py
54 lines (46 loc) · 1.4 KB
/
m2py.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
''' Debug & Test support for matplot to python conversion.
'''
import os
import numpy as np
from scipy.io import loadmat
def dmpdat(s, e):
""" Dump a data structure with its name & shape.
Params:
-------
s: str. The name of the structure
e: expression. An expression to dump. Implicitly assumes e is
array_like
"""
print("%s:" % s)
print(e)
print("%s.shape:" % s)
print(e.shape)
print("%s.dtype:" % s)
print(e.dtype)
print("-------------------------------------------")
def hbrk(msg=None):
if msg is not None:
print(msg)
exit(-1)
def brk(s, e):
""" Used for debugging, just break the script, dumping data.
"""
dmpdat(s, e)
exit(-1)
def chkdat(t, s, e, rtol=1e-05, atol=1e-08):
""" Check this matrix against data dumped by octave, with
given tolerance
"""
mat = loadmat(os.path.join('check_data', t, s) + '.mat')['ex']
is_equal = np.allclose(e, mat, rtol=rtol, atol=atol)
#is_equal = np.array_equal(e, mat)
print("%s:%s:iEqual=%d" % (t, s, is_equal))
if not is_equal:
dmpdat(s + '<python>', e)
dmpdat(s + '<matlab>', mat)
np.savetxt(os.path.join("check_data", t, s) + '_python_err', e)
np.savetxt(os.path.join("check_data", t, s) + '_matlab_err', mat)
print("FAILED check on expr: %s, signal: %s" % (s, t))
#hbrk()
return is_equal