Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- ckpts/universal/global_step40/zero/13.post_attention_layernorm.weight/fp32.pt +3 -0
- ckpts/universal/global_step40/zero/24.mlp.dense_h_to_4h_swiglu.weight/exp_avg.pt +3 -0
- ckpts/universal/global_step40/zero/24.mlp.dense_h_to_4h_swiglu.weight/exp_avg_sq.pt +3 -0
- ckpts/universal/global_step40/zero/29.vocab_parallel_projection.weight/exp_avg.pt +3 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/_fortran.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/_idl.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/_mmio.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/_netcdf.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/harwell_boeing.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/idl.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/mmio.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/netcdf.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/__pycache__/wavfile.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/__init__.py +17 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/__pycache__/_fortran_format_parser.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/__pycache__/hb.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/_fortran_format_parser.py +309 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/hb.py +571 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/__init__.py +0 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/__pycache__/test_fortran_format.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/__pycache__/test_hb.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/test_fortran_format.py +74 -0
- venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/test_hb.py +65 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/__init__.py +28 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/__pycache__/_arffread.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/__pycache__/arffread.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/_arffread.py +907 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/arffread.py +28 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/__init__.py +0 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/__pycache__/test_arffread.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/iris.arff +225 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/missing.arff +8 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/nodata.arff +11 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/quoted_nominal.arff +13 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/quoted_nominal_spaces.arff +13 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test1.arff +10 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test10.arff +0 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test11.arff +11 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test2.arff +15 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test3.arff +6 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test4.arff +11 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test5.arff +26 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test6.arff +12 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test7.arff +15 -0
- venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test8.arff +12 -0
ckpts/universal/global_step40/zero/13.post_attention_layernorm.weight/fp32.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f0eb26ef7305299dd4da47cec54a2b762bdb6a98fbf780c7af9773dbbb42dda3
|
3 |
+
size 9293
|
ckpts/universal/global_step40/zero/24.mlp.dense_h_to_4h_swiglu.weight/exp_avg.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bc512fb9715785b1f6611043918a379903723366559bdc6249e6a672b335b887
|
3 |
+
size 33555612
|
ckpts/universal/global_step40/zero/24.mlp.dense_h_to_4h_swiglu.weight/exp_avg_sq.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7e02662ffe684f6dfc1e8c9f2cf87cce6301260735c550275f925a457d6e00cb
|
3 |
+
size 33555627
|
ckpts/universal/global_step40/zero/29.vocab_parallel_projection.weight/exp_avg.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8e77f2371490716045206c0310c7badb2b50202a29b26a6a37f0cc4f1d68b2ff
|
3 |
+
size 415237276
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (3.09 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/_fortran.cpython-310.pyc
ADDED
Binary file (11.1 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/_idl.cpython-310.pyc
ADDED
Binary file (19.2 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/_mmio.cpython-310.pyc
ADDED
Binary file (21.7 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/_netcdf.cpython-310.pyc
ADDED
Binary file (30.8 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/harwell_boeing.cpython-310.pyc
ADDED
Binary file (739 Bytes). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/idl.cpython-310.pyc
ADDED
Binary file (657 Bytes). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/mmio.cpython-310.pyc
ADDED
Binary file (630 Bytes). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/netcdf.cpython-310.pyc
ADDED
Binary file (881 Bytes). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/__pycache__/wavfile.cpython-310.pyc
ADDED
Binary file (21.3 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/__init__.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from .hb import (MalformedHeader, hb_read, hb_write, HBInfo,
|
2 |
+
HBFile, HBMatrixType)
|
3 |
+
from ._fortran_format_parser import (FortranFormatParser, IntFormat,
|
4 |
+
ExpFormat, BadFortranFormat)
|
5 |
+
|
6 |
+
# Deprecated namespaces, to be removed in v2.0.0
|
7 |
+
from . import hb
|
8 |
+
|
9 |
+
__all__ = [
|
10 |
+
'MalformedHeader', 'hb_read', 'hb_write', 'HBInfo',
|
11 |
+
'HBFile', 'HBMatrixType', 'FortranFormatParser', 'IntFormat',
|
12 |
+
'ExpFormat', 'BadFortranFormat', 'hb'
|
13 |
+
]
|
14 |
+
|
15 |
+
from scipy._lib._testutils import PytestTester
|
16 |
+
test = PytestTester(__name__)
|
17 |
+
del PytestTester
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (653 Bytes). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/__pycache__/_fortran_format_parser.cpython-310.pyc
ADDED
Binary file (8.92 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/__pycache__/hb.cpython-310.pyc
ADDED
Binary file (15.3 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/_fortran_format_parser.py
ADDED
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Preliminary module to handle Fortran formats for IO. Does not use this outside
|
3 |
+
scipy.sparse io for now, until the API is deemed reasonable.
|
4 |
+
|
5 |
+
The *Format classes handle conversion between Fortran and Python format, and
|
6 |
+
FortranFormatParser can create *Format instances from raw Fortran format
|
7 |
+
strings (e.g. '(3I4)', '(10I3)', etc...)
|
8 |
+
"""
|
9 |
+
import re
|
10 |
+
|
11 |
+
import numpy as np
|
12 |
+
|
13 |
+
|
14 |
+
__all__ = ["BadFortranFormat", "FortranFormatParser", "IntFormat", "ExpFormat"]
|
15 |
+
|
16 |
+
|
17 |
+
TOKENS = {
|
18 |
+
"LPAR": r"\(",
|
19 |
+
"RPAR": r"\)",
|
20 |
+
"INT_ID": r"I",
|
21 |
+
"EXP_ID": r"E",
|
22 |
+
"INT": r"\d+",
|
23 |
+
"DOT": r"\.",
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
class BadFortranFormat(SyntaxError):
|
28 |
+
pass
|
29 |
+
|
30 |
+
|
31 |
+
def number_digits(n):
|
32 |
+
return int(np.floor(np.log10(np.abs(n))) + 1)
|
33 |
+
|
34 |
+
|
35 |
+
class IntFormat:
|
36 |
+
@classmethod
|
37 |
+
def from_number(cls, n, min=None):
|
38 |
+
"""Given an integer, returns a "reasonable" IntFormat instance to represent
|
39 |
+
any number between 0 and n if n > 0, -n and n if n < 0
|
40 |
+
|
41 |
+
Parameters
|
42 |
+
----------
|
43 |
+
n : int
|
44 |
+
max number one wants to be able to represent
|
45 |
+
min : int
|
46 |
+
minimum number of characters to use for the format
|
47 |
+
|
48 |
+
Returns
|
49 |
+
-------
|
50 |
+
res : IntFormat
|
51 |
+
IntFormat instance with reasonable (see Notes) computed width
|
52 |
+
|
53 |
+
Notes
|
54 |
+
-----
|
55 |
+
Reasonable should be understood as the minimal string length necessary
|
56 |
+
without losing precision. For example, IntFormat.from_number(1) will
|
57 |
+
return an IntFormat instance of width 2, so that any 0 and 1 may be
|
58 |
+
represented as 1-character strings without loss of information.
|
59 |
+
"""
|
60 |
+
width = number_digits(n) + 1
|
61 |
+
if n < 0:
|
62 |
+
width += 1
|
63 |
+
repeat = 80 // width
|
64 |
+
return cls(width, min, repeat=repeat)
|
65 |
+
|
66 |
+
def __init__(self, width, min=None, repeat=None):
|
67 |
+
self.width = width
|
68 |
+
self.repeat = repeat
|
69 |
+
self.min = min
|
70 |
+
|
71 |
+
def __repr__(self):
|
72 |
+
r = "IntFormat("
|
73 |
+
if self.repeat:
|
74 |
+
r += "%d" % self.repeat
|
75 |
+
r += "I%d" % self.width
|
76 |
+
if self.min:
|
77 |
+
r += ".%d" % self.min
|
78 |
+
return r + ")"
|
79 |
+
|
80 |
+
@property
|
81 |
+
def fortran_format(self):
|
82 |
+
r = "("
|
83 |
+
if self.repeat:
|
84 |
+
r += "%d" % self.repeat
|
85 |
+
r += "I%d" % self.width
|
86 |
+
if self.min:
|
87 |
+
r += ".%d" % self.min
|
88 |
+
return r + ")"
|
89 |
+
|
90 |
+
@property
|
91 |
+
def python_format(self):
|
92 |
+
return "%" + str(self.width) + "d"
|
93 |
+
|
94 |
+
|
95 |
+
class ExpFormat:
|
96 |
+
@classmethod
|
97 |
+
def from_number(cls, n, min=None):
|
98 |
+
"""Given a float number, returns a "reasonable" ExpFormat instance to
|
99 |
+
represent any number between -n and n.
|
100 |
+
|
101 |
+
Parameters
|
102 |
+
----------
|
103 |
+
n : float
|
104 |
+
max number one wants to be able to represent
|
105 |
+
min : int
|
106 |
+
minimum number of characters to use for the format
|
107 |
+
|
108 |
+
Returns
|
109 |
+
-------
|
110 |
+
res : ExpFormat
|
111 |
+
ExpFormat instance with reasonable (see Notes) computed width
|
112 |
+
|
113 |
+
Notes
|
114 |
+
-----
|
115 |
+
Reasonable should be understood as the minimal string length necessary
|
116 |
+
to avoid losing precision.
|
117 |
+
"""
|
118 |
+
# len of one number in exp format: sign + 1|0 + "." +
|
119 |
+
# number of digit for fractional part + 'E' + sign of exponent +
|
120 |
+
# len of exponent
|
121 |
+
finfo = np.finfo(n.dtype)
|
122 |
+
# Number of digits for fractional part
|
123 |
+
n_prec = finfo.precision + 1
|
124 |
+
# Number of digits for exponential part
|
125 |
+
n_exp = number_digits(np.max(np.abs([finfo.maxexp, finfo.minexp])))
|
126 |
+
width = 1 + 1 + n_prec + 1 + n_exp + 1
|
127 |
+
if n < 0:
|
128 |
+
width += 1
|
129 |
+
repeat = int(np.floor(80 / width))
|
130 |
+
return cls(width, n_prec, min, repeat=repeat)
|
131 |
+
|
132 |
+
def __init__(self, width, significand, min=None, repeat=None):
|
133 |
+
"""\
|
134 |
+
Parameters
|
135 |
+
----------
|
136 |
+
width : int
|
137 |
+
number of characters taken by the string (includes space).
|
138 |
+
"""
|
139 |
+
self.width = width
|
140 |
+
self.significand = significand
|
141 |
+
self.repeat = repeat
|
142 |
+
self.min = min
|
143 |
+
|
144 |
+
def __repr__(self):
|
145 |
+
r = "ExpFormat("
|
146 |
+
if self.repeat:
|
147 |
+
r += "%d" % self.repeat
|
148 |
+
r += "E%d.%d" % (self.width, self.significand)
|
149 |
+
if self.min:
|
150 |
+
r += "E%d" % self.min
|
151 |
+
return r + ")"
|
152 |
+
|
153 |
+
@property
|
154 |
+
def fortran_format(self):
|
155 |
+
r = "("
|
156 |
+
if self.repeat:
|
157 |
+
r += "%d" % self.repeat
|
158 |
+
r += "E%d.%d" % (self.width, self.significand)
|
159 |
+
if self.min:
|
160 |
+
r += "E%d" % self.min
|
161 |
+
return r + ")"
|
162 |
+
|
163 |
+
@property
|
164 |
+
def python_format(self):
|
165 |
+
return "%" + str(self.width-1) + "." + str(self.significand) + "E"
|
166 |
+
|
167 |
+
|
168 |
+
class Token:
|
169 |
+
def __init__(self, type, value, pos):
|
170 |
+
self.type = type
|
171 |
+
self.value = value
|
172 |
+
self.pos = pos
|
173 |
+
|
174 |
+
def __str__(self):
|
175 |
+
return f"""Token('{self.type}', "{self.value}")"""
|
176 |
+
|
177 |
+
def __repr__(self):
|
178 |
+
return self.__str__()
|
179 |
+
|
180 |
+
|
181 |
+
class Tokenizer:
|
182 |
+
def __init__(self):
|
183 |
+
self.tokens = list(TOKENS.keys())
|
184 |
+
self.res = [re.compile(TOKENS[i]) for i in self.tokens]
|
185 |
+
|
186 |
+
def input(self, s):
|
187 |
+
self.data = s
|
188 |
+
self.curpos = 0
|
189 |
+
self.len = len(s)
|
190 |
+
|
191 |
+
def next_token(self):
|
192 |
+
curpos = self.curpos
|
193 |
+
|
194 |
+
while curpos < self.len:
|
195 |
+
for i, r in enumerate(self.res):
|
196 |
+
m = r.match(self.data, curpos)
|
197 |
+
if m is None:
|
198 |
+
continue
|
199 |
+
else:
|
200 |
+
self.curpos = m.end()
|
201 |
+
return Token(self.tokens[i], m.group(), self.curpos)
|
202 |
+
raise SyntaxError("Unknown character at position %d (%s)"
|
203 |
+
% (self.curpos, self.data[curpos]))
|
204 |
+
|
205 |
+
|
206 |
+
# Grammar for fortran format:
|
207 |
+
# format : LPAR format_string RPAR
|
208 |
+
# format_string : repeated | simple
|
209 |
+
# repeated : repeat simple
|
210 |
+
# simple : int_fmt | exp_fmt
|
211 |
+
# int_fmt : INT_ID width
|
212 |
+
# exp_fmt : simple_exp_fmt
|
213 |
+
# simple_exp_fmt : EXP_ID width DOT significand
|
214 |
+
# extended_exp_fmt : EXP_ID width DOT significand EXP_ID ndigits
|
215 |
+
# repeat : INT
|
216 |
+
# width : INT
|
217 |
+
# significand : INT
|
218 |
+
# ndigits : INT
|
219 |
+
|
220 |
+
# Naive fortran formatter - parser is hand-made
|
221 |
+
class FortranFormatParser:
|
222 |
+
"""Parser for Fortran format strings. The parse method returns a *Format
|
223 |
+
instance.
|
224 |
+
|
225 |
+
Notes
|
226 |
+
-----
|
227 |
+
Only ExpFormat (exponential format for floating values) and IntFormat
|
228 |
+
(integer format) for now.
|
229 |
+
"""
|
230 |
+
def __init__(self):
|
231 |
+
self.tokenizer = Tokenizer()
|
232 |
+
|
233 |
+
def parse(self, s):
|
234 |
+
self.tokenizer.input(s)
|
235 |
+
|
236 |
+
tokens = []
|
237 |
+
|
238 |
+
try:
|
239 |
+
while True:
|
240 |
+
t = self.tokenizer.next_token()
|
241 |
+
if t is None:
|
242 |
+
break
|
243 |
+
else:
|
244 |
+
tokens.append(t)
|
245 |
+
return self._parse_format(tokens)
|
246 |
+
except SyntaxError as e:
|
247 |
+
raise BadFortranFormat(str(e)) from e
|
248 |
+
|
249 |
+
def _get_min(self, tokens):
|
250 |
+
next = tokens.pop(0)
|
251 |
+
if not next.type == "DOT":
|
252 |
+
raise SyntaxError()
|
253 |
+
next = tokens.pop(0)
|
254 |
+
return next.value
|
255 |
+
|
256 |
+
def _expect(self, token, tp):
|
257 |
+
if not token.type == tp:
|
258 |
+
raise SyntaxError()
|
259 |
+
|
260 |
+
def _parse_format(self, tokens):
|
261 |
+
if not tokens[0].type == "LPAR":
|
262 |
+
raise SyntaxError("Expected left parenthesis at position "
|
263 |
+
"%d (got '%s')" % (0, tokens[0].value))
|
264 |
+
elif not tokens[-1].type == "RPAR":
|
265 |
+
raise SyntaxError("Expected right parenthesis at position "
|
266 |
+
"%d (got '%s')" % (len(tokens), tokens[-1].value))
|
267 |
+
|
268 |
+
tokens = tokens[1:-1]
|
269 |
+
types = [t.type for t in tokens]
|
270 |
+
if types[0] == "INT":
|
271 |
+
repeat = int(tokens.pop(0).value)
|
272 |
+
else:
|
273 |
+
repeat = None
|
274 |
+
|
275 |
+
next = tokens.pop(0)
|
276 |
+
if next.type == "INT_ID":
|
277 |
+
next = self._next(tokens, "INT")
|
278 |
+
width = int(next.value)
|
279 |
+
if tokens:
|
280 |
+
min = int(self._get_min(tokens))
|
281 |
+
else:
|
282 |
+
min = None
|
283 |
+
return IntFormat(width, min, repeat)
|
284 |
+
elif next.type == "EXP_ID":
|
285 |
+
next = self._next(tokens, "INT")
|
286 |
+
width = int(next.value)
|
287 |
+
|
288 |
+
next = self._next(tokens, "DOT")
|
289 |
+
|
290 |
+
next = self._next(tokens, "INT")
|
291 |
+
significand = int(next.value)
|
292 |
+
|
293 |
+
if tokens:
|
294 |
+
next = self._next(tokens, "EXP_ID")
|
295 |
+
|
296 |
+
next = self._next(tokens, "INT")
|
297 |
+
min = int(next.value)
|
298 |
+
else:
|
299 |
+
min = None
|
300 |
+
return ExpFormat(width, significand, min, repeat)
|
301 |
+
else:
|
302 |
+
raise SyntaxError("Invalid formatter type %s" % next.value)
|
303 |
+
|
304 |
+
def _next(self, tokens, tp):
|
305 |
+
if not len(tokens) > 0:
|
306 |
+
raise SyntaxError()
|
307 |
+
next = tokens.pop(0)
|
308 |
+
self._expect(next, tp)
|
309 |
+
return next
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/hb.py
ADDED
@@ -0,0 +1,571 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Implementation of Harwell-Boeing read/write.
|
3 |
+
|
4 |
+
At the moment not the full Harwell-Boeing format is supported. Supported
|
5 |
+
features are:
|
6 |
+
|
7 |
+
- assembled, non-symmetric, real matrices
|
8 |
+
- integer for pointer/indices
|
9 |
+
- exponential format for float values, and int format
|
10 |
+
|
11 |
+
"""
|
12 |
+
# TODO:
|
13 |
+
# - Add more support (symmetric/complex matrices, non-assembled matrices ?)
|
14 |
+
|
15 |
+
# XXX: reading is reasonably efficient (>= 85 % is in numpy.fromstring), but
|
16 |
+
# takes a lot of memory. Being faster would require compiled code.
|
17 |
+
# write is not efficient. Although not a terribly exciting task,
|
18 |
+
# having reusable facilities to efficiently read/write fortran-formatted files
|
19 |
+
# would be useful outside this module.
|
20 |
+
|
21 |
+
import warnings
|
22 |
+
|
23 |
+
import numpy as np
|
24 |
+
from scipy.sparse import csc_matrix
|
25 |
+
from ._fortran_format_parser import FortranFormatParser, IntFormat, ExpFormat
|
26 |
+
|
27 |
+
__all__ = ["MalformedHeader", "hb_read", "hb_write", "HBInfo", "HBFile",
|
28 |
+
"HBMatrixType"]
|
29 |
+
|
30 |
+
|
31 |
+
class MalformedHeader(Exception):
|
32 |
+
pass
|
33 |
+
|
34 |
+
|
35 |
+
class LineOverflow(Warning):
|
36 |
+
pass
|
37 |
+
|
38 |
+
|
39 |
+
def _nbytes_full(fmt, nlines):
|
40 |
+
"""Return the number of bytes to read to get every full lines for the
|
41 |
+
given parsed fortran format."""
|
42 |
+
return (fmt.repeat * fmt.width + 1) * (nlines - 1)
|
43 |
+
|
44 |
+
|
45 |
+
class HBInfo:
|
46 |
+
@classmethod
|
47 |
+
def from_data(cls, m, title="Default title", key="0", mxtype=None, fmt=None):
|
48 |
+
"""Create a HBInfo instance from an existing sparse matrix.
|
49 |
+
|
50 |
+
Parameters
|
51 |
+
----------
|
52 |
+
m : sparse matrix
|
53 |
+
the HBInfo instance will derive its parameters from m
|
54 |
+
title : str
|
55 |
+
Title to put in the HB header
|
56 |
+
key : str
|
57 |
+
Key
|
58 |
+
mxtype : HBMatrixType
|
59 |
+
type of the input matrix
|
60 |
+
fmt : dict
|
61 |
+
not implemented
|
62 |
+
|
63 |
+
Returns
|
64 |
+
-------
|
65 |
+
hb_info : HBInfo instance
|
66 |
+
"""
|
67 |
+
m = m.tocsc(copy=False)
|
68 |
+
|
69 |
+
pointer = m.indptr
|
70 |
+
indices = m.indices
|
71 |
+
values = m.data
|
72 |
+
|
73 |
+
nrows, ncols = m.shape
|
74 |
+
nnon_zeros = m.nnz
|
75 |
+
|
76 |
+
if fmt is None:
|
77 |
+
# +1 because HB use one-based indexing (Fortran), and we will write
|
78 |
+
# the indices /pointer as such
|
79 |
+
pointer_fmt = IntFormat.from_number(np.max(pointer+1))
|
80 |
+
indices_fmt = IntFormat.from_number(np.max(indices+1))
|
81 |
+
|
82 |
+
if values.dtype.kind in np.typecodes["AllFloat"]:
|
83 |
+
values_fmt = ExpFormat.from_number(-np.max(np.abs(values)))
|
84 |
+
elif values.dtype.kind in np.typecodes["AllInteger"]:
|
85 |
+
values_fmt = IntFormat.from_number(-np.max(np.abs(values)))
|
86 |
+
else:
|
87 |
+
message = f"type {values.dtype.kind} not implemented yet"
|
88 |
+
raise NotImplementedError(message)
|
89 |
+
else:
|
90 |
+
raise NotImplementedError("fmt argument not supported yet.")
|
91 |
+
|
92 |
+
if mxtype is None:
|
93 |
+
if not np.isrealobj(values):
|
94 |
+
raise ValueError("Complex values not supported yet")
|
95 |
+
if values.dtype.kind in np.typecodes["AllInteger"]:
|
96 |
+
tp = "integer"
|
97 |
+
elif values.dtype.kind in np.typecodes["AllFloat"]:
|
98 |
+
tp = "real"
|
99 |
+
else:
|
100 |
+
raise NotImplementedError("type %s for values not implemented"
|
101 |
+
% values.dtype)
|
102 |
+
mxtype = HBMatrixType(tp, "unsymmetric", "assembled")
|
103 |
+
else:
|
104 |
+
raise ValueError("mxtype argument not handled yet.")
|
105 |
+
|
106 |
+
def _nlines(fmt, size):
|
107 |
+
nlines = size // fmt.repeat
|
108 |
+
if nlines * fmt.repeat != size:
|
109 |
+
nlines += 1
|
110 |
+
return nlines
|
111 |
+
|
112 |
+
pointer_nlines = _nlines(pointer_fmt, pointer.size)
|
113 |
+
indices_nlines = _nlines(indices_fmt, indices.size)
|
114 |
+
values_nlines = _nlines(values_fmt, values.size)
|
115 |
+
|
116 |
+
total_nlines = pointer_nlines + indices_nlines + values_nlines
|
117 |
+
|
118 |
+
return cls(title, key,
|
119 |
+
total_nlines, pointer_nlines, indices_nlines, values_nlines,
|
120 |
+
mxtype, nrows, ncols, nnon_zeros,
|
121 |
+
pointer_fmt.fortran_format, indices_fmt.fortran_format,
|
122 |
+
values_fmt.fortran_format)
|
123 |
+
|
124 |
+
@classmethod
|
125 |
+
def from_file(cls, fid):
|
126 |
+
"""Create a HBInfo instance from a file object containing a matrix in the
|
127 |
+
HB format.
|
128 |
+
|
129 |
+
Parameters
|
130 |
+
----------
|
131 |
+
fid : file-like matrix
|
132 |
+
File or file-like object containing a matrix in the HB format.
|
133 |
+
|
134 |
+
Returns
|
135 |
+
-------
|
136 |
+
hb_info : HBInfo instance
|
137 |
+
"""
|
138 |
+
# First line
|
139 |
+
line = fid.readline().strip("\n")
|
140 |
+
if not len(line) > 72:
|
141 |
+
raise ValueError("Expected at least 72 characters for first line, "
|
142 |
+
"got: \n%s" % line)
|
143 |
+
title = line[:72]
|
144 |
+
key = line[72:]
|
145 |
+
|
146 |
+
# Second line
|
147 |
+
line = fid.readline().strip("\n")
|
148 |
+
if not len(line.rstrip()) >= 56:
|
149 |
+
raise ValueError("Expected at least 56 characters for second line, "
|
150 |
+
"got: \n%s" % line)
|
151 |
+
total_nlines = _expect_int(line[:14])
|
152 |
+
pointer_nlines = _expect_int(line[14:28])
|
153 |
+
indices_nlines = _expect_int(line[28:42])
|
154 |
+
values_nlines = _expect_int(line[42:56])
|
155 |
+
|
156 |
+
rhs_nlines = line[56:72].strip()
|
157 |
+
if rhs_nlines == '':
|
158 |
+
rhs_nlines = 0
|
159 |
+
else:
|
160 |
+
rhs_nlines = _expect_int(rhs_nlines)
|
161 |
+
if not rhs_nlines == 0:
|
162 |
+
raise ValueError("Only files without right hand side supported for "
|
163 |
+
"now.")
|
164 |
+
|
165 |
+
# Third line
|
166 |
+
line = fid.readline().strip("\n")
|
167 |
+
if not len(line) >= 70:
|
168 |
+
raise ValueError("Expected at least 72 character for third line, got:\n"
|
169 |
+
"%s" % line)
|
170 |
+
|
171 |
+
mxtype_s = line[:3].upper()
|
172 |
+
if not len(mxtype_s) == 3:
|
173 |
+
raise ValueError("mxtype expected to be 3 characters long")
|
174 |
+
|
175 |
+
mxtype = HBMatrixType.from_fortran(mxtype_s)
|
176 |
+
if mxtype.value_type not in ["real", "integer"]:
|
177 |
+
raise ValueError("Only real or integer matrices supported for "
|
178 |
+
"now (detected %s)" % mxtype)
|
179 |
+
if not mxtype.structure == "unsymmetric":
|
180 |
+
raise ValueError("Only unsymmetric matrices supported for "
|
181 |
+
"now (detected %s)" % mxtype)
|
182 |
+
if not mxtype.storage == "assembled":
|
183 |
+
raise ValueError("Only assembled matrices supported for now")
|
184 |
+
|
185 |
+
if not line[3:14] == " " * 11:
|
186 |
+
raise ValueError("Malformed data for third line: %s" % line)
|
187 |
+
|
188 |
+
nrows = _expect_int(line[14:28])
|
189 |
+
ncols = _expect_int(line[28:42])
|
190 |
+
nnon_zeros = _expect_int(line[42:56])
|
191 |
+
nelementals = _expect_int(line[56:70])
|
192 |
+
if not nelementals == 0:
|
193 |
+
raise ValueError("Unexpected value %d for nltvl (last entry of line 3)"
|
194 |
+
% nelementals)
|
195 |
+
|
196 |
+
# Fourth line
|
197 |
+
line = fid.readline().strip("\n")
|
198 |
+
|
199 |
+
ct = line.split()
|
200 |
+
if not len(ct) == 3:
|
201 |
+
raise ValueError("Expected 3 formats, got %s" % ct)
|
202 |
+
|
203 |
+
return cls(title, key,
|
204 |
+
total_nlines, pointer_nlines, indices_nlines, values_nlines,
|
205 |
+
mxtype, nrows, ncols, nnon_zeros,
|
206 |
+
ct[0], ct[1], ct[2],
|
207 |
+
rhs_nlines, nelementals)
|
208 |
+
|
209 |
+
def __init__(self, title, key,
|
210 |
+
total_nlines, pointer_nlines, indices_nlines, values_nlines,
|
211 |
+
mxtype, nrows, ncols, nnon_zeros,
|
212 |
+
pointer_format_str, indices_format_str, values_format_str,
|
213 |
+
right_hand_sides_nlines=0, nelementals=0):
|
214 |
+
"""Do not use this directly, but the class ctrs (from_* functions)."""
|
215 |
+
self.title = title
|
216 |
+
self.key = key
|
217 |
+
if title is None:
|
218 |
+
title = "No Title"
|
219 |
+
if len(title) > 72:
|
220 |
+
raise ValueError("title cannot be > 72 characters")
|
221 |
+
|
222 |
+
if key is None:
|
223 |
+
key = "|No Key"
|
224 |
+
if len(key) > 8:
|
225 |
+
warnings.warn("key is > 8 characters (key is %s)" % key,
|
226 |
+
LineOverflow, stacklevel=3)
|
227 |
+
|
228 |
+
self.total_nlines = total_nlines
|
229 |
+
self.pointer_nlines = pointer_nlines
|
230 |
+
self.indices_nlines = indices_nlines
|
231 |
+
self.values_nlines = values_nlines
|
232 |
+
|
233 |
+
parser = FortranFormatParser()
|
234 |
+
pointer_format = parser.parse(pointer_format_str)
|
235 |
+
if not isinstance(pointer_format, IntFormat):
|
236 |
+
raise ValueError("Expected int format for pointer format, got %s"
|
237 |
+
% pointer_format)
|
238 |
+
|
239 |
+
indices_format = parser.parse(indices_format_str)
|
240 |
+
if not isinstance(indices_format, IntFormat):
|
241 |
+
raise ValueError("Expected int format for indices format, got %s" %
|
242 |
+
indices_format)
|
243 |
+
|
244 |
+
values_format = parser.parse(values_format_str)
|
245 |
+
if isinstance(values_format, ExpFormat):
|
246 |
+
if mxtype.value_type not in ["real", "complex"]:
|
247 |
+
raise ValueError(f"Inconsistency between matrix type {mxtype} and "
|
248 |
+
f"value type {values_format}")
|
249 |
+
values_dtype = np.float64
|
250 |
+
elif isinstance(values_format, IntFormat):
|
251 |
+
if mxtype.value_type not in ["integer"]:
|
252 |
+
raise ValueError(f"Inconsistency between matrix type {mxtype} and "
|
253 |
+
f"value type {values_format}")
|
254 |
+
# XXX: fortran int -> dtype association ?
|
255 |
+
values_dtype = int
|
256 |
+
else:
|
257 |
+
raise ValueError(f"Unsupported format for values {values_format!r}")
|
258 |
+
|
259 |
+
self.pointer_format = pointer_format
|
260 |
+
self.indices_format = indices_format
|
261 |
+
self.values_format = values_format
|
262 |
+
|
263 |
+
self.pointer_dtype = np.int32
|
264 |
+
self.indices_dtype = np.int32
|
265 |
+
self.values_dtype = values_dtype
|
266 |
+
|
267 |
+
self.pointer_nlines = pointer_nlines
|
268 |
+
self.pointer_nbytes_full = _nbytes_full(pointer_format, pointer_nlines)
|
269 |
+
|
270 |
+
self.indices_nlines = indices_nlines
|
271 |
+
self.indices_nbytes_full = _nbytes_full(indices_format, indices_nlines)
|
272 |
+
|
273 |
+
self.values_nlines = values_nlines
|
274 |
+
self.values_nbytes_full = _nbytes_full(values_format, values_nlines)
|
275 |
+
|
276 |
+
self.nrows = nrows
|
277 |
+
self.ncols = ncols
|
278 |
+
self.nnon_zeros = nnon_zeros
|
279 |
+
self.nelementals = nelementals
|
280 |
+
self.mxtype = mxtype
|
281 |
+
|
282 |
+
def dump(self):
|
283 |
+
"""Gives the header corresponding to this instance as a string."""
|
284 |
+
header = [self.title.ljust(72) + self.key.ljust(8)]
|
285 |
+
|
286 |
+
header.append("%14d%14d%14d%14d" %
|
287 |
+
(self.total_nlines, self.pointer_nlines,
|
288 |
+
self.indices_nlines, self.values_nlines))
|
289 |
+
header.append("%14s%14d%14d%14d%14d" %
|
290 |
+
(self.mxtype.fortran_format.ljust(14), self.nrows,
|
291 |
+
self.ncols, self.nnon_zeros, 0))
|
292 |
+
|
293 |
+
pffmt = self.pointer_format.fortran_format
|
294 |
+
iffmt = self.indices_format.fortran_format
|
295 |
+
vffmt = self.values_format.fortran_format
|
296 |
+
header.append("%16s%16s%20s" %
|
297 |
+
(pffmt.ljust(16), iffmt.ljust(16), vffmt.ljust(20)))
|
298 |
+
return "\n".join(header)
|
299 |
+
|
300 |
+
|
301 |
+
def _expect_int(value, msg=None):
|
302 |
+
try:
|
303 |
+
return int(value)
|
304 |
+
except ValueError as e:
|
305 |
+
if msg is None:
|
306 |
+
msg = "Expected an int, got %s"
|
307 |
+
raise ValueError(msg % value) from e
|
308 |
+
|
309 |
+
|
310 |
+
def _read_hb_data(content, header):
|
311 |
+
# XXX: look at a way to reduce memory here (big string creation)
|
312 |
+
ptr_string = "".join([content.read(header.pointer_nbytes_full),
|
313 |
+
content.readline()])
|
314 |
+
ptr = np.fromstring(ptr_string,
|
315 |
+
dtype=int, sep=' ')
|
316 |
+
|
317 |
+
ind_string = "".join([content.read(header.indices_nbytes_full),
|
318 |
+
content.readline()])
|
319 |
+
ind = np.fromstring(ind_string,
|
320 |
+
dtype=int, sep=' ')
|
321 |
+
|
322 |
+
val_string = "".join([content.read(header.values_nbytes_full),
|
323 |
+
content.readline()])
|
324 |
+
val = np.fromstring(val_string,
|
325 |
+
dtype=header.values_dtype, sep=' ')
|
326 |
+
|
327 |
+
try:
|
328 |
+
return csc_matrix((val, ind-1, ptr-1),
|
329 |
+
shape=(header.nrows, header.ncols))
|
330 |
+
except ValueError as e:
|
331 |
+
raise e
|
332 |
+
|
333 |
+
|
334 |
+
def _write_data(m, fid, header):
|
335 |
+
m = m.tocsc(copy=False)
|
336 |
+
|
337 |
+
def write_array(f, ar, nlines, fmt):
|
338 |
+
# ar_nlines is the number of full lines, n is the number of items per
|
339 |
+
# line, ffmt the fortran format
|
340 |
+
pyfmt = fmt.python_format
|
341 |
+
pyfmt_full = pyfmt * fmt.repeat
|
342 |
+
|
343 |
+
# for each array to write, we first write the full lines, and special
|
344 |
+
# case for partial line
|
345 |
+
full = ar[:(nlines - 1) * fmt.repeat]
|
346 |
+
for row in full.reshape((nlines-1, fmt.repeat)):
|
347 |
+
f.write(pyfmt_full % tuple(row) + "\n")
|
348 |
+
nremain = ar.size - full.size
|
349 |
+
if nremain > 0:
|
350 |
+
f.write((pyfmt * nremain) % tuple(ar[ar.size - nremain:]) + "\n")
|
351 |
+
|
352 |
+
fid.write(header.dump())
|
353 |
+
fid.write("\n")
|
354 |
+
# +1 is for Fortran one-based indexing
|
355 |
+
write_array(fid, m.indptr+1, header.pointer_nlines,
|
356 |
+
header.pointer_format)
|
357 |
+
write_array(fid, m.indices+1, header.indices_nlines,
|
358 |
+
header.indices_format)
|
359 |
+
write_array(fid, m.data, header.values_nlines,
|
360 |
+
header.values_format)
|
361 |
+
|
362 |
+
|
363 |
+
class HBMatrixType:
|
364 |
+
"""Class to hold the matrix type."""
|
365 |
+
# q2f* translates qualified names to Fortran character
|
366 |
+
_q2f_type = {
|
367 |
+
"real": "R",
|
368 |
+
"complex": "C",
|
369 |
+
"pattern": "P",
|
370 |
+
"integer": "I",
|
371 |
+
}
|
372 |
+
_q2f_structure = {
|
373 |
+
"symmetric": "S",
|
374 |
+
"unsymmetric": "U",
|
375 |
+
"hermitian": "H",
|
376 |
+
"skewsymmetric": "Z",
|
377 |
+
"rectangular": "R"
|
378 |
+
}
|
379 |
+
_q2f_storage = {
|
380 |
+
"assembled": "A",
|
381 |
+
"elemental": "E",
|
382 |
+
}
|
383 |
+
|
384 |
+
_f2q_type = {j: i for i, j in _q2f_type.items()}
|
385 |
+
_f2q_structure = {j: i for i, j in _q2f_structure.items()}
|
386 |
+
_f2q_storage = {j: i for i, j in _q2f_storage.items()}
|
387 |
+
|
388 |
+
@classmethod
|
389 |
+
def from_fortran(cls, fmt):
|
390 |
+
if not len(fmt) == 3:
|
391 |
+
raise ValueError("Fortran format for matrix type should be 3 "
|
392 |
+
"characters long")
|
393 |
+
try:
|
394 |
+
value_type = cls._f2q_type[fmt[0]]
|
395 |
+
structure = cls._f2q_structure[fmt[1]]
|
396 |
+
storage = cls._f2q_storage[fmt[2]]
|
397 |
+
return cls(value_type, structure, storage)
|
398 |
+
except KeyError as e:
|
399 |
+
raise ValueError("Unrecognized format %s" % fmt) from e
|
400 |
+
|
401 |
+
def __init__(self, value_type, structure, storage="assembled"):
|
402 |
+
self.value_type = value_type
|
403 |
+
self.structure = structure
|
404 |
+
self.storage = storage
|
405 |
+
|
406 |
+
if value_type not in self._q2f_type:
|
407 |
+
raise ValueError("Unrecognized type %s" % value_type)
|
408 |
+
if structure not in self._q2f_structure:
|
409 |
+
raise ValueError("Unrecognized structure %s" % structure)
|
410 |
+
if storage not in self._q2f_storage:
|
411 |
+
raise ValueError("Unrecognized storage %s" % storage)
|
412 |
+
|
413 |
+
@property
|
414 |
+
def fortran_format(self):
|
415 |
+
return self._q2f_type[self.value_type] + \
|
416 |
+
self._q2f_structure[self.structure] + \
|
417 |
+
self._q2f_storage[self.storage]
|
418 |
+
|
419 |
+
def __repr__(self):
|
420 |
+
return f"HBMatrixType({self.value_type}, {self.structure}, {self.storage})"
|
421 |
+
|
422 |
+
|
423 |
+
class HBFile:
|
424 |
+
def __init__(self, file, hb_info=None):
|
425 |
+
"""Create a HBFile instance.
|
426 |
+
|
427 |
+
Parameters
|
428 |
+
----------
|
429 |
+
file : file-object
|
430 |
+
StringIO work as well
|
431 |
+
hb_info : HBInfo, optional
|
432 |
+
Should be given as an argument for writing, in which case the file
|
433 |
+
should be writable.
|
434 |
+
"""
|
435 |
+
self._fid = file
|
436 |
+
if hb_info is None:
|
437 |
+
self._hb_info = HBInfo.from_file(file)
|
438 |
+
else:
|
439 |
+
#raise OSError("file %s is not writable, and hb_info "
|
440 |
+
# "was given." % file)
|
441 |
+
self._hb_info = hb_info
|
442 |
+
|
443 |
+
@property
|
444 |
+
def title(self):
|
445 |
+
return self._hb_info.title
|
446 |
+
|
447 |
+
@property
|
448 |
+
def key(self):
|
449 |
+
return self._hb_info.key
|
450 |
+
|
451 |
+
@property
|
452 |
+
def type(self):
|
453 |
+
return self._hb_info.mxtype.value_type
|
454 |
+
|
455 |
+
@property
|
456 |
+
def structure(self):
|
457 |
+
return self._hb_info.mxtype.structure
|
458 |
+
|
459 |
+
@property
|
460 |
+
def storage(self):
|
461 |
+
return self._hb_info.mxtype.storage
|
462 |
+
|
463 |
+
def read_matrix(self):
|
464 |
+
return _read_hb_data(self._fid, self._hb_info)
|
465 |
+
|
466 |
+
def write_matrix(self, m):
|
467 |
+
return _write_data(m, self._fid, self._hb_info)
|
468 |
+
|
469 |
+
|
470 |
+
def hb_read(path_or_open_file):
|
471 |
+
"""Read HB-format file.
|
472 |
+
|
473 |
+
Parameters
|
474 |
+
----------
|
475 |
+
path_or_open_file : path-like or file-like
|
476 |
+
If a file-like object, it is used as-is. Otherwise, it is opened
|
477 |
+
before reading.
|
478 |
+
|
479 |
+
Returns
|
480 |
+
-------
|
481 |
+
data : scipy.sparse.csc_matrix instance
|
482 |
+
The data read from the HB file as a sparse matrix.
|
483 |
+
|
484 |
+
Notes
|
485 |
+
-----
|
486 |
+
At the moment not the full Harwell-Boeing format is supported. Supported
|
487 |
+
features are:
|
488 |
+
|
489 |
+
- assembled, non-symmetric, real matrices
|
490 |
+
- integer for pointer/indices
|
491 |
+
- exponential format for float values, and int format
|
492 |
+
|
493 |
+
Examples
|
494 |
+
--------
|
495 |
+
We can read and write a harwell-boeing format file:
|
496 |
+
|
497 |
+
>>> from scipy.io import hb_read, hb_write
|
498 |
+
>>> from scipy.sparse import csr_matrix, eye
|
499 |
+
>>> data = csr_matrix(eye(3)) # create a sparse matrix
|
500 |
+
>>> hb_write("data.hb", data) # write a hb file
|
501 |
+
>>> print(hb_read("data.hb")) # read a hb file
|
502 |
+
(0, 0) 1.0
|
503 |
+
(1, 1) 1.0
|
504 |
+
(2, 2) 1.0
|
505 |
+
|
506 |
+
"""
|
507 |
+
def _get_matrix(fid):
|
508 |
+
hb = HBFile(fid)
|
509 |
+
return hb.read_matrix()
|
510 |
+
|
511 |
+
if hasattr(path_or_open_file, 'read'):
|
512 |
+
return _get_matrix(path_or_open_file)
|
513 |
+
else:
|
514 |
+
with open(path_or_open_file) as f:
|
515 |
+
return _get_matrix(f)
|
516 |
+
|
517 |
+
|
518 |
+
def hb_write(path_or_open_file, m, hb_info=None):
|
519 |
+
"""Write HB-format file.
|
520 |
+
|
521 |
+
Parameters
|
522 |
+
----------
|
523 |
+
path_or_open_file : path-like or file-like
|
524 |
+
If a file-like object, it is used as-is. Otherwise, it is opened
|
525 |
+
before writing.
|
526 |
+
m : sparse-matrix
|
527 |
+
the sparse matrix to write
|
528 |
+
hb_info : HBInfo
|
529 |
+
contains the meta-data for write
|
530 |
+
|
531 |
+
Returns
|
532 |
+
-------
|
533 |
+
None
|
534 |
+
|
535 |
+
Notes
|
536 |
+
-----
|
537 |
+
At the moment not the full Harwell-Boeing format is supported. Supported
|
538 |
+
features are:
|
539 |
+
|
540 |
+
- assembled, non-symmetric, real matrices
|
541 |
+
- integer for pointer/indices
|
542 |
+
- exponential format for float values, and int format
|
543 |
+
|
544 |
+
Examples
|
545 |
+
--------
|
546 |
+
We can read and write a harwell-boeing format file:
|
547 |
+
|
548 |
+
>>> from scipy.io import hb_read, hb_write
|
549 |
+
>>> from scipy.sparse import csr_matrix, eye
|
550 |
+
>>> data = csr_matrix(eye(3)) # create a sparse matrix
|
551 |
+
>>> hb_write("data.hb", data) # write a hb file
|
552 |
+
>>> print(hb_read("data.hb")) # read a hb file
|
553 |
+
(0, 0) 1.0
|
554 |
+
(1, 1) 1.0
|
555 |
+
(2, 2) 1.0
|
556 |
+
|
557 |
+
"""
|
558 |
+
m = m.tocsc(copy=False)
|
559 |
+
|
560 |
+
if hb_info is None:
|
561 |
+
hb_info = HBInfo.from_data(m)
|
562 |
+
|
563 |
+
def _set_matrix(fid):
|
564 |
+
hb = HBFile(fid, hb_info)
|
565 |
+
return hb.write_matrix(m)
|
566 |
+
|
567 |
+
if hasattr(path_or_open_file, 'write'):
|
568 |
+
return _set_matrix(path_or_open_file)
|
569 |
+
else:
|
570 |
+
with open(path_or_open_file, 'w') as f:
|
571 |
+
return _set_matrix(f)
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/__init__.py
ADDED
File without changes
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (198 Bytes). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/__pycache__/test_fortran_format.cpython-310.pyc
ADDED
Binary file (4.26 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/__pycache__/test_hb.cpython-310.pyc
ADDED
Binary file (2.93 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/test_fortran_format.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
|
3 |
+
from numpy.testing import assert_equal
|
4 |
+
from pytest import raises as assert_raises
|
5 |
+
|
6 |
+
from scipy.io._harwell_boeing import (
|
7 |
+
FortranFormatParser, IntFormat, ExpFormat, BadFortranFormat)
|
8 |
+
|
9 |
+
|
10 |
+
class TestFortranFormatParser:
|
11 |
+
def setup_method(self):
|
12 |
+
self.parser = FortranFormatParser()
|
13 |
+
|
14 |
+
def _test_equal(self, format, ref):
|
15 |
+
ret = self.parser.parse(format)
|
16 |
+
assert_equal(ret.__dict__, ref.__dict__)
|
17 |
+
|
18 |
+
def test_simple_int(self):
|
19 |
+
self._test_equal("(I4)", IntFormat(4))
|
20 |
+
|
21 |
+
def test_simple_repeated_int(self):
|
22 |
+
self._test_equal("(3I4)", IntFormat(4, repeat=3))
|
23 |
+
|
24 |
+
def test_simple_exp(self):
|
25 |
+
self._test_equal("(E4.3)", ExpFormat(4, 3))
|
26 |
+
|
27 |
+
def test_exp_exp(self):
|
28 |
+
self._test_equal("(E8.3E3)", ExpFormat(8, 3, 3))
|
29 |
+
|
30 |
+
def test_repeat_exp(self):
|
31 |
+
self._test_equal("(2E4.3)", ExpFormat(4, 3, repeat=2))
|
32 |
+
|
33 |
+
def test_repeat_exp_exp(self):
|
34 |
+
self._test_equal("(2E8.3E3)", ExpFormat(8, 3, 3, repeat=2))
|
35 |
+
|
36 |
+
def test_wrong_formats(self):
|
37 |
+
def _test_invalid(bad_format):
|
38 |
+
assert_raises(BadFortranFormat, lambda: self.parser.parse(bad_format))
|
39 |
+
_test_invalid("I4")
|
40 |
+
_test_invalid("(E4)")
|
41 |
+
_test_invalid("(E4.)")
|
42 |
+
_test_invalid("(E4.E3)")
|
43 |
+
|
44 |
+
|
45 |
+
class TestIntFormat:
|
46 |
+
def test_to_fortran(self):
|
47 |
+
f = [IntFormat(10), IntFormat(12, 10), IntFormat(12, 10, 3)]
|
48 |
+
res = ["(I10)", "(I12.10)", "(3I12.10)"]
|
49 |
+
|
50 |
+
for i, j in zip(f, res):
|
51 |
+
assert_equal(i.fortran_format, j)
|
52 |
+
|
53 |
+
def test_from_number(self):
|
54 |
+
f = [10, -12, 123456789]
|
55 |
+
r_f = [IntFormat(3, repeat=26), IntFormat(4, repeat=20),
|
56 |
+
IntFormat(10, repeat=8)]
|
57 |
+
for i, j in zip(f, r_f):
|
58 |
+
assert_equal(IntFormat.from_number(i).__dict__, j.__dict__)
|
59 |
+
|
60 |
+
|
61 |
+
class TestExpFormat:
|
62 |
+
def test_to_fortran(self):
|
63 |
+
f = [ExpFormat(10, 5), ExpFormat(12, 10), ExpFormat(12, 10, min=3),
|
64 |
+
ExpFormat(10, 5, repeat=3)]
|
65 |
+
res = ["(E10.5)", "(E12.10)", "(E12.10E3)", "(3E10.5)"]
|
66 |
+
|
67 |
+
for i, j in zip(f, res):
|
68 |
+
assert_equal(i.fortran_format, j)
|
69 |
+
|
70 |
+
def test_from_number(self):
|
71 |
+
f = np.array([1.0, -1.2])
|
72 |
+
r_f = [ExpFormat(24, 16, repeat=3), ExpFormat(25, 16, repeat=3)]
|
73 |
+
for i, j in zip(f, r_f):
|
74 |
+
assert_equal(ExpFormat.from_number(i).__dict__, j.__dict__)
|
venv/lib/python3.10/site-packages/scipy/io/_harwell_boeing/tests/test_hb.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from io import StringIO
|
2 |
+
import tempfile
|
3 |
+
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
from numpy.testing import assert_equal, \
|
7 |
+
assert_array_almost_equal_nulp
|
8 |
+
|
9 |
+
from scipy.sparse import coo_matrix, csc_matrix, rand
|
10 |
+
|
11 |
+
from scipy.io import hb_read, hb_write
|
12 |
+
|
13 |
+
|
14 |
+
SIMPLE = """\
|
15 |
+
No Title |No Key
|
16 |
+
9 4 1 4
|
17 |
+
RUA 100 100 10 0
|
18 |
+
(26I3) (26I3) (3E23.15)
|
19 |
+
1 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
|
20 |
+
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
|
21 |
+
3 3 3 3 3 3 3 4 4 4 6 6 6 6 6 6 6 6 6 6 6 8 9 9 9 9
|
22 |
+
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11
|
23 |
+
37 71 89 18 30 45 70 19 25 52
|
24 |
+
2.971243799687726e-01 3.662366682877375e-01 4.786962174699534e-01
|
25 |
+
6.490068647991184e-01 6.617490424831662e-02 8.870370343191623e-01
|
26 |
+
4.196478590163001e-01 5.649603072111251e-01 9.934423887087086e-01
|
27 |
+
6.912334991524289e-01
|
28 |
+
"""
|
29 |
+
|
30 |
+
SIMPLE_MATRIX = coo_matrix(
|
31 |
+
((0.297124379969, 0.366236668288, 0.47869621747, 0.649006864799,
|
32 |
+
0.0661749042483, 0.887037034319, 0.419647859016,
|
33 |
+
0.564960307211, 0.993442388709, 0.691233499152,),
|
34 |
+
(np.array([[36, 70, 88, 17, 29, 44, 69, 18, 24, 51],
|
35 |
+
[0, 4, 58, 61, 61, 72, 72, 73, 99, 99]]))))
|
36 |
+
|
37 |
+
|
38 |
+
def assert_csc_almost_equal(r, l):
|
39 |
+
r = csc_matrix(r)
|
40 |
+
l = csc_matrix(l)
|
41 |
+
assert_equal(r.indptr, l.indptr)
|
42 |
+
assert_equal(r.indices, l.indices)
|
43 |
+
assert_array_almost_equal_nulp(r.data, l.data, 10000)
|
44 |
+
|
45 |
+
|
46 |
+
class TestHBReader:
|
47 |
+
def test_simple(self):
|
48 |
+
m = hb_read(StringIO(SIMPLE))
|
49 |
+
assert_csc_almost_equal(m, SIMPLE_MATRIX)
|
50 |
+
|
51 |
+
|
52 |
+
class TestHBReadWrite:
|
53 |
+
|
54 |
+
def check_save_load(self, value):
|
55 |
+
with tempfile.NamedTemporaryFile(mode='w+t') as file:
|
56 |
+
hb_write(file, value)
|
57 |
+
file.file.seek(0)
|
58 |
+
value_loaded = hb_read(file)
|
59 |
+
assert_csc_almost_equal(value, value_loaded)
|
60 |
+
|
61 |
+
def test_simple(self):
|
62 |
+
random_matrix = rand(10, 100, 0.1)
|
63 |
+
for matrix_format in ('coo', 'csc', 'csr', 'bsr', 'dia', 'dok', 'lil'):
|
64 |
+
matrix = random_matrix.asformat(matrix_format, copy=False)
|
65 |
+
self.check_save_load(matrix)
|
venv/lib/python3.10/site-packages/scipy/io/arff/__init__.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Module to read ARFF files
|
3 |
+
=========================
|
4 |
+
ARFF is the standard data format for WEKA.
|
5 |
+
It is a text file format which support numerical, string and data values.
|
6 |
+
The format can also represent missing data and sparse data.
|
7 |
+
|
8 |
+
Notes
|
9 |
+
-----
|
10 |
+
The ARFF support in ``scipy.io`` provides file reading functionality only.
|
11 |
+
For more extensive ARFF functionality, see `liac-arff
|
12 |
+
<https://github.com/renatopp/liac-arff>`_.
|
13 |
+
|
14 |
+
See the `WEKA website <http://weka.wikispaces.com/ARFF>`_
|
15 |
+
for more details about the ARFF format and available datasets.
|
16 |
+
|
17 |
+
"""
|
18 |
+
from ._arffread import *
|
19 |
+
from . import _arffread
|
20 |
+
|
21 |
+
# Deprecated namespaces, to be removed in v2.0.0
|
22 |
+
from .import arffread
|
23 |
+
|
24 |
+
__all__ = _arffread.__all__ + ['arffread']
|
25 |
+
|
26 |
+
from scipy._lib._testutils import PytestTester
|
27 |
+
test = PytestTester(__name__)
|
28 |
+
del PytestTester
|
venv/lib/python3.10/site-packages/scipy/io/arff/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (940 Bytes). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/arff/__pycache__/_arffread.cpython-310.pyc
ADDED
Binary file (22.7 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/arff/__pycache__/arffread.cpython-310.pyc
ADDED
Binary file (1.12 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/arff/_arffread.py
ADDED
@@ -0,0 +1,907 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Last Change: Mon Aug 20 08:00 PM 2007 J
|
2 |
+
import re
|
3 |
+
import datetime
|
4 |
+
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
import csv
|
8 |
+
import ctypes
|
9 |
+
|
10 |
+
"""A module to read arff files."""
|
11 |
+
|
12 |
+
__all__ = ['MetaData', 'loadarff', 'ArffError', 'ParseArffError']
|
13 |
+
|
14 |
+
# An Arff file is basically two parts:
|
15 |
+
# - header
|
16 |
+
# - data
|
17 |
+
#
|
18 |
+
# A header has each of its components starting by @META where META is one of
|
19 |
+
# the keyword (attribute of relation, for now).
|
20 |
+
|
21 |
+
# TODO:
|
22 |
+
# - both integer and reals are treated as numeric -> the integer info
|
23 |
+
# is lost!
|
24 |
+
# - Replace ValueError by ParseError or something
|
25 |
+
|
26 |
+
# We know can handle the following:
|
27 |
+
# - numeric and nominal attributes
|
28 |
+
# - missing values for numeric attributes
|
29 |
+
|
30 |
+
r_meta = re.compile(r'^\s*@')
|
31 |
+
# Match a comment
|
32 |
+
r_comment = re.compile(r'^%')
|
33 |
+
# Match an empty line
|
34 |
+
r_empty = re.compile(r'^\s+$')
|
35 |
+
# Match a header line, that is a line which starts by @ + a word
|
36 |
+
r_headerline = re.compile(r'^\s*@\S*')
|
37 |
+
r_datameta = re.compile(r'^@[Dd][Aa][Tt][Aa]')
|
38 |
+
r_relation = re.compile(r'^@[Rr][Ee][Ll][Aa][Tt][Ii][Oo][Nn]\s*(\S*)')
|
39 |
+
r_attribute = re.compile(r'^\s*@[Aa][Tt][Tt][Rr][Ii][Bb][Uu][Tt][Ee]\s*(..*$)')
|
40 |
+
|
41 |
+
r_nominal = re.compile(r'{(.+)}')
|
42 |
+
r_date = re.compile(r"[Dd][Aa][Tt][Ee]\s+[\"']?(.+?)[\"']?$")
|
43 |
+
|
44 |
+
# To get attributes name enclosed with ''
|
45 |
+
r_comattrval = re.compile(r"'(..+)'\s+(..+$)")
|
46 |
+
# To get normal attributes
|
47 |
+
r_wcomattrval = re.compile(r"(\S+)\s+(..+$)")
|
48 |
+
|
49 |
+
# ------------------------
|
50 |
+
# Module defined exception
|
51 |
+
# ------------------------
|
52 |
+
|
53 |
+
|
54 |
+
class ArffError(OSError):
|
55 |
+
pass
|
56 |
+
|
57 |
+
|
58 |
+
class ParseArffError(ArffError):
|
59 |
+
pass
|
60 |
+
|
61 |
+
|
62 |
+
# ----------
|
63 |
+
# Attributes
|
64 |
+
# ----------
|
65 |
+
class Attribute:
|
66 |
+
|
67 |
+
type_name = None
|
68 |
+
|
69 |
+
def __init__(self, name):
|
70 |
+
self.name = name
|
71 |
+
self.range = None
|
72 |
+
self.dtype = np.object_
|
73 |
+
|
74 |
+
@classmethod
|
75 |
+
def parse_attribute(cls, name, attr_string):
|
76 |
+
"""
|
77 |
+
Parse the attribute line if it knows how. Returns the parsed
|
78 |
+
attribute, or None.
|
79 |
+
"""
|
80 |
+
return None
|
81 |
+
|
82 |
+
def parse_data(self, data_str):
|
83 |
+
"""
|
84 |
+
Parse a value of this type.
|
85 |
+
"""
|
86 |
+
return None
|
87 |
+
|
88 |
+
def __str__(self):
|
89 |
+
"""
|
90 |
+
Parse a value of this type.
|
91 |
+
"""
|
92 |
+
return self.name + ',' + self.type_name
|
93 |
+
|
94 |
+
|
95 |
+
class NominalAttribute(Attribute):
|
96 |
+
|
97 |
+
type_name = 'nominal'
|
98 |
+
|
99 |
+
def __init__(self, name, values):
|
100 |
+
super().__init__(name)
|
101 |
+
self.values = values
|
102 |
+
self.range = values
|
103 |
+
self.dtype = (np.bytes_, max(len(i) for i in values))
|
104 |
+
|
105 |
+
@staticmethod
|
106 |
+
def _get_nom_val(atrv):
|
107 |
+
"""Given a string containing a nominal type, returns a tuple of the
|
108 |
+
possible values.
|
109 |
+
|
110 |
+
A nominal type is defined as something framed between braces ({}).
|
111 |
+
|
112 |
+
Parameters
|
113 |
+
----------
|
114 |
+
atrv : str
|
115 |
+
Nominal type definition
|
116 |
+
|
117 |
+
Returns
|
118 |
+
-------
|
119 |
+
poss_vals : tuple
|
120 |
+
possible values
|
121 |
+
|
122 |
+
Examples
|
123 |
+
--------
|
124 |
+
>>> from scipy.io.arff._arffread import NominalAttribute
|
125 |
+
>>> NominalAttribute._get_nom_val("{floup, bouga, fl, ratata}")
|
126 |
+
('floup', 'bouga', 'fl', 'ratata')
|
127 |
+
"""
|
128 |
+
m = r_nominal.match(atrv)
|
129 |
+
if m:
|
130 |
+
attrs, _ = split_data_line(m.group(1))
|
131 |
+
return tuple(attrs)
|
132 |
+
else:
|
133 |
+
raise ValueError("This does not look like a nominal string")
|
134 |
+
|
135 |
+
@classmethod
|
136 |
+
def parse_attribute(cls, name, attr_string):
|
137 |
+
"""
|
138 |
+
Parse the attribute line if it knows how. Returns the parsed
|
139 |
+
attribute, or None.
|
140 |
+
|
141 |
+
For nominal attributes, the attribute string would be like '{<attr_1>,
|
142 |
+
<attr2>, <attr_3>}'.
|
143 |
+
"""
|
144 |
+
if attr_string[0] == '{':
|
145 |
+
values = cls._get_nom_val(attr_string)
|
146 |
+
return cls(name, values)
|
147 |
+
else:
|
148 |
+
return None
|
149 |
+
|
150 |
+
def parse_data(self, data_str):
|
151 |
+
"""
|
152 |
+
Parse a value of this type.
|
153 |
+
"""
|
154 |
+
if data_str in self.values:
|
155 |
+
return data_str
|
156 |
+
elif data_str == '?':
|
157 |
+
return data_str
|
158 |
+
else:
|
159 |
+
raise ValueError(f"{str(data_str)} value not in {str(self.values)}")
|
160 |
+
|
161 |
+
def __str__(self):
|
162 |
+
msg = self.name + ",{"
|
163 |
+
for i in range(len(self.values)-1):
|
164 |
+
msg += self.values[i] + ","
|
165 |
+
msg += self.values[-1]
|
166 |
+
msg += "}"
|
167 |
+
return msg
|
168 |
+
|
169 |
+
|
170 |
+
class NumericAttribute(Attribute):
|
171 |
+
|
172 |
+
def __init__(self, name):
|
173 |
+
super().__init__(name)
|
174 |
+
self.type_name = 'numeric'
|
175 |
+
self.dtype = np.float64
|
176 |
+
|
177 |
+
@classmethod
|
178 |
+
def parse_attribute(cls, name, attr_string):
|
179 |
+
"""
|
180 |
+
Parse the attribute line if it knows how. Returns the parsed
|
181 |
+
attribute, or None.
|
182 |
+
|
183 |
+
For numeric attributes, the attribute string would be like
|
184 |
+
'numeric' or 'int' or 'real'.
|
185 |
+
"""
|
186 |
+
|
187 |
+
attr_string = attr_string.lower().strip()
|
188 |
+
|
189 |
+
if (attr_string[:len('numeric')] == 'numeric' or
|
190 |
+
attr_string[:len('int')] == 'int' or
|
191 |
+
attr_string[:len('real')] == 'real'):
|
192 |
+
return cls(name)
|
193 |
+
else:
|
194 |
+
return None
|
195 |
+
|
196 |
+
def parse_data(self, data_str):
|
197 |
+
"""
|
198 |
+
Parse a value of this type.
|
199 |
+
|
200 |
+
Parameters
|
201 |
+
----------
|
202 |
+
data_str : str
|
203 |
+
string to convert
|
204 |
+
|
205 |
+
Returns
|
206 |
+
-------
|
207 |
+
f : float
|
208 |
+
where float can be nan
|
209 |
+
|
210 |
+
Examples
|
211 |
+
--------
|
212 |
+
>>> from scipy.io.arff._arffread import NumericAttribute
|
213 |
+
>>> atr = NumericAttribute('atr')
|
214 |
+
>>> atr.parse_data('1')
|
215 |
+
1.0
|
216 |
+
>>> atr.parse_data('1\\n')
|
217 |
+
1.0
|
218 |
+
>>> atr.parse_data('?\\n')
|
219 |
+
nan
|
220 |
+
"""
|
221 |
+
if '?' in data_str:
|
222 |
+
return np.nan
|
223 |
+
else:
|
224 |
+
return float(data_str)
|
225 |
+
|
226 |
+
def _basic_stats(self, data):
|
227 |
+
nbfac = data.size * 1. / (data.size - 1)
|
228 |
+
return (np.nanmin(data), np.nanmax(data),
|
229 |
+
np.mean(data), np.std(data) * nbfac)
|
230 |
+
|
231 |
+
|
232 |
+
class StringAttribute(Attribute):
|
233 |
+
|
234 |
+
def __init__(self, name):
|
235 |
+
super().__init__(name)
|
236 |
+
self.type_name = 'string'
|
237 |
+
|
238 |
+
@classmethod
|
239 |
+
def parse_attribute(cls, name, attr_string):
|
240 |
+
"""
|
241 |
+
Parse the attribute line if it knows how. Returns the parsed
|
242 |
+
attribute, or None.
|
243 |
+
|
244 |
+
For string attributes, the attribute string would be like
|
245 |
+
'string'.
|
246 |
+
"""
|
247 |
+
|
248 |
+
attr_string = attr_string.lower().strip()
|
249 |
+
|
250 |
+
if attr_string[:len('string')] == 'string':
|
251 |
+
return cls(name)
|
252 |
+
else:
|
253 |
+
return None
|
254 |
+
|
255 |
+
|
256 |
+
class DateAttribute(Attribute):
|
257 |
+
|
258 |
+
def __init__(self, name, date_format, datetime_unit):
|
259 |
+
super().__init__(name)
|
260 |
+
self.date_format = date_format
|
261 |
+
self.datetime_unit = datetime_unit
|
262 |
+
self.type_name = 'date'
|
263 |
+
self.range = date_format
|
264 |
+
self.dtype = np.datetime64(0, self.datetime_unit)
|
265 |
+
|
266 |
+
@staticmethod
|
267 |
+
def _get_date_format(atrv):
|
268 |
+
m = r_date.match(atrv)
|
269 |
+
if m:
|
270 |
+
pattern = m.group(1).strip()
|
271 |
+
# convert time pattern from Java's SimpleDateFormat to C's format
|
272 |
+
datetime_unit = None
|
273 |
+
if "yyyy" in pattern:
|
274 |
+
pattern = pattern.replace("yyyy", "%Y")
|
275 |
+
datetime_unit = "Y"
|
276 |
+
elif "yy":
|
277 |
+
pattern = pattern.replace("yy", "%y")
|
278 |
+
datetime_unit = "Y"
|
279 |
+
if "MM" in pattern:
|
280 |
+
pattern = pattern.replace("MM", "%m")
|
281 |
+
datetime_unit = "M"
|
282 |
+
if "dd" in pattern:
|
283 |
+
pattern = pattern.replace("dd", "%d")
|
284 |
+
datetime_unit = "D"
|
285 |
+
if "HH" in pattern:
|
286 |
+
pattern = pattern.replace("HH", "%H")
|
287 |
+
datetime_unit = "h"
|
288 |
+
if "mm" in pattern:
|
289 |
+
pattern = pattern.replace("mm", "%M")
|
290 |
+
datetime_unit = "m"
|
291 |
+
if "ss" in pattern:
|
292 |
+
pattern = pattern.replace("ss", "%S")
|
293 |
+
datetime_unit = "s"
|
294 |
+
if "z" in pattern or "Z" in pattern:
|
295 |
+
raise ValueError("Date type attributes with time zone not "
|
296 |
+
"supported, yet")
|
297 |
+
|
298 |
+
if datetime_unit is None:
|
299 |
+
raise ValueError("Invalid or unsupported date format")
|
300 |
+
|
301 |
+
return pattern, datetime_unit
|
302 |
+
else:
|
303 |
+
raise ValueError("Invalid or no date format")
|
304 |
+
|
305 |
+
@classmethod
|
306 |
+
def parse_attribute(cls, name, attr_string):
|
307 |
+
"""
|
308 |
+
Parse the attribute line if it knows how. Returns the parsed
|
309 |
+
attribute, or None.
|
310 |
+
|
311 |
+
For date attributes, the attribute string would be like
|
312 |
+
'date <format>'.
|
313 |
+
"""
|
314 |
+
|
315 |
+
attr_string_lower = attr_string.lower().strip()
|
316 |
+
|
317 |
+
if attr_string_lower[:len('date')] == 'date':
|
318 |
+
date_format, datetime_unit = cls._get_date_format(attr_string)
|
319 |
+
return cls(name, date_format, datetime_unit)
|
320 |
+
else:
|
321 |
+
return None
|
322 |
+
|
323 |
+
def parse_data(self, data_str):
|
324 |
+
"""
|
325 |
+
Parse a value of this type.
|
326 |
+
"""
|
327 |
+
date_str = data_str.strip().strip("'").strip('"')
|
328 |
+
if date_str == '?':
|
329 |
+
return np.datetime64('NaT', self.datetime_unit)
|
330 |
+
else:
|
331 |
+
dt = datetime.datetime.strptime(date_str, self.date_format)
|
332 |
+
return np.datetime64(dt).astype(
|
333 |
+
"datetime64[%s]" % self.datetime_unit)
|
334 |
+
|
335 |
+
def __str__(self):
|
336 |
+
return super().__str__() + ',' + self.date_format
|
337 |
+
|
338 |
+
|
339 |
+
class RelationalAttribute(Attribute):
|
340 |
+
|
341 |
+
def __init__(self, name):
|
342 |
+
super().__init__(name)
|
343 |
+
self.type_name = 'relational'
|
344 |
+
self.dtype = np.object_
|
345 |
+
self.attributes = []
|
346 |
+
self.dialect = None
|
347 |
+
|
348 |
+
@classmethod
|
349 |
+
def parse_attribute(cls, name, attr_string):
|
350 |
+
"""
|
351 |
+
Parse the attribute line if it knows how. Returns the parsed
|
352 |
+
attribute, or None.
|
353 |
+
|
354 |
+
For date attributes, the attribute string would be like
|
355 |
+
'date <format>'.
|
356 |
+
"""
|
357 |
+
|
358 |
+
attr_string_lower = attr_string.lower().strip()
|
359 |
+
|
360 |
+
if attr_string_lower[:len('relational')] == 'relational':
|
361 |
+
return cls(name)
|
362 |
+
else:
|
363 |
+
return None
|
364 |
+
|
365 |
+
def parse_data(self, data_str):
|
366 |
+
# Copy-pasted
|
367 |
+
elems = list(range(len(self.attributes)))
|
368 |
+
|
369 |
+
escaped_string = data_str.encode().decode("unicode-escape")
|
370 |
+
|
371 |
+
row_tuples = []
|
372 |
+
|
373 |
+
for raw in escaped_string.split("\n"):
|
374 |
+
row, self.dialect = split_data_line(raw, self.dialect)
|
375 |
+
|
376 |
+
row_tuples.append(tuple(
|
377 |
+
[self.attributes[i].parse_data(row[i]) for i in elems]))
|
378 |
+
|
379 |
+
return np.array(row_tuples,
|
380 |
+
[(a.name, a.dtype) for a in self.attributes])
|
381 |
+
|
382 |
+
def __str__(self):
|
383 |
+
return (super().__str__() + '\n\t' +
|
384 |
+
'\n\t'.join(str(a) for a in self.attributes))
|
385 |
+
|
386 |
+
|
387 |
+
# -----------------
|
388 |
+
# Various utilities
|
389 |
+
# -----------------
|
390 |
+
def to_attribute(name, attr_string):
|
391 |
+
attr_classes = (NominalAttribute, NumericAttribute, DateAttribute,
|
392 |
+
StringAttribute, RelationalAttribute)
|
393 |
+
|
394 |
+
for cls in attr_classes:
|
395 |
+
attr = cls.parse_attribute(name, attr_string)
|
396 |
+
if attr is not None:
|
397 |
+
return attr
|
398 |
+
|
399 |
+
raise ParseArffError("unknown attribute %s" % attr_string)
|
400 |
+
|
401 |
+
|
402 |
+
def csv_sniffer_has_bug_last_field():
|
403 |
+
"""
|
404 |
+
Checks if the bug https://bugs.python.org/issue30157 is unpatched.
|
405 |
+
"""
|
406 |
+
|
407 |
+
# We only compute this once.
|
408 |
+
has_bug = getattr(csv_sniffer_has_bug_last_field, "has_bug", None)
|
409 |
+
|
410 |
+
if has_bug is None:
|
411 |
+
dialect = csv.Sniffer().sniff("3, 'a'")
|
412 |
+
csv_sniffer_has_bug_last_field.has_bug = dialect.quotechar != "'"
|
413 |
+
has_bug = csv_sniffer_has_bug_last_field.has_bug
|
414 |
+
|
415 |
+
return has_bug
|
416 |
+
|
417 |
+
|
418 |
+
def workaround_csv_sniffer_bug_last_field(sniff_line, dialect, delimiters):
|
419 |
+
"""
|
420 |
+
Workaround for the bug https://bugs.python.org/issue30157 if is unpatched.
|
421 |
+
"""
|
422 |
+
if csv_sniffer_has_bug_last_field():
|
423 |
+
# Reuses code from the csv module
|
424 |
+
right_regex = r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)' # noqa: E501
|
425 |
+
|
426 |
+
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?", # noqa: E501
|
427 |
+
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # .*?", # noqa: E501
|
428 |
+
right_regex, # ,".*?"
|
429 |
+
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) # noqa: E501
|
430 |
+
regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
|
431 |
+
matches = regexp.findall(sniff_line)
|
432 |
+
if matches:
|
433 |
+
break
|
434 |
+
|
435 |
+
# If it does not match the expression that was bugged,
|
436 |
+
# then this bug does not apply
|
437 |
+
if restr != right_regex:
|
438 |
+
return
|
439 |
+
|
440 |
+
groupindex = regexp.groupindex
|
441 |
+
|
442 |
+
# There is only one end of the string
|
443 |
+
assert len(matches) == 1
|
444 |
+
m = matches[0]
|
445 |
+
|
446 |
+
n = groupindex['quote'] - 1
|
447 |
+
quote = m[n]
|
448 |
+
|
449 |
+
n = groupindex['delim'] - 1
|
450 |
+
delim = m[n]
|
451 |
+
|
452 |
+
n = groupindex['space'] - 1
|
453 |
+
space = bool(m[n])
|
454 |
+
|
455 |
+
dq_regexp = re.compile(
|
456 |
+
rf"(({re.escape(delim)})|^)\W*{quote}[^{re.escape(delim)}\n]*{quote}[^{re.escape(delim)}\n]*{quote}\W*(({re.escape(delim)})|$)", re.MULTILINE # noqa: E501
|
457 |
+
)
|
458 |
+
|
459 |
+
doublequote = bool(dq_regexp.search(sniff_line))
|
460 |
+
|
461 |
+
dialect.quotechar = quote
|
462 |
+
if delim in delimiters:
|
463 |
+
dialect.delimiter = delim
|
464 |
+
dialect.doublequote = doublequote
|
465 |
+
dialect.skipinitialspace = space
|
466 |
+
|
467 |
+
|
468 |
+
def split_data_line(line, dialect=None):
|
469 |
+
delimiters = ",\t"
|
470 |
+
|
471 |
+
# This can not be done in a per reader basis, and relational fields
|
472 |
+
# can be HUGE
|
473 |
+
csv.field_size_limit(int(ctypes.c_ulong(-1).value // 2))
|
474 |
+
|
475 |
+
# Remove the line end if any
|
476 |
+
if line[-1] == '\n':
|
477 |
+
line = line[:-1]
|
478 |
+
|
479 |
+
# Remove potential trailing whitespace
|
480 |
+
line = line.strip()
|
481 |
+
|
482 |
+
sniff_line = line
|
483 |
+
|
484 |
+
# Add a delimiter if none is present, so that the csv.Sniffer
|
485 |
+
# does not complain for a single-field CSV.
|
486 |
+
if not any(d in line for d in delimiters):
|
487 |
+
sniff_line += ","
|
488 |
+
|
489 |
+
if dialect is None:
|
490 |
+
dialect = csv.Sniffer().sniff(sniff_line, delimiters=delimiters)
|
491 |
+
workaround_csv_sniffer_bug_last_field(sniff_line=sniff_line,
|
492 |
+
dialect=dialect,
|
493 |
+
delimiters=delimiters)
|
494 |
+
|
495 |
+
row = next(csv.reader([line], dialect))
|
496 |
+
|
497 |
+
return row, dialect
|
498 |
+
|
499 |
+
|
500 |
+
# --------------
|
501 |
+
# Parsing header
|
502 |
+
# --------------
|
503 |
+
def tokenize_attribute(iterable, attribute):
|
504 |
+
"""Parse a raw string in header (e.g., starts by @attribute).
|
505 |
+
|
506 |
+
Given a raw string attribute, try to get the name and type of the
|
507 |
+
attribute. Constraints:
|
508 |
+
|
509 |
+
* The first line must start with @attribute (case insensitive, and
|
510 |
+
space like characters before @attribute are allowed)
|
511 |
+
* Works also if the attribute is spread on multilines.
|
512 |
+
* Works if empty lines or comments are in between
|
513 |
+
|
514 |
+
Parameters
|
515 |
+
----------
|
516 |
+
attribute : str
|
517 |
+
the attribute string.
|
518 |
+
|
519 |
+
Returns
|
520 |
+
-------
|
521 |
+
name : str
|
522 |
+
name of the attribute
|
523 |
+
value : str
|
524 |
+
value of the attribute
|
525 |
+
next : str
|
526 |
+
next line to be parsed
|
527 |
+
|
528 |
+
Examples
|
529 |
+
--------
|
530 |
+
If attribute is a string defined in python as r"floupi real", will
|
531 |
+
return floupi as name, and real as value.
|
532 |
+
|
533 |
+
>>> from scipy.io.arff._arffread import tokenize_attribute
|
534 |
+
>>> iterable = iter([0] * 10) # dummy iterator
|
535 |
+
>>> tokenize_attribute(iterable, r"@attribute floupi real")
|
536 |
+
('floupi', 'real', 0)
|
537 |
+
|
538 |
+
If attribute is r"'floupi 2' real", will return 'floupi 2' as name,
|
539 |
+
and real as value.
|
540 |
+
|
541 |
+
>>> tokenize_attribute(iterable, r" @attribute 'floupi 2' real ")
|
542 |
+
('floupi 2', 'real', 0)
|
543 |
+
|
544 |
+
"""
|
545 |
+
sattr = attribute.strip()
|
546 |
+
mattr = r_attribute.match(sattr)
|
547 |
+
if mattr:
|
548 |
+
# atrv is everything after @attribute
|
549 |
+
atrv = mattr.group(1)
|
550 |
+
if r_comattrval.match(atrv):
|
551 |
+
name, type = tokenize_single_comma(atrv)
|
552 |
+
next_item = next(iterable)
|
553 |
+
elif r_wcomattrval.match(atrv):
|
554 |
+
name, type = tokenize_single_wcomma(atrv)
|
555 |
+
next_item = next(iterable)
|
556 |
+
else:
|
557 |
+
# Not sure we should support this, as it does not seem supported by
|
558 |
+
# weka.
|
559 |
+
raise ValueError("multi line not supported yet")
|
560 |
+
else:
|
561 |
+
raise ValueError("First line unparsable: %s" % sattr)
|
562 |
+
|
563 |
+
attribute = to_attribute(name, type)
|
564 |
+
|
565 |
+
if type.lower() == 'relational':
|
566 |
+
next_item = read_relational_attribute(iterable, attribute, next_item)
|
567 |
+
# raise ValueError("relational attributes not supported yet")
|
568 |
+
|
569 |
+
return attribute, next_item
|
570 |
+
|
571 |
+
|
572 |
+
def tokenize_single_comma(val):
|
573 |
+
# XXX we match twice the same string (here and at the caller level). It is
|
574 |
+
# stupid, but it is easier for now...
|
575 |
+
m = r_comattrval.match(val)
|
576 |
+
if m:
|
577 |
+
try:
|
578 |
+
name = m.group(1).strip()
|
579 |
+
type = m.group(2).strip()
|
580 |
+
except IndexError as e:
|
581 |
+
raise ValueError("Error while tokenizing attribute") from e
|
582 |
+
else:
|
583 |
+
raise ValueError("Error while tokenizing single %s" % val)
|
584 |
+
return name, type
|
585 |
+
|
586 |
+
|
587 |
+
def tokenize_single_wcomma(val):
|
588 |
+
# XXX we match twice the same string (here and at the caller level). It is
|
589 |
+
# stupid, but it is easier for now...
|
590 |
+
m = r_wcomattrval.match(val)
|
591 |
+
if m:
|
592 |
+
try:
|
593 |
+
name = m.group(1).strip()
|
594 |
+
type = m.group(2).strip()
|
595 |
+
except IndexError as e:
|
596 |
+
raise ValueError("Error while tokenizing attribute") from e
|
597 |
+
else:
|
598 |
+
raise ValueError("Error while tokenizing single %s" % val)
|
599 |
+
return name, type
|
600 |
+
|
601 |
+
|
602 |
+
def read_relational_attribute(ofile, relational_attribute, i):
|
603 |
+
"""Read the nested attributes of a relational attribute"""
|
604 |
+
|
605 |
+
r_end_relational = re.compile(r'^@[Ee][Nn][Dd]\s*' +
|
606 |
+
relational_attribute.name + r'\s*$')
|
607 |
+
|
608 |
+
while not r_end_relational.match(i):
|
609 |
+
m = r_headerline.match(i)
|
610 |
+
if m:
|
611 |
+
isattr = r_attribute.match(i)
|
612 |
+
if isattr:
|
613 |
+
attr, i = tokenize_attribute(ofile, i)
|
614 |
+
relational_attribute.attributes.append(attr)
|
615 |
+
else:
|
616 |
+
raise ValueError("Error parsing line %s" % i)
|
617 |
+
else:
|
618 |
+
i = next(ofile)
|
619 |
+
|
620 |
+
i = next(ofile)
|
621 |
+
return i
|
622 |
+
|
623 |
+
|
624 |
+
def read_header(ofile):
|
625 |
+
"""Read the header of the iterable ofile."""
|
626 |
+
i = next(ofile)
|
627 |
+
|
628 |
+
# Pass first comments
|
629 |
+
while r_comment.match(i):
|
630 |
+
i = next(ofile)
|
631 |
+
|
632 |
+
# Header is everything up to DATA attribute ?
|
633 |
+
relation = None
|
634 |
+
attributes = []
|
635 |
+
while not r_datameta.match(i):
|
636 |
+
m = r_headerline.match(i)
|
637 |
+
if m:
|
638 |
+
isattr = r_attribute.match(i)
|
639 |
+
if isattr:
|
640 |
+
attr, i = tokenize_attribute(ofile, i)
|
641 |
+
attributes.append(attr)
|
642 |
+
else:
|
643 |
+
isrel = r_relation.match(i)
|
644 |
+
if isrel:
|
645 |
+
relation = isrel.group(1)
|
646 |
+
else:
|
647 |
+
raise ValueError("Error parsing line %s" % i)
|
648 |
+
i = next(ofile)
|
649 |
+
else:
|
650 |
+
i = next(ofile)
|
651 |
+
|
652 |
+
return relation, attributes
|
653 |
+
|
654 |
+
|
655 |
+
class MetaData:
|
656 |
+
"""Small container to keep useful information on a ARFF dataset.
|
657 |
+
|
658 |
+
Knows about attributes names and types.
|
659 |
+
|
660 |
+
Examples
|
661 |
+
--------
|
662 |
+
::
|
663 |
+
|
664 |
+
data, meta = loadarff('iris.arff')
|
665 |
+
# This will print the attributes names of the iris.arff dataset
|
666 |
+
for i in meta:
|
667 |
+
print(i)
|
668 |
+
# This works too
|
669 |
+
meta.names()
|
670 |
+
# Getting attribute type
|
671 |
+
types = meta.types()
|
672 |
+
|
673 |
+
Methods
|
674 |
+
-------
|
675 |
+
names
|
676 |
+
types
|
677 |
+
|
678 |
+
Notes
|
679 |
+
-----
|
680 |
+
Also maintains the list of attributes in order, i.e., doing for i in
|
681 |
+
meta, where meta is an instance of MetaData, will return the
|
682 |
+
different attribute names in the order they were defined.
|
683 |
+
"""
|
684 |
+
def __init__(self, rel, attr):
|
685 |
+
self.name = rel
|
686 |
+
self._attributes = {a.name: a for a in attr}
|
687 |
+
|
688 |
+
def __repr__(self):
|
689 |
+
msg = ""
|
690 |
+
msg += "Dataset: %s\n" % self.name
|
691 |
+
for i in self._attributes:
|
692 |
+
msg += f"\t{i}'s type is {self._attributes[i].type_name}"
|
693 |
+
if self._attributes[i].range:
|
694 |
+
msg += ", range is %s" % str(self._attributes[i].range)
|
695 |
+
msg += '\n'
|
696 |
+
return msg
|
697 |
+
|
698 |
+
def __iter__(self):
|
699 |
+
return iter(self._attributes)
|
700 |
+
|
701 |
+
def __getitem__(self, key):
|
702 |
+
attr = self._attributes[key]
|
703 |
+
|
704 |
+
return (attr.type_name, attr.range)
|
705 |
+
|
706 |
+
def names(self):
|
707 |
+
"""Return the list of attribute names.
|
708 |
+
|
709 |
+
Returns
|
710 |
+
-------
|
711 |
+
attrnames : list of str
|
712 |
+
The attribute names.
|
713 |
+
"""
|
714 |
+
return list(self._attributes)
|
715 |
+
|
716 |
+
def types(self):
|
717 |
+
"""Return the list of attribute types.
|
718 |
+
|
719 |
+
Returns
|
720 |
+
-------
|
721 |
+
attr_types : list of str
|
722 |
+
The attribute types.
|
723 |
+
"""
|
724 |
+
attr_types = [self._attributes[name].type_name
|
725 |
+
for name in self._attributes]
|
726 |
+
return attr_types
|
727 |
+
|
728 |
+
|
729 |
+
def loadarff(f):
|
730 |
+
"""
|
731 |
+
Read an arff file.
|
732 |
+
|
733 |
+
The data is returned as a record array, which can be accessed much like
|
734 |
+
a dictionary of NumPy arrays. For example, if one of the attributes is
|
735 |
+
called 'pressure', then its first 10 data points can be accessed from the
|
736 |
+
``data`` record array like so: ``data['pressure'][0:10]``
|
737 |
+
|
738 |
+
|
739 |
+
Parameters
|
740 |
+
----------
|
741 |
+
f : file-like or str
|
742 |
+
File-like object to read from, or filename to open.
|
743 |
+
|
744 |
+
Returns
|
745 |
+
-------
|
746 |
+
data : record array
|
747 |
+
The data of the arff file, accessible by attribute names.
|
748 |
+
meta : `MetaData`
|
749 |
+
Contains information about the arff file such as name and
|
750 |
+
type of attributes, the relation (name of the dataset), etc.
|
751 |
+
|
752 |
+
Raises
|
753 |
+
------
|
754 |
+
ParseArffError
|
755 |
+
This is raised if the given file is not ARFF-formatted.
|
756 |
+
NotImplementedError
|
757 |
+
The ARFF file has an attribute which is not supported yet.
|
758 |
+
|
759 |
+
Notes
|
760 |
+
-----
|
761 |
+
|
762 |
+
This function should be able to read most arff files. Not
|
763 |
+
implemented functionality include:
|
764 |
+
|
765 |
+
* date type attributes
|
766 |
+
* string type attributes
|
767 |
+
|
768 |
+
It can read files with numeric and nominal attributes. It cannot read
|
769 |
+
files with sparse data ({} in the file). However, this function can
|
770 |
+
read files with missing data (? in the file), representing the data
|
771 |
+
points as NaNs.
|
772 |
+
|
773 |
+
Examples
|
774 |
+
--------
|
775 |
+
>>> from scipy.io import arff
|
776 |
+
>>> from io import StringIO
|
777 |
+
>>> content = \"\"\"
|
778 |
+
... @relation foo
|
779 |
+
... @attribute width numeric
|
780 |
+
... @attribute height numeric
|
781 |
+
... @attribute color {red,green,blue,yellow,black}
|
782 |
+
... @data
|
783 |
+
... 5.0,3.25,blue
|
784 |
+
... 4.5,3.75,green
|
785 |
+
... 3.0,4.00,red
|
786 |
+
... \"\"\"
|
787 |
+
>>> f = StringIO(content)
|
788 |
+
>>> data, meta = arff.loadarff(f)
|
789 |
+
>>> data
|
790 |
+
array([(5.0, 3.25, 'blue'), (4.5, 3.75, 'green'), (3.0, 4.0, 'red')],
|
791 |
+
dtype=[('width', '<f8'), ('height', '<f8'), ('color', '|S6')])
|
792 |
+
>>> meta
|
793 |
+
Dataset: foo
|
794 |
+
\twidth's type is numeric
|
795 |
+
\theight's type is numeric
|
796 |
+
\tcolor's type is nominal, range is ('red', 'green', 'blue', 'yellow', 'black')
|
797 |
+
|
798 |
+
"""
|
799 |
+
if hasattr(f, 'read'):
|
800 |
+
ofile = f
|
801 |
+
else:
|
802 |
+
ofile = open(f)
|
803 |
+
try:
|
804 |
+
return _loadarff(ofile)
|
805 |
+
finally:
|
806 |
+
if ofile is not f: # only close what we opened
|
807 |
+
ofile.close()
|
808 |
+
|
809 |
+
|
810 |
+
def _loadarff(ofile):
|
811 |
+
# Parse the header file
|
812 |
+
try:
|
813 |
+
rel, attr = read_header(ofile)
|
814 |
+
except ValueError as e:
|
815 |
+
msg = "Error while parsing header, error was: " + str(e)
|
816 |
+
raise ParseArffError(msg) from e
|
817 |
+
|
818 |
+
# Check whether we have a string attribute (not supported yet)
|
819 |
+
hasstr = False
|
820 |
+
for a in attr:
|
821 |
+
if isinstance(a, StringAttribute):
|
822 |
+
hasstr = True
|
823 |
+
|
824 |
+
meta = MetaData(rel, attr)
|
825 |
+
|
826 |
+
# XXX The following code is not great
|
827 |
+
# Build the type descriptor descr and the list of converters to convert
|
828 |
+
# each attribute to the suitable type (which should match the one in
|
829 |
+
# descr).
|
830 |
+
|
831 |
+
# This can be used once we want to support integer as integer values and
|
832 |
+
# not as numeric anymore (using masked arrays ?).
|
833 |
+
|
834 |
+
if hasstr:
|
835 |
+
# How to support string efficiently ? Ideally, we should know the max
|
836 |
+
# size of the string before allocating the numpy array.
|
837 |
+
raise NotImplementedError("String attributes not supported yet, sorry")
|
838 |
+
|
839 |
+
ni = len(attr)
|
840 |
+
|
841 |
+
def generator(row_iter, delim=','):
|
842 |
+
# TODO: this is where we are spending time (~80%). I think things
|
843 |
+
# could be made more efficiently:
|
844 |
+
# - We could for example "compile" the function, because some values
|
845 |
+
# do not change here.
|
846 |
+
# - The function to convert a line to dtyped values could also be
|
847 |
+
# generated on the fly from a string and be executed instead of
|
848 |
+
# looping.
|
849 |
+
# - The regex are overkill: for comments, checking that a line starts
|
850 |
+
# by % should be enough and faster, and for empty lines, same thing
|
851 |
+
# --> this does not seem to change anything.
|
852 |
+
|
853 |
+
# 'compiling' the range since it does not change
|
854 |
+
# Note, I have already tried zipping the converters and
|
855 |
+
# row elements and got slightly worse performance.
|
856 |
+
elems = list(range(ni))
|
857 |
+
|
858 |
+
dialect = None
|
859 |
+
for raw in row_iter:
|
860 |
+
# We do not abstract skipping comments and empty lines for
|
861 |
+
# performance reasons.
|
862 |
+
if r_comment.match(raw) or r_empty.match(raw):
|
863 |
+
continue
|
864 |
+
|
865 |
+
row, dialect = split_data_line(raw, dialect)
|
866 |
+
|
867 |
+
yield tuple([attr[i].parse_data(row[i]) for i in elems])
|
868 |
+
|
869 |
+
a = list(generator(ofile))
|
870 |
+
# No error should happen here: it is a bug otherwise
|
871 |
+
data = np.array(a, [(a.name, a.dtype) for a in attr])
|
872 |
+
return data, meta
|
873 |
+
|
874 |
+
|
875 |
+
# ----
|
876 |
+
# Misc
|
877 |
+
# ----
|
878 |
+
def basic_stats(data):
|
879 |
+
nbfac = data.size * 1. / (data.size - 1)
|
880 |
+
return np.nanmin(data), np.nanmax(data), np.mean(data), np.std(data) * nbfac
|
881 |
+
|
882 |
+
|
883 |
+
def print_attribute(name, tp, data):
|
884 |
+
type = tp.type_name
|
885 |
+
if type == 'numeric' or type == 'real' or type == 'integer':
|
886 |
+
min, max, mean, std = basic_stats(data)
|
887 |
+
print(f"{name},{type},{min:f},{max:f},{mean:f},{std:f}")
|
888 |
+
else:
|
889 |
+
print(str(tp))
|
890 |
+
|
891 |
+
|
892 |
+
def test_weka(filename):
|
893 |
+
data, meta = loadarff(filename)
|
894 |
+
print(len(data.dtype))
|
895 |
+
print(data.size)
|
896 |
+
for i in meta:
|
897 |
+
print_attribute(i, meta[i], data[i])
|
898 |
+
|
899 |
+
|
900 |
+
# make sure nose does not find this as a test
|
901 |
+
test_weka.__test__ = False
|
902 |
+
|
903 |
+
|
904 |
+
if __name__ == '__main__':
|
905 |
+
import sys
|
906 |
+
filename = sys.argv[1]
|
907 |
+
test_weka(filename)
|
venv/lib/python3.10/site-packages/scipy/io/arff/arffread.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file is not meant for public use and will be removed in SciPy v2.0.0.
|
2 |
+
# Use the `scipy.io.arff` namespace for importing the functions
|
3 |
+
# included below.
|
4 |
+
|
5 |
+
from scipy._lib.deprecation import _sub_module_deprecation
|
6 |
+
|
7 |
+
__all__ = [ # noqa: F822
|
8 |
+
'MetaData', 'loadarff', 'ArffError', 'ParseArffError',
|
9 |
+
'r_meta', 'r_comment', 'r_empty', 'r_headerline',
|
10 |
+
'r_datameta', 'r_relation', 'r_attribute', 'r_nominal',
|
11 |
+
'r_date', 'r_comattrval', 'r_wcomattrval', 'Attribute',
|
12 |
+
'NominalAttribute', 'NumericAttribute', 'StringAttribute',
|
13 |
+
'DateAttribute', 'RelationalAttribute', 'to_attribute',
|
14 |
+
'csv_sniffer_has_bug_last_field', 'workaround_csv_sniffer_bug_last_field',
|
15 |
+
'split_data_line', 'tokenize_attribute', 'tokenize_single_comma',
|
16 |
+
'tokenize_single_wcomma', 'read_relational_attribute', 'read_header',
|
17 |
+
'basic_stats', 'print_attribute', 'test_weka'
|
18 |
+
]
|
19 |
+
|
20 |
+
|
21 |
+
def __dir__():
|
22 |
+
return __all__
|
23 |
+
|
24 |
+
|
25 |
+
def __getattr__(name):
|
26 |
+
return _sub_module_deprecation(sub_package="io.arff", module="arffread",
|
27 |
+
private_modules=["_arffread"], all=__all__,
|
28 |
+
attribute=name)
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/__init__.py
ADDED
File without changes
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (187 Bytes). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/__pycache__/test_arffread.cpython-310.pyc
ADDED
Binary file (12.5 kB). View file
|
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/iris.arff
ADDED
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
% 1. Title: Iris Plants Database
|
2 |
+
%
|
3 |
+
% 2. Sources:
|
4 |
+
% (a) Creator: R.A. Fisher
|
5 |
+
% (b) Donor: Michael Marshall (MARSHALL%[email protected])
|
6 |
+
% (c) Date: July, 1988
|
7 |
+
%
|
8 |
+
% 3. Past Usage:
|
9 |
+
% - Publications: too many to mention!!! Here are a few.
|
10 |
+
% 1. Fisher,R.A. "The use of multiple measurements in taxonomic problems"
|
11 |
+
% Annual Eugenics, 7, Part II, 179-188 (1936); also in "Contributions
|
12 |
+
% to Mathematical Statistics" (John Wiley, NY, 1950).
|
13 |
+
% 2. Duda,R.O., & Hart,P.E. (1973) Pattern Classification and Scene Analysis.
|
14 |
+
% (Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218.
|
15 |
+
% 3. Dasarathy, B.V. (1980) "Nosing Around the Neighborhood: A New System
|
16 |
+
% Structure and Classification Rule for Recognition in Partially Exposed
|
17 |
+
% Environments". IEEE Transactions on Pattern Analysis and Machine
|
18 |
+
% Intelligence, Vol. PAMI-2, No. 1, 67-71.
|
19 |
+
% -- Results:
|
20 |
+
% -- very low misclassification rates (0% for the setosa class)
|
21 |
+
% 4. Gates, G.W. (1972) "The Reduced Nearest Neighbor Rule". IEEE
|
22 |
+
% Transactions on Information Theory, May 1972, 431-433.
|
23 |
+
% -- Results:
|
24 |
+
% -- very low misclassification rates again
|
25 |
+
% 5. See also: 1988 MLC Proceedings, 54-64. Cheeseman et al's AUTOCLASS II
|
26 |
+
% conceptual clustering system finds 3 classes in the data.
|
27 |
+
%
|
28 |
+
% 4. Relevant Information:
|
29 |
+
% --- This is perhaps the best known database to be found in the pattern
|
30 |
+
% recognition literature. Fisher's paper is a classic in the field
|
31 |
+
% and is referenced frequently to this day. (See Duda & Hart, for
|
32 |
+
% example.) The data set contains 3 classes of 50 instances each,
|
33 |
+
% where each class refers to a type of iris plant. One class is
|
34 |
+
% linearly separable from the other 2; the latter are NOT linearly
|
35 |
+
% separable from each other.
|
36 |
+
% --- Predicted attribute: class of iris plant.
|
37 |
+
% --- This is an exceedingly simple domain.
|
38 |
+
%
|
39 |
+
% 5. Number of Instances: 150 (50 in each of three classes)
|
40 |
+
%
|
41 |
+
% 6. Number of Attributes: 4 numeric, predictive attributes and the class
|
42 |
+
%
|
43 |
+
% 7. Attribute Information:
|
44 |
+
% 1. sepal length in cm
|
45 |
+
% 2. sepal width in cm
|
46 |
+
% 3. petal length in cm
|
47 |
+
% 4. petal width in cm
|
48 |
+
% 5. class:
|
49 |
+
% -- Iris Setosa
|
50 |
+
% -- Iris Versicolour
|
51 |
+
% -- Iris Virginica
|
52 |
+
%
|
53 |
+
% 8. Missing Attribute Values: None
|
54 |
+
%
|
55 |
+
% Summary Statistics:
|
56 |
+
% Min Max Mean SD Class Correlation
|
57 |
+
% sepal length: 4.3 7.9 5.84 0.83 0.7826
|
58 |
+
% sepal width: 2.0 4.4 3.05 0.43 -0.4194
|
59 |
+
% petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)
|
60 |
+
% petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)
|
61 |
+
%
|
62 |
+
% 9. Class Distribution: 33.3% for each of 3 classes.
|
63 |
+
|
64 |
+
@RELATION iris
|
65 |
+
|
66 |
+
@ATTRIBUTE sepallength REAL
|
67 |
+
@ATTRIBUTE sepalwidth REAL
|
68 |
+
@ATTRIBUTE petallength REAL
|
69 |
+
@ATTRIBUTE petalwidth REAL
|
70 |
+
@ATTRIBUTE class {Iris-setosa,Iris-versicolor,Iris-virginica}
|
71 |
+
|
72 |
+
@DATA
|
73 |
+
5.1,3.5,1.4,0.2,Iris-setosa
|
74 |
+
4.9,3.0,1.4,0.2,Iris-setosa
|
75 |
+
4.7,3.2,1.3,0.2,Iris-setosa
|
76 |
+
4.6,3.1,1.5,0.2,Iris-setosa
|
77 |
+
5.0,3.6,1.4,0.2,Iris-setosa
|
78 |
+
5.4,3.9,1.7,0.4,Iris-setosa
|
79 |
+
4.6,3.4,1.4,0.3,Iris-setosa
|
80 |
+
5.0,3.4,1.5,0.2,Iris-setosa
|
81 |
+
4.4,2.9,1.4,0.2,Iris-setosa
|
82 |
+
4.9,3.1,1.5,0.1,Iris-setosa
|
83 |
+
5.4,3.7,1.5,0.2,Iris-setosa
|
84 |
+
4.8,3.4,1.6,0.2,Iris-setosa
|
85 |
+
4.8,3.0,1.4,0.1,Iris-setosa
|
86 |
+
4.3,3.0,1.1,0.1,Iris-setosa
|
87 |
+
5.8,4.0,1.2,0.2,Iris-setosa
|
88 |
+
5.7,4.4,1.5,0.4,Iris-setosa
|
89 |
+
5.4,3.9,1.3,0.4,Iris-setosa
|
90 |
+
5.1,3.5,1.4,0.3,Iris-setosa
|
91 |
+
5.7,3.8,1.7,0.3,Iris-setosa
|
92 |
+
5.1,3.8,1.5,0.3,Iris-setosa
|
93 |
+
5.4,3.4,1.7,0.2,Iris-setosa
|
94 |
+
5.1,3.7,1.5,0.4,Iris-setosa
|
95 |
+
4.6,3.6,1.0,0.2,Iris-setosa
|
96 |
+
5.1,3.3,1.7,0.5,Iris-setosa
|
97 |
+
4.8,3.4,1.9,0.2,Iris-setosa
|
98 |
+
5.0,3.0,1.6,0.2,Iris-setosa
|
99 |
+
5.0,3.4,1.6,0.4,Iris-setosa
|
100 |
+
5.2,3.5,1.5,0.2,Iris-setosa
|
101 |
+
5.2,3.4,1.4,0.2,Iris-setosa
|
102 |
+
4.7,3.2,1.6,0.2,Iris-setosa
|
103 |
+
4.8,3.1,1.6,0.2,Iris-setosa
|
104 |
+
5.4,3.4,1.5,0.4,Iris-setosa
|
105 |
+
5.2,4.1,1.5,0.1,Iris-setosa
|
106 |
+
5.5,4.2,1.4,0.2,Iris-setosa
|
107 |
+
4.9,3.1,1.5,0.1,Iris-setosa
|
108 |
+
5.0,3.2,1.2,0.2,Iris-setosa
|
109 |
+
5.5,3.5,1.3,0.2,Iris-setosa
|
110 |
+
4.9,3.1,1.5,0.1,Iris-setosa
|
111 |
+
4.4,3.0,1.3,0.2,Iris-setosa
|
112 |
+
5.1,3.4,1.5,0.2,Iris-setosa
|
113 |
+
5.0,3.5,1.3,0.3,Iris-setosa
|
114 |
+
4.5,2.3,1.3,0.3,Iris-setosa
|
115 |
+
4.4,3.2,1.3,0.2,Iris-setosa
|
116 |
+
5.0,3.5,1.6,0.6,Iris-setosa
|
117 |
+
5.1,3.8,1.9,0.4,Iris-setosa
|
118 |
+
4.8,3.0,1.4,0.3,Iris-setosa
|
119 |
+
5.1,3.8,1.6,0.2,Iris-setosa
|
120 |
+
4.6,3.2,1.4,0.2,Iris-setosa
|
121 |
+
5.3,3.7,1.5,0.2,Iris-setosa
|
122 |
+
5.0,3.3,1.4,0.2,Iris-setosa
|
123 |
+
7.0,3.2,4.7,1.4,Iris-versicolor
|
124 |
+
6.4,3.2,4.5,1.5,Iris-versicolor
|
125 |
+
6.9,3.1,4.9,1.5,Iris-versicolor
|
126 |
+
5.5,2.3,4.0,1.3,Iris-versicolor
|
127 |
+
6.5,2.8,4.6,1.5,Iris-versicolor
|
128 |
+
5.7,2.8,4.5,1.3,Iris-versicolor
|
129 |
+
6.3,3.3,4.7,1.6,Iris-versicolor
|
130 |
+
4.9,2.4,3.3,1.0,Iris-versicolor
|
131 |
+
6.6,2.9,4.6,1.3,Iris-versicolor
|
132 |
+
5.2,2.7,3.9,1.4,Iris-versicolor
|
133 |
+
5.0,2.0,3.5,1.0,Iris-versicolor
|
134 |
+
5.9,3.0,4.2,1.5,Iris-versicolor
|
135 |
+
6.0,2.2,4.0,1.0,Iris-versicolor
|
136 |
+
6.1,2.9,4.7,1.4,Iris-versicolor
|
137 |
+
5.6,2.9,3.6,1.3,Iris-versicolor
|
138 |
+
6.7,3.1,4.4,1.4,Iris-versicolor
|
139 |
+
5.6,3.0,4.5,1.5,Iris-versicolor
|
140 |
+
5.8,2.7,4.1,1.0,Iris-versicolor
|
141 |
+
6.2,2.2,4.5,1.5,Iris-versicolor
|
142 |
+
5.6,2.5,3.9,1.1,Iris-versicolor
|
143 |
+
5.9,3.2,4.8,1.8,Iris-versicolor
|
144 |
+
6.1,2.8,4.0,1.3,Iris-versicolor
|
145 |
+
6.3,2.5,4.9,1.5,Iris-versicolor
|
146 |
+
6.1,2.8,4.7,1.2,Iris-versicolor
|
147 |
+
6.4,2.9,4.3,1.3,Iris-versicolor
|
148 |
+
6.6,3.0,4.4,1.4,Iris-versicolor
|
149 |
+
6.8,2.8,4.8,1.4,Iris-versicolor
|
150 |
+
6.7,3.0,5.0,1.7,Iris-versicolor
|
151 |
+
6.0,2.9,4.5,1.5,Iris-versicolor
|
152 |
+
5.7,2.6,3.5,1.0,Iris-versicolor
|
153 |
+
5.5,2.4,3.8,1.1,Iris-versicolor
|
154 |
+
5.5,2.4,3.7,1.0,Iris-versicolor
|
155 |
+
5.8,2.7,3.9,1.2,Iris-versicolor
|
156 |
+
6.0,2.7,5.1,1.6,Iris-versicolor
|
157 |
+
5.4,3.0,4.5,1.5,Iris-versicolor
|
158 |
+
6.0,3.4,4.5,1.6,Iris-versicolor
|
159 |
+
6.7,3.1,4.7,1.5,Iris-versicolor
|
160 |
+
6.3,2.3,4.4,1.3,Iris-versicolor
|
161 |
+
5.6,3.0,4.1,1.3,Iris-versicolor
|
162 |
+
5.5,2.5,4.0,1.3,Iris-versicolor
|
163 |
+
5.5,2.6,4.4,1.2,Iris-versicolor
|
164 |
+
6.1,3.0,4.6,1.4,Iris-versicolor
|
165 |
+
5.8,2.6,4.0,1.2,Iris-versicolor
|
166 |
+
5.0,2.3,3.3,1.0,Iris-versicolor
|
167 |
+
5.6,2.7,4.2,1.3,Iris-versicolor
|
168 |
+
5.7,3.0,4.2,1.2,Iris-versicolor
|
169 |
+
5.7,2.9,4.2,1.3,Iris-versicolor
|
170 |
+
6.2,2.9,4.3,1.3,Iris-versicolor
|
171 |
+
5.1,2.5,3.0,1.1,Iris-versicolor
|
172 |
+
5.7,2.8,4.1,1.3,Iris-versicolor
|
173 |
+
6.3,3.3,6.0,2.5,Iris-virginica
|
174 |
+
5.8,2.7,5.1,1.9,Iris-virginica
|
175 |
+
7.1,3.0,5.9,2.1,Iris-virginica
|
176 |
+
6.3,2.9,5.6,1.8,Iris-virginica
|
177 |
+
6.5,3.0,5.8,2.2,Iris-virginica
|
178 |
+
7.6,3.0,6.6,2.1,Iris-virginica
|
179 |
+
4.9,2.5,4.5,1.7,Iris-virginica
|
180 |
+
7.3,2.9,6.3,1.8,Iris-virginica
|
181 |
+
6.7,2.5,5.8,1.8,Iris-virginica
|
182 |
+
7.2,3.6,6.1,2.5,Iris-virginica
|
183 |
+
6.5,3.2,5.1,2.0,Iris-virginica
|
184 |
+
6.4,2.7,5.3,1.9,Iris-virginica
|
185 |
+
6.8,3.0,5.5,2.1,Iris-virginica
|
186 |
+
5.7,2.5,5.0,2.0,Iris-virginica
|
187 |
+
5.8,2.8,5.1,2.4,Iris-virginica
|
188 |
+
6.4,3.2,5.3,2.3,Iris-virginica
|
189 |
+
6.5,3.0,5.5,1.8,Iris-virginica
|
190 |
+
7.7,3.8,6.7,2.2,Iris-virginica
|
191 |
+
7.7,2.6,6.9,2.3,Iris-virginica
|
192 |
+
6.0,2.2,5.0,1.5,Iris-virginica
|
193 |
+
6.9,3.2,5.7,2.3,Iris-virginica
|
194 |
+
5.6,2.8,4.9,2.0,Iris-virginica
|
195 |
+
7.7,2.8,6.7,2.0,Iris-virginica
|
196 |
+
6.3,2.7,4.9,1.8,Iris-virginica
|
197 |
+
6.7,3.3,5.7,2.1,Iris-virginica
|
198 |
+
7.2,3.2,6.0,1.8,Iris-virginica
|
199 |
+
6.2,2.8,4.8,1.8,Iris-virginica
|
200 |
+
6.1,3.0,4.9,1.8,Iris-virginica
|
201 |
+
6.4,2.8,5.6,2.1,Iris-virginica
|
202 |
+
7.2,3.0,5.8,1.6,Iris-virginica
|
203 |
+
7.4,2.8,6.1,1.9,Iris-virginica
|
204 |
+
7.9,3.8,6.4,2.0,Iris-virginica
|
205 |
+
6.4,2.8,5.6,2.2,Iris-virginica
|
206 |
+
6.3,2.8,5.1,1.5,Iris-virginica
|
207 |
+
6.1,2.6,5.6,1.4,Iris-virginica
|
208 |
+
7.7,3.0,6.1,2.3,Iris-virginica
|
209 |
+
6.3,3.4,5.6,2.4,Iris-virginica
|
210 |
+
6.4,3.1,5.5,1.8,Iris-virginica
|
211 |
+
6.0,3.0,4.8,1.8,Iris-virginica
|
212 |
+
6.9,3.1,5.4,2.1,Iris-virginica
|
213 |
+
6.7,3.1,5.6,2.4,Iris-virginica
|
214 |
+
6.9,3.1,5.1,2.3,Iris-virginica
|
215 |
+
5.8,2.7,5.1,1.9,Iris-virginica
|
216 |
+
6.8,3.2,5.9,2.3,Iris-virginica
|
217 |
+
6.7,3.3,5.7,2.5,Iris-virginica
|
218 |
+
6.7,3.0,5.2,2.3,Iris-virginica
|
219 |
+
6.3,2.5,5.0,1.9,Iris-virginica
|
220 |
+
6.5,3.0,5.2,2.0,Iris-virginica
|
221 |
+
6.2,3.4,5.4,2.3,Iris-virginica
|
222 |
+
5.9,3.0,5.1,1.8,Iris-virginica
|
223 |
+
%
|
224 |
+
%
|
225 |
+
%
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/missing.arff
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
% This arff file contains some missing data
|
2 |
+
@relation missing
|
3 |
+
@attribute yop real
|
4 |
+
@attribute yap real
|
5 |
+
@data
|
6 |
+
1,5
|
7 |
+
2,4
|
8 |
+
?,?
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/nodata.arff
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@RELATION iris
|
2 |
+
|
3 |
+
@ATTRIBUTE sepallength REAL
|
4 |
+
@ATTRIBUTE sepalwidth REAL
|
5 |
+
@ATTRIBUTE petallength REAL
|
6 |
+
@ATTRIBUTE petalwidth REAL
|
7 |
+
@ATTRIBUTE class {Iris-setosa,Iris-versicolor,Iris-virginica}
|
8 |
+
|
9 |
+
@DATA
|
10 |
+
|
11 |
+
% This file has no data
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/quoted_nominal.arff
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
% Regression test for issue #10232 : Exception in loadarff with quoted nominal attributes
|
2 |
+
% Spaces between elements are stripped by the parser
|
3 |
+
|
4 |
+
@relation SOME_DATA
|
5 |
+
@attribute age numeric
|
6 |
+
@attribute smoker {'yes', 'no'}
|
7 |
+
@data
|
8 |
+
18, 'no'
|
9 |
+
24, 'yes'
|
10 |
+
44, 'no'
|
11 |
+
56, 'no'
|
12 |
+
89,'yes'
|
13 |
+
11, 'no'
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/quoted_nominal_spaces.arff
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
% Regression test for issue #10232 : Exception in loadarff with quoted nominal attributes
|
2 |
+
% Spaces inside quotes are NOT stripped by the parser
|
3 |
+
|
4 |
+
@relation SOME_DATA
|
5 |
+
@attribute age numeric
|
6 |
+
@attribute smoker {' yes', 'no '}
|
7 |
+
@data
|
8 |
+
18,'no '
|
9 |
+
24,' yes'
|
10 |
+
44,'no '
|
11 |
+
56,'no '
|
12 |
+
89,' yes'
|
13 |
+
11,'no '
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test1.arff
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@RELATION test1
|
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 |
+
0.1, 0.2, 0.3, 0.4,class1
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test10.arff
ADDED
The diff for this file is too large to render.
See raw diff
|
|
venv/lib/python3.10/site-packages/scipy/io/arff/tests/data/test11.arff
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@RELATION test11
|
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
|
venv/lib/python3.10/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
|
venv/lib/python3.10/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
|
venv/lib/python3.10/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
|
venv/lib/python3.10/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
|
venv/lib/python3.10/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
|
venv/lib/python3.10/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"
|
venv/lib/python3.10/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"
|