File: IntOrderTest_Impl.py

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 (456 lines) | stat: -rw-r--r-- 10,339 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
#
# File:          IntOrderTest_Impl.py
# Symbol:        Ordering.IntOrderTest-v0.1
# Symbol Type:   class
# Babel Version: 0.10.2
# Description:   Implementation of sidl class Ordering.IntOrderTest in Python.
# 
# WARNING: Automatically generated; changes will be lost
# 
# babel-version = 0.10.2
#


"""This class provides methods to verify that the array ordering
capabilities work for arrays of int.
"""

# DO-NOT-DELETE splicer.begin(_initial)
from Numeric import *;
# DO-NOT-DELETE splicer.end(_initial)

import Ordering.IntOrderTest
import sidl.ClassInfo
import sidl.BaseInterface
import sidl.BaseClass

# DO-NOT-DELETE splicer.begin(_before_static)
def iFunc(ind):
  res = 0
  for i in range(len(ind)):
    res = res + (i+1) * ind[i]
  return res

def isIMatrix(A):
  if (len(A.shape) == 1):
    for i in range(A.shape[0]):
      if (A[i] != iFunc((i,))):
        return 0
  else:
    if (len(A.shape) == 2):
      for i in range(A.shape[0]):
        for j in range(A.shape[1]):
          if (A[i,j] != iFunc((i, j))):
              return 0
    else:
      if (len(A.shape) == 4):
        for i in range(A.shape[0]):
          for j in range(A.shape[1]):
            for k in range(A.shape[2]):
              for l in range(A.shape[3]):
                if (A[i,j,k,l] != iFunc((i, j, k, l))):
                    return 0
      else:
        return 0
  return 1
# DO-NOT-DELETE splicer.end(_before_static)

def makeColumnIMatrix(size, useCreateCol):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # int size
  # bool useCreateCol
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # array<int,2,column-major> _return
  #

  """\
Create a column-major matrix satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(makeColumnIMatrix)
  res = zeros((size, size), Int32)
  for i in range(size):
    for j in range(size):
      res[i,j] = iFunc((i,j))
  return res
  # DO-NOT-DELETE splicer.end(makeColumnIMatrix)

def makeRowIMatrix(size, useCreateRow):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # int size
  # bool useCreateRow
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # array<int,2,row-major> _return
  #

  """\
Create a row-major matrix satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(makeRowIMatrix)
  res = zeros((size, size), Int32)
  for i in range(size):
    for j in range(size):
      res[i,j] = iFunc((i,j))
  return res
  # DO-NOT-DELETE splicer.end(makeRowIMatrix)

def makeIMatrix(size, useCreateColumn):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # int size
  # bool useCreateColumn
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # array<int,4> _return
  #

  """\
Create a 4-D matrix satisfying condition I.  Each dimension has
size elements numbers 0 through size-1.
"""
  # DO-NOT-DELETE splicer.begin(makeIMatrix)
  res = zeros((size, size, size, size), Int32)
  for i in range(size):
    for j in range(size):
      for k in range(size):
        for l in range(size):
          res[i,j,k,l] = iFunc((i,j,k,l))
  return res
  # DO-NOT-DELETE splicer.end(makeIMatrix)

def createColumnIMatrix(size, useCreateCol):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # int size
  # bool useCreateCol
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # array<int,2,column-major> res
  #

  """\
Create a column-major matrix satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(createColumnIMatrix)
  if (useCreateCol):
    return makeColumnIMatrix(size, 1)
  else:
    return makeRowIMatrix(size, 1)
  # DO-NOT-DELETE splicer.end(createColumnIMatrix)

def createRowIMatrix(size, useCreateRow):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # int size
  # bool useCreateRow
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # array<int,2,row-major> res
  #

  """\
Create a row-major matrix satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(createRowIMatrix)
  if (useCreateRow):
    return makeRowIMatrix(size, 1)
  else:
    return makeColumnIMatrix(size, 1)
  # DO-NOT-DELETE splicer.end(createRowIMatrix)

def ensureColumn(a):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,2,column-major> a
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # array<int,2,column-major> a
  #

  """\
Make sure an array is column-major.  No changes to the dimension or
values in a are made.
"""
  # DO-NOT-DELETE splicer.begin(ensureColumn)
  return a
  # DO-NOT-DELETE splicer.end(ensureColumn)

def ensureRow(a):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,2,row-major> a
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # array<int,2,row-major> a
  #

  """\
Make sure an array is row-major.  No changes to the dimension or
values in a are made.
"""
  # DO-NOT-DELETE splicer.begin(ensureRow)
  return a
  # DO-NOT-DELETE splicer.end(ensureRow)

def isIMatrixOne(A):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int> A
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
 Return <code>true</code> iff the implementation sees
 an incoming array satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(isIMatrixOne)
  return isIMatrix(A)                 
  # DO-NOT-DELETE splicer.end(isIMatrixOne)

def isColumnIMatrixOne(A):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,column-major> A
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
Return <code>true</code> iff the implementation sees
an incoming column-major array satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(isColumnIMatrixOne)
  return isIMatrix(A)                 
  # DO-NOT-DELETE splicer.end(isColumnIMatrixOne)

def isRowIMatrixOne(A):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,row-major> A
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
Return <code>true</code> iff the implementation sees
an incoming row-major array satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(isRowIMatrixOne)
  return isIMatrix(A)                 
  # DO-NOT-DELETE splicer.end(isRowIMatrixOne)

def isIMatrixTwo(A):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,2> A
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
 Return <code>true</code> iff the implementation sees
 an incoming array satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(isIMatrixTwo)
  return isIMatrix(A)                 
  # DO-NOT-DELETE splicer.end(isIMatrixTwo)

def isColumnIMatrixTwo(A):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,2,column-major> A
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
Return <code>true</code> iff the implementation sees
an incoming column-major array satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(isColumnIMatrixTwo)
  return isIMatrix(A)                 
  # DO-NOT-DELETE splicer.end(isColumnIMatrixTwo)

def isRowIMatrixTwo(A):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,2,row-major> A
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
Return <code>true</code> iff the implementation sees
an incoming row-major array satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(isRowIMatrixTwo)
  return isIMatrix(A)                 
  # DO-NOT-DELETE splicer.end(isRowIMatrixTwo)

def isIMatrixFour(A):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,4> A
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
 Return <code>true</code> iff the implementation sees
 an incoming array satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(isIMatrixFour)
  return isIMatrix(A)                 
  # DO-NOT-DELETE splicer.end(isIMatrixFour)

def isColumnIMatrixFour(A):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,4,column-major> A
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
Return <code>true</code> iff the implementation sees
an incoming column-major array satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(isColumnIMatrixFour)
  return isIMatrix(A)                 
  # DO-NOT-DELETE splicer.end(isColumnIMatrixFour)

def isRowIMatrixFour(A):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # array<int,4,row-major> A
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
Return <code>true</code> iff the implementation sees
an incoming row-major array satisfying condition I.
"""
  # DO-NOT-DELETE splicer.begin(isRowIMatrixFour)
  return isIMatrix(A)                 
  # DO-NOT-DELETE splicer.end(isRowIMatrixFour)

def isSliceWorking(useCreateCol):
  #
  # sidl EXPECTED INCOMING TYPES
  # ============================
  # bool useCreateCol
  #

  #
  # sidl EXPECTED RETURN VALUE(s)
  # =============================
  # bool _return
  #

  """\
Return <code>true</code> iff the implementation of slice
and smart copy is correct.
"""
  # DO-NOT-DELETE splicer.begin(isSliceWorking)
  return 1
  # DO-NOT-DELETE splicer.end(isSliceWorking)

# DO-NOT-DELETE splicer.begin(_before_type)
# Put your code here...
# DO-NOT-DELETE splicer.end(_before_type)

class IntOrderTest:
  """\
This class provides methods to verify that the array ordering
capabilities work for arrays of int.
"""

  # All calls to sidl methods should use __IORself

  def __init__(self, IORself):
    self.__IORself = IORself
    # DO-NOT-DELETE splicer.begin(__init__)
    # Put your code here...
    # DO-NOT-DELETE splicer.end(__init__)

# DO-NOT-DELETE splicer.begin(_final)
# Put your code here...
# DO-NOT-DELETE splicer.end(_final)