@@ -126,6 +126,174 @@ public void testBenchmarkUInt8() throws Exception {
126126 // test if MLArray objects are equal
127127 assertEquals ("Test if value red from file equals value stored" , mluint8 , mlArrayRetrived );
128128 }
129+
130+ @ Test
131+ public void testMultipleDimArrayRealFromMatlabCreatedFile () throws IOException {
132+ int ndims = 5 ;
133+ int [] dims = new int []{2 , 3 , 4 , 5 , 6 };
134+ File file = getTestFile ("multiDimMatrix.mat" );
135+ MatFileReader reader = new MatFileReader (file );
136+ MLDouble mlArray = (MLDouble ) reader .getMLArray ("in" );
137+
138+ int testNDims = mlArray .getNDimensions ();
139+ Assert .assertEquals (ndims , testNDims );
140+
141+ int [] testDims = mlArray .getDimensions ();
142+ for (int i = 0 ; i < ndims ; i ++){
143+ Assert .assertEquals (dims [i ], testDims [i ]);
144+ }
145+
146+ Double expectedVal = 0.0 ;
147+ for (int i = 0 ; i < dims [4 ]; i ++) {
148+ for (int j = 0 ; j < dims [3 ]; j ++) {
149+ for (int k = 0 ; k < dims [2 ]; k ++) {
150+ for (int l = 0 ; l < dims [1 ]; l ++) {
151+ for (int m = 0 ; m < dims [0 ]; m ++, expectedVal += 1.0 ) {
152+ Double actual = mlArray .getReal ( mlArray .getIndexCM (m , l , k , j , i ) );
153+ Assert .assertEquals ( expectedVal , actual );
154+ }
155+ }
156+ }
157+ }
158+ }
159+ }
160+
161+ @ Test
162+ public void testMultipleDimArrayRealWIndicesFromMatlabCreatedFile () throws IOException {
163+ int ndims = 5 ;
164+ int [] dims = new int []{2 , 3 , 4 , 5 , 6 };
165+ File file = getTestFile ("multiDimMatrix.mat" );
166+ MatFileReader reader = new MatFileReader (file );
167+ MLDouble mlArray = (MLDouble ) reader .getMLArray ("in" );
168+
169+ int testNDims = mlArray .getNDimensions ();
170+ Assert .assertEquals (ndims , testNDims );
171+
172+ int [] testDims = mlArray .getDimensions ();
173+ for (int i = 0 ; i < ndims ; i ++){
174+ Assert .assertEquals (dims [i ], testDims [i ]);
175+ }
176+
177+ Double expectedVal = 0.0 ;
178+ for (int i = 0 ; i < dims [4 ]; i ++) {
179+ for (int j = 0 ; j < dims [3 ]; j ++) {
180+ for (int k = 0 ; k < dims [2 ]; k ++) {
181+ for (int l = 0 ; l < dims [1 ]; l ++) {
182+ for (int m = 0 ; m < dims [0 ]; m ++, expectedVal += 1.0 ) {
183+ Double actual = mlArray .getRealCM ( m , l , k , j , i );
184+ Assert .assertEquals ( expectedVal , actual );
185+ }
186+ }
187+ }
188+ }
189+ }
190+ }
191+
192+ @ Test
193+ public void testMultipleDimArrayGetFromMatlabCreatedFile () throws IOException {
194+ int ndims = 5 ;
195+ int [] dims = new int []{2 , 3 , 4 , 5 , 6 };
196+ File file = getTestFile ("multiDimMatrix.mat" );
197+ MatFileReader reader = new MatFileReader (file );
198+ MLDouble mlArray = (MLDouble ) reader .getMLArray ("in" );
199+
200+ int testNDims = mlArray .getNDimensions ();
201+ Assert .assertEquals (ndims , testNDims );
202+
203+ int [] testDims = mlArray .getDimensions ();
204+ for (int i = 0 ; i < ndims ; i ++){
205+ Assert .assertEquals (dims [i ], testDims [i ]);
206+ }
207+
208+ Double expectedVal = 0.0 ;
209+ for (int i = 0 ; i < dims [4 ]; i ++) {
210+ for (int j = 0 ; j < dims [3 ]; j ++) {
211+ for (int k = 0 ; k < dims [2 ]; k ++) {
212+ for (int l = 0 ; l < dims [1 ]; l ++) {
213+ for (int m = 0 ; m < dims [0 ]; m ++, expectedVal += 1.0 ) {
214+ Double actual = mlArray .getCM ( m , l , k , j , i );
215+ Assert .assertEquals ( expectedVal , actual );
216+ }
217+ }
218+ }
219+ }
220+ }
221+ }
222+
223+ @ Test
224+ public void testMultipleDimArrayComplexFromMatlabCreatedFile () throws IOException {
225+ int ndims = 5 ;
226+ int [] dims = new int []{2 , 3 , 4 , 5 , 6 };
227+ File file = getTestFile ("multiDimComplexMatrix.mat" );
228+ MatFileReader reader = new MatFileReader (file );
229+ MLDouble mlArray = (MLDouble ) reader .getMLArray ("in" );
230+
231+ int testNDims = mlArray .getNDimensions ();
232+ Assert .assertEquals (ndims , testNDims );
233+
234+ int [] testDims = mlArray .getDimensions ();
235+ for (int i = 0 ; i < ndims ; i ++){
236+ Assert .assertEquals (dims [i ], testDims [i ]);
237+ }
238+
239+ Double expectedValRe = 0.0 ;
240+ for (int i = 0 ; i < dims [4 ]; i ++) {
241+ for (int j = 0 ; j < dims [3 ]; j ++) {
242+ for (int k = 0 ; k < dims [2 ]; k ++) {
243+ for (int l = 0 ; l < dims [1 ]; l ++) {
244+ for (int m = 0 ; m < dims [0 ]; m ++, expectedValRe += 1.0 ) {
245+ Double actualRe = mlArray .getReal ( mlArray .getIndexCM (m , l , k , j , i ) );
246+ Assert .assertEquals ( expectedValRe , actualRe );
247+ Double actualIm = mlArray .getImaginary ( mlArray .getIndexCM (m , l , k , j , i ) );
248+ Double expectedValIm = 0.0 ;
249+ if (expectedValRe != 0.0 ) {
250+ expectedValIm = expectedValRe * -1.0 ;
251+ }
252+ Assert .assertEquals ( expectedValIm , actualIm );
253+ }
254+ }
255+ }
256+ }
257+ }
258+ }
259+
260+ @ Test
261+ public void testMultipleDimArrayComplexWIndicesFromMatlabCreatedFile () throws IOException {
262+ int ndims = 5 ;
263+ int [] dims = new int []{2 , 3 , 4 , 5 , 6 };
264+ File file = getTestFile ("multiDimComplexMatrix.mat" );
265+ MatFileReader reader = new MatFileReader (file );
266+ MLDouble mlArray = (MLDouble ) reader .getMLArray ("in" );
267+
268+ int testNDims = mlArray .getNDimensions ();
269+ Assert .assertEquals (ndims , testNDims );
270+
271+ int [] testDims = mlArray .getDimensions ();
272+ for (int i = 0 ; i < ndims ; i ++){
273+ Assert .assertEquals (dims [i ], testDims [i ]);
274+ }
275+
276+ Double expectedValRe = 0.0 ;
277+ for (int i = 0 ; i < dims [4 ]; i ++) {
278+ for (int j = 0 ; j < dims [3 ]; j ++) {
279+ for (int k = 0 ; k < dims [2 ]; k ++) {
280+ for (int l = 0 ; l < dims [1 ]; l ++) {
281+ for (int m = 0 ; m < dims [0 ]; m ++, expectedValRe += 1.0 ) {
282+ Double actualRe = mlArray .getRealCM ( m , l , k , j , i );
283+ Assert .assertEquals ( expectedValRe , actualRe );
284+ Double actualIm = mlArray .getImaginaryCM ( m , l , k , j , i );
285+ Double expectedValIm = 0.0 ;
286+ if (expectedValRe != 0.0 ) {
287+ expectedValIm = expectedValRe * -1.0 ;
288+ }
289+ Assert .assertEquals ( expectedValIm , actualIm );
290+ }
291+ }
292+ }
293+ }
294+ }
295+ }
296+
129297
130298 @ Test
131299 public void testCellFromMatlabCreatedFile () throws IOException {
0 commit comments