File: IntOrderTest_Impl.java

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (545 lines) | stat: -rw-r--r-- 15,587 bytes parent folder | download
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
/*
 * File:          IntOrderTest_Impl.java
 * Symbol:        Ordering.IntOrderTest-v0.1
 * Symbol Type:   class
 * Babel Version: 0.10.2
 * Description:   Server-side implementation for Ordering.IntOrderTest
 * 
 * WARNING: Automatically generated; only changes within splicers preserved
 * 
 * babel-version = 0.10.2
 */

package Ordering;

import sidl.ClassInfo;
import sidl.BaseInterface;
import sidl.BaseClass;

// DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest._imports)
// Put additional imports here...
// DO-NOT-DELETE splicer.end(Ordering.IntOrderTest._imports)

/**
 * Symbol "Ordering.IntOrderTest" (version 0.1)
 * 
 * This class provides methods to verify that the array ordering
 * capabilities work for arrays of int.
 */
public class IntOrderTest_Impl extends IntOrderTest
{

  // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest._data)

  static int iFunc(int[] ind, int dim)
  {
    int res = 0;
    int i;
    for(i = 0; i < dim ; ++i) {
      res += (i+1)*ind[i];
    }
    return res;
  }

  static boolean incIndex(int[] ind, sidl.Integer.Array A)
  {
    int i = 0;
    int dimen = A._dim();
    while (i < dimen) {
      if (++(ind[i]) > A._upper(i)) {
        ind[i] = A._lower(i);
        ++i;
      }
      else {
        return true;
      }
    }
    /* we're all done */
    return false;
  }

  static boolean isIMatrix(sidl.Integer.Array A)
  {
    if (A != null) {
      int dimen = A._dim();
      int i;
      int[] cindex = {0,0,0,0,0,0,0}; 
      for(i = 0; i < dimen; ++i){
        cindex[i] = A._lower(i);
        if (A._lower(i) > A._upper(i)) {
          return true;
        }
      }
      do { 
        if (iFunc(cindex, dimen) != 
            A._get(cindex[0],cindex[1],cindex[2],cindex[3],cindex[4],cindex[5],cindex[6])) { 
          return false;
        }
      } while (incIndex(cindex, A));
      return true;
    }
    return false;
  }

  static void fillIMatrix(sidl.Integer.Array A)
  {
    if (A != null) {
      int dimen = A._dim();
      int i;
      int[] cindex = {0,0,0,0,0,0,0};  
      for(i = 0; i < dimen; ++i){
        cindex[i] = A._lower(i);
        if (A._lower(i) > A._upper(i)){
          return;
        }
      }
      do {
        A._set(cindex[0], cindex[1], cindex[2], cindex[3], cindex[4], cindex[5],
               cindex[6], iFunc(cindex, dimen));
      } while (incIndex(cindex, A));
    }
  }


  // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest._data)

  static { 
  // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest._load)
  // Put load function implementation here...
  // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest._load)
  }

  /**
   * User defined constructor
   */
  public IntOrderTest_Impl(long IORpointer){
    super(IORpointer);
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.IntOrderTest)
    // add construction details here
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.IntOrderTest)
  }

  /**
   * User defined destructing method
   */
  public void finalize() throws Throwable{
    super.finalize();
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest._dtor)
    // add destruction details here
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest._dtor)
  }

  // user defined static methods:
  /**
   * Create a column-major matrix satisfying condition I.
   */
  public static sidl.Integer.Array2 makeColumnIMatrix_Impl (
    /*in*/ int size,
    /*in*/ boolean useCreateCol ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.makeColumnIMatrix)
    sidl.Integer.Array2 res;
    if (useCreateCol) {
      res = new sidl.Integer.Array2(size, size, false);
    }
    else {
      res = new sidl.Integer.Array2(size, size, true);
    }
    fillIMatrix(res);
    return res;
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.makeColumnIMatrix)
  }

  /**
   * Create a row-major matrix satisfying condition I.
   */
  public static sidl.Integer.Array2 makeRowIMatrix_Impl (
    /*in*/ int size,
    /*in*/ boolean useCreateRow ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.makeRowIMatrix)
    // insert implementation here
        sidl.Integer.Array2 res;
    if (useCreateRow) {
      res = new sidl.Integer.Array2(size, size, true);
    }
    else {
      res = new sidl.Integer.Array2(size, size, false);
    }
    fillIMatrix(res);
    return res;
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.makeRowIMatrix)
  }

  /**
   * Create a 4-D matrix satisfying condition I.  Each dimension has
   * size elements numbers 0 through size-1.
   */
  public static sidl.Integer.Array4 makeIMatrix_Impl (
    /*in*/ int size,
    /*in*/ boolean useCreateColumn ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.makeIMatrix)
    sidl.Integer.Array4 res;
    sidl.Integer.Array A;
    int[] lower = {0,0,0,0};
    int upper[] = new int[4];
    upper[0] = upper[1] = upper[2] = upper[3] = size - 1;
    if (useCreateColumn) {
      A = new sidl.Integer.Array(4, lower,upper, false);
    }
    else {
      A = new sidl.Integer.Array(4, lower,upper, true);
    }
    fillIMatrix(A);
    res = (sidl.Integer.Array4) A._dcast();
    return res;
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.makeIMatrix)
  }

  /**
   * Create a column-major matrix satisfying condition I.
   */
  public static void createColumnIMatrix_Impl (
    /*in*/ int size,
    /*in*/ boolean useCreateCol,
    /*out*/ sidl.Integer.Array2.Holder res ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.createColumnIMatrix)
    sidl.Integer.Array2 A;
    if (useCreateCol) {
      A = new sidl.Integer.Array2(size, size, false);
    }
    else {
      A = new sidl.Integer.Array2(size, size, true);
    }
    fillIMatrix(A);
    res.set(A);
    return ;
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.createColumnIMatrix)
  }

  /**
   * Create a row-major matrix satisfying condition I.
   */
  public static void createRowIMatrix_Impl (
    /*in*/ int size,
    /*in*/ boolean useCreateRow,
    /*out*/ sidl.Integer.Array2.Holder res ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.createRowIMatrix)
    // insert implementation here
        sidl.Integer.Array2 A;
    if (useCreateRow) {
      A = new sidl.Integer.Array2(size, size, true);
    }
    else {
      A = new sidl.Integer.Array2(size, size, false);
    }
    fillIMatrix(A);
    res.set(A);
    return ;
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.createRowIMatrix)
  }

  /**
   * Make sure an array is column-major.  No changes to the dimension or
   * values in a are made.
   */
  public static void ensureColumn_Impl (
    /*inout*/ sidl.Integer.Array2.Holder a ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.ensureColumn)
    // Do nothing?
    return ;
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.ensureColumn)
  }

  /**
   * Make sure an array is row-major.  No changes to the dimension or
   * values in a are made.
   */
  public static void ensureRow_Impl (
    /*inout*/ sidl.Integer.Array2.Holder a ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.ensureRow)
    // Do nothing?
    return ;
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.ensureRow)
  }

  /**
   *  Return <code>true</code> iff the implementation sees
   *  an incoming array satisfying condition I.
   */
  public static boolean isIMatrixOne_Impl (
    /*in*/ sidl.Integer.Array1 A ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isIMatrixOne)
    // insert implementation here
    return isIMatrix(A);
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isIMatrixOne)
  }

  /**
   * Return <code>true</code> iff the implementation sees
   * an incoming column-major array satisfying condition I.
   */
  public static boolean isColumnIMatrixOne_Impl (
    /*in*/ sidl.Integer.Array1 A ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isColumnIMatrixOne)
    // insert implementation here
    return A._isColumnOrder() && isIMatrix(A);
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isColumnIMatrixOne)
  }

  /**
   * Return <code>true</code> iff the implementation sees
   * an incoming row-major array satisfying condition I.
   */
  public static boolean isRowIMatrixOne_Impl (
    /*in*/ sidl.Integer.Array1 A ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isRowIMatrixOne)
    // insert implementation here
    return A._isRowOrder() && isIMatrix(A);
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isRowIMatrixOne)
  }

  /**
   *  Return <code>true</code> iff the implementation sees
   *  an incoming array satisfying condition I.
   */
  public static boolean isIMatrixTwo_Impl (
    /*in*/ sidl.Integer.Array2 A ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isIMatrixTwo)
    // insert implementation here
    return isIMatrix(A);
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isIMatrixTwo)
  }

  /**
   * Return <code>true</code> iff the implementation sees
   * an incoming column-major array satisfying condition I.
   */
  public static boolean isColumnIMatrixTwo_Impl (
    /*in*/ sidl.Integer.Array2 A ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isColumnIMatrixTwo)
    // insert implementation here
    return A._isColumnOrder() && isIMatrix(A);
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isColumnIMatrixTwo)
  }

  /**
   * Return <code>true</code> iff the implementation sees
   * an incoming row-major array satisfying condition I.
   */
  public static boolean isRowIMatrixTwo_Impl (
    /*in*/ sidl.Integer.Array2 A ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isRowIMatrixTwo)
    // insert implementation here
    return A._isRowOrder() && isIMatrix(A);
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isRowIMatrixTwo)
  }

  /**
   *  Return <code>true</code> iff the implementation sees
   *  an incoming array satisfying condition I.
   */
  public static boolean isIMatrixFour_Impl (
    /*in*/ sidl.Integer.Array4 A ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isIMatrixFour)
    // insert implementation here
    return isIMatrix(A);
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isIMatrixFour)
  }

  /**
   * Return <code>true</code> iff the implementation sees
   * an incoming column-major array satisfying condition I.
   */
  public static boolean isColumnIMatrixFour_Impl (
    /*in*/ sidl.Integer.Array4 A ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isColumnIMatrixFour)
    // insert implementation here
    return A._isColumnOrder() && isIMatrix(A);
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isColumnIMatrixFour)
  }

  /**
   * Return <code>true</code> iff the implementation sees
   * an incoming row-major array satisfying condition I.
   */
  public static boolean isRowIMatrixFour_Impl (
    /*in*/ sidl.Integer.Array4 A ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isRowIMatrixFour)
    // insert implementation here
    return A._isRowOrder() && isIMatrix(A);
    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isRowIMatrixFour)
  }

  /**
   * Return <code>true</code> iff the implementation of slice
   * and smart copy is correct.
   */
  public static boolean isSliceWorking_Impl (
    /*in*/ boolean useCreateCol ) 
  {
    // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest.isSliceWorking)
    // insert implementation here
    boolean res = true;
    int maxDim = 16;
    int halfDim = maxDim >> 1;
    sidl.Integer.Array A = null;
    sidl.Integer.Array B = null; 
    sidl.Integer.Array1 B1 =null;
    sidl.Integer.Array2 B2 =null;
    sidl.Integer.Array3 B3 =null;
    sidl.Integer.Array4 B4 =null;
    sidl.Integer.Array5 B5 =null;
    sidl.Integer.Array6 B6 =null;
    int ind[] = new int[2];
    int stride[] = {2, 2};
    int numElem[] = new int[2];
    int newIndex[] = new int[2];
    numElem[0] = numElem[1] = halfDim;
    if (useCreateCol) {
      A = Ordering.IntOrderTest.makeColumnIMatrix(maxDim,false);
    } else {
      A = Ordering.IntOrderTest.makeRowIMatrix(maxDim,false);
    }
    B = A._slice(2, numElem, null, stride, null);
    if (!(B != null && B._dim() == 2)) {
      return false;
    }
    B2 = (sidl.Integer.Array2) B._dcast();
    for(ind[1] = newIndex[1] = 0; newIndex[1] < halfDim; 
        ++newIndex[1], ind[1] += 2) {
      for(ind[0] = newIndex[0] = 0; newIndex[0] < halfDim;
          ++newIndex[0], ind[0] += 2) {
        if ((B2.get(newIndex[0], newIndex[1]) != iFunc(ind,2))) {
          return false;
        }
      }
    }

    B = null;
    B2 = null;
    ind[0] = ind[1] = 1;
    newIndex[0] = newIndex[1] = 0;
    B = A._slice(2, numElem, ind, stride, newIndex);
    if (!(B != null && B._dim() == 2)) {
      return false;
    }
    B2 = (sidl.Integer.Array2) B._dcast();
    for(newIndex[1] = 0; newIndex[1] < halfDim; 
        ++newIndex[1], ind[1] += 2) {
      for(ind[0] = 1, newIndex[0] = 0; newIndex[0] < halfDim;
          ++newIndex[0], ind[0] += 2) {
        if ((B2.get(newIndex[0], newIndex[1]) != iFunc(ind,2))) {
          return false;
        }
      }
    }
    
    B = null;
    B2 = null;

    ind[0] = ind[1] = 1;
    newIndex[1] = newIndex[0] = 1;
    B = A._slice(2, numElem, ind, stride, newIndex);
    if (!(B != null && B._dim() == 2)) {
      return false;
    }
    B2 = (sidl.Integer.Array2) B._dcast();

    for(newIndex[1] = 1; newIndex[1] <= halfDim; 
        ++newIndex[1], ind[1] += 2) {
      for(ind[0] = 1, newIndex[0] = 1; newIndex[0] <= halfDim;
          ++newIndex[0], ind[0] += 2) {
        if ((B2.get(newIndex[0], newIndex[1]) != iFunc(ind,2)) || 
            (B2.get(newIndex[0], newIndex[1]) != 
            A._get(ind[0], ind[1], 0,0,0,0,0))) {
          
          return false;
        }
      }
    }
    
    B = null;
    B2 = null;
    numElem[0] = 0;
    numElem[1] = maxDim;
    B = A._slice(1, numElem, null, null, null);
    if (!(B != null && B._dim() == 1)) {
      return false;
    }
    B1 = (sidl.Integer.Array1) B._dcast();
    ind[0] = newIndex[0] = 0;
    for(ind[1] = newIndex[1] = 0; newIndex[1] < maxDim; 
        ++newIndex[1], ++ind[1]) {
      if (B1.get(newIndex[1]) != 
          A._get(ind[0], ind[1],0,0,0,0,0)) {
        return false;
      }
    }
  
    B = null;
    B1 = null;
    numElem[0] = maxDim;
    numElem[1] = 0;
    ind[0] = 0;
    ind[1] = 8;
    newIndex[0] = newIndex[1] = 0;
    B = A._slice(1, numElem, ind, null, newIndex);
    if (!(B != null && (B._dim() == 1))) {
      return false;
    }
    B1 = (sidl.Integer.Array1) B._dcast();

    for(ind[0] = newIndex[0] = 0; newIndex[0] < maxDim; 
        ++newIndex[0], ++ind[0]) {
      if (B1.get(newIndex[0]) != 
          A._get(ind[0], ind[1],0,0,0,0,0)) {
        return false;
      }
    }
  
    B = null;
    B1 = null;
    numElem[0] = maxDim;
    numElem[1] = 0;
    ind[0] = 0;
    ind[1] = 0;
    B = A._slice(1, numElem, ind, null, null);
    if (!(B != null && (B._dim() == 1))) {
      return false;
    }
    B1 = (sidl.Integer.Array1) B._dcast();
    if (!(Ordering.IntOrderTest.isIMatrixOne(B1) &&
          Ordering.IntOrderTest.isColumnIMatrixOne(B1) &&
          Ordering.IntOrderTest.isRowIMatrixOne(B1))) {
      return false;
    }
  
    return res;

    // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest.isSliceWorking)
  }


  // user defined non-static methods: (none)

  // DO-NOT-DELETE splicer.begin(Ordering.IntOrderTest._misc)
  // Put miscellaneous code here
  // DO-NOT-DELETE splicer.end(Ordering.IntOrderTest._misc)

} // end class IntOrderTest