Add loan-advisor-agent (part 3)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test2.arff +15 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test3.arff +6 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test4.arff +11 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test5.arff +26 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test6.arff +12 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test7.arff +15 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test8.arff +12 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test9.arff +14 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/test_arffread.py +421 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/harwell_boeing.py +17 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/idl.py +17 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__init__.py +66 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/__init__.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_byteordercodes.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_mio.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_mio4.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_mio5.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_mio5_params.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_miobase.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/byteordercodes.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio4.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio5.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio5_params.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio5_utils.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio_utils.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/miobase.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/streams.cpython-312.pyc +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_byteordercodes.py +75 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio.py +377 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio4.py +632 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio5.py +901 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio5_params.py +281 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio5_utils.cp312-win_amd64.dll.a +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio5_utils.cp312-win_amd64.pyd +3 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio_utils.cp312-win_amd64.dll.a +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio_utils.cp312-win_amd64.pyd +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_miobase.py +435 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_streams.cp312-win_amd64.dll.a +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_streams.cp312-win_amd64.pyd +3 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/byteordercodes.py +17 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio.py +16 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio4.py +17 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio5.py +19 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio5_params.py +18 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio5_utils.py +17 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio_utils.py +17 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/miobase.py +16 -0
- loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/streams.py +16 -0
.gitattributes
CHANGED
|
@@ -578,3 +578,5 @@ loan-advisor-agent/.venv/Lib/site-packages/scipy/interpolate/_ppoly.cp312-win_am
|
|
| 578 |
loan-advisor-agent/.venv/Lib/site-packages/scipy/interpolate/_rbfinterp_pythran.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
| 579 |
loan-advisor-agent/.venv/Lib/site-packages/scipy/interpolate/_rgi_cython.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
| 580 |
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/_fast_matrix_market/_fmm_core.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 578 |
loan-advisor-agent/.venv/Lib/site-packages/scipy/interpolate/_rbfinterp_pythran.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
| 579 |
loan-advisor-agent/.venv/Lib/site-packages/scipy/interpolate/_rgi_cython.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
| 580 |
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/_fast_matrix_market/_fmm_core.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
| 581 |
+
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio5_utils.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
| 582 |
+
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_streams.cp312-win_amd64.pyd filter=lfs diff=lfs merge=lfs -text
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test2.arff
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@RELATION test2
|
| 2 |
+
|
| 3 |
+
@ATTRIBUTE attr0 REAL
|
| 4 |
+
@ATTRIBUTE attr1 real
|
| 5 |
+
@ATTRIBUTE attr2 integer
|
| 6 |
+
@ATTRIBUTE attr3 Integer
|
| 7 |
+
@ATTRIBUTE attr4 Numeric
|
| 8 |
+
@ATTRIBUTE attr5 numeric
|
| 9 |
+
@ATTRIBUTE attr6 string
|
| 10 |
+
@ATTRIBUTE attr7 STRING
|
| 11 |
+
@ATTRIBUTE attr8 {bla}
|
| 12 |
+
@ATTRIBUTE attr9 {bla, bla}
|
| 13 |
+
|
| 14 |
+
@DATA
|
| 15 |
+
0.1, 0.2, 0.3, 0.4,class1
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test3.arff
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@RELATION test3
|
| 2 |
+
|
| 3 |
+
@ATTRIBUTE attr0 crap
|
| 4 |
+
|
| 5 |
+
@DATA
|
| 6 |
+
0.1, 0.2, 0.3, 0.4,class1
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test4.arff
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@RELATION test5
|
| 2 |
+
|
| 3 |
+
@ATTRIBUTE attr0 REAL
|
| 4 |
+
@ATTRIBUTE attr1 REAL
|
| 5 |
+
@ATTRIBUTE attr2 REAL
|
| 6 |
+
@ATTRIBUTE attr3 REAL
|
| 7 |
+
@ATTRIBUTE class {class0, class1, class2, class3}
|
| 8 |
+
@DATA
|
| 9 |
+
0.1, 0.2, 0.3, 0.4,class1
|
| 10 |
+
-0.1, -0.2, -0.3, -0.4,class2
|
| 11 |
+
1, 2, 3, 4,class3
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test5.arff
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@RELATION test4
|
| 2 |
+
|
| 3 |
+
@ATTRIBUTE attr0 REAL
|
| 4 |
+
@ATTRIBUTE attr1 REAL
|
| 5 |
+
@ATTRIBUTE attr2 REAL
|
| 6 |
+
@ATTRIBUTE attr3 REAL
|
| 7 |
+
@ATTRIBUTE class {class0, class1, class2, class3}
|
| 8 |
+
|
| 9 |
+
@DATA
|
| 10 |
+
|
| 11 |
+
% lsdflkjhaksjdhf
|
| 12 |
+
|
| 13 |
+
% lsdflkjhaksjdhf
|
| 14 |
+
|
| 15 |
+
0.1, 0.2, 0.3, 0.4,class1
|
| 16 |
+
% laksjdhf
|
| 17 |
+
|
| 18 |
+
% lsdflkjhaksjdhf
|
| 19 |
+
-0.1, -0.2, -0.3, -0.4,class2
|
| 20 |
+
|
| 21 |
+
% lsdflkjhaksjdhf
|
| 22 |
+
% lsdflkjhaksjdhf
|
| 23 |
+
|
| 24 |
+
% lsdflkjhaksjdhf
|
| 25 |
+
|
| 26 |
+
1, 2, 3, 4,class3
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test6.arff
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@RELATION test6
|
| 2 |
+
|
| 3 |
+
@ATTRIBUTE attr0 REAL
|
| 4 |
+
@ATTRIBUTE attr1 REAL
|
| 5 |
+
@ATTRIBUTE attr2 REAL
|
| 6 |
+
@ATTRIBUTE attr3 REAL
|
| 7 |
+
@ATTRIBUTE class {C}
|
| 8 |
+
|
| 9 |
+
@DATA
|
| 10 |
+
0.1, 0.2, 0.3, 0.4,C
|
| 11 |
+
-0.1, -0.2, -0.3, -0.4,C
|
| 12 |
+
1, 2, 3, 4,C
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test7.arff
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@RELATION test7
|
| 2 |
+
|
| 3 |
+
@ATTRIBUTE attr_year DATE yyyy
|
| 4 |
+
@ATTRIBUTE attr_month DATE yyyy-MM
|
| 5 |
+
@ATTRIBUTE attr_date DATE yyyy-MM-dd
|
| 6 |
+
@ATTRIBUTE attr_datetime_local DATE "yyyy-MM-dd HH:mm"
|
| 7 |
+
@ATTRIBUTE attr_datetime_missing DATE "yyyy-MM-dd HH:mm"
|
| 8 |
+
|
| 9 |
+
@DATA
|
| 10 |
+
1999,1999-01,1999-01-31,"1999-01-31 00:01",?
|
| 11 |
+
2004,2004-12,2004-12-01,"2004-12-01 23:59","2004-12-01 23:59"
|
| 12 |
+
1817,1817-04,1817-04-28,"1817-04-28 13:00",?
|
| 13 |
+
2100,2100-09,2100-09-10,"2100-09-10 12:00",?
|
| 14 |
+
2013,2013-11,2013-11-30,"2013-11-30 04:55","2013-11-30 04:55"
|
| 15 |
+
1631,1631-10,1631-10-15,"1631-10-15 20:04","1631-10-15 20:04"
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test8.arff
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@RELATION test8
|
| 2 |
+
|
| 3 |
+
@ATTRIBUTE attr_datetime_utc DATE "yyyy-MM-dd HH:mm Z"
|
| 4 |
+
@ATTRIBUTE attr_datetime_full DATE "yy-MM-dd HH:mm:ss z"
|
| 5 |
+
|
| 6 |
+
@DATA
|
| 7 |
+
"1999-01-31 00:01 UTC","99-01-31 00:01:08 +0430"
|
| 8 |
+
"2004-12-01 23:59 UTC","04-12-01 23:59:59 -0800"
|
| 9 |
+
"1817-04-28 13:00 UTC","17-04-28 13:00:33 +1000"
|
| 10 |
+
"2100-09-10 12:00 UTC","21-09-10 12:00:21 -0300"
|
| 11 |
+
"2013-11-30 04:55 UTC","13-11-30 04:55:48 -1100"
|
| 12 |
+
"1631-10-15 20:04 UTC","31-10-15 20:04:10 +0000"
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/data/test9.arff
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@RELATION test9
|
| 2 |
+
|
| 3 |
+
@ATTRIBUTE attr_date_number RELATIONAL
|
| 4 |
+
@ATTRIBUTE attr_date DATE "yyyy-MM-dd"
|
| 5 |
+
@ATTRIBUTE attr_number INTEGER
|
| 6 |
+
@END attr_date_number
|
| 7 |
+
|
| 8 |
+
@DATA
|
| 9 |
+
"1999-01-31 1\n1935-11-27 10"
|
| 10 |
+
"2004-12-01 2\n1942-08-13 20"
|
| 11 |
+
"1817-04-28 3"
|
| 12 |
+
"2100-09-10 4\n1957-04-17 40\n1721-01-14 400"
|
| 13 |
+
"2013-11-30 5"
|
| 14 |
+
"1631-10-15 6"
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/arff/tests/test_arffread.py
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
|
| 10 |
+
from numpy.testing import (assert_array_almost_equal,
|
| 11 |
+
assert_array_equal, assert_equal, assert_)
|
| 12 |
+
from pytest import raises as assert_raises
|
| 13 |
+
|
| 14 |
+
from scipy.io.arff import loadarff
|
| 15 |
+
from scipy.io.arff._arffread import read_header, ParseArffError
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
data_path = pjoin(os.path.dirname(__file__), 'data')
|
| 19 |
+
|
| 20 |
+
test1 = pjoin(data_path, 'test1.arff')
|
| 21 |
+
test2 = pjoin(data_path, 'test2.arff')
|
| 22 |
+
test3 = pjoin(data_path, 'test3.arff')
|
| 23 |
+
|
| 24 |
+
test4 = pjoin(data_path, 'test4.arff')
|
| 25 |
+
test5 = pjoin(data_path, 'test5.arff')
|
| 26 |
+
test6 = pjoin(data_path, 'test6.arff')
|
| 27 |
+
test7 = pjoin(data_path, 'test7.arff')
|
| 28 |
+
test8 = pjoin(data_path, 'test8.arff')
|
| 29 |
+
test9 = pjoin(data_path, 'test9.arff')
|
| 30 |
+
test10 = pjoin(data_path, 'test10.arff')
|
| 31 |
+
test11 = pjoin(data_path, 'test11.arff')
|
| 32 |
+
test_quoted_nominal = pjoin(data_path, 'quoted_nominal.arff')
|
| 33 |
+
test_quoted_nominal_spaces = pjoin(data_path, 'quoted_nominal_spaces.arff')
|
| 34 |
+
|
| 35 |
+
expect4_data = [(0.1, 0.2, 0.3, 0.4, 'class1'),
|
| 36 |
+
(-0.1, -0.2, -0.3, -0.4, 'class2'),
|
| 37 |
+
(1, 2, 3, 4, 'class3')]
|
| 38 |
+
expected_types = ['numeric', 'numeric', 'numeric', 'numeric', 'nominal']
|
| 39 |
+
|
| 40 |
+
missing = pjoin(data_path, 'missing.arff')
|
| 41 |
+
expect_missing_raw = np.array([[1, 5], [2, 4], [np.nan, np.nan]])
|
| 42 |
+
expect_missing = np.empty(3, [('yop', float), ('yap', float)])
|
| 43 |
+
expect_missing['yop'] = expect_missing_raw[:, 0]
|
| 44 |
+
expect_missing['yap'] = expect_missing_raw[:, 1]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class TestData:
|
| 48 |
+
def test1(self):
|
| 49 |
+
# Parsing trivial file with nothing.
|
| 50 |
+
self._test(test4)
|
| 51 |
+
|
| 52 |
+
def test2(self):
|
| 53 |
+
# Parsing trivial file with some comments in the data section.
|
| 54 |
+
self._test(test5)
|
| 55 |
+
|
| 56 |
+
def test3(self):
|
| 57 |
+
# Parsing trivial file with nominal attribute of 1 character.
|
| 58 |
+
self._test(test6)
|
| 59 |
+
|
| 60 |
+
def test4(self):
|
| 61 |
+
# Parsing trivial file with trailing spaces in attribute declaration.
|
| 62 |
+
self._test(test11)
|
| 63 |
+
|
| 64 |
+
def _test(self, test_file):
|
| 65 |
+
data, meta = loadarff(test_file)
|
| 66 |
+
for i in range(len(data)):
|
| 67 |
+
for j in range(4):
|
| 68 |
+
assert_array_almost_equal(expect4_data[i][j], data[i][j])
|
| 69 |
+
assert_equal(meta.types(), expected_types)
|
| 70 |
+
|
| 71 |
+
def test_filelike(self):
|
| 72 |
+
# Test reading from file-like object (StringIO)
|
| 73 |
+
with open(test1) as f1:
|
| 74 |
+
data1, meta1 = loadarff(f1)
|
| 75 |
+
with open(test1) as f2:
|
| 76 |
+
data2, meta2 = loadarff(StringIO(f2.read()))
|
| 77 |
+
assert_(data1 == data2)
|
| 78 |
+
assert_(repr(meta1) == repr(meta2))
|
| 79 |
+
|
| 80 |
+
def test_path(self):
|
| 81 |
+
# Test reading from `pathlib.Path` object
|
| 82 |
+
from pathlib import Path
|
| 83 |
+
|
| 84 |
+
with open(test1) as f1:
|
| 85 |
+
data1, meta1 = loadarff(f1)
|
| 86 |
+
|
| 87 |
+
data2, meta2 = loadarff(Path(test1))
|
| 88 |
+
|
| 89 |
+
assert_(data1 == data2)
|
| 90 |
+
assert_(repr(meta1) == repr(meta2))
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class TestMissingData:
|
| 94 |
+
def test_missing(self):
|
| 95 |
+
data, meta = loadarff(missing)
|
| 96 |
+
for i in ['yop', 'yap']:
|
| 97 |
+
assert_array_almost_equal(data[i], expect_missing[i])
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class TestNoData:
|
| 101 |
+
def test_nodata(self):
|
| 102 |
+
# The file nodata.arff has no data in the @DATA section.
|
| 103 |
+
# Reading it should result in an array with length 0.
|
| 104 |
+
nodata_filename = os.path.join(data_path, 'nodata.arff')
|
| 105 |
+
data, meta = loadarff(nodata_filename)
|
| 106 |
+
if sys.byteorder == 'big':
|
| 107 |
+
end = '>'
|
| 108 |
+
else:
|
| 109 |
+
end = '<'
|
| 110 |
+
expected_dtype = np.dtype([('sepallength', f'{end}f8'),
|
| 111 |
+
('sepalwidth', f'{end}f8'),
|
| 112 |
+
('petallength', f'{end}f8'),
|
| 113 |
+
('petalwidth', f'{end}f8'),
|
| 114 |
+
('class', 'S15')])
|
| 115 |
+
assert_equal(data.dtype, expected_dtype)
|
| 116 |
+
assert_equal(data.size, 0)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class TestHeader:
|
| 120 |
+
def test_type_parsing(self):
|
| 121 |
+
# Test parsing type of attribute from their value.
|
| 122 |
+
with open(test2) as ofile:
|
| 123 |
+
rel, attrs = read_header(ofile)
|
| 124 |
+
|
| 125 |
+
expected = ['numeric', 'numeric', 'numeric', 'numeric', 'numeric',
|
| 126 |
+
'numeric', 'string', 'string', 'nominal', 'nominal']
|
| 127 |
+
|
| 128 |
+
for i in range(len(attrs)):
|
| 129 |
+
assert_(attrs[i].type_name == expected[i])
|
| 130 |
+
|
| 131 |
+
def test_badtype_parsing(self):
|
| 132 |
+
# Test parsing wrong type of attribute from their value.
|
| 133 |
+
def badtype_read():
|
| 134 |
+
with open(test3) as ofile:
|
| 135 |
+
_, _ = read_header(ofile)
|
| 136 |
+
|
| 137 |
+
assert_raises(ParseArffError, badtype_read)
|
| 138 |
+
|
| 139 |
+
def test_fullheader1(self):
|
| 140 |
+
# Parsing trivial header with nothing.
|
| 141 |
+
with open(test1) as ofile:
|
| 142 |
+
rel, attrs = read_header(ofile)
|
| 143 |
+
|
| 144 |
+
# Test relation
|
| 145 |
+
assert_(rel == 'test1')
|
| 146 |
+
|
| 147 |
+
# Test numerical attributes
|
| 148 |
+
assert_(len(attrs) == 5)
|
| 149 |
+
for i in range(4):
|
| 150 |
+
assert_(attrs[i].name == f'attr{i}')
|
| 151 |
+
assert_(attrs[i].type_name == 'numeric')
|
| 152 |
+
|
| 153 |
+
# Test nominal attribute
|
| 154 |
+
assert_(attrs[4].name == 'class')
|
| 155 |
+
assert_(attrs[4].values == ('class0', 'class1', 'class2', 'class3'))
|
| 156 |
+
|
| 157 |
+
def test_dateheader(self):
|
| 158 |
+
with open(test7) as ofile:
|
| 159 |
+
rel, attrs = read_header(ofile)
|
| 160 |
+
|
| 161 |
+
assert_(rel == 'test7')
|
| 162 |
+
|
| 163 |
+
assert_(len(attrs) == 5)
|
| 164 |
+
|
| 165 |
+
assert_(attrs[0].name == 'attr_year')
|
| 166 |
+
assert_(attrs[0].date_format == '%Y')
|
| 167 |
+
|
| 168 |
+
assert_(attrs[1].name == 'attr_month')
|
| 169 |
+
assert_(attrs[1].date_format == '%Y-%m')
|
| 170 |
+
|
| 171 |
+
assert_(attrs[2].name == 'attr_date')
|
| 172 |
+
assert_(attrs[2].date_format == '%Y-%m-%d')
|
| 173 |
+
|
| 174 |
+
assert_(attrs[3].name == 'attr_datetime_local')
|
| 175 |
+
assert_(attrs[3].date_format == '%Y-%m-%d %H:%M')
|
| 176 |
+
|
| 177 |
+
assert_(attrs[4].name == 'attr_datetime_missing')
|
| 178 |
+
assert_(attrs[4].date_format == '%Y-%m-%d %H:%M')
|
| 179 |
+
|
| 180 |
+
def test_dateheader_unsupported(self):
|
| 181 |
+
def read_dateheader_unsupported():
|
| 182 |
+
with open(test8) as ofile:
|
| 183 |
+
_, _ = read_header(ofile)
|
| 184 |
+
|
| 185 |
+
assert_raises(ValueError, read_dateheader_unsupported)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class TestDateAttribute:
|
| 189 |
+
def setup_method(self):
|
| 190 |
+
self.data, self.meta = loadarff(test7)
|
| 191 |
+
|
| 192 |
+
def test_year_attribute(self):
|
| 193 |
+
expected = np.array([
|
| 194 |
+
'1999',
|
| 195 |
+
'2004',
|
| 196 |
+
'1817',
|
| 197 |
+
'2100',
|
| 198 |
+
'2013',
|
| 199 |
+
'1631'
|
| 200 |
+
], dtype='datetime64[Y]')
|
| 201 |
+
|
| 202 |
+
assert_array_equal(self.data["attr_year"], expected)
|
| 203 |
+
|
| 204 |
+
def test_month_attribute(self):
|
| 205 |
+
expected = np.array([
|
| 206 |
+
'1999-01',
|
| 207 |
+
'2004-12',
|
| 208 |
+
'1817-04',
|
| 209 |
+
'2100-09',
|
| 210 |
+
'2013-11',
|
| 211 |
+
'1631-10'
|
| 212 |
+
], dtype='datetime64[M]')
|
| 213 |
+
|
| 214 |
+
assert_array_equal(self.data["attr_month"], expected)
|
| 215 |
+
|
| 216 |
+
def test_date_attribute(self):
|
| 217 |
+
expected = np.array([
|
| 218 |
+
'1999-01-31',
|
| 219 |
+
'2004-12-01',
|
| 220 |
+
'1817-04-28',
|
| 221 |
+
'2100-09-10',
|
| 222 |
+
'2013-11-30',
|
| 223 |
+
'1631-10-15'
|
| 224 |
+
], dtype='datetime64[D]')
|
| 225 |
+
|
| 226 |
+
assert_array_equal(self.data["attr_date"], expected)
|
| 227 |
+
|
| 228 |
+
def test_datetime_local_attribute(self):
|
| 229 |
+
expected = np.array([
|
| 230 |
+
datetime.datetime(year=1999, month=1, day=31, hour=0, minute=1),
|
| 231 |
+
datetime.datetime(year=2004, month=12, day=1, hour=23, minute=59),
|
| 232 |
+
datetime.datetime(year=1817, month=4, day=28, hour=13, minute=0),
|
| 233 |
+
datetime.datetime(year=2100, month=9, day=10, hour=12, minute=0),
|
| 234 |
+
datetime.datetime(year=2013, month=11, day=30, hour=4, minute=55),
|
| 235 |
+
datetime.datetime(year=1631, month=10, day=15, hour=20, minute=4)
|
| 236 |
+
], dtype='datetime64[m]')
|
| 237 |
+
|
| 238 |
+
assert_array_equal(self.data["attr_datetime_local"], expected)
|
| 239 |
+
|
| 240 |
+
def test_datetime_missing(self):
|
| 241 |
+
expected = np.array([
|
| 242 |
+
'nat',
|
| 243 |
+
'2004-12-01T23:59',
|
| 244 |
+
'nat',
|
| 245 |
+
'nat',
|
| 246 |
+
'2013-11-30T04:55',
|
| 247 |
+
'1631-10-15T20:04'
|
| 248 |
+
], dtype='datetime64[m]')
|
| 249 |
+
|
| 250 |
+
assert_array_equal(self.data["attr_datetime_missing"], expected)
|
| 251 |
+
|
| 252 |
+
def test_datetime_timezone(self):
|
| 253 |
+
assert_raises(ParseArffError, loadarff, test8)
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
class TestRelationalAttribute:
|
| 257 |
+
def setup_method(self):
|
| 258 |
+
self.data, self.meta = loadarff(test9)
|
| 259 |
+
|
| 260 |
+
def test_attributes(self):
|
| 261 |
+
assert_equal(len(self.meta._attributes), 1)
|
| 262 |
+
|
| 263 |
+
relational = list(self.meta._attributes.values())[0]
|
| 264 |
+
|
| 265 |
+
assert_equal(relational.name, 'attr_date_number')
|
| 266 |
+
assert_equal(relational.type_name, 'relational')
|
| 267 |
+
assert_equal(len(relational.attributes), 2)
|
| 268 |
+
assert_equal(relational.attributes[0].name,
|
| 269 |
+
'attr_date')
|
| 270 |
+
assert_equal(relational.attributes[0].type_name,
|
| 271 |
+
'date')
|
| 272 |
+
assert_equal(relational.attributes[1].name,
|
| 273 |
+
'attr_number')
|
| 274 |
+
assert_equal(relational.attributes[1].type_name,
|
| 275 |
+
'numeric')
|
| 276 |
+
|
| 277 |
+
def test_data(self):
|
| 278 |
+
dtype_instance = [('attr_date', 'datetime64[D]'),
|
| 279 |
+
('attr_number', np.float64)]
|
| 280 |
+
|
| 281 |
+
expected = [
|
| 282 |
+
np.array([('1999-01-31', 1), ('1935-11-27', 10)],
|
| 283 |
+
dtype=dtype_instance),
|
| 284 |
+
np.array([('2004-12-01', 2), ('1942-08-13', 20)],
|
| 285 |
+
dtype=dtype_instance),
|
| 286 |
+
np.array([('1817-04-28', 3)],
|
| 287 |
+
dtype=dtype_instance),
|
| 288 |
+
np.array([('2100-09-10', 4), ('1957-04-17', 40),
|
| 289 |
+
('1721-01-14', 400)],
|
| 290 |
+
dtype=dtype_instance),
|
| 291 |
+
np.array([('2013-11-30', 5)],
|
| 292 |
+
dtype=dtype_instance),
|
| 293 |
+
np.array([('1631-10-15', 6)],
|
| 294 |
+
dtype=dtype_instance)
|
| 295 |
+
]
|
| 296 |
+
|
| 297 |
+
for i in range(len(self.data["attr_date_number"])):
|
| 298 |
+
assert_array_equal(self.data["attr_date_number"][i],
|
| 299 |
+
expected[i])
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
class TestRelationalAttributeLong:
|
| 303 |
+
def setup_method(self):
|
| 304 |
+
self.data, self.meta = loadarff(test10)
|
| 305 |
+
|
| 306 |
+
def test_attributes(self):
|
| 307 |
+
assert_equal(len(self.meta._attributes), 1)
|
| 308 |
+
|
| 309 |
+
relational = list(self.meta._attributes.values())[0]
|
| 310 |
+
|
| 311 |
+
assert_equal(relational.name, 'attr_relational')
|
| 312 |
+
assert_equal(relational.type_name, 'relational')
|
| 313 |
+
assert_equal(len(relational.attributes), 1)
|
| 314 |
+
assert_equal(relational.attributes[0].name,
|
| 315 |
+
'attr_number')
|
| 316 |
+
assert_equal(relational.attributes[0].type_name, 'numeric')
|
| 317 |
+
|
| 318 |
+
def test_data(self):
|
| 319 |
+
dtype_instance = [('attr_number', np.float64)]
|
| 320 |
+
|
| 321 |
+
expected = np.array([(n,) for n in range(30000)],
|
| 322 |
+
dtype=dtype_instance)
|
| 323 |
+
|
| 324 |
+
assert_array_equal(self.data["attr_relational"][0],
|
| 325 |
+
expected)
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
class TestQuotedNominal:
|
| 329 |
+
"""
|
| 330 |
+
Regression test for issue #10232:
|
| 331 |
+
|
| 332 |
+
Exception in loadarff with quoted nominal attributes.
|
| 333 |
+
"""
|
| 334 |
+
|
| 335 |
+
def setup_method(self):
|
| 336 |
+
self.data, self.meta = loadarff(test_quoted_nominal)
|
| 337 |
+
|
| 338 |
+
def test_attributes(self):
|
| 339 |
+
assert_equal(len(self.meta._attributes), 2)
|
| 340 |
+
|
| 341 |
+
age, smoker = self.meta._attributes.values()
|
| 342 |
+
|
| 343 |
+
assert_equal(age.name, 'age')
|
| 344 |
+
assert_equal(age.type_name, 'numeric')
|
| 345 |
+
assert_equal(smoker.name, 'smoker')
|
| 346 |
+
assert_equal(smoker.type_name, 'nominal')
|
| 347 |
+
assert_equal(smoker.values, ['yes', 'no'])
|
| 348 |
+
|
| 349 |
+
def test_data(self):
|
| 350 |
+
|
| 351 |
+
age_dtype_instance = np.float64
|
| 352 |
+
smoker_dtype_instance = '<S3'
|
| 353 |
+
|
| 354 |
+
age_expected = np.array([
|
| 355 |
+
18,
|
| 356 |
+
24,
|
| 357 |
+
44,
|
| 358 |
+
56,
|
| 359 |
+
89,
|
| 360 |
+
11,
|
| 361 |
+
], dtype=age_dtype_instance)
|
| 362 |
+
|
| 363 |
+
smoker_expected = np.array([
|
| 364 |
+
'no',
|
| 365 |
+
'yes',
|
| 366 |
+
'no',
|
| 367 |
+
'no',
|
| 368 |
+
'yes',
|
| 369 |
+
'no',
|
| 370 |
+
], dtype=smoker_dtype_instance)
|
| 371 |
+
|
| 372 |
+
assert_array_equal(self.data["age"], age_expected)
|
| 373 |
+
assert_array_equal(self.data["smoker"], smoker_expected)
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
class TestQuotedNominalSpaces:
|
| 377 |
+
"""
|
| 378 |
+
Regression test for issue #10232:
|
| 379 |
+
|
| 380 |
+
Exception in loadarff with quoted nominal attributes.
|
| 381 |
+
"""
|
| 382 |
+
|
| 383 |
+
def setup_method(self):
|
| 384 |
+
self.data, self.meta = loadarff(test_quoted_nominal_spaces)
|
| 385 |
+
|
| 386 |
+
def test_attributes(self):
|
| 387 |
+
assert_equal(len(self.meta._attributes), 2)
|
| 388 |
+
|
| 389 |
+
age, smoker = self.meta._attributes.values()
|
| 390 |
+
|
| 391 |
+
assert_equal(age.name, 'age')
|
| 392 |
+
assert_equal(age.type_name, 'numeric')
|
| 393 |
+
assert_equal(smoker.name, 'smoker')
|
| 394 |
+
assert_equal(smoker.type_name, 'nominal')
|
| 395 |
+
assert_equal(smoker.values, [' yes', 'no '])
|
| 396 |
+
|
| 397 |
+
def test_data(self):
|
| 398 |
+
|
| 399 |
+
age_dtype_instance = np.float64
|
| 400 |
+
smoker_dtype_instance = '<S5'
|
| 401 |
+
|
| 402 |
+
age_expected = np.array([
|
| 403 |
+
18,
|
| 404 |
+
24,
|
| 405 |
+
44,
|
| 406 |
+
56,
|
| 407 |
+
89,
|
| 408 |
+
11,
|
| 409 |
+
], dtype=age_dtype_instance)
|
| 410 |
+
|
| 411 |
+
smoker_expected = np.array([
|
| 412 |
+
'no ',
|
| 413 |
+
' yes',
|
| 414 |
+
'no ',
|
| 415 |
+
'no ',
|
| 416 |
+
' yes',
|
| 417 |
+
'no ',
|
| 418 |
+
], dtype=smoker_dtype_instance)
|
| 419 |
+
|
| 420 |
+
assert_array_equal(self.data["age"], age_expected)
|
| 421 |
+
assert_array_equal(self.data["smoker"], smoker_expected)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/harwell_boeing.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__ = ["hb_read", "hb_write"] # noqa: F822
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def __dir__():
|
| 11 |
+
return __all__
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def __getattr__(name):
|
| 15 |
+
return _sub_module_deprecation(sub_package="io", module="harwell_boeing",
|
| 16 |
+
private_modules=["_harwell_boeing"], all=__all__,
|
| 17 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/idl.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__ = ["readsav"] # noqa: F822
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def __dir__():
|
| 11 |
+
return __all__
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def __getattr__(name):
|
| 15 |
+
return _sub_module_deprecation(sub_package="io", module="idl",
|
| 16 |
+
private_modules=["_idl"], all=__all__,
|
| 17 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__init__.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MATLAB® file utilities (:mod:`scipy.io.matlab`)
|
| 3 |
+
===============================================
|
| 4 |
+
|
| 5 |
+
.. currentmodule:: scipy.io.matlab
|
| 6 |
+
|
| 7 |
+
This submodule is meant to provide lower-level file utilities related to reading
|
| 8 |
+
and writing MATLAB files.
|
| 9 |
+
|
| 10 |
+
.. autosummary::
|
| 11 |
+
:toctree: generated/
|
| 12 |
+
|
| 13 |
+
matfile_version - Get the MATLAB file version
|
| 14 |
+
MatReadError - Exception indicating a read issue
|
| 15 |
+
MatReadWarning - Warning class for read issues
|
| 16 |
+
MatWriteError - Exception indicating a write issue
|
| 17 |
+
MatWriteWarning - Warning class for write issues
|
| 18 |
+
mat_struct - Class used when ``struct_as_record=False``
|
| 19 |
+
varmats_from_mat - Pull variables out of mat 5 file as a sequence of mat file objects
|
| 20 |
+
|
| 21 |
+
.. autosummary::
|
| 22 |
+
:toctree: generated/
|
| 23 |
+
:template: autosummary/ndarray_subclass.rst
|
| 24 |
+
:nosignatures:
|
| 25 |
+
|
| 26 |
+
MatlabObject - Class for a MATLAB object
|
| 27 |
+
MatlabOpaque - Class for a MATLAB opaque matrix
|
| 28 |
+
MatlabFunction - Class for a MATLAB function object
|
| 29 |
+
|
| 30 |
+
The following utilities that live in the :mod:`scipy.io`
|
| 31 |
+
namespace also exist in this namespace:
|
| 32 |
+
|
| 33 |
+
.. autosummary::
|
| 34 |
+
:toctree: generated/
|
| 35 |
+
|
| 36 |
+
loadmat - Read a MATLAB style mat file (version 4 through 7.1)
|
| 37 |
+
savemat - Write a MATLAB style mat file (version 4 through 7.1)
|
| 38 |
+
whosmat - List contents of a MATLAB style mat file (version 4 through 7.1)
|
| 39 |
+
|
| 40 |
+
Notes
|
| 41 |
+
-----
|
| 42 |
+
MATLAB® is a registered trademark of The MathWorks, Inc., 3 Apple Hill
|
| 43 |
+
Drive, Natick, MA 01760-2098, USA.
|
| 44 |
+
|
| 45 |
+
"""
|
| 46 |
+
# Matlab file read and write utilities
|
| 47 |
+
from ._mio import loadmat, savemat, whosmat
|
| 48 |
+
from ._mio5 import MatlabFunction, varmats_from_mat
|
| 49 |
+
from ._mio5_params import MatlabObject, MatlabOpaque, mat_struct
|
| 50 |
+
from ._miobase import (matfile_version, MatReadError, MatReadWarning,
|
| 51 |
+
MatWriteError, MatWriteWarning)
|
| 52 |
+
|
| 53 |
+
# Deprecated namespaces, to be removed in v2.0.0
|
| 54 |
+
from .import (mio, mio5, mio5_params, mio4, byteordercodes,
|
| 55 |
+
miobase, mio_utils, streams, mio5_utils)
|
| 56 |
+
|
| 57 |
+
__all__ = [
|
| 58 |
+
'loadmat', 'savemat', 'whosmat', 'MatlabObject',
|
| 59 |
+
'matfile_version', 'MatReadError', 'MatReadWarning',
|
| 60 |
+
'MatWriteError', 'MatWriteWarning', 'mat_struct', 'MatlabOpaque',
|
| 61 |
+
'MatlabFunction', 'varmats_from_mat',
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
from scipy._lib._testutils import PytestTester
|
| 65 |
+
test = PytestTester(__name__)
|
| 66 |
+
del PytestTester
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (2.44 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_byteordercodes.cpython-312.pyc
ADDED
|
Binary file (2.26 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_mio.cpython-312.pyc
ADDED
|
Binary file (15.1 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_mio4.cpython-312.pyc
ADDED
|
Binary file (27.6 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_mio5.cpython-312.pyc
ADDED
|
Binary file (39.6 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_mio5_params.cpython-312.pyc
ADDED
|
Binary file (7.53 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/_miobase.cpython-312.pyc
ADDED
|
Binary file (14.4 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/byteordercodes.cpython-312.pyc
ADDED
|
Binary file (750 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio.cpython-312.pyc
ADDED
|
Binary file (688 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio4.cpython-312.pyc
ADDED
|
Binary file (718 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio5.cpython-312.pyc
ADDED
|
Binary file (771 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio5_params.cpython-312.pyc
ADDED
|
Binary file (744 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio5_utils.cpython-312.pyc
ADDED
|
Binary file (736 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/mio_utils.cpython-312.pyc
ADDED
|
Binary file (733 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/miobase.cpython-312.pyc
ADDED
|
Binary file (718 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/__pycache__/streams.cpython-312.pyc
ADDED
|
Binary file (727 Bytes). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_byteordercodes.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
''' Byteorder utilities for system - numpy byteorder encoding
|
| 2 |
+
|
| 3 |
+
Converts a variety of string codes for little endian, big endian,
|
| 4 |
+
native byte order and swapped byte order to explicit NumPy endian
|
| 5 |
+
codes - one of '<' (little endian) or '>' (big endian)
|
| 6 |
+
|
| 7 |
+
'''
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
__all__ = [
|
| 11 |
+
'aliases', 'native_code', 'swapped_code',
|
| 12 |
+
'sys_is_le', 'to_numpy_code'
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
sys_is_le = sys.byteorder == 'little'
|
| 16 |
+
native_code = sys_is_le and '<' or '>'
|
| 17 |
+
swapped_code = sys_is_le and '>' or '<'
|
| 18 |
+
|
| 19 |
+
aliases = {'little': ('little', '<', 'l', 'le'),
|
| 20 |
+
'big': ('big', '>', 'b', 'be'),
|
| 21 |
+
'native': ('native', '='),
|
| 22 |
+
'swapped': ('swapped', 'S')}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def to_numpy_code(code):
|
| 26 |
+
"""
|
| 27 |
+
Convert various order codings to NumPy format.
|
| 28 |
+
|
| 29 |
+
Parameters
|
| 30 |
+
----------
|
| 31 |
+
code : str
|
| 32 |
+
The code to convert. It is converted to lower case before parsing.
|
| 33 |
+
Legal values are:
|
| 34 |
+
'little', 'big', 'l', 'b', 'le', 'be', '<', '>', 'native', '=',
|
| 35 |
+
'swapped', 's'.
|
| 36 |
+
|
| 37 |
+
Returns
|
| 38 |
+
-------
|
| 39 |
+
out_code : {'<', '>'}
|
| 40 |
+
Here '<' is the numpy dtype code for little endian,
|
| 41 |
+
and '>' is the code for big endian.
|
| 42 |
+
|
| 43 |
+
Examples
|
| 44 |
+
--------
|
| 45 |
+
>>> import sys
|
| 46 |
+
>>> from scipy.io.matlab._byteordercodes import to_numpy_code
|
| 47 |
+
>>> sys_is_le = (sys.byteorder == 'little')
|
| 48 |
+
>>> sys_is_le
|
| 49 |
+
True
|
| 50 |
+
>>> to_numpy_code('big')
|
| 51 |
+
'>'
|
| 52 |
+
>>> to_numpy_code('little')
|
| 53 |
+
'<'
|
| 54 |
+
>>> nc = to_numpy_code('native')
|
| 55 |
+
>>> nc == '<' if sys_is_le else nc == '>'
|
| 56 |
+
True
|
| 57 |
+
>>> sc = to_numpy_code('swapped')
|
| 58 |
+
>>> sc == '>' if sys_is_le else sc == '<'
|
| 59 |
+
True
|
| 60 |
+
|
| 61 |
+
"""
|
| 62 |
+
code = code.lower()
|
| 63 |
+
if code is None:
|
| 64 |
+
return native_code
|
| 65 |
+
if code in aliases['little']:
|
| 66 |
+
return '<'
|
| 67 |
+
elif code in aliases['big']:
|
| 68 |
+
return '>'
|
| 69 |
+
elif code in aliases['native']:
|
| 70 |
+
return native_code
|
| 71 |
+
elif code in aliases['swapped']:
|
| 72 |
+
return swapped_code
|
| 73 |
+
else:
|
| 74 |
+
raise ValueError(
|
| 75 |
+
f'We cannot handle byte order {code}')
|
loan-advisor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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Module for reading and writing matlab (TM) .mat files
|
| 3 |
+
"""
|
| 4 |
+
# Authors: Travis Oliphant, Matthew Brett
|
| 5 |
+
|
| 6 |
+
from contextlib import contextmanager
|
| 7 |
+
|
| 8 |
+
from ._miobase import _get_matfile_version, docfiller
|
| 9 |
+
from ._mio4 import MatFile4Reader, MatFile4Writer
|
| 10 |
+
from ._mio5 import MatFile5Reader, MatFile5Writer
|
| 11 |
+
|
| 12 |
+
__all__ = ['loadmat', 'savemat', 'whosmat']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@contextmanager
|
| 16 |
+
def _open_file_context(file_like, appendmat, mode='rb'):
|
| 17 |
+
f, opened = _open_file(file_like, appendmat, mode)
|
| 18 |
+
try:
|
| 19 |
+
yield f
|
| 20 |
+
finally:
|
| 21 |
+
if opened:
|
| 22 |
+
f.close()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _open_file(file_like, appendmat, mode='rb'):
|
| 26 |
+
"""
|
| 27 |
+
Open `file_like` and return as file-like object. First, check if object is
|
| 28 |
+
already file-like; if so, return it as-is. Otherwise, try to pass it
|
| 29 |
+
to open(). If that fails, and `file_like` is a string, and `appendmat` is true,
|
| 30 |
+
append '.mat' and try again.
|
| 31 |
+
"""
|
| 32 |
+
reqs = {'read'} if set(mode) & set('r+') else set()
|
| 33 |
+
if set(mode) & set('wax+'):
|
| 34 |
+
reqs.add('write')
|
| 35 |
+
if reqs.issubset(dir(file_like)):
|
| 36 |
+
return file_like, False
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
return open(file_like, mode), True
|
| 40 |
+
except OSError as e:
|
| 41 |
+
# Probably "not found"
|
| 42 |
+
if isinstance(file_like, str):
|
| 43 |
+
if appendmat and not file_like.endswith('.mat'):
|
| 44 |
+
file_like += '.mat'
|
| 45 |
+
return open(file_like, mode), True
|
| 46 |
+
else:
|
| 47 |
+
raise OSError(
|
| 48 |
+
'Reader needs file name or open file-like object'
|
| 49 |
+
) from e
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@docfiller
|
| 53 |
+
def mat_reader_factory(file_name, appendmat=True, **kwargs):
|
| 54 |
+
"""
|
| 55 |
+
Create reader for matlab .mat format files.
|
| 56 |
+
|
| 57 |
+
Parameters
|
| 58 |
+
----------
|
| 59 |
+
%(file_arg)s
|
| 60 |
+
%(append_arg)s
|
| 61 |
+
%(load_args)s
|
| 62 |
+
%(struct_arg)s
|
| 63 |
+
|
| 64 |
+
Returns
|
| 65 |
+
-------
|
| 66 |
+
matreader : MatFileReader object
|
| 67 |
+
Initialized instance of MatFileReader class matching the mat file
|
| 68 |
+
type detected in `filename`.
|
| 69 |
+
file_opened : bool
|
| 70 |
+
Whether the file was opened by this routine.
|
| 71 |
+
|
| 72 |
+
"""
|
| 73 |
+
byte_stream, file_opened = _open_file(file_name, appendmat)
|
| 74 |
+
mjv, mnv = _get_matfile_version(byte_stream)
|
| 75 |
+
if mjv == 0:
|
| 76 |
+
return MatFile4Reader(byte_stream, **kwargs), file_opened
|
| 77 |
+
elif mjv == 1:
|
| 78 |
+
return MatFile5Reader(byte_stream, **kwargs), file_opened
|
| 79 |
+
elif mjv == 2:
|
| 80 |
+
raise NotImplementedError('Please use HDF reader for matlab v7.3 '
|
| 81 |
+
'files, e.g. h5py')
|
| 82 |
+
else:
|
| 83 |
+
raise TypeError(f'Did not recognize version {mjv}')
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@docfiller
|
| 87 |
+
def loadmat(file_name, mdict=None, appendmat=True, *, spmatrix=True, **kwargs):
|
| 88 |
+
"""
|
| 89 |
+
Load MATLAB file.
|
| 90 |
+
|
| 91 |
+
Parameters
|
| 92 |
+
----------
|
| 93 |
+
file_name : str
|
| 94 |
+
Name of the mat file (do not need .mat extension if
|
| 95 |
+
appendmat==True). Can also pass open file-like object.
|
| 96 |
+
mdict : dict, optional
|
| 97 |
+
Dictionary in which to insert matfile variables.
|
| 98 |
+
appendmat : bool, optional
|
| 99 |
+
True to append the .mat extension to the end of the given
|
| 100 |
+
filename, if not already present. Default is True.
|
| 101 |
+
spmatrix : bool, optional (default: True)
|
| 102 |
+
If ``True``, return sparse matrix. Otherwise return sparse array.
|
| 103 |
+
Format is `COO` for MatFile 4 and `CSC` for MatFile 5.
|
| 104 |
+
Only relevant for sparse variables.
|
| 105 |
+
byte_order : str or None, optional
|
| 106 |
+
None by default, implying byte order guessed from mat
|
| 107 |
+
file. Otherwise can be one of ('native', '=', 'little', '<',
|
| 108 |
+
'BIG', '>').
|
| 109 |
+
mat_dtype : bool, optional
|
| 110 |
+
If True, return arrays in same dtype as would be loaded into
|
| 111 |
+
MATLAB (instead of the dtype with which they are saved).
|
| 112 |
+
squeeze_me : bool, optional
|
| 113 |
+
Whether to squeeze unit matrix dimensions or not.
|
| 114 |
+
chars_as_strings : bool, optional
|
| 115 |
+
Whether to convert char arrays to string arrays.
|
| 116 |
+
matlab_compatible : bool, optional
|
| 117 |
+
Returns matrices as would be loaded by MATLAB (implies
|
| 118 |
+
squeeze_me=False, chars_as_strings=False, mat_dtype=True,
|
| 119 |
+
struct_as_record=True).
|
| 120 |
+
struct_as_record : bool, optional
|
| 121 |
+
Whether to load MATLAB structs as NumPy record arrays, or as
|
| 122 |
+
old-style NumPy arrays with dtype=object. Setting this flag to
|
| 123 |
+
False replicates the behavior of scipy version 0.7.x (returning
|
| 124 |
+
NumPy object arrays). The default setting is True, because it
|
| 125 |
+
allows easier round-trip load and save of MATLAB files.
|
| 126 |
+
verify_compressed_data_integrity : bool, optional
|
| 127 |
+
Whether the length of compressed sequences in the MATLAB file
|
| 128 |
+
should be checked, to ensure that they are not longer than we expect.
|
| 129 |
+
It is advisable to enable this (the default) because overlong
|
| 130 |
+
compressed sequences in MATLAB files generally indicate that the
|
| 131 |
+
files have experienced some sort of corruption.
|
| 132 |
+
variable_names : None or sequence
|
| 133 |
+
If None (the default) - read all variables in file. Otherwise,
|
| 134 |
+
`variable_names` should be a sequence of strings, giving names of the
|
| 135 |
+
MATLAB variables to read from the file. The reader will skip any
|
| 136 |
+
variable with a name not in this sequence, possibly saving some read
|
| 137 |
+
processing.
|
| 138 |
+
simplify_cells : False, optional
|
| 139 |
+
If True, return a simplified dict structure (which is useful if the mat
|
| 140 |
+
file contains cell arrays). Note that this only affects the structure
|
| 141 |
+
of the result and not its contents (which is identical for both output
|
| 142 |
+
structures). If True, this automatically sets `struct_as_record` to
|
| 143 |
+
False and `squeeze_me` to True, which is required to simplify cells.
|
| 144 |
+
uint16_codec : str, optional
|
| 145 |
+
The codec to use for decoding characters, which are stored as uint16
|
| 146 |
+
values. The default uses the system encoding, but this can be manually
|
| 147 |
+
set to other values such as 'ascii', 'latin1', and 'utf-8'. This
|
| 148 |
+
parameter is relevant only for files stored as v6 and above, and not
|
| 149 |
+
for files stored as v4.
|
| 150 |
+
|
| 151 |
+
Returns
|
| 152 |
+
-------
|
| 153 |
+
mat_dict : dict
|
| 154 |
+
dictionary with variable names as keys, and loaded matrices as values.
|
| 155 |
+
|
| 156 |
+
Notes
|
| 157 |
+
-----
|
| 158 |
+
v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.
|
| 159 |
+
|
| 160 |
+
You will need an HDF5 Python library to read MATLAB 7.3 format mat
|
| 161 |
+
files. Because SciPy does not supply one, we do not implement the
|
| 162 |
+
HDF5 / 7.3 interface here.
|
| 163 |
+
|
| 164 |
+
Examples
|
| 165 |
+
--------
|
| 166 |
+
>>> from os.path import dirname, join as pjoin
|
| 167 |
+
>>> import scipy.io as sio
|
| 168 |
+
|
| 169 |
+
Get the filename for an example .mat file from the tests/data directory.
|
| 170 |
+
|
| 171 |
+
>>> data_dir = pjoin(dirname(sio.__file__), 'matlab', 'tests', 'data')
|
| 172 |
+
>>> mat_fname = pjoin(data_dir, 'testdouble_7.4_GLNX86.mat')
|
| 173 |
+
|
| 174 |
+
Load the .mat file contents.
|
| 175 |
+
|
| 176 |
+
>>> mat_contents = sio.loadmat(mat_fname, spmatrix=False)
|
| 177 |
+
|
| 178 |
+
The result is a dictionary, one key/value pair for each variable:
|
| 179 |
+
|
| 180 |
+
>>> sorted(mat_contents.keys())
|
| 181 |
+
['__globals__', '__header__', '__version__', 'testdouble']
|
| 182 |
+
>>> mat_contents['testdouble']
|
| 183 |
+
array([[0. , 0.78539816, 1.57079633, 2.35619449, 3.14159265,
|
| 184 |
+
3.92699082, 4.71238898, 5.49778714, 6.28318531]])
|
| 185 |
+
|
| 186 |
+
By default SciPy reads MATLAB structs as structured NumPy arrays where the
|
| 187 |
+
dtype fields are of type `object` and the names correspond to the MATLAB
|
| 188 |
+
struct field names. This can be disabled by setting the optional argument
|
| 189 |
+
`struct_as_record=False`.
|
| 190 |
+
|
| 191 |
+
Get the filename for an example .mat file that contains a MATLAB struct
|
| 192 |
+
called `teststruct` and load the contents.
|
| 193 |
+
|
| 194 |
+
>>> matstruct_fname = pjoin(data_dir, 'teststruct_7.4_GLNX86.mat')
|
| 195 |
+
>>> matstruct_contents = sio.loadmat(matstruct_fname)
|
| 196 |
+
>>> teststruct = matstruct_contents['teststruct']
|
| 197 |
+
>>> teststruct.dtype
|
| 198 |
+
dtype([('stringfield', 'O'), ('doublefield', 'O'), ('complexfield', 'O')])
|
| 199 |
+
|
| 200 |
+
The size of the structured array is the size of the MATLAB struct, not the
|
| 201 |
+
number of elements in any particular field. The shape defaults to 2-D
|
| 202 |
+
unless the optional argument `squeeze_me=True`, in which case all length 1
|
| 203 |
+
dimensions are removed.
|
| 204 |
+
|
| 205 |
+
>>> teststruct.size
|
| 206 |
+
1
|
| 207 |
+
>>> teststruct.shape
|
| 208 |
+
(1, 1)
|
| 209 |
+
|
| 210 |
+
Get the 'stringfield' of the first element in the MATLAB struct.
|
| 211 |
+
|
| 212 |
+
>>> teststruct[0, 0]['stringfield']
|
| 213 |
+
array(['Rats live on no evil star.'],
|
| 214 |
+
dtype='<U26')
|
| 215 |
+
|
| 216 |
+
Get the first element of the 'doublefield'.
|
| 217 |
+
|
| 218 |
+
>>> teststruct['doublefield'][0, 0]
|
| 219 |
+
array([[ 1.41421356, 2.71828183, 3.14159265]])
|
| 220 |
+
|
| 221 |
+
Load the MATLAB struct, squeezing out length 1 dimensions, and get the item
|
| 222 |
+
from the 'complexfield'.
|
| 223 |
+
|
| 224 |
+
>>> matstruct_squeezed = sio.loadmat(matstruct_fname, squeeze_me=True)
|
| 225 |
+
>>> matstruct_squeezed['teststruct'].shape
|
| 226 |
+
()
|
| 227 |
+
>>> matstruct_squeezed['teststruct']['complexfield'].shape
|
| 228 |
+
()
|
| 229 |
+
>>> matstruct_squeezed['teststruct']['complexfield'].item()
|
| 230 |
+
array([ 1.41421356+1.41421356j, 2.71828183+2.71828183j,
|
| 231 |
+
3.14159265+3.14159265j])
|
| 232 |
+
"""
|
| 233 |
+
variable_names = kwargs.pop('variable_names', None)
|
| 234 |
+
with _open_file_context(file_name, appendmat) as f:
|
| 235 |
+
MR, _ = mat_reader_factory(f, **kwargs)
|
| 236 |
+
matfile_dict = MR.get_variables(variable_names)
|
| 237 |
+
if spmatrix:
|
| 238 |
+
from scipy.sparse import issparse, coo_matrix, csc_matrix
|
| 239 |
+
for name, var in list(matfile_dict.items()):
|
| 240 |
+
if issparse(var):
|
| 241 |
+
fmt_matrix = coo_matrix if var.format == "coo" else csc_matrix
|
| 242 |
+
matfile_dict[name] = fmt_matrix(var)
|
| 243 |
+
|
| 244 |
+
if mdict is not None:
|
| 245 |
+
mdict.update(matfile_dict)
|
| 246 |
+
else:
|
| 247 |
+
mdict = matfile_dict
|
| 248 |
+
|
| 249 |
+
return mdict
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
@docfiller
|
| 253 |
+
def savemat(file_name, mdict,
|
| 254 |
+
appendmat=True,
|
| 255 |
+
format='5',
|
| 256 |
+
long_field_names=False,
|
| 257 |
+
do_compression=False,
|
| 258 |
+
oned_as='row'):
|
| 259 |
+
"""
|
| 260 |
+
Save a dictionary of names and arrays into a MATLAB-style .mat file.
|
| 261 |
+
|
| 262 |
+
This saves the array objects in the given dictionary to a MATLAB-
|
| 263 |
+
style .mat file.
|
| 264 |
+
|
| 265 |
+
Parameters
|
| 266 |
+
----------
|
| 267 |
+
file_name : str or file-like object
|
| 268 |
+
Name of the .mat file (.mat extension not needed if ``appendmat ==
|
| 269 |
+
True``).
|
| 270 |
+
Can also pass open file_like object.
|
| 271 |
+
mdict : dict
|
| 272 |
+
Dictionary from which to save matfile variables. Note that if this dict
|
| 273 |
+
has a key starting with ``_`` or a sub-dict has a key starting with ``_``
|
| 274 |
+
or a digit, these key's items will not be saved in the mat file and
|
| 275 |
+
`MatWriteWarning` will be issued.
|
| 276 |
+
appendmat : bool, optional
|
| 277 |
+
True (the default) to append the .mat extension to the end of the
|
| 278 |
+
given filename, if not already present.
|
| 279 |
+
format : {'5', '4'}, string, optional
|
| 280 |
+
'5' (the default) for MATLAB 5 and up (to 7.2),
|
| 281 |
+
'4' for MATLAB 4 .mat files.
|
| 282 |
+
long_field_names : bool, optional
|
| 283 |
+
False (the default) - maximum field name length in a structure is
|
| 284 |
+
31 characters which is the documented maximum length.
|
| 285 |
+
True - maximum field name length in a structure is 63 characters
|
| 286 |
+
which works for MATLAB 7.6+.
|
| 287 |
+
do_compression : bool, optional
|
| 288 |
+
Whether or not to compress matrices on write. Default is False.
|
| 289 |
+
oned_as : {'row', 'column'}, optional
|
| 290 |
+
If 'column', write 1-D NumPy arrays as column vectors.
|
| 291 |
+
If 'row', write 1-D NumPy arrays as row vectors.
|
| 292 |
+
|
| 293 |
+
Examples
|
| 294 |
+
--------
|
| 295 |
+
>>> from scipy.io import savemat
|
| 296 |
+
>>> import numpy as np
|
| 297 |
+
>>> a = np.arange(20)
|
| 298 |
+
>>> mdic = {"a": a, "label": "experiment"}
|
| 299 |
+
>>> mdic
|
| 300 |
+
{'a': array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
| 301 |
+
17, 18, 19]),
|
| 302 |
+
'label': 'experiment'}
|
| 303 |
+
>>> savemat("matlab_matrix.mat", mdic)
|
| 304 |
+
"""
|
| 305 |
+
with _open_file_context(file_name, appendmat, 'wb') as file_stream:
|
| 306 |
+
if format == '4':
|
| 307 |
+
if long_field_names:
|
| 308 |
+
message = "Long field names are not available for version 4 files"
|
| 309 |
+
raise ValueError(message)
|
| 310 |
+
MW = MatFile4Writer(file_stream, oned_as)
|
| 311 |
+
elif format == '5':
|
| 312 |
+
MW = MatFile5Writer(file_stream,
|
| 313 |
+
do_compression=do_compression,
|
| 314 |
+
unicode_strings=True,
|
| 315 |
+
long_field_names=long_field_names,
|
| 316 |
+
oned_as=oned_as)
|
| 317 |
+
else:
|
| 318 |
+
raise ValueError("Format should be '4' or '5'")
|
| 319 |
+
MW.put_variables(mdict)
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
@docfiller
|
| 323 |
+
def whosmat(file_name, appendmat=True, **kwargs):
|
| 324 |
+
"""
|
| 325 |
+
List variables inside a MATLAB file.
|
| 326 |
+
|
| 327 |
+
Parameters
|
| 328 |
+
----------
|
| 329 |
+
%(file_arg)s
|
| 330 |
+
%(append_arg)s
|
| 331 |
+
%(load_args)s
|
| 332 |
+
%(struct_arg)s
|
| 333 |
+
|
| 334 |
+
Returns
|
| 335 |
+
-------
|
| 336 |
+
variables : list of tuples
|
| 337 |
+
A list of tuples, where each tuple holds the matrix name (a string),
|
| 338 |
+
its shape (tuple of ints), and its data class (a string).
|
| 339 |
+
Possible data classes are: int8, uint8, int16, uint16, int32, uint32,
|
| 340 |
+
int64, uint64, single, double, cell, struct, object, char, sparse,
|
| 341 |
+
function, opaque, logical, unknown.
|
| 342 |
+
|
| 343 |
+
Notes
|
| 344 |
+
-----
|
| 345 |
+
v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.
|
| 346 |
+
|
| 347 |
+
You will need an HDF5 python library to read matlab 7.3 format mat
|
| 348 |
+
files (e.g. h5py). Because SciPy does not supply one, we do not implement the
|
| 349 |
+
HDF5 / 7.3 interface here.
|
| 350 |
+
|
| 351 |
+
.. versionadded:: 0.12.0
|
| 352 |
+
|
| 353 |
+
Examples
|
| 354 |
+
--------
|
| 355 |
+
>>> from io import BytesIO
|
| 356 |
+
>>> import numpy as np
|
| 357 |
+
>>> from scipy.io import savemat, whosmat
|
| 358 |
+
|
| 359 |
+
Create some arrays, and use `savemat` to write them to a ``BytesIO``
|
| 360 |
+
instance.
|
| 361 |
+
|
| 362 |
+
>>> a = np.array([[10, 20, 30], [11, 21, 31]], dtype=np.int32)
|
| 363 |
+
>>> b = np.geomspace(1, 10, 5)
|
| 364 |
+
>>> f = BytesIO()
|
| 365 |
+
>>> savemat(f, {'a': a, 'b': b})
|
| 366 |
+
|
| 367 |
+
Use `whosmat` to inspect ``f``. Each tuple in the output list gives
|
| 368 |
+
the name, shape and data type of the array in ``f``.
|
| 369 |
+
|
| 370 |
+
>>> whosmat(f)
|
| 371 |
+
[('a', (2, 3), 'int32'), ('b', (1, 5), 'double')]
|
| 372 |
+
|
| 373 |
+
"""
|
| 374 |
+
with _open_file_context(file_name, appendmat) as f:
|
| 375 |
+
ML, file_opened = mat_reader_factory(f, **kwargs)
|
| 376 |
+
variables = ML.list_variables()
|
| 377 |
+
return variables
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio4.py
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
''' Classes for read / write of matlab (TM) 4 files
|
| 2 |
+
'''
|
| 3 |
+
import sys
|
| 4 |
+
import warnings
|
| 5 |
+
import math
|
| 6 |
+
from operator import mul
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
|
| 10 |
+
import scipy.sparse
|
| 11 |
+
|
| 12 |
+
from ._miobase import (MatFileReader, docfiller, matdims, read_dtype,
|
| 13 |
+
convert_dtypes, arr_to_chars, arr_dtype_number)
|
| 14 |
+
|
| 15 |
+
from ._mio_utils import squeeze_element, chars_to_strings
|
| 16 |
+
from functools import reduce
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
__all__ = [
|
| 20 |
+
'MatFile4Reader', 'MatFile4Writer', 'SYS_LITTLE_ENDIAN',
|
| 21 |
+
'VarHeader4', 'VarReader4', 'VarWriter4', 'arr_to_2d', 'mclass_info',
|
| 22 |
+
'mdtypes_template', 'miDOUBLE', 'miINT16', 'miINT32', 'miSINGLE',
|
| 23 |
+
'miUINT16', 'miUINT8', 'mxCHAR_CLASS', 'mxFULL_CLASS', 'mxSPARSE_CLASS',
|
| 24 |
+
'np_to_mtypes', 'order_codes'
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
SYS_LITTLE_ENDIAN = sys.byteorder == 'little'
|
| 29 |
+
|
| 30 |
+
miDOUBLE = 0
|
| 31 |
+
miSINGLE = 1
|
| 32 |
+
miINT32 = 2
|
| 33 |
+
miINT16 = 3
|
| 34 |
+
miUINT16 = 4
|
| 35 |
+
miUINT8 = 5
|
| 36 |
+
|
| 37 |
+
mdtypes_template = {
|
| 38 |
+
miDOUBLE: 'f8',
|
| 39 |
+
miSINGLE: 'f4',
|
| 40 |
+
miINT32: 'i4',
|
| 41 |
+
miINT16: 'i2',
|
| 42 |
+
miUINT16: 'u2',
|
| 43 |
+
miUINT8: 'u1',
|
| 44 |
+
'header': [('mopt', 'i4'),
|
| 45 |
+
('mrows', 'i4'),
|
| 46 |
+
('ncols', 'i4'),
|
| 47 |
+
('imagf', 'i4'),
|
| 48 |
+
('namlen', 'i4')],
|
| 49 |
+
'U1': 'U1',
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
np_to_mtypes = {
|
| 53 |
+
'f8': miDOUBLE,
|
| 54 |
+
'c32': miDOUBLE,
|
| 55 |
+
'c24': miDOUBLE,
|
| 56 |
+
'c16': miDOUBLE,
|
| 57 |
+
'f4': miSINGLE,
|
| 58 |
+
'c8': miSINGLE,
|
| 59 |
+
'i4': miINT32,
|
| 60 |
+
'i2': miINT16,
|
| 61 |
+
'u2': miUINT16,
|
| 62 |
+
'u1': miUINT8,
|
| 63 |
+
'S1': miUINT8,
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
# matrix classes
|
| 67 |
+
mxFULL_CLASS = 0
|
| 68 |
+
mxCHAR_CLASS = 1
|
| 69 |
+
mxSPARSE_CLASS = 2
|
| 70 |
+
|
| 71 |
+
order_codes = {
|
| 72 |
+
0: '<',
|
| 73 |
+
1: '>',
|
| 74 |
+
2: 'VAX D-float', # !
|
| 75 |
+
3: 'VAX G-float',
|
| 76 |
+
4: 'Cray', # !!
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
mclass_info = {
|
| 80 |
+
mxFULL_CLASS: 'double',
|
| 81 |
+
mxCHAR_CLASS: 'char',
|
| 82 |
+
mxSPARSE_CLASS: 'sparse',
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
_MAX_INTP = np.iinfo(np.intp).max
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class VarHeader4:
|
| 90 |
+
# Mat4 variables never logical or global
|
| 91 |
+
is_logical = False
|
| 92 |
+
is_global = False
|
| 93 |
+
|
| 94 |
+
def __init__(self,
|
| 95 |
+
name,
|
| 96 |
+
dtype,
|
| 97 |
+
mclass,
|
| 98 |
+
dims,
|
| 99 |
+
is_complex):
|
| 100 |
+
self.name = name
|
| 101 |
+
self.dtype = dtype
|
| 102 |
+
self.mclass = mclass
|
| 103 |
+
self.dims = dims
|
| 104 |
+
self.is_complex = is_complex
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class VarReader4:
|
| 108 |
+
''' Class to read matlab 4 variables '''
|
| 109 |
+
|
| 110 |
+
def __init__(self, file_reader):
|
| 111 |
+
self.file_reader = file_reader
|
| 112 |
+
self.mat_stream = file_reader.mat_stream
|
| 113 |
+
self.dtypes = file_reader.dtypes
|
| 114 |
+
self.chars_as_strings = file_reader.chars_as_strings
|
| 115 |
+
self.squeeze_me = file_reader.squeeze_me
|
| 116 |
+
|
| 117 |
+
def read_header(self):
|
| 118 |
+
''' Read and return header for variable '''
|
| 119 |
+
data = read_dtype(self.mat_stream, self.dtypes['header'])
|
| 120 |
+
name = self.mat_stream.read(int(data['namlen'])).strip(b'\x00')
|
| 121 |
+
if data['mopt'] < 0 or data['mopt'] > 5000:
|
| 122 |
+
raise ValueError('Mat 4 mopt wrong format, byteswapping problem?')
|
| 123 |
+
M, rest = divmod(data['mopt'], 1000) # order code
|
| 124 |
+
if M not in (0, 1):
|
| 125 |
+
warnings.warn(f"We do not support byte ordering '{order_codes[M]}';"
|
| 126 |
+
" returned data may be corrupt",
|
| 127 |
+
UserWarning, stacklevel=3)
|
| 128 |
+
O, rest = divmod(rest, 100) # unused, should be 0
|
| 129 |
+
if O != 0:
|
| 130 |
+
raise ValueError('O in MOPT integer should be 0, wrong format?')
|
| 131 |
+
P, rest = divmod(rest, 10) # data type code e.g miDOUBLE (see above)
|
| 132 |
+
T = rest # matrix type code e.g., mxFULL_CLASS (see above)
|
| 133 |
+
dims = (data['mrows'], data['ncols'])
|
| 134 |
+
is_complex = data['imagf'] == 1
|
| 135 |
+
dtype = self.dtypes[P]
|
| 136 |
+
return VarHeader4(
|
| 137 |
+
name,
|
| 138 |
+
dtype,
|
| 139 |
+
T,
|
| 140 |
+
dims,
|
| 141 |
+
is_complex)
|
| 142 |
+
|
| 143 |
+
def array_from_header(self, hdr, process=True):
|
| 144 |
+
mclass = hdr.mclass
|
| 145 |
+
if mclass == mxFULL_CLASS:
|
| 146 |
+
arr = self.read_full_array(hdr)
|
| 147 |
+
elif mclass == mxCHAR_CLASS:
|
| 148 |
+
arr = self.read_char_array(hdr)
|
| 149 |
+
if process and self.chars_as_strings:
|
| 150 |
+
arr = chars_to_strings(arr)
|
| 151 |
+
elif mclass == mxSPARSE_CLASS:
|
| 152 |
+
# no current processing (below) makes sense for sparse
|
| 153 |
+
return self.read_sparse_array(hdr)
|
| 154 |
+
else:
|
| 155 |
+
raise TypeError(f'No reader for class code {mclass}')
|
| 156 |
+
if process and self.squeeze_me:
|
| 157 |
+
return squeeze_element(arr)
|
| 158 |
+
return arr
|
| 159 |
+
|
| 160 |
+
def read_sub_array(self, hdr, copy=True):
|
| 161 |
+
''' Mat4 read using header `hdr` dtype and dims
|
| 162 |
+
|
| 163 |
+
Parameters
|
| 164 |
+
----------
|
| 165 |
+
hdr : object
|
| 166 |
+
object with attributes ``dtype``, ``dims``. dtype is assumed to be
|
| 167 |
+
the correct endianness
|
| 168 |
+
copy : bool, optional
|
| 169 |
+
copies array before return if True (default True)
|
| 170 |
+
(buffer is usually read only)
|
| 171 |
+
|
| 172 |
+
Returns
|
| 173 |
+
-------
|
| 174 |
+
arr : ndarray
|
| 175 |
+
of dtype given by `hdr` ``dtype`` and shape given by `hdr` ``dims``
|
| 176 |
+
'''
|
| 177 |
+
dt = hdr.dtype
|
| 178 |
+
# Fast product for large (>2GB) arrays.
|
| 179 |
+
num_bytes = reduce(mul, hdr.dims, np.int64(dt.itemsize))
|
| 180 |
+
if num_bytes > _MAX_INTP:
|
| 181 |
+
raise ValueError(
|
| 182 |
+
f"Variable '{hdr.name.decode('latin1')}' has byte length "
|
| 183 |
+
f"longer than largest possible NumPy array on this platform.")
|
| 184 |
+
buffer = self.mat_stream.read(num_bytes)
|
| 185 |
+
if len(buffer) != num_bytes:
|
| 186 |
+
raise ValueError(
|
| 187 |
+
f"Not enough bytes to read matrix "
|
| 188 |
+
f"'{hdr.name.decode('latin1')}'; is this a badly-formed file? "
|
| 189 |
+
f"Consider listing matrices with `whosmat` and loading named "
|
| 190 |
+
f"matrices with `variable_names` kwarg to `loadmat`")
|
| 191 |
+
arr = np.ndarray(shape=hdr.dims,
|
| 192 |
+
dtype=dt,
|
| 193 |
+
buffer=buffer,
|
| 194 |
+
order='F')
|
| 195 |
+
if copy:
|
| 196 |
+
arr = arr.copy()
|
| 197 |
+
return arr
|
| 198 |
+
|
| 199 |
+
def read_full_array(self, hdr):
|
| 200 |
+
''' Full (rather than sparse) matrix getter
|
| 201 |
+
|
| 202 |
+
Read matrix (array) can be real or complex
|
| 203 |
+
|
| 204 |
+
Parameters
|
| 205 |
+
----------
|
| 206 |
+
hdr : ``VarHeader4`` instance
|
| 207 |
+
|
| 208 |
+
Returns
|
| 209 |
+
-------
|
| 210 |
+
arr : ndarray
|
| 211 |
+
complex array if ``hdr.is_complex`` is True, otherwise a real
|
| 212 |
+
numeric array
|
| 213 |
+
'''
|
| 214 |
+
if hdr.is_complex:
|
| 215 |
+
# avoid array copy to save memory
|
| 216 |
+
res = self.read_sub_array(hdr, copy=False)
|
| 217 |
+
res_j = self.read_sub_array(hdr, copy=False)
|
| 218 |
+
return res + (res_j * 1j)
|
| 219 |
+
return self.read_sub_array(hdr)
|
| 220 |
+
|
| 221 |
+
def read_char_array(self, hdr):
|
| 222 |
+
''' latin-1 text matrix (char matrix) reader
|
| 223 |
+
|
| 224 |
+
Parameters
|
| 225 |
+
----------
|
| 226 |
+
hdr : ``VarHeader4`` instance
|
| 227 |
+
|
| 228 |
+
Returns
|
| 229 |
+
-------
|
| 230 |
+
arr : ndarray
|
| 231 |
+
with dtype 'U1', shape given by `hdr` ``dims``
|
| 232 |
+
'''
|
| 233 |
+
arr = self.read_sub_array(hdr).astype(np.uint8)
|
| 234 |
+
S = arr.tobytes().decode('latin-1')
|
| 235 |
+
return np.ndarray(shape=hdr.dims,
|
| 236 |
+
dtype=np.dtype('U1'),
|
| 237 |
+
buffer=np.array(S)).copy()
|
| 238 |
+
|
| 239 |
+
def read_sparse_array(self, hdr):
|
| 240 |
+
''' Read and return sparse matrix type
|
| 241 |
+
|
| 242 |
+
Parameters
|
| 243 |
+
----------
|
| 244 |
+
hdr : ``VarHeader4`` instance
|
| 245 |
+
|
| 246 |
+
Returns
|
| 247 |
+
-------
|
| 248 |
+
arr : coo_array
|
| 249 |
+
with dtype ``float`` and shape read from the sparse array data
|
| 250 |
+
|
| 251 |
+
Notes
|
| 252 |
+
-----
|
| 253 |
+
MATLAB 4 real sparse arrays are saved in a N+1 by 3 array format, where
|
| 254 |
+
N is the number of non-zero values. Column 1 values [0:N] are the
|
| 255 |
+
(1-based) row indices of the each non-zero value, column 2 [0:N] are the
|
| 256 |
+
column indices, column 3 [0:N] are the (real) values. The last values
|
| 257 |
+
[-1,0:2] of the rows, column indices are shape[0] and shape[1]
|
| 258 |
+
respectively of the output matrix. The last value for the values column
|
| 259 |
+
is a padding 0. mrows and ncols values from the header give the shape of
|
| 260 |
+
the stored matrix, here [N+1, 3]. Complex data are saved as a 4 column
|
| 261 |
+
matrix, where the fourth column contains the imaginary component; the
|
| 262 |
+
last value is again 0. Complex sparse data do *not* have the header
|
| 263 |
+
``imagf`` field set to True; the fact that the data are complex is only
|
| 264 |
+
detectable because there are 4 storage columns.
|
| 265 |
+
'''
|
| 266 |
+
res = self.read_sub_array(hdr)
|
| 267 |
+
tmp = res[:-1,:]
|
| 268 |
+
# All numbers are float64 in Matlab, but SciPy sparse expects int shape
|
| 269 |
+
dims = (int(res[-1,0]), int(res[-1,1]))
|
| 270 |
+
I = np.ascontiguousarray(tmp[:,0],dtype='intc') # fixes byte order also
|
| 271 |
+
J = np.ascontiguousarray(tmp[:,1],dtype='intc')
|
| 272 |
+
I -= 1 # for 1-based indexing
|
| 273 |
+
J -= 1
|
| 274 |
+
if res.shape[1] == 3:
|
| 275 |
+
V = np.ascontiguousarray(tmp[:,2],dtype='float')
|
| 276 |
+
else:
|
| 277 |
+
V = np.ascontiguousarray(tmp[:,2],dtype='complex')
|
| 278 |
+
V.imag = tmp[:,3]
|
| 279 |
+
return scipy.sparse.coo_array((V,(I,J)), dims)
|
| 280 |
+
|
| 281 |
+
def shape_from_header(self, hdr):
|
| 282 |
+
'''Read the shape of the array described by the header.
|
| 283 |
+
The file position after this call is unspecified.
|
| 284 |
+
'''
|
| 285 |
+
mclass = hdr.mclass
|
| 286 |
+
if mclass == mxFULL_CLASS:
|
| 287 |
+
shape = tuple(map(int, hdr.dims))
|
| 288 |
+
elif mclass == mxCHAR_CLASS:
|
| 289 |
+
shape = tuple(map(int, hdr.dims))
|
| 290 |
+
if self.chars_as_strings:
|
| 291 |
+
shape = shape[:-1]
|
| 292 |
+
elif mclass == mxSPARSE_CLASS:
|
| 293 |
+
dt = hdr.dtype
|
| 294 |
+
dims = hdr.dims
|
| 295 |
+
|
| 296 |
+
if not (len(dims) == 2 and dims[0] >= 1 and dims[1] >= 1):
|
| 297 |
+
return ()
|
| 298 |
+
|
| 299 |
+
# Read only the row and column counts
|
| 300 |
+
self.mat_stream.seek(dt.itemsize * (dims[0] - 1), 1)
|
| 301 |
+
rows = np.ndarray(shape=(), dtype=dt,
|
| 302 |
+
buffer=self.mat_stream.read(dt.itemsize))
|
| 303 |
+
self.mat_stream.seek(dt.itemsize * (dims[0] - 1), 1)
|
| 304 |
+
cols = np.ndarray(shape=(), dtype=dt,
|
| 305 |
+
buffer=self.mat_stream.read(dt.itemsize))
|
| 306 |
+
|
| 307 |
+
shape = (int(rows), int(cols))
|
| 308 |
+
else:
|
| 309 |
+
raise TypeError(f'No reader for class code {mclass}')
|
| 310 |
+
|
| 311 |
+
if self.squeeze_me:
|
| 312 |
+
shape = tuple([x for x in shape if x != 1])
|
| 313 |
+
return shape
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
class MatFile4Reader(MatFileReader):
|
| 317 |
+
''' Reader for Mat4 files '''
|
| 318 |
+
@docfiller
|
| 319 |
+
def __init__(self, mat_stream, *args, **kwargs):
|
| 320 |
+
''' Initialize matlab 4 file reader
|
| 321 |
+
|
| 322 |
+
%(matstream_arg)s
|
| 323 |
+
%(load_args)s
|
| 324 |
+
'''
|
| 325 |
+
super().__init__(mat_stream, *args, **kwargs)
|
| 326 |
+
self._matrix_reader = None
|
| 327 |
+
|
| 328 |
+
def guess_byte_order(self):
|
| 329 |
+
self.mat_stream.seek(0)
|
| 330 |
+
mopt = read_dtype(self.mat_stream, np.dtype('i4'))
|
| 331 |
+
self.mat_stream.seek(0)
|
| 332 |
+
if mopt == 0:
|
| 333 |
+
return '<'
|
| 334 |
+
if mopt < 0 or mopt > 5000:
|
| 335 |
+
# Number must have been byteswapped
|
| 336 |
+
return SYS_LITTLE_ENDIAN and '>' or '<'
|
| 337 |
+
# Not byteswapped
|
| 338 |
+
return SYS_LITTLE_ENDIAN and '<' or '>'
|
| 339 |
+
|
| 340 |
+
def initialize_read(self):
|
| 341 |
+
''' Run when beginning read of variables
|
| 342 |
+
|
| 343 |
+
Sets up readers from parameters in `self`
|
| 344 |
+
'''
|
| 345 |
+
self.dtypes = convert_dtypes(mdtypes_template, self.byte_order)
|
| 346 |
+
self._matrix_reader = VarReader4(self)
|
| 347 |
+
|
| 348 |
+
def read_var_header(self):
|
| 349 |
+
''' Read and return header, next position
|
| 350 |
+
|
| 351 |
+
Parameters
|
| 352 |
+
----------
|
| 353 |
+
None
|
| 354 |
+
|
| 355 |
+
Returns
|
| 356 |
+
-------
|
| 357 |
+
header : object
|
| 358 |
+
object that can be passed to self.read_var_array, and that
|
| 359 |
+
has attributes ``name`` and ``is_global``
|
| 360 |
+
next_position : int
|
| 361 |
+
position in stream of next variable
|
| 362 |
+
'''
|
| 363 |
+
hdr = self._matrix_reader.read_header()
|
| 364 |
+
# Fast product for large (>2GB) arrays.
|
| 365 |
+
remaining_bytes = reduce(mul, hdr.dims, np.int64(hdr.dtype.itemsize))
|
| 366 |
+
if hdr.is_complex and not hdr.mclass == mxSPARSE_CLASS:
|
| 367 |
+
remaining_bytes *= 2
|
| 368 |
+
next_position = self.mat_stream.tell() + remaining_bytes
|
| 369 |
+
return hdr, next_position
|
| 370 |
+
|
| 371 |
+
def read_var_array(self, header, process=True):
|
| 372 |
+
''' Read array, given `header`
|
| 373 |
+
|
| 374 |
+
Parameters
|
| 375 |
+
----------
|
| 376 |
+
header : header object
|
| 377 |
+
object with fields defining variable header
|
| 378 |
+
process : {True, False}, optional
|
| 379 |
+
If True, apply recursive post-processing during loading of array.
|
| 380 |
+
|
| 381 |
+
Returns
|
| 382 |
+
-------
|
| 383 |
+
arr : array
|
| 384 |
+
array with post-processing applied or not according to
|
| 385 |
+
`process`.
|
| 386 |
+
'''
|
| 387 |
+
return self._matrix_reader.array_from_header(header, process)
|
| 388 |
+
|
| 389 |
+
def get_variables(self, variable_names=None):
|
| 390 |
+
''' get variables from stream as dictionary
|
| 391 |
+
|
| 392 |
+
Parameters
|
| 393 |
+
----------
|
| 394 |
+
variable_names : None or str or sequence of str, optional
|
| 395 |
+
variable name, or sequence of variable names to get from Mat file /
|
| 396 |
+
file stream. If None, then get all variables in file.
|
| 397 |
+
'''
|
| 398 |
+
if isinstance(variable_names, str):
|
| 399 |
+
variable_names = [variable_names]
|
| 400 |
+
elif variable_names is not None:
|
| 401 |
+
variable_names = list(variable_names)
|
| 402 |
+
self.mat_stream.seek(0)
|
| 403 |
+
# set up variable reader
|
| 404 |
+
self.initialize_read()
|
| 405 |
+
mdict = {}
|
| 406 |
+
while not self.end_of_stream():
|
| 407 |
+
hdr, next_position = self.read_var_header()
|
| 408 |
+
name = 'None' if hdr.name is None else hdr.name.decode('latin1')
|
| 409 |
+
if variable_names is not None and name not in variable_names:
|
| 410 |
+
self.mat_stream.seek(next_position)
|
| 411 |
+
continue
|
| 412 |
+
mdict[name] = self.read_var_array(hdr)
|
| 413 |
+
self.mat_stream.seek(next_position)
|
| 414 |
+
if variable_names is not None:
|
| 415 |
+
variable_names.remove(name)
|
| 416 |
+
if len(variable_names) == 0:
|
| 417 |
+
break
|
| 418 |
+
return mdict
|
| 419 |
+
|
| 420 |
+
def list_variables(self):
|
| 421 |
+
''' list variables from stream '''
|
| 422 |
+
self.mat_stream.seek(0)
|
| 423 |
+
# set up variable reader
|
| 424 |
+
self.initialize_read()
|
| 425 |
+
vars = []
|
| 426 |
+
while not self.end_of_stream():
|
| 427 |
+
hdr, next_position = self.read_var_header()
|
| 428 |
+
name = 'None' if hdr.name is None else hdr.name.decode('latin1')
|
| 429 |
+
shape = self._matrix_reader.shape_from_header(hdr)
|
| 430 |
+
info = mclass_info.get(hdr.mclass, 'unknown')
|
| 431 |
+
vars.append((name, shape, info))
|
| 432 |
+
|
| 433 |
+
self.mat_stream.seek(next_position)
|
| 434 |
+
return vars
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
def arr_to_2d(arr, oned_as='row'):
|
| 438 |
+
''' Make ``arr`` exactly two dimensional
|
| 439 |
+
|
| 440 |
+
If `arr` has more than 2 dimensions, raise a ValueError
|
| 441 |
+
|
| 442 |
+
Parameters
|
| 443 |
+
----------
|
| 444 |
+
arr : array
|
| 445 |
+
oned_as : {'row', 'column'}, optional
|
| 446 |
+
Whether to reshape 1-D vectors as row vectors or column vectors.
|
| 447 |
+
See documentation for ``matdims`` for more detail
|
| 448 |
+
|
| 449 |
+
Returns
|
| 450 |
+
-------
|
| 451 |
+
arr2d : array
|
| 452 |
+
2-D version of the array
|
| 453 |
+
'''
|
| 454 |
+
dims = matdims(arr, oned_as)
|
| 455 |
+
if len(dims) > 2:
|
| 456 |
+
raise ValueError('Matlab 4 files cannot save arrays with more than '
|
| 457 |
+
'2 dimensions')
|
| 458 |
+
return arr.reshape(dims)
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
class VarWriter4:
|
| 462 |
+
def __init__(self, file_writer):
|
| 463 |
+
self.file_stream = file_writer.file_stream
|
| 464 |
+
self.oned_as = file_writer.oned_as
|
| 465 |
+
|
| 466 |
+
def write_bytes(self, arr):
|
| 467 |
+
self.file_stream.write(arr.tobytes(order='F'))
|
| 468 |
+
|
| 469 |
+
def write_string(self, s):
|
| 470 |
+
self.file_stream.write(s)
|
| 471 |
+
|
| 472 |
+
def write_header(self, name, shape, P=miDOUBLE, T=mxFULL_CLASS, imagf=0):
|
| 473 |
+
''' Write header for given data options
|
| 474 |
+
|
| 475 |
+
Parameters
|
| 476 |
+
----------
|
| 477 |
+
name : str
|
| 478 |
+
name of variable
|
| 479 |
+
shape : sequence
|
| 480 |
+
Shape of array as it will be read in matlab
|
| 481 |
+
P : int, optional
|
| 482 |
+
code for mat4 data type, one of ``miDOUBLE, miSINGLE, miINT32,
|
| 483 |
+
miINT16, miUINT16, miUINT8``
|
| 484 |
+
T : int, optional
|
| 485 |
+
code for mat4 matrix class, one of ``mxFULL_CLASS, mxCHAR_CLASS,
|
| 486 |
+
mxSPARSE_CLASS``
|
| 487 |
+
imagf : int, optional
|
| 488 |
+
flag indicating complex
|
| 489 |
+
'''
|
| 490 |
+
header = np.empty((), mdtypes_template['header'])
|
| 491 |
+
M = not SYS_LITTLE_ENDIAN
|
| 492 |
+
O = 0
|
| 493 |
+
header['mopt'] = (M * 1000 +
|
| 494 |
+
O * 100 +
|
| 495 |
+
P * 10 +
|
| 496 |
+
T)
|
| 497 |
+
header['mrows'] = shape[0]
|
| 498 |
+
header['ncols'] = shape[1]
|
| 499 |
+
header['imagf'] = imagf
|
| 500 |
+
header['namlen'] = len(name) + 1
|
| 501 |
+
self.write_bytes(header)
|
| 502 |
+
data = name + '\0'
|
| 503 |
+
self.write_string(data.encode('latin1'))
|
| 504 |
+
|
| 505 |
+
def write(self, arr, name):
|
| 506 |
+
''' Write matrix `arr`, with name `name`
|
| 507 |
+
|
| 508 |
+
Parameters
|
| 509 |
+
----------
|
| 510 |
+
arr : array_like
|
| 511 |
+
array to write
|
| 512 |
+
name : str
|
| 513 |
+
name in matlab workspace
|
| 514 |
+
'''
|
| 515 |
+
# we need to catch sparse first, because np.asarray returns an
|
| 516 |
+
# an object array for scipy.sparse
|
| 517 |
+
if scipy.sparse.issparse(arr):
|
| 518 |
+
self.write_sparse(arr, name)
|
| 519 |
+
return
|
| 520 |
+
arr = np.asarray(arr)
|
| 521 |
+
dt = arr.dtype
|
| 522 |
+
if not dt.isnative:
|
| 523 |
+
arr = arr.astype(dt.newbyteorder('='))
|
| 524 |
+
dtt = dt.type
|
| 525 |
+
if dtt is np.object_:
|
| 526 |
+
raise TypeError('Cannot save object arrays in Mat4')
|
| 527 |
+
elif dtt is np.void:
|
| 528 |
+
raise TypeError('Cannot save void type arrays')
|
| 529 |
+
elif dtt in (np.str_, np.bytes_):
|
| 530 |
+
self.write_char(arr, name)
|
| 531 |
+
return
|
| 532 |
+
self.write_numeric(arr, name)
|
| 533 |
+
|
| 534 |
+
def write_numeric(self, arr, name):
|
| 535 |
+
arr = arr_to_2d(arr, self.oned_as)
|
| 536 |
+
imagf = arr.dtype.kind == 'c'
|
| 537 |
+
try:
|
| 538 |
+
P = np_to_mtypes[arr.dtype.str[1:]]
|
| 539 |
+
except KeyError:
|
| 540 |
+
if imagf:
|
| 541 |
+
arr = arr.astype('c128')
|
| 542 |
+
else:
|
| 543 |
+
arr = arr.astype('f8')
|
| 544 |
+
P = miDOUBLE
|
| 545 |
+
self.write_header(name,
|
| 546 |
+
arr.shape,
|
| 547 |
+
P=P,
|
| 548 |
+
T=mxFULL_CLASS,
|
| 549 |
+
imagf=imagf)
|
| 550 |
+
if imagf:
|
| 551 |
+
self.write_bytes(arr.real)
|
| 552 |
+
self.write_bytes(arr.imag)
|
| 553 |
+
else:
|
| 554 |
+
self.write_bytes(arr)
|
| 555 |
+
|
| 556 |
+
def write_char(self, arr, name):
|
| 557 |
+
if arr.dtype.type == np.str_ and arr.dtype.itemsize != np.dtype('U1').itemsize:
|
| 558 |
+
arr = arr_to_chars(arr)
|
| 559 |
+
arr = arr_to_2d(arr, self.oned_as)
|
| 560 |
+
dims = arr.shape
|
| 561 |
+
self.write_header(
|
| 562 |
+
name,
|
| 563 |
+
dims,
|
| 564 |
+
P=miUINT8,
|
| 565 |
+
T=mxCHAR_CLASS)
|
| 566 |
+
if arr.dtype.kind == 'U':
|
| 567 |
+
# Recode unicode to latin1
|
| 568 |
+
n_chars = math.prod(dims)
|
| 569 |
+
st_arr = np.ndarray(shape=(),
|
| 570 |
+
dtype=arr_dtype_number(arr, n_chars),
|
| 571 |
+
buffer=arr)
|
| 572 |
+
st = st_arr.item().encode('latin-1')
|
| 573 |
+
arr = np.ndarray(shape=dims, dtype='S1', buffer=st)
|
| 574 |
+
self.write_bytes(arr)
|
| 575 |
+
|
| 576 |
+
def write_sparse(self, arr, name):
|
| 577 |
+
''' Sparse matrices are 2-D
|
| 578 |
+
|
| 579 |
+
See docstring for VarReader4.read_sparse_array
|
| 580 |
+
'''
|
| 581 |
+
A = arr.tocoo() # convert to sparse COO format (ijv)
|
| 582 |
+
imagf = A.dtype.kind == 'c'
|
| 583 |
+
ijv = np.zeros((A.nnz + 1, 3+imagf), dtype='f8')
|
| 584 |
+
ijv[:-1,0] = A.row
|
| 585 |
+
ijv[:-1,1] = A.col
|
| 586 |
+
ijv[:-1,0:2] += 1 # 1 based indexing
|
| 587 |
+
if imagf:
|
| 588 |
+
ijv[:-1,2] = A.data.real
|
| 589 |
+
ijv[:-1,3] = A.data.imag
|
| 590 |
+
else:
|
| 591 |
+
ijv[:-1,2] = A.data
|
| 592 |
+
ijv[-1,0:2] = A.shape
|
| 593 |
+
self.write_header(
|
| 594 |
+
name,
|
| 595 |
+
ijv.shape,
|
| 596 |
+
P=miDOUBLE,
|
| 597 |
+
T=mxSPARSE_CLASS)
|
| 598 |
+
self.write_bytes(ijv)
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
class MatFile4Writer:
|
| 602 |
+
''' Class for writing matlab 4 format files '''
|
| 603 |
+
def __init__(self, file_stream, oned_as=None):
|
| 604 |
+
self.file_stream = file_stream
|
| 605 |
+
if oned_as is None:
|
| 606 |
+
oned_as = 'row'
|
| 607 |
+
self.oned_as = oned_as
|
| 608 |
+
self._matrix_writer = None
|
| 609 |
+
|
| 610 |
+
def put_variables(self, mdict, write_header=None):
|
| 611 |
+
''' Write variables in `mdict` to stream
|
| 612 |
+
|
| 613 |
+
Parameters
|
| 614 |
+
----------
|
| 615 |
+
mdict : mapping
|
| 616 |
+
mapping with method ``items`` return name, contents pairs
|
| 617 |
+
where ``name`` which will appeak in the matlab workspace in
|
| 618 |
+
file load, and ``contents`` is something writeable to a
|
| 619 |
+
matlab file, such as a NumPy array.
|
| 620 |
+
write_header : {None, True, False}
|
| 621 |
+
If True, then write the matlab file header before writing the
|
| 622 |
+
variables. If None (the default) then write the file header
|
| 623 |
+
if we are at position 0 in the stream. By setting False
|
| 624 |
+
here, and setting the stream position to the end of the file,
|
| 625 |
+
you can append variables to a matlab file
|
| 626 |
+
'''
|
| 627 |
+
# there is no header for a matlab 4 mat file, so we ignore the
|
| 628 |
+
# ``write_header`` input argument. It's there for compatibility
|
| 629 |
+
# with the matlab 5 version of this method
|
| 630 |
+
self._matrix_writer = VarWriter4(self)
|
| 631 |
+
for name, var in mdict.items():
|
| 632 |
+
self._matrix_writer.write(var, name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio5.py
ADDED
|
@@ -0,0 +1,901 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
''' Classes for read / write of matlab (TM) 5 files
|
| 2 |
+
|
| 3 |
+
The matfile specification last found here:
|
| 4 |
+
|
| 5 |
+
https://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf
|
| 6 |
+
|
| 7 |
+
(as of December 5 2008)
|
| 8 |
+
|
| 9 |
+
=================================
|
| 10 |
+
Note on functions and mat files
|
| 11 |
+
=================================
|
| 12 |
+
|
| 13 |
+
The document above does not give any hints as to the storage of matlab
|
| 14 |
+
function handles, or anonymous function handles. I had, therefore, to
|
| 15 |
+
guess the format of matlab arrays of ``mxFUNCTION_CLASS`` and
|
| 16 |
+
``mxOPAQUE_CLASS`` by looking at example mat files.
|
| 17 |
+
|
| 18 |
+
``mxFUNCTION_CLASS`` stores all types of matlab functions. It seems to
|
| 19 |
+
contain a struct matrix with a set pattern of fields. For anonymous
|
| 20 |
+
functions, a sub-fields of one of these fields seems to contain the
|
| 21 |
+
well-named ``mxOPAQUE_CLASS``. This seems to contain:
|
| 22 |
+
|
| 23 |
+
* array flags as for any matlab matrix
|
| 24 |
+
* 3 int8 strings
|
| 25 |
+
* a matrix
|
| 26 |
+
|
| 27 |
+
It seems that whenever the mat file contains a ``mxOPAQUE_CLASS``
|
| 28 |
+
instance, there is also an un-named matrix (name == '') at the end of
|
| 29 |
+
the mat file. I'll call this the ``__function_workspace__`` matrix.
|
| 30 |
+
|
| 31 |
+
When I saved two anonymous functions in a mat file, or appended another
|
| 32 |
+
anonymous function to the mat file, there was still only one
|
| 33 |
+
``__function_workspace__`` un-named matrix at the end, but larger than
|
| 34 |
+
that for a mat file with a single anonymous function, suggesting that
|
| 35 |
+
the workspaces for the two functions had been merged.
|
| 36 |
+
|
| 37 |
+
The ``__function_workspace__`` matrix appears to be of double class
|
| 38 |
+
(``mxCLASS_DOUBLE``), but stored as uint8, the memory for which is in
|
| 39 |
+
the format of a mini .mat file, without the first 124 bytes of the file
|
| 40 |
+
header (the description and the subsystem_offset), but with the version
|
| 41 |
+
U2 bytes, and the S2 endian test bytes. There follow 4 zero bytes,
|
| 42 |
+
presumably for 8 byte padding, and then a series of ``miMATRIX``
|
| 43 |
+
entries, as in a standard mat file. The ``miMATRIX`` entries appear to
|
| 44 |
+
be series of un-named (name == '') matrices, and may also contain arrays
|
| 45 |
+
of this same mini-mat format.
|
| 46 |
+
|
| 47 |
+
I guess that:
|
| 48 |
+
|
| 49 |
+
* saving an anonymous function back to a mat file will need the
|
| 50 |
+
associated ``__function_workspace__`` matrix saved as well for the
|
| 51 |
+
anonymous function to work correctly.
|
| 52 |
+
* appending to a mat file that has a ``__function_workspace__`` would
|
| 53 |
+
involve first pulling off this workspace, appending, checking whether
|
| 54 |
+
there were any more anonymous functions appended, and then somehow
|
| 55 |
+
merging the relevant workspaces, and saving at the end of the mat
|
| 56 |
+
file.
|
| 57 |
+
|
| 58 |
+
The mat files I was playing with are in ``tests/data``:
|
| 59 |
+
|
| 60 |
+
* sqr.mat
|
| 61 |
+
* parabola.mat
|
| 62 |
+
* some_functions.mat
|
| 63 |
+
|
| 64 |
+
See ``tests/test_mio.py:test_mio_funcs.py`` for the debugging
|
| 65 |
+
script I was working with.
|
| 66 |
+
|
| 67 |
+
Small fragments of current code adapted from matfile.py by Heiko
|
| 68 |
+
Henkelmann; parts of the code for simplify_cells=True adapted from
|
| 69 |
+
http://blog.nephics.com/2019/08/28/better-loadmat-for-scipy/.
|
| 70 |
+
'''
|
| 71 |
+
|
| 72 |
+
import math
|
| 73 |
+
import os
|
| 74 |
+
import time
|
| 75 |
+
import sys
|
| 76 |
+
import zlib
|
| 77 |
+
|
| 78 |
+
from io import BytesIO
|
| 79 |
+
|
| 80 |
+
import warnings
|
| 81 |
+
|
| 82 |
+
import numpy as np
|
| 83 |
+
|
| 84 |
+
import scipy.sparse
|
| 85 |
+
|
| 86 |
+
from ._byteordercodes import native_code, swapped_code
|
| 87 |
+
|
| 88 |
+
from ._miobase import (MatFileReader, docfiller, matdims, read_dtype,
|
| 89 |
+
arr_to_chars, arr_dtype_number, MatWriteError,
|
| 90 |
+
MatReadError, MatReadWarning, MatWriteWarning)
|
| 91 |
+
|
| 92 |
+
# Reader object for matlab 5 format variables
|
| 93 |
+
from ._mio5_utils import VarReader5
|
| 94 |
+
|
| 95 |
+
# Constants and helper objects
|
| 96 |
+
from ._mio5_params import (MatlabObject, MatlabFunction, MDTYPES, NP_TO_MTYPES,
|
| 97 |
+
NP_TO_MXTYPES, miCOMPRESSED, miMATRIX, miINT8,
|
| 98 |
+
miUTF8, miUINT32, mxCELL_CLASS, mxSTRUCT_CLASS,
|
| 99 |
+
mxOBJECT_CLASS, mxCHAR_CLASS, mxSPARSE_CLASS,
|
| 100 |
+
mxDOUBLE_CLASS, mclass_info, mat_struct)
|
| 101 |
+
|
| 102 |
+
from ._streams import ZlibInputStream
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def _has_struct(elem):
|
| 106 |
+
"""Determine if elem is an array and if first array item is a struct."""
|
| 107 |
+
return (isinstance(elem, np.ndarray) and (elem.size > 0) and (elem.ndim > 0) and
|
| 108 |
+
isinstance(elem[0], mat_struct))
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def _inspect_cell_array(ndarray):
|
| 112 |
+
"""Construct lists from cell arrays (loaded as numpy ndarrays), recursing
|
| 113 |
+
into items if they contain mat_struct objects."""
|
| 114 |
+
elem_list = []
|
| 115 |
+
for sub_elem in ndarray:
|
| 116 |
+
if isinstance(sub_elem, mat_struct):
|
| 117 |
+
elem_list.append(_matstruct_to_dict(sub_elem))
|
| 118 |
+
elif _has_struct(sub_elem):
|
| 119 |
+
elem_list.append(_inspect_cell_array(sub_elem))
|
| 120 |
+
else:
|
| 121 |
+
elem_list.append(sub_elem)
|
| 122 |
+
return elem_list
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _matstruct_to_dict(matobj):
|
| 126 |
+
"""Construct nested dicts from mat_struct objects."""
|
| 127 |
+
d = {}
|
| 128 |
+
for f in matobj._fieldnames:
|
| 129 |
+
elem = matobj.__dict__[f]
|
| 130 |
+
if isinstance(elem, mat_struct):
|
| 131 |
+
d[f] = _matstruct_to_dict(elem)
|
| 132 |
+
elif _has_struct(elem):
|
| 133 |
+
d[f] = _inspect_cell_array(elem)
|
| 134 |
+
else:
|
| 135 |
+
d[f] = elem
|
| 136 |
+
return d
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _simplify_cells(d):
|
| 140 |
+
"""Convert mat objects in dict to nested dicts."""
|
| 141 |
+
for key in d:
|
| 142 |
+
if isinstance(d[key], mat_struct):
|
| 143 |
+
d[key] = _matstruct_to_dict(d[key])
|
| 144 |
+
elif _has_struct(d[key]):
|
| 145 |
+
d[key] = _inspect_cell_array(d[key])
|
| 146 |
+
return d
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class MatFile5Reader(MatFileReader):
|
| 150 |
+
''' Reader for Mat 5 mat files
|
| 151 |
+
Adds the following attribute to base class
|
| 152 |
+
|
| 153 |
+
uint16_codec - char codec to use for uint16 char arrays
|
| 154 |
+
(defaults to system default codec)
|
| 155 |
+
|
| 156 |
+
Uses variable reader that has the following standard interface (see
|
| 157 |
+
abstract class in ``miobase``::
|
| 158 |
+
|
| 159 |
+
__init__(self, file_reader)
|
| 160 |
+
read_header(self)
|
| 161 |
+
array_from_header(self)
|
| 162 |
+
|
| 163 |
+
and added interface::
|
| 164 |
+
|
| 165 |
+
set_stream(self, stream)
|
| 166 |
+
read_full_tag(self)
|
| 167 |
+
|
| 168 |
+
'''
|
| 169 |
+
@docfiller
|
| 170 |
+
def __init__(self,
|
| 171 |
+
mat_stream,
|
| 172 |
+
byte_order=None,
|
| 173 |
+
mat_dtype=False,
|
| 174 |
+
squeeze_me=False,
|
| 175 |
+
chars_as_strings=True,
|
| 176 |
+
matlab_compatible=False,
|
| 177 |
+
struct_as_record=True,
|
| 178 |
+
verify_compressed_data_integrity=True,
|
| 179 |
+
uint16_codec=None,
|
| 180 |
+
simplify_cells=False):
|
| 181 |
+
'''Initializer for matlab 5 file format reader
|
| 182 |
+
|
| 183 |
+
%(matstream_arg)s
|
| 184 |
+
%(load_args)s
|
| 185 |
+
%(struct_arg)s
|
| 186 |
+
uint16_codec : {None, string}
|
| 187 |
+
Set codec to use for uint16 char arrays (e.g., 'utf-8').
|
| 188 |
+
Use system default codec if None
|
| 189 |
+
'''
|
| 190 |
+
super().__init__(
|
| 191 |
+
mat_stream,
|
| 192 |
+
byte_order,
|
| 193 |
+
mat_dtype,
|
| 194 |
+
squeeze_me,
|
| 195 |
+
chars_as_strings,
|
| 196 |
+
matlab_compatible,
|
| 197 |
+
struct_as_record,
|
| 198 |
+
verify_compressed_data_integrity,
|
| 199 |
+
simplify_cells)
|
| 200 |
+
# Set uint16 codec
|
| 201 |
+
if not uint16_codec:
|
| 202 |
+
uint16_codec = sys.getdefaultencoding()
|
| 203 |
+
self.uint16_codec = uint16_codec
|
| 204 |
+
# placeholders for readers - see initialize_read method
|
| 205 |
+
self._file_reader = None
|
| 206 |
+
self._matrix_reader = None
|
| 207 |
+
|
| 208 |
+
def guess_byte_order(self):
|
| 209 |
+
''' Guess byte order.
|
| 210 |
+
Sets stream pointer to 0'''
|
| 211 |
+
self.mat_stream.seek(126)
|
| 212 |
+
mi = self.mat_stream.read(2)
|
| 213 |
+
self.mat_stream.seek(0)
|
| 214 |
+
return mi == b'IM' and '<' or '>'
|
| 215 |
+
|
| 216 |
+
def read_file_header(self):
|
| 217 |
+
''' Read in mat 5 file header '''
|
| 218 |
+
hdict = {}
|
| 219 |
+
hdr_dtype = MDTYPES[self.byte_order]['dtypes']['file_header']
|
| 220 |
+
hdr = read_dtype(self.mat_stream, hdr_dtype)
|
| 221 |
+
hdict['__header__'] = hdr['description'].item().strip(b' \t\n\000')
|
| 222 |
+
v_major = hdr['version'] >> 8
|
| 223 |
+
v_minor = hdr['version'] & 0xFF
|
| 224 |
+
hdict['__version__'] = f'{v_major}.{v_minor}'
|
| 225 |
+
return hdict
|
| 226 |
+
|
| 227 |
+
def initialize_read(self):
|
| 228 |
+
''' Run when beginning read of variables
|
| 229 |
+
|
| 230 |
+
Sets up readers from parameters in `self`
|
| 231 |
+
'''
|
| 232 |
+
# reader for top level stream. We need this extra top-level
|
| 233 |
+
# reader because we use the matrix_reader object to contain
|
| 234 |
+
# compressed matrices (so they have their own stream)
|
| 235 |
+
self._file_reader = VarReader5(self)
|
| 236 |
+
# reader for matrix streams
|
| 237 |
+
self._matrix_reader = VarReader5(self)
|
| 238 |
+
|
| 239 |
+
def read_var_header(self):
|
| 240 |
+
''' Read header, return header, next position
|
| 241 |
+
|
| 242 |
+
Header has to define at least .name and .is_global
|
| 243 |
+
|
| 244 |
+
Parameters
|
| 245 |
+
----------
|
| 246 |
+
None
|
| 247 |
+
|
| 248 |
+
Returns
|
| 249 |
+
-------
|
| 250 |
+
header : object
|
| 251 |
+
object that can be passed to self.read_var_array, and that
|
| 252 |
+
has attributes .name and .is_global
|
| 253 |
+
next_position : int
|
| 254 |
+
position in stream of next variable
|
| 255 |
+
'''
|
| 256 |
+
mdtype, byte_count = self._file_reader.read_full_tag()
|
| 257 |
+
if not byte_count > 0:
|
| 258 |
+
raise ValueError("Did not read any bytes")
|
| 259 |
+
next_pos = self.mat_stream.tell() + byte_count
|
| 260 |
+
if mdtype == miCOMPRESSED:
|
| 261 |
+
# Make new stream from compressed data
|
| 262 |
+
stream = ZlibInputStream(self.mat_stream, byte_count)
|
| 263 |
+
self._matrix_reader.set_stream(stream)
|
| 264 |
+
check_stream_limit = self.verify_compressed_data_integrity
|
| 265 |
+
mdtype, byte_count = self._matrix_reader.read_full_tag()
|
| 266 |
+
else:
|
| 267 |
+
check_stream_limit = False
|
| 268 |
+
self._matrix_reader.set_stream(self.mat_stream)
|
| 269 |
+
if not mdtype == miMATRIX:
|
| 270 |
+
raise TypeError(f'Expecting miMATRIX type here, got {mdtype}')
|
| 271 |
+
header = self._matrix_reader.read_header(check_stream_limit)
|
| 272 |
+
return header, next_pos
|
| 273 |
+
|
| 274 |
+
def read_var_array(self, header, process=True):
|
| 275 |
+
''' Read array, given `header`
|
| 276 |
+
|
| 277 |
+
Parameters
|
| 278 |
+
----------
|
| 279 |
+
header : header object
|
| 280 |
+
object with fields defining variable header
|
| 281 |
+
process : {True, False} bool, optional
|
| 282 |
+
If True, apply recursive post-processing during loading of
|
| 283 |
+
array.
|
| 284 |
+
|
| 285 |
+
Returns
|
| 286 |
+
-------
|
| 287 |
+
arr : array
|
| 288 |
+
array with post-processing applied or not according to
|
| 289 |
+
`process`.
|
| 290 |
+
'''
|
| 291 |
+
return self._matrix_reader.array_from_header(header, process)
|
| 292 |
+
|
| 293 |
+
def get_variables(self, variable_names=None):
|
| 294 |
+
''' get variables from stream as dictionary
|
| 295 |
+
|
| 296 |
+
variable_names - optional list of variable names to get
|
| 297 |
+
|
| 298 |
+
If variable_names is None, then get all variables in file
|
| 299 |
+
'''
|
| 300 |
+
if isinstance(variable_names, str):
|
| 301 |
+
variable_names = [variable_names]
|
| 302 |
+
elif variable_names is not None:
|
| 303 |
+
variable_names = list(variable_names)
|
| 304 |
+
|
| 305 |
+
self.mat_stream.seek(0)
|
| 306 |
+
# Here we pass all the parameters in self to the reading objects
|
| 307 |
+
self.initialize_read()
|
| 308 |
+
mdict = self.read_file_header()
|
| 309 |
+
mdict['__globals__'] = []
|
| 310 |
+
while not self.end_of_stream():
|
| 311 |
+
hdr, next_position = self.read_var_header()
|
| 312 |
+
name = 'None' if hdr.name is None else hdr.name.decode('latin1')
|
| 313 |
+
if name in mdict:
|
| 314 |
+
msg = (
|
| 315 |
+
f'Duplicate variable name "{name}" in stream'
|
| 316 |
+
" - replacing previous with new\nConsider"
|
| 317 |
+
"scipy.io.matlab.varmats_from_mat to split "
|
| 318 |
+
"file into single variable files"
|
| 319 |
+
)
|
| 320 |
+
warnings.warn(msg, MatReadWarning, stacklevel=2)
|
| 321 |
+
if name == '':
|
| 322 |
+
# can only be a matlab 7 function workspace
|
| 323 |
+
name = '__function_workspace__'
|
| 324 |
+
# We want to keep this raw because mat_dtype processing
|
| 325 |
+
# will break the format (uint8 as mxDOUBLE_CLASS)
|
| 326 |
+
process = False
|
| 327 |
+
else:
|
| 328 |
+
process = True
|
| 329 |
+
if variable_names is not None and name not in variable_names:
|
| 330 |
+
self.mat_stream.seek(next_position)
|
| 331 |
+
continue
|
| 332 |
+
try:
|
| 333 |
+
res = self.read_var_array(hdr, process)
|
| 334 |
+
except MatReadError as err:
|
| 335 |
+
warnings.warn(
|
| 336 |
+
f'Unreadable variable "{name}", because "{err}"',
|
| 337 |
+
Warning, stacklevel=2)
|
| 338 |
+
res = f"Read error: {err}"
|
| 339 |
+
self.mat_stream.seek(next_position)
|
| 340 |
+
mdict[name] = res
|
| 341 |
+
if hdr.is_global:
|
| 342 |
+
mdict['__globals__'].append(name)
|
| 343 |
+
if variable_names is not None:
|
| 344 |
+
variable_names.remove(name)
|
| 345 |
+
if len(variable_names) == 0:
|
| 346 |
+
break
|
| 347 |
+
if self.simplify_cells:
|
| 348 |
+
return _simplify_cells(mdict)
|
| 349 |
+
else:
|
| 350 |
+
return mdict
|
| 351 |
+
|
| 352 |
+
def list_variables(self):
|
| 353 |
+
''' list variables from stream '''
|
| 354 |
+
self.mat_stream.seek(0)
|
| 355 |
+
# Here we pass all the parameters in self to the reading objects
|
| 356 |
+
self.initialize_read()
|
| 357 |
+
self.read_file_header()
|
| 358 |
+
vars = []
|
| 359 |
+
while not self.end_of_stream():
|
| 360 |
+
hdr, next_position = self.read_var_header()
|
| 361 |
+
name = 'None' if hdr.name is None else hdr.name.decode('latin1')
|
| 362 |
+
if name == '':
|
| 363 |
+
# can only be a matlab 7 function workspace
|
| 364 |
+
name = '__function_workspace__'
|
| 365 |
+
|
| 366 |
+
shape = self._matrix_reader.shape_from_header(hdr)
|
| 367 |
+
if hdr.is_logical:
|
| 368 |
+
info = 'logical'
|
| 369 |
+
else:
|
| 370 |
+
info = mclass_info.get(hdr.mclass, 'unknown')
|
| 371 |
+
vars.append((name, shape, info))
|
| 372 |
+
|
| 373 |
+
self.mat_stream.seek(next_position)
|
| 374 |
+
return vars
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def varmats_from_mat(file_obj):
|
| 378 |
+
""" Pull variables out of mat 5 file as a sequence of mat file objects
|
| 379 |
+
|
| 380 |
+
This can be useful with a difficult mat file, containing unreadable
|
| 381 |
+
variables. This routine pulls the variables out in raw form and puts them,
|
| 382 |
+
unread, back into a file stream for saving or reading. Another use is the
|
| 383 |
+
pathological case where there is more than one variable of the same name in
|
| 384 |
+
the file; this routine returns the duplicates, whereas the standard reader
|
| 385 |
+
will overwrite duplicates in the returned dictionary.
|
| 386 |
+
|
| 387 |
+
The file pointer in `file_obj` will be undefined. File pointers for the
|
| 388 |
+
returned file-like objects are set at 0.
|
| 389 |
+
|
| 390 |
+
Parameters
|
| 391 |
+
----------
|
| 392 |
+
file_obj : file-like
|
| 393 |
+
file object containing mat file
|
| 394 |
+
|
| 395 |
+
Returns
|
| 396 |
+
-------
|
| 397 |
+
named_mats : list
|
| 398 |
+
list contains tuples of (name, BytesIO) where BytesIO is a file-like
|
| 399 |
+
object containing mat file contents as for a single variable. The
|
| 400 |
+
BytesIO contains a string with the original header and a single var. If
|
| 401 |
+
``var_file_obj`` is an individual BytesIO instance, then save as a mat
|
| 402 |
+
file with something like ``open('test.mat',
|
| 403 |
+
'wb').write(var_file_obj.read())``
|
| 404 |
+
|
| 405 |
+
Examples
|
| 406 |
+
--------
|
| 407 |
+
>>> import scipy.io
|
| 408 |
+
>>> import numpy as np
|
| 409 |
+
>>> from io import BytesIO
|
| 410 |
+
>>> from scipy.io.matlab._mio5 import varmats_from_mat
|
| 411 |
+
>>> mat_fileobj = BytesIO()
|
| 412 |
+
>>> scipy.io.savemat(mat_fileobj, {'b': np.arange(10), 'a': 'a string'})
|
| 413 |
+
>>> varmats = varmats_from_mat(mat_fileobj)
|
| 414 |
+
>>> sorted([name for name, str_obj in varmats])
|
| 415 |
+
['a', 'b']
|
| 416 |
+
"""
|
| 417 |
+
rdr = MatFile5Reader(file_obj)
|
| 418 |
+
file_obj.seek(0)
|
| 419 |
+
# Raw read of top-level file header
|
| 420 |
+
hdr_len = MDTYPES[native_code]['dtypes']['file_header'].itemsize
|
| 421 |
+
raw_hdr = file_obj.read(hdr_len)
|
| 422 |
+
# Initialize variable reading
|
| 423 |
+
file_obj.seek(0)
|
| 424 |
+
rdr.initialize_read()
|
| 425 |
+
rdr.read_file_header()
|
| 426 |
+
next_position = file_obj.tell()
|
| 427 |
+
named_mats = []
|
| 428 |
+
while not rdr.end_of_stream():
|
| 429 |
+
start_position = next_position
|
| 430 |
+
hdr, next_position = rdr.read_var_header()
|
| 431 |
+
name = 'None' if hdr.name is None else hdr.name.decode('latin1')
|
| 432 |
+
# Read raw variable string
|
| 433 |
+
file_obj.seek(start_position)
|
| 434 |
+
byte_count = next_position - start_position
|
| 435 |
+
var_str = file_obj.read(byte_count)
|
| 436 |
+
# write to stringio object
|
| 437 |
+
out_obj = BytesIO()
|
| 438 |
+
out_obj.write(raw_hdr)
|
| 439 |
+
out_obj.write(var_str)
|
| 440 |
+
out_obj.seek(0)
|
| 441 |
+
named_mats.append((name, out_obj))
|
| 442 |
+
return named_mats
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
class EmptyStructMarker:
|
| 446 |
+
""" Class to indicate presence of empty matlab struct on output """
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def to_writeable(source):
|
| 450 |
+
''' Convert input object ``source`` to something we can write
|
| 451 |
+
|
| 452 |
+
Parameters
|
| 453 |
+
----------
|
| 454 |
+
source : object
|
| 455 |
+
|
| 456 |
+
Returns
|
| 457 |
+
-------
|
| 458 |
+
arr : None or ndarray or EmptyStructMarker
|
| 459 |
+
If `source` cannot be converted to something we can write to a matfile,
|
| 460 |
+
return None. If `source` is equivalent to an empty dictionary, return
|
| 461 |
+
``EmptyStructMarker``. Otherwise return `source` converted to an
|
| 462 |
+
ndarray with contents for writing to matfile.
|
| 463 |
+
'''
|
| 464 |
+
if isinstance(source, np.ndarray):
|
| 465 |
+
return source
|
| 466 |
+
if source is None:
|
| 467 |
+
return None
|
| 468 |
+
if hasattr(source, "__array__"):
|
| 469 |
+
return np.asarray(source)
|
| 470 |
+
# Objects that implement mappings
|
| 471 |
+
is_mapping = (hasattr(source, 'keys') and hasattr(source, 'values') and
|
| 472 |
+
hasattr(source, 'items'))
|
| 473 |
+
# Objects that don't implement mappings, but do have dicts
|
| 474 |
+
if isinstance(source, np.generic):
|
| 475 |
+
# NumPy scalars are never mappings (PyPy issue workaround)
|
| 476 |
+
pass
|
| 477 |
+
elif not is_mapping and hasattr(source, '__dict__'):
|
| 478 |
+
source = {key: value for key, value in source.__dict__.items()
|
| 479 |
+
if not key.startswith('_')}
|
| 480 |
+
is_mapping = True
|
| 481 |
+
if is_mapping:
|
| 482 |
+
dtype = []
|
| 483 |
+
values = []
|
| 484 |
+
for field, value in source.items():
|
| 485 |
+
if isinstance(field, str):
|
| 486 |
+
if field[0] not in '_0123456789':
|
| 487 |
+
dtype.append((str(field), object))
|
| 488 |
+
values.append(value)
|
| 489 |
+
else:
|
| 490 |
+
msg = (f"Starting field name with a underscore "
|
| 491 |
+
f"or a digit ({field}) is ignored")
|
| 492 |
+
warnings.warn(msg, MatWriteWarning, stacklevel=2)
|
| 493 |
+
if dtype:
|
| 494 |
+
return np.array([tuple(values)], dtype)
|
| 495 |
+
else:
|
| 496 |
+
return EmptyStructMarker
|
| 497 |
+
# Next try and convert to an array
|
| 498 |
+
try:
|
| 499 |
+
narr = np.asanyarray(source)
|
| 500 |
+
except ValueError:
|
| 501 |
+
narr = np.asanyarray(source, dtype=object)
|
| 502 |
+
if narr.dtype.type in (object, np.object_) and \
|
| 503 |
+
narr.shape == () and narr == source:
|
| 504 |
+
# No interesting conversion possible
|
| 505 |
+
return None
|
| 506 |
+
return narr
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
# Native byte ordered dtypes for convenience for writers
|
| 510 |
+
NDT_FILE_HDR = MDTYPES[native_code]['dtypes']['file_header']
|
| 511 |
+
NDT_TAG_FULL = MDTYPES[native_code]['dtypes']['tag_full']
|
| 512 |
+
NDT_TAG_SMALL = MDTYPES[native_code]['dtypes']['tag_smalldata']
|
| 513 |
+
NDT_ARRAY_FLAGS = MDTYPES[native_code]['dtypes']['array_flags']
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
class VarWriter5:
|
| 517 |
+
''' Generic matlab matrix writing class '''
|
| 518 |
+
mat_tag = np.zeros((), NDT_TAG_FULL)
|
| 519 |
+
mat_tag['mdtype'] = miMATRIX
|
| 520 |
+
|
| 521 |
+
def __init__(self, file_writer):
|
| 522 |
+
self.file_stream = file_writer.file_stream
|
| 523 |
+
self.unicode_strings = file_writer.unicode_strings
|
| 524 |
+
self.long_field_names = file_writer.long_field_names
|
| 525 |
+
self.oned_as = file_writer.oned_as
|
| 526 |
+
# These are used for top level writes, and unset after
|
| 527 |
+
self._var_name = None
|
| 528 |
+
self._var_is_global = False
|
| 529 |
+
|
| 530 |
+
def write_bytes(self, arr):
|
| 531 |
+
self.file_stream.write(arr.tobytes(order='F'))
|
| 532 |
+
|
| 533 |
+
def write_string(self, s):
|
| 534 |
+
self.file_stream.write(s)
|
| 535 |
+
|
| 536 |
+
def write_element(self, arr, mdtype=None):
|
| 537 |
+
''' write tag and data '''
|
| 538 |
+
if mdtype is None:
|
| 539 |
+
mdtype = NP_TO_MTYPES[arr.dtype.str[1:]]
|
| 540 |
+
# Array needs to be in native byte order
|
| 541 |
+
if arr.dtype.byteorder == swapped_code:
|
| 542 |
+
arr = arr.byteswap().view(arr.dtype.newbyteorder())
|
| 543 |
+
byte_count = arr.size*arr.itemsize
|
| 544 |
+
if byte_count <= 4:
|
| 545 |
+
self.write_smalldata_element(arr, mdtype, byte_count)
|
| 546 |
+
else:
|
| 547 |
+
self.write_regular_element(arr, mdtype, byte_count)
|
| 548 |
+
|
| 549 |
+
def write_smalldata_element(self, arr, mdtype, byte_count):
|
| 550 |
+
# write tag with embedded data
|
| 551 |
+
tag = np.zeros((), NDT_TAG_SMALL)
|
| 552 |
+
tag['byte_count_mdtype'] = (byte_count << 16) + mdtype
|
| 553 |
+
# if arr.tobytes is < 4, the element will be zero-padded as needed.
|
| 554 |
+
tag['data'] = arr.tobytes(order='F')
|
| 555 |
+
self.write_bytes(tag)
|
| 556 |
+
|
| 557 |
+
def write_regular_element(self, arr, mdtype, byte_count):
|
| 558 |
+
# write tag, data
|
| 559 |
+
tag = np.zeros((), NDT_TAG_FULL)
|
| 560 |
+
tag['mdtype'] = mdtype
|
| 561 |
+
tag['byte_count'] = byte_count
|
| 562 |
+
self.write_bytes(tag)
|
| 563 |
+
self.write_bytes(arr)
|
| 564 |
+
# pad to next 64-bit boundary
|
| 565 |
+
bc_mod_8 = byte_count % 8
|
| 566 |
+
if bc_mod_8:
|
| 567 |
+
self.file_stream.write(b'\x00' * (8-bc_mod_8))
|
| 568 |
+
|
| 569 |
+
def write_header(self,
|
| 570 |
+
shape,
|
| 571 |
+
mclass,
|
| 572 |
+
is_complex=False,
|
| 573 |
+
is_logical=False,
|
| 574 |
+
nzmax=0):
|
| 575 |
+
''' Write header for given data options
|
| 576 |
+
shape : sequence
|
| 577 |
+
array shape
|
| 578 |
+
mclass - mat5 matrix class
|
| 579 |
+
is_complex - True if matrix is complex
|
| 580 |
+
is_logical - True if matrix is logical
|
| 581 |
+
nzmax - max non zero elements for sparse arrays
|
| 582 |
+
|
| 583 |
+
We get the name and the global flag from the object, and reset
|
| 584 |
+
them to defaults after we've used them
|
| 585 |
+
'''
|
| 586 |
+
# get name and is_global from one-shot object store
|
| 587 |
+
name = self._var_name
|
| 588 |
+
is_global = self._var_is_global
|
| 589 |
+
# initialize the top-level matrix tag, store position
|
| 590 |
+
self._mat_tag_pos = self.file_stream.tell()
|
| 591 |
+
self.write_bytes(self.mat_tag)
|
| 592 |
+
# write array flags (complex, global, logical, class, nzmax)
|
| 593 |
+
af = np.zeros((), NDT_ARRAY_FLAGS)
|
| 594 |
+
af['data_type'] = miUINT32
|
| 595 |
+
af['byte_count'] = 8
|
| 596 |
+
flags = is_complex << 3 | is_global << 2 | is_logical << 1
|
| 597 |
+
af['flags_class'] = mclass | flags << 8
|
| 598 |
+
af['nzmax'] = nzmax
|
| 599 |
+
self.write_bytes(af)
|
| 600 |
+
# shape
|
| 601 |
+
self.write_element(np.array(shape, dtype='i4'))
|
| 602 |
+
# write name
|
| 603 |
+
name = np.asarray(name)
|
| 604 |
+
if name == '': # empty string zero-terminated
|
| 605 |
+
self.write_smalldata_element(name, miINT8, 0)
|
| 606 |
+
else:
|
| 607 |
+
self.write_element(name, miINT8)
|
| 608 |
+
# reset the one-shot store to defaults
|
| 609 |
+
self._var_name = ''
|
| 610 |
+
self._var_is_global = False
|
| 611 |
+
|
| 612 |
+
def update_matrix_tag(self, start_pos):
|
| 613 |
+
curr_pos = self.file_stream.tell()
|
| 614 |
+
self.file_stream.seek(start_pos)
|
| 615 |
+
byte_count = curr_pos - start_pos - 8
|
| 616 |
+
if byte_count >= 2**32:
|
| 617 |
+
raise MatWriteError("Matrix too large to save with Matlab "
|
| 618 |
+
"5 format")
|
| 619 |
+
self.mat_tag['byte_count'] = byte_count
|
| 620 |
+
self.write_bytes(self.mat_tag)
|
| 621 |
+
self.file_stream.seek(curr_pos)
|
| 622 |
+
|
| 623 |
+
def write_top(self, arr, name, is_global):
|
| 624 |
+
""" Write variable at top level of mat file
|
| 625 |
+
|
| 626 |
+
Parameters
|
| 627 |
+
----------
|
| 628 |
+
arr : array_like
|
| 629 |
+
array-like object to create writer for
|
| 630 |
+
name : str, optional
|
| 631 |
+
name as it will appear in matlab workspace
|
| 632 |
+
default is empty string
|
| 633 |
+
is_global : {False, True}, optional
|
| 634 |
+
whether variable will be global on load into matlab
|
| 635 |
+
"""
|
| 636 |
+
# these are set before the top-level header write, and unset at
|
| 637 |
+
# the end of the same write, because they do not apply for lower levels
|
| 638 |
+
self._var_is_global = is_global
|
| 639 |
+
self._var_name = name
|
| 640 |
+
# write the header and data
|
| 641 |
+
self.write(arr)
|
| 642 |
+
|
| 643 |
+
def write(self, arr):
|
| 644 |
+
''' Write `arr` to stream at top and sub levels
|
| 645 |
+
|
| 646 |
+
Parameters
|
| 647 |
+
----------
|
| 648 |
+
arr : array_like
|
| 649 |
+
array-like object to create writer for
|
| 650 |
+
'''
|
| 651 |
+
# store position, so we can update the matrix tag
|
| 652 |
+
mat_tag_pos = self.file_stream.tell()
|
| 653 |
+
# First check if these are sparse
|
| 654 |
+
if scipy.sparse.issparse(arr):
|
| 655 |
+
self.write_sparse(arr)
|
| 656 |
+
self.update_matrix_tag(mat_tag_pos)
|
| 657 |
+
return
|
| 658 |
+
# Try to convert things that aren't arrays
|
| 659 |
+
narr = to_writeable(arr)
|
| 660 |
+
if narr is None:
|
| 661 |
+
raise TypeError(f'Could not convert {arr} (type {type(arr)}) to array')
|
| 662 |
+
if isinstance(narr, MatlabObject):
|
| 663 |
+
self.write_object(narr)
|
| 664 |
+
elif isinstance(narr, MatlabFunction):
|
| 665 |
+
raise MatWriteError('Cannot write matlab functions')
|
| 666 |
+
elif narr is EmptyStructMarker: # empty struct array
|
| 667 |
+
self.write_empty_struct()
|
| 668 |
+
elif narr.dtype.fields: # struct array
|
| 669 |
+
self.write_struct(narr)
|
| 670 |
+
elif narr.dtype.hasobject: # cell array
|
| 671 |
+
self.write_cells(narr)
|
| 672 |
+
elif narr.dtype.kind in ('U', 'S'):
|
| 673 |
+
if self.unicode_strings:
|
| 674 |
+
codec = 'UTF8'
|
| 675 |
+
else:
|
| 676 |
+
codec = 'ascii'
|
| 677 |
+
self.write_char(narr, codec)
|
| 678 |
+
else:
|
| 679 |
+
self.write_numeric(narr)
|
| 680 |
+
self.update_matrix_tag(mat_tag_pos)
|
| 681 |
+
|
| 682 |
+
def write_numeric(self, arr):
|
| 683 |
+
imagf = arr.dtype.kind == 'c'
|
| 684 |
+
logif = arr.dtype.kind == 'b'
|
| 685 |
+
try:
|
| 686 |
+
mclass = NP_TO_MXTYPES[arr.dtype.str[1:]]
|
| 687 |
+
except KeyError:
|
| 688 |
+
# No matching matlab type, probably complex256 / float128 / float96
|
| 689 |
+
# Cast data to complex128 / float64.
|
| 690 |
+
if imagf:
|
| 691 |
+
arr = arr.astype('c128')
|
| 692 |
+
elif logif:
|
| 693 |
+
arr = arr.astype('i1') # Should only contain 0/1
|
| 694 |
+
else:
|
| 695 |
+
arr = arr.astype('f8')
|
| 696 |
+
mclass = mxDOUBLE_CLASS
|
| 697 |
+
self.write_header(matdims(arr, self.oned_as),
|
| 698 |
+
mclass,
|
| 699 |
+
is_complex=imagf,
|
| 700 |
+
is_logical=logif)
|
| 701 |
+
if imagf:
|
| 702 |
+
self.write_element(arr.real)
|
| 703 |
+
self.write_element(arr.imag)
|
| 704 |
+
else:
|
| 705 |
+
self.write_element(arr)
|
| 706 |
+
|
| 707 |
+
def write_char(self, arr, codec='ascii'):
|
| 708 |
+
''' Write string array `arr` with given `codec`
|
| 709 |
+
'''
|
| 710 |
+
if arr.size == 0 or np.all(arr == ''):
|
| 711 |
+
# This an empty string array or a string array containing
|
| 712 |
+
# only empty strings. Matlab cannot distinguish between a
|
| 713 |
+
# string array that is empty, and a string array containing
|
| 714 |
+
# only empty strings, because it stores strings as arrays of
|
| 715 |
+
# char. There is no way of having an array of char that is
|
| 716 |
+
# not empty, but contains an empty string. We have to
|
| 717 |
+
# special-case the array-with-empty-strings because even
|
| 718 |
+
# empty strings have zero padding, which would otherwise
|
| 719 |
+
# appear in matlab as a string with a space.
|
| 720 |
+
shape = (0,) * np.max([arr.ndim, 2])
|
| 721 |
+
self.write_header(shape, mxCHAR_CLASS)
|
| 722 |
+
self.write_smalldata_element(arr, miUTF8, 0)
|
| 723 |
+
return
|
| 724 |
+
# non-empty string.
|
| 725 |
+
#
|
| 726 |
+
# Convert to char array
|
| 727 |
+
arr = arr_to_chars(arr)
|
| 728 |
+
# We have to write the shape directly, because we are going
|
| 729 |
+
# recode the characters, and the resulting stream of chars
|
| 730 |
+
# may have a different length
|
| 731 |
+
shape = arr.shape
|
| 732 |
+
self.write_header(shape, mxCHAR_CLASS)
|
| 733 |
+
if arr.dtype.kind == 'U' and arr.size:
|
| 734 |
+
# Make one long string from all the characters. We need to
|
| 735 |
+
# transpose here, because we're flattening the array, before
|
| 736 |
+
# we write the bytes. The bytes have to be written in
|
| 737 |
+
# Fortran order.
|
| 738 |
+
n_chars = math.prod(shape)
|
| 739 |
+
st_arr = np.ndarray(shape=(),
|
| 740 |
+
dtype=arr_dtype_number(arr, n_chars),
|
| 741 |
+
buffer=arr.T.copy()) # Fortran order
|
| 742 |
+
# Recode with codec to give byte string
|
| 743 |
+
st = st_arr.item().encode(codec)
|
| 744 |
+
# Reconstruct as 1-D byte array
|
| 745 |
+
arr = np.ndarray(shape=(len(st),),
|
| 746 |
+
dtype='S1',
|
| 747 |
+
buffer=st)
|
| 748 |
+
self.write_element(arr, mdtype=miUTF8)
|
| 749 |
+
|
| 750 |
+
def write_sparse(self, arr):
|
| 751 |
+
''' Sparse matrices are 2D
|
| 752 |
+
'''
|
| 753 |
+
A = arr.tocsc() # convert to sparse CSC format
|
| 754 |
+
A.sort_indices() # MATLAB expects sorted row indices
|
| 755 |
+
is_complex = (A.dtype.kind == 'c')
|
| 756 |
+
is_logical = (A.dtype.kind == 'b')
|
| 757 |
+
nz = A.nnz
|
| 758 |
+
self.write_header(matdims(arr, self.oned_as),
|
| 759 |
+
mxSPARSE_CLASS,
|
| 760 |
+
is_complex=is_complex,
|
| 761 |
+
is_logical=is_logical,
|
| 762 |
+
# matlab won't load file with 0 nzmax
|
| 763 |
+
nzmax=1 if nz == 0 else nz)
|
| 764 |
+
self.write_element(A.indices.astype('i4'))
|
| 765 |
+
self.write_element(A.indptr.astype('i4'))
|
| 766 |
+
self.write_element(A.data.real)
|
| 767 |
+
if is_complex:
|
| 768 |
+
self.write_element(A.data.imag)
|
| 769 |
+
|
| 770 |
+
def write_cells(self, arr):
|
| 771 |
+
self.write_header(matdims(arr, self.oned_as),
|
| 772 |
+
mxCELL_CLASS)
|
| 773 |
+
# loop over data, column major
|
| 774 |
+
A = np.atleast_2d(arr).flatten('F')
|
| 775 |
+
for el in A:
|
| 776 |
+
self.write(el)
|
| 777 |
+
|
| 778 |
+
def write_empty_struct(self):
|
| 779 |
+
self.write_header((1, 1), mxSTRUCT_CLASS)
|
| 780 |
+
# max field name length set to 1 in an example matlab struct
|
| 781 |
+
self.write_element(np.array(1, dtype=np.int32))
|
| 782 |
+
# Field names element is empty
|
| 783 |
+
self.write_element(np.array([], dtype=np.int8))
|
| 784 |
+
|
| 785 |
+
def write_struct(self, arr):
|
| 786 |
+
self.write_header(matdims(arr, self.oned_as),
|
| 787 |
+
mxSTRUCT_CLASS)
|
| 788 |
+
self._write_items(arr)
|
| 789 |
+
|
| 790 |
+
def _write_items(self, arr):
|
| 791 |
+
# write fieldnames
|
| 792 |
+
fieldnames = [f[0] for f in arr.dtype.descr]
|
| 793 |
+
length = max([len(fieldname) for fieldname in fieldnames])+1
|
| 794 |
+
max_length = (self.long_field_names and 64) or 32
|
| 795 |
+
if length > max_length:
|
| 796 |
+
raise ValueError(
|
| 797 |
+
f"Field names are restricted to {max_length - 1} characters"
|
| 798 |
+
)
|
| 799 |
+
self.write_element(np.array([length], dtype='i4'))
|
| 800 |
+
self.write_element(np.array(fieldnames, dtype=f'S{length}'), mdtype=miINT8)
|
| 801 |
+
A = np.atleast_2d(arr).flatten('F')
|
| 802 |
+
for el in A:
|
| 803 |
+
for f in fieldnames:
|
| 804 |
+
self.write(el[f])
|
| 805 |
+
|
| 806 |
+
def write_object(self, arr):
|
| 807 |
+
'''Same as writing structs, except different mx class, and extra
|
| 808 |
+
classname element after header
|
| 809 |
+
'''
|
| 810 |
+
self.write_header(matdims(arr, self.oned_as),
|
| 811 |
+
mxOBJECT_CLASS)
|
| 812 |
+
self.write_element(np.array(arr.classname, dtype='S'),
|
| 813 |
+
mdtype=miINT8)
|
| 814 |
+
self._write_items(arr)
|
| 815 |
+
|
| 816 |
+
|
| 817 |
+
class MatFile5Writer:
|
| 818 |
+
''' Class for writing mat5 files '''
|
| 819 |
+
|
| 820 |
+
@docfiller
|
| 821 |
+
def __init__(self, file_stream,
|
| 822 |
+
do_compression=False,
|
| 823 |
+
unicode_strings=False,
|
| 824 |
+
global_vars=None,
|
| 825 |
+
long_field_names=False,
|
| 826 |
+
oned_as='row'):
|
| 827 |
+
''' Initialize writer for matlab 5 format files
|
| 828 |
+
|
| 829 |
+
Parameters
|
| 830 |
+
----------
|
| 831 |
+
%(do_compression)s
|
| 832 |
+
%(unicode_strings)s
|
| 833 |
+
global_vars : None or sequence of strings, optional
|
| 834 |
+
Names of variables to be marked as global for matlab
|
| 835 |
+
%(long_fields)s
|
| 836 |
+
%(oned_as)s
|
| 837 |
+
'''
|
| 838 |
+
self.file_stream = file_stream
|
| 839 |
+
self.do_compression = do_compression
|
| 840 |
+
self.unicode_strings = unicode_strings
|
| 841 |
+
if global_vars:
|
| 842 |
+
self.global_vars = global_vars
|
| 843 |
+
else:
|
| 844 |
+
self.global_vars = []
|
| 845 |
+
self.long_field_names = long_field_names
|
| 846 |
+
self.oned_as = oned_as
|
| 847 |
+
self._matrix_writer = None
|
| 848 |
+
|
| 849 |
+
def write_file_header(self):
|
| 850 |
+
# write header
|
| 851 |
+
hdr = np.zeros((), NDT_FILE_HDR)
|
| 852 |
+
hdr['description'] = (f'MATLAB 5.0 MAT-file Platform: {os.name}, '
|
| 853 |
+
f'Created on: {time.asctime()}')
|
| 854 |
+
hdr['version'] = 0x0100
|
| 855 |
+
hdr['endian_test'] = np.ndarray(shape=(),
|
| 856 |
+
dtype='S2',
|
| 857 |
+
buffer=np.uint16(0x4d49))
|
| 858 |
+
self.file_stream.write(hdr.tobytes())
|
| 859 |
+
|
| 860 |
+
def put_variables(self, mdict, write_header=None):
|
| 861 |
+
''' Write variables in `mdict` to stream
|
| 862 |
+
|
| 863 |
+
Parameters
|
| 864 |
+
----------
|
| 865 |
+
mdict : mapping
|
| 866 |
+
mapping with method ``items`` returns name, contents pairs where
|
| 867 |
+
``name`` which will appear in the matlab workspace in file load, and
|
| 868 |
+
``contents`` is something writeable to a matlab file, such as a NumPy
|
| 869 |
+
array.
|
| 870 |
+
write_header : {None, True, False}, optional
|
| 871 |
+
If True, then write the matlab file header before writing the
|
| 872 |
+
variables. If None (the default) then write the file header
|
| 873 |
+
if we are at position 0 in the stream. By setting False
|
| 874 |
+
here, and setting the stream position to the end of the file,
|
| 875 |
+
you can append variables to a matlab file
|
| 876 |
+
'''
|
| 877 |
+
# write header if requested, or None and start of file
|
| 878 |
+
if write_header is None:
|
| 879 |
+
write_header = self.file_stream.tell() == 0
|
| 880 |
+
if write_header:
|
| 881 |
+
self.write_file_header()
|
| 882 |
+
self._matrix_writer = VarWriter5(self)
|
| 883 |
+
for name, var in mdict.items():
|
| 884 |
+
if name[0] == '_':
|
| 885 |
+
msg = (f"Starting field name with a "
|
| 886 |
+
f"underscore ({name}) is ignored")
|
| 887 |
+
warnings.warn(msg, MatWriteWarning, stacklevel=2)
|
| 888 |
+
continue
|
| 889 |
+
is_global = name in self.global_vars
|
| 890 |
+
if self.do_compression:
|
| 891 |
+
stream = BytesIO()
|
| 892 |
+
self._matrix_writer.file_stream = stream
|
| 893 |
+
self._matrix_writer.write_top(var, name.encode('latin1'), is_global)
|
| 894 |
+
out_str = zlib.compress(stream.getvalue())
|
| 895 |
+
tag = np.empty((), NDT_TAG_FULL)
|
| 896 |
+
tag['mdtype'] = miCOMPRESSED
|
| 897 |
+
tag['byte_count'] = len(out_str)
|
| 898 |
+
self.file_stream.write(tag.tobytes())
|
| 899 |
+
self.file_stream.write(out_str)
|
| 900 |
+
else: # not compressing
|
| 901 |
+
self._matrix_writer.write_top(var, name.encode('latin1'), is_global)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio5_params.py
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
''' Constants and classes for matlab 5 read and write
|
| 2 |
+
|
| 3 |
+
See also mio5_utils.pyx where these same constants arise as c enums.
|
| 4 |
+
|
| 5 |
+
If you make changes in this file, don't forget to change mio5_utils.pyx
|
| 6 |
+
'''
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
from ._miobase import convert_dtypes
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
__all__ = [
|
| 13 |
+
'MDTYPES', 'MatlabFunction', 'MatlabObject', 'MatlabOpaque',
|
| 14 |
+
'NP_TO_MTYPES', 'NP_TO_MXTYPES', 'OPAQUE_DTYPE', 'codecs_template',
|
| 15 |
+
'mat_struct', 'mclass_dtypes_template', 'mclass_info', 'mdtypes_template',
|
| 16 |
+
'miCOMPRESSED', 'miDOUBLE', 'miINT16', 'miINT32', 'miINT64', 'miINT8',
|
| 17 |
+
'miMATRIX', 'miSINGLE', 'miUINT16', 'miUINT32', 'miUINT64', 'miUINT8',
|
| 18 |
+
'miUTF16', 'miUTF32', 'miUTF8', 'mxCELL_CLASS', 'mxCHAR_CLASS',
|
| 19 |
+
'mxDOUBLE_CLASS', 'mxFUNCTION_CLASS', 'mxINT16_CLASS', 'mxINT32_CLASS',
|
| 20 |
+
'mxINT64_CLASS', 'mxINT8_CLASS', 'mxOBJECT_CLASS',
|
| 21 |
+
'mxOBJECT_CLASS_FROM_MATRIX_H', 'mxOPAQUE_CLASS', 'mxSINGLE_CLASS',
|
| 22 |
+
'mxSPARSE_CLASS', 'mxSTRUCT_CLASS', 'mxUINT16_CLASS', 'mxUINT32_CLASS',
|
| 23 |
+
'mxUINT64_CLASS', 'mxUINT8_CLASS'
|
| 24 |
+
]
|
| 25 |
+
miINT8 = 1
|
| 26 |
+
miUINT8 = 2
|
| 27 |
+
miINT16 = 3
|
| 28 |
+
miUINT16 = 4
|
| 29 |
+
miINT32 = 5
|
| 30 |
+
miUINT32 = 6
|
| 31 |
+
miSINGLE = 7
|
| 32 |
+
miDOUBLE = 9
|
| 33 |
+
miINT64 = 12
|
| 34 |
+
miUINT64 = 13
|
| 35 |
+
miMATRIX = 14
|
| 36 |
+
miCOMPRESSED = 15
|
| 37 |
+
miUTF8 = 16
|
| 38 |
+
miUTF16 = 17
|
| 39 |
+
miUTF32 = 18
|
| 40 |
+
|
| 41 |
+
mxCELL_CLASS = 1
|
| 42 |
+
mxSTRUCT_CLASS = 2
|
| 43 |
+
# The March 2008 edition of "Matlab 7 MAT-File Format" says that
|
| 44 |
+
# mxOBJECT_CLASS = 3, whereas matrix.h says that mxLOGICAL = 3.
|
| 45 |
+
# Matlab 2008a appears to save logicals as type 9, so we assume that
|
| 46 |
+
# the document is correct. See type 18, below.
|
| 47 |
+
mxOBJECT_CLASS = 3
|
| 48 |
+
mxCHAR_CLASS = 4
|
| 49 |
+
mxSPARSE_CLASS = 5
|
| 50 |
+
mxDOUBLE_CLASS = 6
|
| 51 |
+
mxSINGLE_CLASS = 7
|
| 52 |
+
mxINT8_CLASS = 8
|
| 53 |
+
mxUINT8_CLASS = 9
|
| 54 |
+
mxINT16_CLASS = 10
|
| 55 |
+
mxUINT16_CLASS = 11
|
| 56 |
+
mxINT32_CLASS = 12
|
| 57 |
+
mxUINT32_CLASS = 13
|
| 58 |
+
# The following are not in the March 2008 edition of "Matlab 7
|
| 59 |
+
# MAT-File Format," but were guessed from matrix.h.
|
| 60 |
+
mxINT64_CLASS = 14
|
| 61 |
+
mxUINT64_CLASS = 15
|
| 62 |
+
mxFUNCTION_CLASS = 16
|
| 63 |
+
# Not doing anything with these at the moment.
|
| 64 |
+
mxOPAQUE_CLASS = 17 # This appears to be a function workspace
|
| 65 |
+
# Thread 'saving/loading symbol table of annymous functions',
|
| 66 |
+
# octave-maintainers, April-May 2007
|
| 67 |
+
# https://lists.gnu.org/archive/html/octave-maintainers/2007-04/msg00031.html
|
| 68 |
+
# https://lists.gnu.org/archive/html/octave-maintainers/2007-05/msg00032.html
|
| 69 |
+
# (Was/Deprecated: https://www-old.cae.wisc.edu/pipermail/octave-maintainers/2007-May/002824.html)
|
| 70 |
+
mxOBJECT_CLASS_FROM_MATRIX_H = 18
|
| 71 |
+
|
| 72 |
+
mdtypes_template = {
|
| 73 |
+
miINT8: 'i1',
|
| 74 |
+
miUINT8: 'u1',
|
| 75 |
+
miINT16: 'i2',
|
| 76 |
+
miUINT16: 'u2',
|
| 77 |
+
miINT32: 'i4',
|
| 78 |
+
miUINT32: 'u4',
|
| 79 |
+
miSINGLE: 'f4',
|
| 80 |
+
miDOUBLE: 'f8',
|
| 81 |
+
miINT64: 'i8',
|
| 82 |
+
miUINT64: 'u8',
|
| 83 |
+
miUTF8: 'u1',
|
| 84 |
+
miUTF16: 'u2',
|
| 85 |
+
miUTF32: 'u4',
|
| 86 |
+
'file_header': [('description', 'S116'),
|
| 87 |
+
('subsystem_offset', 'i8'),
|
| 88 |
+
('version', 'u2'),
|
| 89 |
+
('endian_test', 'S2')],
|
| 90 |
+
'tag_full': [('mdtype', 'u4'), ('byte_count', 'u4')],
|
| 91 |
+
'tag_smalldata':[('byte_count_mdtype', 'u4'), ('data', 'S4')],
|
| 92 |
+
'array_flags': [('data_type', 'u4'),
|
| 93 |
+
('byte_count', 'u4'),
|
| 94 |
+
('flags_class','u4'),
|
| 95 |
+
('nzmax', 'u4')],
|
| 96 |
+
'U1': 'U1',
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
mclass_dtypes_template = {
|
| 100 |
+
mxINT8_CLASS: 'i1',
|
| 101 |
+
mxUINT8_CLASS: 'u1',
|
| 102 |
+
mxINT16_CLASS: 'i2',
|
| 103 |
+
mxUINT16_CLASS: 'u2',
|
| 104 |
+
mxINT32_CLASS: 'i4',
|
| 105 |
+
mxUINT32_CLASS: 'u4',
|
| 106 |
+
mxINT64_CLASS: 'i8',
|
| 107 |
+
mxUINT64_CLASS: 'u8',
|
| 108 |
+
mxSINGLE_CLASS: 'f4',
|
| 109 |
+
mxDOUBLE_CLASS: 'f8',
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
mclass_info = {
|
| 113 |
+
mxINT8_CLASS: 'int8',
|
| 114 |
+
mxUINT8_CLASS: 'uint8',
|
| 115 |
+
mxINT16_CLASS: 'int16',
|
| 116 |
+
mxUINT16_CLASS: 'uint16',
|
| 117 |
+
mxINT32_CLASS: 'int32',
|
| 118 |
+
mxUINT32_CLASS: 'uint32',
|
| 119 |
+
mxINT64_CLASS: 'int64',
|
| 120 |
+
mxUINT64_CLASS: 'uint64',
|
| 121 |
+
mxSINGLE_CLASS: 'single',
|
| 122 |
+
mxDOUBLE_CLASS: 'double',
|
| 123 |
+
mxCELL_CLASS: 'cell',
|
| 124 |
+
mxSTRUCT_CLASS: 'struct',
|
| 125 |
+
mxOBJECT_CLASS: 'object',
|
| 126 |
+
mxCHAR_CLASS: 'char',
|
| 127 |
+
mxSPARSE_CLASS: 'sparse',
|
| 128 |
+
mxFUNCTION_CLASS: 'function',
|
| 129 |
+
mxOPAQUE_CLASS: 'opaque',
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
NP_TO_MTYPES = {
|
| 133 |
+
'f8': miDOUBLE,
|
| 134 |
+
'c32': miDOUBLE,
|
| 135 |
+
'c24': miDOUBLE,
|
| 136 |
+
'c16': miDOUBLE,
|
| 137 |
+
'f4': miSINGLE,
|
| 138 |
+
'c8': miSINGLE,
|
| 139 |
+
'i8': miINT64,
|
| 140 |
+
'i4': miINT32,
|
| 141 |
+
'i2': miINT16,
|
| 142 |
+
'i1': miINT8,
|
| 143 |
+
'u8': miUINT64,
|
| 144 |
+
'u4': miUINT32,
|
| 145 |
+
'u2': miUINT16,
|
| 146 |
+
'u1': miUINT8,
|
| 147 |
+
'S1': miUINT8,
|
| 148 |
+
'U1': miUTF16,
|
| 149 |
+
'b1': miUINT8, # not standard but seems MATLAB uses this (gh-4022)
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
NP_TO_MXTYPES = {
|
| 154 |
+
'f8': mxDOUBLE_CLASS,
|
| 155 |
+
'c32': mxDOUBLE_CLASS,
|
| 156 |
+
'c24': mxDOUBLE_CLASS,
|
| 157 |
+
'c16': mxDOUBLE_CLASS,
|
| 158 |
+
'f4': mxSINGLE_CLASS,
|
| 159 |
+
'c8': mxSINGLE_CLASS,
|
| 160 |
+
'i8': mxINT64_CLASS,
|
| 161 |
+
'i4': mxINT32_CLASS,
|
| 162 |
+
'i2': mxINT16_CLASS,
|
| 163 |
+
'i1': mxINT8_CLASS,
|
| 164 |
+
'u8': mxUINT64_CLASS,
|
| 165 |
+
'u4': mxUINT32_CLASS,
|
| 166 |
+
'u2': mxUINT16_CLASS,
|
| 167 |
+
'u1': mxUINT8_CLASS,
|
| 168 |
+
'S1': mxUINT8_CLASS,
|
| 169 |
+
'b1': mxUINT8_CLASS, # not standard but seems MATLAB uses this
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
''' Before release v7.1 (release 14) matlab (TM) used the system
|
| 173 |
+
default character encoding scheme padded out to 16-bits. Release 14
|
| 174 |
+
and later use Unicode. When saving character data, R14 checks if it
|
| 175 |
+
can be encoded in 7-bit ascii, and saves in that format if so.'''
|
| 176 |
+
|
| 177 |
+
codecs_template = {
|
| 178 |
+
miUTF8: {'codec': 'utf_8', 'width': 1},
|
| 179 |
+
miUTF16: {'codec': 'utf_16', 'width': 2},
|
| 180 |
+
miUTF32: {'codec': 'utf_32','width': 4},
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def _convert_codecs(template, byte_order):
|
| 185 |
+
''' Convert codec template mapping to byte order
|
| 186 |
+
|
| 187 |
+
Set codecs not on this system to None
|
| 188 |
+
|
| 189 |
+
Parameters
|
| 190 |
+
----------
|
| 191 |
+
template : mapping
|
| 192 |
+
key, value are respectively codec name, and root name for codec
|
| 193 |
+
(without byte order suffix)
|
| 194 |
+
byte_order : {'<', '>'}
|
| 195 |
+
code for little or big endian
|
| 196 |
+
|
| 197 |
+
Returns
|
| 198 |
+
-------
|
| 199 |
+
codecs : dict
|
| 200 |
+
key, value are name, codec (as in .encode(codec))
|
| 201 |
+
'''
|
| 202 |
+
codecs = {}
|
| 203 |
+
postfix = byte_order == '<' and '_le' or '_be'
|
| 204 |
+
for k, v in template.items():
|
| 205 |
+
codec = v['codec']
|
| 206 |
+
try:
|
| 207 |
+
" ".encode(codec)
|
| 208 |
+
except LookupError:
|
| 209 |
+
codecs[k] = None
|
| 210 |
+
continue
|
| 211 |
+
if v['width'] > 1:
|
| 212 |
+
codec += postfix
|
| 213 |
+
codecs[k] = codec
|
| 214 |
+
return codecs.copy()
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
MDTYPES = {}
|
| 218 |
+
for _bytecode in '<>':
|
| 219 |
+
_def = {'dtypes': convert_dtypes(mdtypes_template, _bytecode),
|
| 220 |
+
'classes': convert_dtypes(mclass_dtypes_template, _bytecode),
|
| 221 |
+
'codecs': _convert_codecs(codecs_template, _bytecode)}
|
| 222 |
+
MDTYPES[_bytecode] = _def
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
class mat_struct:
|
| 226 |
+
"""Placeholder for holding read data from structs.
|
| 227 |
+
|
| 228 |
+
We use instances of this class when the user passes False as a value to the
|
| 229 |
+
``struct_as_record`` parameter of the :func:`scipy.io.loadmat` function.
|
| 230 |
+
"""
|
| 231 |
+
pass
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
class MatlabObject(np.ndarray):
|
| 235 |
+
"""Subclass of ndarray to signal this is a matlab object.
|
| 236 |
+
|
| 237 |
+
This is a simple subclass of :class:`numpy.ndarray` meant to be used
|
| 238 |
+
by :func:`scipy.io.loadmat` and should not be instantiated directly.
|
| 239 |
+
"""
|
| 240 |
+
|
| 241 |
+
def __new__(cls, input_array, classname=None):
|
| 242 |
+
# Input array is an already formed ndarray instance
|
| 243 |
+
# We first cast to be our class type
|
| 244 |
+
obj = np.asarray(input_array).view(cls)
|
| 245 |
+
# add the new attribute to the created instance
|
| 246 |
+
obj.classname = classname
|
| 247 |
+
# Finally, we must return the newly created object:
|
| 248 |
+
return obj
|
| 249 |
+
|
| 250 |
+
def __array_finalize__(self,obj):
|
| 251 |
+
# reset the attribute from passed original object
|
| 252 |
+
self.classname = getattr(obj, 'classname', None)
|
| 253 |
+
# We do not need to return anything
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
class MatlabFunction(np.ndarray):
|
| 257 |
+
"""Subclass for a MATLAB function.
|
| 258 |
+
|
| 259 |
+
This is a simple subclass of :class:`numpy.ndarray` meant to be used
|
| 260 |
+
by :func:`scipy.io.loadmat` and should not be directly instantiated.
|
| 261 |
+
"""
|
| 262 |
+
|
| 263 |
+
def __new__(cls, input_array):
|
| 264 |
+
obj = np.asarray(input_array).view(cls)
|
| 265 |
+
return obj
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
class MatlabOpaque(np.ndarray):
|
| 269 |
+
"""Subclass for a MATLAB opaque matrix.
|
| 270 |
+
|
| 271 |
+
This is a simple subclass of :class:`numpy.ndarray` meant to be used
|
| 272 |
+
by :func:`scipy.io.loadmat` and should not be directly instantiated.
|
| 273 |
+
"""
|
| 274 |
+
|
| 275 |
+
def __new__(cls, input_array):
|
| 276 |
+
obj = np.asarray(input_array).view(cls)
|
| 277 |
+
return obj
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
OPAQUE_DTYPE = np.dtype(
|
| 281 |
+
[('s0', 'O'), ('s1', 'O'), ('s2', 'O'), ('arr', 'O')])
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio5_utils.cp312-win_amd64.dll.a
ADDED
|
Binary file (1.59 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio5_utils.cp312-win_amd64.pyd
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ab0536b6d57881314284cc17a90479dbade9441434643b9fd649b6ddaedea637
|
| 3 |
+
size 178176
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio_utils.cp312-win_amd64.dll.a
ADDED
|
Binary file (1.58 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_mio_utils.cp312-win_amd64.pyd
ADDED
|
Binary file (52.7 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_miobase.py
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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Travis Oliphant, Matthew Brett
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
Base classes for MATLAB file stream reading.
|
| 5 |
+
|
| 6 |
+
MATLAB is a registered trademark of the Mathworks inc.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from typing import Final
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
from scipy._lib import doccer
|
| 13 |
+
|
| 14 |
+
from . import _byteordercodes as boc
|
| 15 |
+
|
| 16 |
+
__all__ = [
|
| 17 |
+
'MatReadError', 'MatReadWarning', 'MatWriteError', 'MatWriteWarning',
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
class MatReadError(Exception):
|
| 21 |
+
"""Exception indicating a read issue."""
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class MatWriteError(Exception):
|
| 25 |
+
"""Exception indicating a write issue."""
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class MatReadWarning(UserWarning):
|
| 29 |
+
"""Warning class for read issues."""
|
| 30 |
+
|
| 31 |
+
class MatWriteWarning(UserWarning):
|
| 32 |
+
"""Warning class for write issues."""
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
doc_dict = \
|
| 36 |
+
{'file_arg':
|
| 37 |
+
'''file_name : str
|
| 38 |
+
Name of the mat file (do not need .mat extension if
|
| 39 |
+
appendmat==True) Can also pass open file-like object.''',
|
| 40 |
+
'append_arg':
|
| 41 |
+
'''appendmat : bool, optional
|
| 42 |
+
True to append the .mat extension to the end of the given
|
| 43 |
+
filename, if not already present. Default is True.''',
|
| 44 |
+
'load_args':
|
| 45 |
+
'''byte_order : str or None, optional
|
| 46 |
+
None by default, implying byte order guessed from mat
|
| 47 |
+
file. Otherwise can be one of ('native', '=', 'little', '<',
|
| 48 |
+
'BIG', '>').
|
| 49 |
+
mat_dtype : bool, optional
|
| 50 |
+
If True, return arrays in same dtype as would be loaded into
|
| 51 |
+
MATLAB (instead of the dtype with which they are saved).
|
| 52 |
+
squeeze_me : bool, optional
|
| 53 |
+
Whether to squeeze unit matrix dimensions or not.
|
| 54 |
+
chars_as_strings : bool, optional
|
| 55 |
+
Whether to convert char arrays to string arrays.
|
| 56 |
+
matlab_compatible : bool, optional
|
| 57 |
+
Returns matrices as would be loaded by MATLAB (implies
|
| 58 |
+
squeeze_me=False, chars_as_strings=False, mat_dtype=True,
|
| 59 |
+
struct_as_record=True).''',
|
| 60 |
+
'struct_arg':
|
| 61 |
+
'''struct_as_record : bool, optional
|
| 62 |
+
Whether to load MATLAB structs as NumPy record arrays, or as
|
| 63 |
+
old-style NumPy arrays with dtype=object. Setting this flag to
|
| 64 |
+
False replicates the behavior of SciPy version 0.7.x (returning
|
| 65 |
+
numpy object arrays). The default setting is True, because it
|
| 66 |
+
allows easier round-trip load and save of MATLAB files.''',
|
| 67 |
+
'matstream_arg':
|
| 68 |
+
'''mat_stream : file-like
|
| 69 |
+
Object with file API, open for reading.''',
|
| 70 |
+
'long_fields':
|
| 71 |
+
'''long_field_names : bool, optional
|
| 72 |
+
* False - maximum field name length in a structure is 31 characters
|
| 73 |
+
which is the documented maximum length. This is the default.
|
| 74 |
+
* True - maximum field name length in a structure is 63 characters
|
| 75 |
+
which works for MATLAB 7.6''',
|
| 76 |
+
'do_compression':
|
| 77 |
+
'''do_compression : bool, optional
|
| 78 |
+
Whether to compress matrices on write. Default is False.''',
|
| 79 |
+
'oned_as':
|
| 80 |
+
'''oned_as : {'row', 'column'}, optional
|
| 81 |
+
If 'column', write 1-D NumPy arrays as column vectors.
|
| 82 |
+
If 'row', write 1D NumPy arrays as row vectors.''',
|
| 83 |
+
'unicode_strings':
|
| 84 |
+
'''unicode_strings : bool, optional
|
| 85 |
+
If True, write strings as Unicode, else MATLAB usual encoding.'''}
|
| 86 |
+
|
| 87 |
+
docfiller: Final = doccer.filldoc(doc_dict)
|
| 88 |
+
|
| 89 |
+
'''
|
| 90 |
+
|
| 91 |
+
Note on architecture
|
| 92 |
+
======================
|
| 93 |
+
|
| 94 |
+
There are three sets of parameters relevant for reading files. The
|
| 95 |
+
first are *file read parameters* - containing options that are common
|
| 96 |
+
for reading the whole file, and therefore every variable within that
|
| 97 |
+
file. At the moment these are:
|
| 98 |
+
|
| 99 |
+
* mat_stream
|
| 100 |
+
* dtypes (derived from byte code)
|
| 101 |
+
* byte_order
|
| 102 |
+
* chars_as_strings
|
| 103 |
+
* squeeze_me
|
| 104 |
+
* struct_as_record (MATLAB 5 files)
|
| 105 |
+
* class_dtypes (derived from order code, MATLAB 5 files)
|
| 106 |
+
* codecs (MATLAB 5 files)
|
| 107 |
+
* uint16_codec (MATLAB 5 files)
|
| 108 |
+
|
| 109 |
+
Another set of parameters are those that apply only to the current
|
| 110 |
+
variable being read - the *header*:
|
| 111 |
+
|
| 112 |
+
* header related variables (different for v4 and v5 mat files)
|
| 113 |
+
* is_complex
|
| 114 |
+
* mclass
|
| 115 |
+
* var_stream
|
| 116 |
+
|
| 117 |
+
With the header, we need ``next_position`` to tell us where the next
|
| 118 |
+
variable in the stream is.
|
| 119 |
+
|
| 120 |
+
Then, for each element in a matrix, there can be *element read
|
| 121 |
+
parameters*. An element is, for example, one element in a MATLAB cell
|
| 122 |
+
array. At the moment, these are:
|
| 123 |
+
|
| 124 |
+
* mat_dtype
|
| 125 |
+
|
| 126 |
+
The file-reading object contains the *file read parameters*. The
|
| 127 |
+
*header* is passed around as a data object, or may be read and discarded
|
| 128 |
+
in a single function. The *element read parameters* - the mat_dtype in
|
| 129 |
+
this instance, is passed into a general post-processing function - see
|
| 130 |
+
``mio_utils`` for details.
|
| 131 |
+
'''
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def convert_dtypes(dtype_template, order_code):
|
| 135 |
+
''' Convert dtypes in mapping to given order
|
| 136 |
+
|
| 137 |
+
Parameters
|
| 138 |
+
----------
|
| 139 |
+
dtype_template : mapping
|
| 140 |
+
mapping with values returning numpy dtype from ``np.dtype(val)``
|
| 141 |
+
order_code : str
|
| 142 |
+
an order code suitable for using in ``dtype.newbyteorder()``
|
| 143 |
+
|
| 144 |
+
Returns
|
| 145 |
+
-------
|
| 146 |
+
dtypes : mapping
|
| 147 |
+
mapping where values have been replaced by
|
| 148 |
+
``np.dtype(val).newbyteorder(order_code)``
|
| 149 |
+
|
| 150 |
+
'''
|
| 151 |
+
dtypes = dtype_template.copy()
|
| 152 |
+
for k in dtypes:
|
| 153 |
+
dtypes[k] = np.dtype(dtypes[k]).newbyteorder(order_code)
|
| 154 |
+
return dtypes
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def read_dtype(mat_stream, a_dtype):
|
| 158 |
+
"""
|
| 159 |
+
Generic get of byte stream data of known type
|
| 160 |
+
|
| 161 |
+
Parameters
|
| 162 |
+
----------
|
| 163 |
+
mat_stream : file_like object
|
| 164 |
+
MATLAB (tm) mat file stream
|
| 165 |
+
a_dtype : dtype
|
| 166 |
+
dtype of array to read. `a_dtype` is assumed to be correct
|
| 167 |
+
endianness.
|
| 168 |
+
|
| 169 |
+
Returns
|
| 170 |
+
-------
|
| 171 |
+
arr : ndarray
|
| 172 |
+
Array of dtype `a_dtype` read from stream.
|
| 173 |
+
|
| 174 |
+
"""
|
| 175 |
+
num_bytes = a_dtype.itemsize
|
| 176 |
+
arr = np.ndarray(shape=(),
|
| 177 |
+
dtype=a_dtype,
|
| 178 |
+
buffer=mat_stream.read(num_bytes),
|
| 179 |
+
order='F')
|
| 180 |
+
return arr
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def matfile_version(file_name, *, appendmat=True):
|
| 184 |
+
"""
|
| 185 |
+
Return major, minor tuple depending on apparent mat file type
|
| 186 |
+
|
| 187 |
+
Where:
|
| 188 |
+
|
| 189 |
+
#. 0,x -> version 4 format mat files
|
| 190 |
+
#. 1,x -> version 5 format mat files
|
| 191 |
+
#. 2,x -> version 7.3 format mat files (HDF format)
|
| 192 |
+
|
| 193 |
+
Parameters
|
| 194 |
+
----------
|
| 195 |
+
file_name : str
|
| 196 |
+
Name of the mat file (do not need .mat extension if
|
| 197 |
+
appendmat==True). Can also pass open file-like object.
|
| 198 |
+
appendmat : bool, optional
|
| 199 |
+
True to append the .mat extension to the end of the given
|
| 200 |
+
filename, if not already present. Default is True.
|
| 201 |
+
|
| 202 |
+
Returns
|
| 203 |
+
-------
|
| 204 |
+
major_version : {0, 1, 2}
|
| 205 |
+
major MATLAB File format version
|
| 206 |
+
minor_version : int
|
| 207 |
+
minor MATLAB file format version
|
| 208 |
+
|
| 209 |
+
Raises
|
| 210 |
+
------
|
| 211 |
+
MatReadError
|
| 212 |
+
If the file is empty.
|
| 213 |
+
ValueError
|
| 214 |
+
The matfile version is unknown.
|
| 215 |
+
|
| 216 |
+
Notes
|
| 217 |
+
-----
|
| 218 |
+
Has the side effect of setting the file read pointer to 0
|
| 219 |
+
"""
|
| 220 |
+
from ._mio import _open_file_context
|
| 221 |
+
with _open_file_context(file_name, appendmat=appendmat) as fileobj:
|
| 222 |
+
return _get_matfile_version(fileobj)
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
get_matfile_version = matfile_version
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
_HDR_N_BYTES = 20
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def _get_matfile_version(fileobj):
|
| 232 |
+
# Mat4 files have a zero somewhere in first 4 bytes
|
| 233 |
+
fileobj.seek(0)
|
| 234 |
+
hdr_bytes = fileobj.read(_HDR_N_BYTES)
|
| 235 |
+
if len(hdr_bytes) < _HDR_N_BYTES:
|
| 236 |
+
raise MatReadError("Mat file appears to be truncated")
|
| 237 |
+
if hdr_bytes.count(0) == _HDR_N_BYTES:
|
| 238 |
+
raise MatReadError("Mat file appears to be corrupt "
|
| 239 |
+
f"(first {_HDR_N_BYTES} bytes == 0)")
|
| 240 |
+
mopt_ints = np.ndarray(shape=(4,), dtype=np.uint8, buffer=hdr_bytes[:4])
|
| 241 |
+
if 0 in mopt_ints:
|
| 242 |
+
fileobj.seek(0)
|
| 243 |
+
return (0,0)
|
| 244 |
+
# For 5 format or 7.3 format we need to read an integer in the
|
| 245 |
+
# header. Bytes 124 through 128 contain a version integer and an
|
| 246 |
+
# endian test string
|
| 247 |
+
fileobj.seek(124)
|
| 248 |
+
tst_str = fileobj.read(4)
|
| 249 |
+
fileobj.seek(0)
|
| 250 |
+
maj_ind = int(tst_str[2] == b'I'[0])
|
| 251 |
+
maj_val = int(tst_str[maj_ind])
|
| 252 |
+
min_val = int(tst_str[1 - maj_ind])
|
| 253 |
+
ret = (maj_val, min_val)
|
| 254 |
+
if maj_val in (1, 2):
|
| 255 |
+
return ret
|
| 256 |
+
raise ValueError('Unknown mat file type, version {}, {}'.format(*ret))
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def matdims(arr, oned_as='column'):
|
| 260 |
+
"""
|
| 261 |
+
Determine equivalent MATLAB dimensions for given array
|
| 262 |
+
|
| 263 |
+
Parameters
|
| 264 |
+
----------
|
| 265 |
+
arr : ndarray
|
| 266 |
+
Input array
|
| 267 |
+
oned_as : {'column', 'row'}, optional
|
| 268 |
+
Whether 1-D arrays are returned as MATLAB row or column matrices.
|
| 269 |
+
Default is 'column'.
|
| 270 |
+
|
| 271 |
+
Returns
|
| 272 |
+
-------
|
| 273 |
+
dims : tuple
|
| 274 |
+
Shape tuple, in the form MATLAB expects it.
|
| 275 |
+
|
| 276 |
+
Notes
|
| 277 |
+
-----
|
| 278 |
+
We had to decide what shape a 1 dimensional array would be by
|
| 279 |
+
default. ``np.atleast_2d`` thinks it is a row vector. The
|
| 280 |
+
default for a vector in MATLAB (e.g., ``>> 1:12``) is a row vector.
|
| 281 |
+
|
| 282 |
+
Versions of scipy up to and including 0.11 resulted (accidentally)
|
| 283 |
+
in 1-D arrays being read as column vectors. For the moment, we
|
| 284 |
+
maintain the same tradition here.
|
| 285 |
+
|
| 286 |
+
Examples
|
| 287 |
+
--------
|
| 288 |
+
>>> import numpy as np
|
| 289 |
+
>>> from scipy.io.matlab._miobase import matdims
|
| 290 |
+
>>> matdims(np.array(1)) # NumPy scalar
|
| 291 |
+
(1, 1)
|
| 292 |
+
>>> matdims(np.array([1])) # 1-D array, 1 element
|
| 293 |
+
(1, 1)
|
| 294 |
+
>>> matdims(np.array([1,2])) # 1-D array, 2 elements
|
| 295 |
+
(2, 1)
|
| 296 |
+
>>> matdims(np.array([[2],[3]])) # 2-D array, column vector
|
| 297 |
+
(2, 1)
|
| 298 |
+
>>> matdims(np.array([[2,3]])) # 2-D array, row vector
|
| 299 |
+
(1, 2)
|
| 300 |
+
>>> matdims(np.array([[[2,3]]])) # 3-D array, rowish vector
|
| 301 |
+
(1, 1, 2)
|
| 302 |
+
>>> matdims(np.array([])) # empty 1-D array
|
| 303 |
+
(0, 0)
|
| 304 |
+
>>> matdims(np.array([[]])) # empty 2-D array
|
| 305 |
+
(0, 0)
|
| 306 |
+
>>> matdims(np.array([[[]]])) # empty 3-D array
|
| 307 |
+
(0, 0, 0)
|
| 308 |
+
|
| 309 |
+
Optional argument flips 1-D shape behavior.
|
| 310 |
+
|
| 311 |
+
>>> matdims(np.array([1,2]), 'row') # 1-D array, 2 elements
|
| 312 |
+
(1, 2)
|
| 313 |
+
|
| 314 |
+
The argument has to make sense though
|
| 315 |
+
|
| 316 |
+
>>> matdims(np.array([1,2]), 'bizarre')
|
| 317 |
+
Traceback (most recent call last):
|
| 318 |
+
...
|
| 319 |
+
ValueError: 1-D option "bizarre" is strange
|
| 320 |
+
|
| 321 |
+
"""
|
| 322 |
+
shape = arr.shape
|
| 323 |
+
if shape == (): # scalar
|
| 324 |
+
return (1, 1)
|
| 325 |
+
if len(shape) == 1: # 1D
|
| 326 |
+
if shape[0] == 0:
|
| 327 |
+
return (0, 0)
|
| 328 |
+
elif oned_as == 'column':
|
| 329 |
+
return shape + (1,)
|
| 330 |
+
elif oned_as == 'row':
|
| 331 |
+
return (1,) + shape
|
| 332 |
+
else:
|
| 333 |
+
raise ValueError(f'1-D option "{oned_as}" is strange')
|
| 334 |
+
return shape
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
class MatVarReader:
|
| 338 |
+
''' Abstract class defining required interface for var readers'''
|
| 339 |
+
def __init__(self, file_reader):
|
| 340 |
+
pass
|
| 341 |
+
|
| 342 |
+
def read_header(self):
|
| 343 |
+
''' Returns header '''
|
| 344 |
+
pass
|
| 345 |
+
|
| 346 |
+
def array_from_header(self, header):
|
| 347 |
+
''' Reads array given header '''
|
| 348 |
+
pass
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
class MatFileReader:
|
| 352 |
+
""" Base object for reading mat files
|
| 353 |
+
|
| 354 |
+
To make this class functional, you will need to override the
|
| 355 |
+
following methods:
|
| 356 |
+
|
| 357 |
+
matrix_getter_factory - gives object to fetch next matrix from stream
|
| 358 |
+
guess_byte_order - guesses file byte order from file
|
| 359 |
+
"""
|
| 360 |
+
|
| 361 |
+
@docfiller
|
| 362 |
+
def __init__(self, mat_stream,
|
| 363 |
+
byte_order=None,
|
| 364 |
+
mat_dtype=False,
|
| 365 |
+
squeeze_me=False,
|
| 366 |
+
chars_as_strings=True,
|
| 367 |
+
matlab_compatible=False,
|
| 368 |
+
struct_as_record=True,
|
| 369 |
+
verify_compressed_data_integrity=True,
|
| 370 |
+
simplify_cells=False):
|
| 371 |
+
'''
|
| 372 |
+
Initializer for mat file reader
|
| 373 |
+
|
| 374 |
+
mat_stream : file-like
|
| 375 |
+
object with file API, open for reading
|
| 376 |
+
%(load_args)s
|
| 377 |
+
'''
|
| 378 |
+
# Initialize stream
|
| 379 |
+
self.mat_stream = mat_stream
|
| 380 |
+
self.dtypes = {}
|
| 381 |
+
if not byte_order:
|
| 382 |
+
byte_order = self.guess_byte_order()
|
| 383 |
+
else:
|
| 384 |
+
byte_order = boc.to_numpy_code(byte_order)
|
| 385 |
+
self.byte_order = byte_order
|
| 386 |
+
self.struct_as_record = struct_as_record
|
| 387 |
+
if matlab_compatible:
|
| 388 |
+
self.set_matlab_compatible()
|
| 389 |
+
else:
|
| 390 |
+
self.squeeze_me = squeeze_me
|
| 391 |
+
self.chars_as_strings = chars_as_strings
|
| 392 |
+
self.mat_dtype = mat_dtype
|
| 393 |
+
self.verify_compressed_data_integrity = verify_compressed_data_integrity
|
| 394 |
+
self.simplify_cells = simplify_cells
|
| 395 |
+
if simplify_cells:
|
| 396 |
+
self.squeeze_me = True
|
| 397 |
+
self.struct_as_record = False
|
| 398 |
+
|
| 399 |
+
def set_matlab_compatible(self):
|
| 400 |
+
''' Sets options to return arrays as MATLAB loads them '''
|
| 401 |
+
self.mat_dtype = True
|
| 402 |
+
self.squeeze_me = False
|
| 403 |
+
self.chars_as_strings = False
|
| 404 |
+
|
| 405 |
+
def guess_byte_order(self):
|
| 406 |
+
''' As we do not know what file type we have, assume native '''
|
| 407 |
+
return boc.native_code
|
| 408 |
+
|
| 409 |
+
def end_of_stream(self):
|
| 410 |
+
b = self.mat_stream.read(1)
|
| 411 |
+
curpos = self.mat_stream.tell()
|
| 412 |
+
self.mat_stream.seek(curpos-1)
|
| 413 |
+
return len(b) == 0
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
def arr_dtype_number(arr, num):
|
| 417 |
+
''' Return dtype for given number of items per element'''
|
| 418 |
+
return np.dtype(arr.dtype.str[:2] + str(num))
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
def arr_to_chars(arr):
|
| 422 |
+
''' Convert string array to char array '''
|
| 423 |
+
dims = list(arr.shape)
|
| 424 |
+
if not dims:
|
| 425 |
+
dims = [1]
|
| 426 |
+
dims.append(int(arr.dtype.str[2:]))
|
| 427 |
+
arr = np.ndarray(shape=dims,
|
| 428 |
+
dtype=arr_dtype_number(arr, 1),
|
| 429 |
+
buffer=arr)
|
| 430 |
+
empties = [arr == np.array('', dtype=arr.dtype)]
|
| 431 |
+
if not np.any(empties):
|
| 432 |
+
return arr
|
| 433 |
+
arr = arr.copy()
|
| 434 |
+
arr[tuple(empties)] = ' '
|
| 435 |
+
return arr
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_streams.cp312-win_amd64.dll.a
ADDED
|
Binary file (1.56 kB). View file
|
|
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/_streams.cp312-win_amd64.pyd
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ff3b4b033ae5440170646ade943197f45ed07c6224f943419388e3e54b6bc4a
|
| 3 |
+
size 105984
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/byteordercodes.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io.matlab` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__: list[str] = []
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def __dir__():
|
| 11 |
+
return __all__
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def __getattr__(name):
|
| 15 |
+
return _sub_module_deprecation(sub_package="io.matlab", module="byteordercodes",
|
| 16 |
+
private_modules=["_byteordercodes"], all=__all__,
|
| 17 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io.matlab` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__ = ["loadmat", "savemat", "whosmat"] # noqa: F822
|
| 8 |
+
|
| 9 |
+
def __dir__():
|
| 10 |
+
return __all__
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def __getattr__(name):
|
| 14 |
+
return _sub_module_deprecation(sub_package="io.matlab", module="mio",
|
| 15 |
+
private_modules=["_mio"], all=__all__,
|
| 16 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio4.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io.matlab` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__: list[str] = []
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def __dir__():
|
| 11 |
+
return __all__
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def __getattr__(name):
|
| 15 |
+
return _sub_module_deprecation(sub_package="io.matlab", module="mio4",
|
| 16 |
+
private_modules=["_mio4"], all=__all__,
|
| 17 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio5.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io.matlab` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__ = [ # noqa: F822
|
| 8 |
+
'MatWriteError', 'MatReadError', 'MatReadWarning', 'MatlabObject',
|
| 9 |
+
'MatlabFunction', 'mat_struct', 'varmats_from_mat',
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
def __dir__():
|
| 13 |
+
return __all__
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def __getattr__(name):
|
| 17 |
+
return _sub_module_deprecation(sub_package="io.matlab", module="mio5",
|
| 18 |
+
private_modules=["_mio5"], all=__all__,
|
| 19 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio5_params.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io.matlab` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__ = [ # noqa: F822
|
| 8 |
+
'MatlabFunction', 'MatlabObject', 'MatlabOpaque', 'mat_struct',
|
| 9 |
+
]
|
| 10 |
+
|
| 11 |
+
def __dir__():
|
| 12 |
+
return __all__
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def __getattr__(name):
|
| 16 |
+
return _sub_module_deprecation(sub_package="io.matlab", module="mio5_params",
|
| 17 |
+
private_modules=["_mio5_params"], all=__all__,
|
| 18 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio5_utils.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io.matlab` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__: list[str] = []
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def __dir__():
|
| 11 |
+
return __all__
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def __getattr__(name):
|
| 15 |
+
return _sub_module_deprecation(sub_package="io.matlab", module="mio5_utils",
|
| 16 |
+
private_modules=["_mio5_utils"], all=__all__,
|
| 17 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/mio_utils.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io.matlab` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__: list[str] = []
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def __dir__():
|
| 11 |
+
return __all__
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def __getattr__(name):
|
| 15 |
+
return _sub_module_deprecation(sub_package="io.matlab", module="mio_utils",
|
| 16 |
+
private_modules=["_mio_utils"], all=__all__,
|
| 17 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/miobase.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io.matlab` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__ = ["MatReadError", "MatReadWarning", "MatWriteError"] # noqa: F822
|
| 8 |
+
|
| 9 |
+
def __dir__():
|
| 10 |
+
return __all__
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def __getattr__(name):
|
| 14 |
+
return _sub_module_deprecation(sub_package="io.matlab", module="miobase",
|
| 15 |
+
private_modules=["_miobase"], all=__all__,
|
| 16 |
+
attribute=name)
|
loan-advisor-agent/.venv/Lib/site-packages/scipy/io/matlab/streams.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
| 2 |
+
# Use the `scipy.io.matlab` namespace for importing the functions
|
| 3 |
+
# included below.
|
| 4 |
+
|
| 5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
| 6 |
+
|
| 7 |
+
__all__: list[str] = []
|
| 8 |
+
|
| 9 |
+
def __dir__():
|
| 10 |
+
return __all__
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def __getattr__(name):
|
| 14 |
+
return _sub_module_deprecation(sub_package="io.matlab", module="streams",
|
| 15 |
+
private_modules=["_streams"], all=__all__,
|
| 16 |
+
attribute=name)
|