1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - Vincent Couvert <vincent.couvert@inria.fr>
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
// <-- CLI SHELL MODE -->
// This Scilab script loads MAT-files to test the MATIO module
clear all
//
// Loads all MAT-files
//
binFormats = ["-v4";"-v6";"-v7"];
for formatIndex = 1:size(binFormats, "*")
matFiles = gsort(listfiles("SCI/modules/matio/tests/unit_tests/*" + binFormats(formatIndex) + ".mat"), "r", "i");
for fileIndex=1:size(matFiles, "*")
disp(fileparts(matFiles(fileIndex), "fname") + fileparts(matFiles(fileIndex), "extension"));
loadmatfile(matFiles(fileIndex));
end
//
// TESTS FOR CELL ARRAYS
//
if binFormats(formatIndex) <> "-v4" then // Cell arrays can not be stored in Matlab 4 binary files
assert_checkequal(emptycell , cell());
assert_checkequal(scalarcell , makecell([1 1], 1.23));
assert_checkequal(rowcell , makecell([1 3], "abc", [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i], 1.23));
assert_checkequal(colcell , makecell([3 1], [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i], "abc", 1.23));
assert_checkequal(arraycell , makecell([2 3], "a", [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i], int8(1), "abc", 1.23, eye(100,100)));
assert_checkequal(stringcell , makecell([2 3], "abc", "def", "ghi", "jkl", "mno", "pqr"));
clear emptycell scalarcell rowcell colcell arraycell stringcell
end
//
// TESTS FOR STRUCTURE ARRAYS
//
if binFormats(formatIndex) <> "-v4" then // Struct arrays can not be stored in Matlab 4 binary files
sciemptystruct = struct();
assert_checkequal(emptystruct , sciemptystruct);
sciscalarstruct = struct("f1", 10, "ftwo", "Hello", "field3", int8(12));
assert_checkequal(scalarstruct , sciscalarstruct);
scirowstruct = struct("field1", 10, "field2", "Hello", "field3", int8(12));
scirowstruct(1,2).field1 = "test";
scirowstruct(1,2).field2 = eye(10, 10);
scirowstruct(1,3).field2 = "a field contents";
scirowstruct(1,3).field3 = 1.23+4.56*%i;
assert_checkequal(rowstruct , scirowstruct);
scicolstruct = struct("name", 10, "phone", "Hello", "address", int8(12));
scicolstruct(2,1).name = "test";
scicolstruct(2,1).phone = eye(10, 10);
scicolstruct(3,1).phone = "a field contents";
scicolstruct(3,1).address = 1.23+4.56*%i;
assert_checkequal(colstruct , scicolstruct);
sciarraystruct = struct("field1", 10, "field2", "Hello", "field3", int8(12));
sciarraystruct(1,2).field1 = "test";
sciarraystruct(1,2).field2 = eye(10, 10);
sciarraystruct(1,3).field2 = "a field contents";
sciarraystruct(1,3).field3 = 1.23+4.56*%i;
sciarraystruct(2,1).name = "test";
sciarraystruct(2,1).phone = eye(10, 10);
sciarraystruct(3,1).phone = "a field contents";
sciarraystruct(3,1).address = 1.23+4.56*%i;
assert_checkequal(arraystruct , sciarraystruct);
clear emptystruct scalarstruct rowstruct colstruct arraystruct
clear sciemptystruct sciscalarstruct scirowstruct scicolstruct sciarraystruct
end
//
// TESTS FOR OBJECTS
//
// TODO
//
// TESTS FOR CHARACTER ARRAYS
//
assert_checkequal(emptystringmatrix , "");
assert_checkequal(stringscalar , "a");
assert_checkequal(stringrowvector , ["abc"]);
assert_checkequal(stringcolvector , ["a";"b";"c"]);
assert_checkequal(stringmatrix , ["abc";"def"]);
clear emptystringmatrix stringscalar stringrowvector stringcolvector stringmatrix
//
// TESTS FOR DOUBLE PRECISION ARRAYS
//
assert_checkequal(emptydoublematrix , []);
assert_checkequal(realdoublescalar , 1.23);
assert_checkequal(cplxdoublescalar , 1.23 + 4.56*%i);
assert_checkequal(realdoublerowvector , [1.23 -4.56 7.89]);
assert_checkequal(cplxdoublerowvector , [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i]);
assert_checkequal(realdoublecolvector , [1.23;-4.56;7.89]);
assert_checkequal(cplxdoublecolvector , [1.23+7.89*%i;4.56-1.23*%i;7.89+4.56*%i]);
assert_checkequal(realdoublematrix , [1.23 -4.56 7.89;9.87 6.54 -3.21]);
assert_checkequal(cplxdoublematrix , [1.23+7.89*%i 4.56-1.23*%i 7.89+4.56*%i;9.87+3.21*%i 6.54+9.87*%i 3.21-6.54*%i]);
clear emptydoublematrix realdoublescalar cplxdoublescalar realdoublerowvector cplxdoublerowvector realdoublecolvector cplxdoublecolvector realdoublematrix cplxdoublematrix
//
// TESTS FOR SINGLE PRECISION ARRAYS
//
// TODO
//
// TESTS FOR SPARSE MATRICES
//
if binFormats(formatIndex) <> "-v4" then // Integers can not be stored in Matlab 4 binary files
assert_checkequal(emptysparse , []);
assert_checkequal(realscalarsparse , sparse(1.23));
//assert_checkequal(cplxscalarsparse , sparse(1.23 + 4.56i));
assert_checkequal(realrowvectorsparse , sparse([1.23 0 7.89]));
//assert_checkequal(cplxrowvectorsparse , sparse([1.23+7.89i 0 7.89+4.56i]));
assert_checkequal(realcolvectorsparse , sparse([1.23;0;7.89]));
//assert_checkequal(cplxcolvectorsparse , sparse([1.23+7.89i;;7.89+4.56i]));
assert_checkequal(realmatrixsparse , sparse([1.23 0 7.89;0 6.54 -3.21]));
//assert_checkequal(cplxmatrixsparse , sparse([1.23+7.89i 0 7.89+4.56i;0 6.54+9.87i 3.21-6.54i]));
end
if binFormats(formatIndex) <> "-v4" then // Integers can not be stored in Matlab 4 binary files
//
// TESTS FOR 8-BITS SIGNED INTEGERS
//
assert_checkequal(emptyint8matrix , int8([]));
assert_checkequal(int8scalar , int8(1));
assert_checkequal(int8rowvector , int8([1 -4 7]));
assert_checkequal(int8colvector , int8([1;-4;7]));
assert_checkequal(int8matrix , int8([1 -4 7;-9 6 -3]));
clear emptyint8matrix int8scalar int8rowvector int8colvector int8matrix
//
// TESTS FOR 16-BITS SIGNED INTEGERS
//
assert_checkequal(emptyint16matrix , int16([]));
assert_checkequal(int16scalar , int16(1));
assert_checkequal(int16rowvector , int16([1 -4 7]));
assert_checkequal(int16colvector , int16([1;-4;7]));
assert_checkequal(int16matrix , int16([1 -4 7;-9 6 -3]));
clear emptyint16matrix int16scalar int16rowvector int16colvector int16matrix
//
// TESTS FOR 32-BITS SIGNED INTEGERS
//
assert_checkequal(emptyint32matrix , int32([]));
assert_checkequal(int32scalar , int32(1));
assert_checkequal(int32rowvector , int32([1 -4 7]));
assert_checkequal(int32colvector , int32([1;-4;7]));
assert_checkequal(int32matrix , int32([1 -4 7;-9 6 -3]));
clear emptyint32matrix int32scalar int32rowvector int32colvector int32matrix
// TODO: int64 tests ?
//
// TESTS FOR 8-BITS UNSIGNED INTEGERS
//
assert_checkequal(emptyuint8matrix , uint8([]));
assert_checkequal(uint8scalar , uint8(1));
//assert_checkequal(uint8rowvector , uint8([1 -4 7]));
assert_checkequal(uint8rowvector , uint8([1 0 7]));
//assert_checkequal(uint8colvector , uint8([1;-4;7]));
assert_checkequal(uint8colvector , uint8([1;0;7]));
//assert_checkequal(uint8matrix , uint8([1 -4 7;-9 6 -3]));
assert_checkequal(uint8matrix , uint8([1 0 7;0 6 0]));
clear emptyuint8matrix uint8scalar uint8rowvector uint8colvector uint8matrix
//
// TESTS FOR 16-BITS UNSIGNED INTEGERS
//
assert_checkequal(emptyuint16matrix , uint16([]));
assert_checkequal(uint16scalar , uint16(1));
//assert_checkequal(uint16rowvector , uint16([1 -4 7]));
assert_checkequal(uint16rowvector , uint16([1 0 7]));
//assert_checkequal(uint16colvector , uint16([1;-4;7]));
assert_checkequal(uint16colvector , uint16([1;0;7]));
//assert_checkequal(uint16matrix , uint16([1 -4 7;-9 6 -3]));
assert_checkequal(uint16matrix , uint16([1 0 7;0 6 0]));
clear emptyuint16matrix uint16scalar uint16rowvector uint16colvector uint16matrix
//
// TESTS FOR 32-BITS UNSIGNED INTEGERS
//
assert_checkequal(emptyuint32matrix , uint32([]));
assert_checkequal(uint32scalar , uint32(1));
//assert_checkequal(uint32rowvector , uint32([1 -4 7]));
assert_checkequal(uint32rowvector , uint32([1 0 7]));
//assert_checkequal(uint32colvector , uint32([1;-4;7]));
assert_checkequal(uint32colvector , uint32([1;0;7]));
//assert_checkequal(uint32matrix , uint32([1 -4 7;-9 6 -3]));
assert_checkequal(uint32matrix , uint32([1 0 7;0 6 0]));
clear emptyuint32matrix uint32scalar uint32rowvector uint32colvector uint32matrix
// TODO: uint64 tests ?
//
// TESTS FOR ND-ARRAYS
//
assert_checkequal(emptyNDarray.dims , int32([0 0 0]));
assert_checkequal(emptyNDarray.entries , []);
assert_checkequal(realdoubleNDarray , matrix(1:24, 2, 3, 4));
assert_checkequal(complexdoubleNDarray , matrix((1:24) + (1:24)*%i, 2, 3, 4));
clear emptyNDarray realdoubleNDarray complexdoubleNDarray
end
//
// MISC
//
assert_checkequal(eye100x100 , eye(100,100));
end
// TODO: read all variables from a single file ?
|