~jtaylor/ubuntu/precise/python-numpy/multiarch-fix-818867

« back to all changes in this revision

Viewing changes to numpy/f2py/lib/test_scalar_in_out.py

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik, Riku Voipio, Tiziano Zito, Carlos Galisteo, Ondrej Certik
  • Date: 2008-07-08 15:08:16 UTC
  • mfrom: (0.1.21 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080708150816-ekf992jcp2k1eua3
Tags: 1:1.1.0-3
[ Riku Voipio ]
* debian/control: atlas is not available on armel, and after a quick look
  neither on alpha. I'd also suggest dropping
  libatlas-sse-dev|libatlas-sse2-dev|libatlas-3dnow-dev alternative combo
  away, these are potentially dangerous on buildd's. Ondrej: dropped.
  (Closes: #489568)

[ Tiziano Zito ]
* patch: build _dotblas.c when ATLAS is not installed, build-conflict with
  atlas, build-depend on blas+lapack only, as it used to be (Closes: #489726)

[ Carlos Galisteo ]
* debian/control
  - Added Homepage field.

[ Ondrej Certik ]
* Checked the package on i386 and amd64, both with and without atlas, all
  tests run and the numpy package is faster if atlas is around. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
"""
3
 
Tests for intent(in,out) arguments in Fortran subroutine's.
4
 
 
5
 
-----
6
 
Permission to use, modify, and distribute this software is given under the
7
 
terms of the NumPy License. See http://scipy.org.
8
 
 
9
 
NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
10
 
Author: Pearu Peterson <pearu@cens.ioc.ee>
11
 
Created: Oct 2006
12
 
-----
13
 
"""
14
 
 
15
 
import os
16
 
import sys
17
 
from numpy.testing import *
18
 
 
19
 
def build(fortran_code, rebuild=True, build_dir='tmp'):
20
 
    modulename = os.path.splitext(os.path.basename(__file__))[0]+'_ext'
21
 
    try:
22
 
        exec ('import %s as m' % (modulename))
23
 
        if rebuild and os.stat(m.__file__)[8] < os.stat(__file__)[8]:
24
 
            del sys.modules[m.__name__] # soft unload extension module
25
 
            os.remove(m.__file__)
26
 
            raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
27
 
    except ImportError,msg:
28
 
        assert str(msg)==('No module named %s' % (modulename)) \
29
 
               or str(msg).startswith('%s is newer than' % (__file__)),str(msg)
30
 
        print msg, ', recompiling %s.' % (modulename)
31
 
        if not os.path.isdir(build_dir): os.makedirs(build_dir)
32
 
        fname = os.path.join(build_dir,'%s_source.f' % (modulename))
33
 
        f = open(fname,'w')
34
 
        f.write(fortran_code)
35
 
        f.close()
36
 
        sys_argv = ['--build-dir',build_dir]
37
 
        #sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
38
 
        from main import build_extension
39
 
        sys_argv.extend(['-m',modulename, fname])
40
 
        build_extension(sys_argv)
41
 
        status = os.system(' '.join([sys.executable] + sys.argv))
42
 
        sys.exit(status)
43
 
    return m
44
 
 
45
 
fortran_code = '''
46
 
      subroutine fooint1(a)
47
 
      integer*1 a
48
 
!f2py intent(in,out) a
49
 
      a = a + 1
50
 
      end
51
 
      subroutine fooint2(a)
52
 
      integer*2 a
53
 
!f2py intent(in,out) a
54
 
      a = a + 1
55
 
      end
56
 
      subroutine fooint4(a)
57
 
      integer*4 a
58
 
!f2py intent(in,out) a
59
 
      a = a + 1
60
 
      end
61
 
      subroutine fooint8(a)
62
 
      integer*8 a
63
 
!f2py intent(in,out) a
64
 
      a = a + 1
65
 
      end
66
 
      subroutine foofloat4(a)
67
 
      real*4 a
68
 
!f2py intent(in,out) a
69
 
      a = a + 1.0e0
70
 
      end
71
 
      subroutine foofloat8(a)
72
 
      real*8 a
73
 
!f2py intent(in,out) a
74
 
      a = a + 1.0d0
75
 
      end
76
 
      subroutine foocomplex8(a)
77
 
      complex*8 a
78
 
!f2py intent(in,out) a
79
 
      a = a + 1.0e0
80
 
      end
81
 
      subroutine foocomplex16(a)
82
 
      complex*16 a
83
 
!f2py intent(in,out) a
84
 
      a = a + 1.0d0
85
 
      end
86
 
      subroutine foobool1(a)
87
 
      logical*1 a
88
 
!f2py intent(in,out) a
89
 
      a = .not. a
90
 
      end
91
 
      subroutine foobool2(a)
92
 
      logical*2 a
93
 
!f2py intent(in,out) a
94
 
      a = .not. a
95
 
      end
96
 
      subroutine foobool4(a)
97
 
      logical*4 a
98
 
!f2py intent(in,out) a
99
 
      a = .not. a
100
 
      end
101
 
      subroutine foobool8(a)
102
 
      logical*8 a
103
 
!f2py intent(in,out) a
104
 
      a = .not. a
105
 
      end
106
 
      subroutine foostring1(a)
107
 
      character*1 a
108
 
!f2py intent(in,out) a
109
 
      a = "1"
110
 
      end
111
 
      subroutine foostring5(a)
112
 
      character*5 a
113
 
!f2py intent(in,out) a
114
 
      a(1:2) = "12"
115
 
      end
116
 
      subroutine foostringstar(a)
117
 
      character*(*) a
118
 
!f2py intent(in,out) a
119
 
      if (len(a).gt.0) then
120
 
        a(1:1) = "1"
121
 
      endif
122
 
      end
123
 
'''
124
 
 
125
 
# tester note: set rebuild=True when changing fortan_code and for SVN
126
 
m = build(fortran_code, rebuild=True)
127
 
 
128
 
from numpy import *
129
 
 
130
 
class test_m(NumpyTestCase):
131
 
 
132
 
    def check_foo_integer1(self, level=1):
133
 
        i = int8(2)
134
 
        e = int8(3)
135
 
        func = m.fooint1
136
 
        assert isinstance(i,int8),`type(i)`
137
 
        r = func(i)
138
 
        assert isinstance(r,int8),`type(r)`
139
 
        assert i is not r,`id(i),id(r)`
140
 
        assert_equal(r,e)
141
 
 
142
 
        r = func(2)
143
 
        assert isinstance(r,int8),`type(r)`
144
 
        assert_equal(r,e)
145
 
 
146
 
        for intx in [int64,int16,int32]:
147
 
            r = func(intx(2))
148
 
            assert isinstance(r,int8),`type(r)`
149
 
            assert_equal(r,e)
150
 
 
151
 
        r = func(2.0)
152
 
        assert isinstance(r,int8),`type(r)`
153
 
        assert_equal(r,e)
154
 
 
155
 
        r = func(2.2)
156
 
        assert isinstance(r,int8),`type(r)`
157
 
        assert_equal(r,e)
158
 
 
159
 
        r = func([2])
160
 
        assert isinstance(r,int8),`type(r)`
161
 
        assert_equal(r,e)
162
 
 
163
 
        self.assertRaises(TypeError,lambda :func(2.2j))
164
 
        self.assertRaises(TypeError,lambda :func([2,1]))
165
 
        self.assertRaises(TypeError,lambda :func({}))
166
 
 
167
 
    def check_foo_integer2(self, level=1):
168
 
        i = int16(2)
169
 
        e = int16(3)
170
 
        func = m.fooint2
171
 
        assert isinstance(i,int16),`type(i)`
172
 
        r = func(i)
173
 
        assert isinstance(r,int16),`type(r)`
174
 
        assert i is not r,`id(i),id(r)`
175
 
        assert_equal(r,e)
176
 
 
177
 
        r = func(2)
178
 
        assert isinstance(r,int16),`type(r)`
179
 
        assert_equal(r,e)
180
 
 
181
 
        for intx in [int8,int64,int32]:
182
 
            r = func(intx(2))
183
 
            assert isinstance(r,int16),`type(r)`
184
 
            assert_equal(r,e)
185
 
 
186
 
        r = func(2.0)
187
 
        assert isinstance(r,int16),`type(r)`
188
 
        assert_equal(r,e)
189
 
 
190
 
        r = func(2.2)
191
 
        assert isinstance(r,int16),`type(r)`
192
 
        assert_equal(r,e)
193
 
 
194
 
        r = func([2])
195
 
        assert isinstance(r,int16),`type(r)`
196
 
        assert_equal(r,e)
197
 
 
198
 
        self.assertRaises(TypeError,lambda :func(2.2j))
199
 
        self.assertRaises(TypeError,lambda :func([2,1]))
200
 
        self.assertRaises(TypeError,lambda :func({}))
201
 
 
202
 
    def check_foo_integer4(self, level=1):
203
 
        i = int32(2)
204
 
        e = int32(3)
205
 
        func = m.fooint4
206
 
        assert isinstance(i,int32),`type(i)`
207
 
        r = func(i)
208
 
        assert isinstance(r,int32),`type(r)`
209
 
        assert i is not r,`id(i),id(r)`
210
 
        assert_equal(r,e)
211
 
 
212
 
        r = func(2)
213
 
        assert isinstance(r,int32),`type(r)`
214
 
        assert_equal(r,e)
215
 
 
216
 
        for intx in [int8,int16,int64]:
217
 
            r = func(intx(2))
218
 
            assert isinstance(r,int32),`type(r)`
219
 
            assert_equal(r,e)
220
 
 
221
 
        r = func(2.0)
222
 
        assert isinstance(r,int32),`type(r)`
223
 
        assert_equal(r,e)
224
 
 
225
 
        r = func(2.2)
226
 
        assert isinstance(r,int32),`type(r)`
227
 
        assert_equal(r,e)
228
 
 
229
 
        r = func([2])
230
 
        assert isinstance(r,int32),`type(r)`
231
 
        assert_equal(r,e)
232
 
 
233
 
        self.assertRaises(TypeError,lambda :func(2.2j))
234
 
        self.assertRaises(TypeError,lambda :func([2,1]))
235
 
        self.assertRaises(TypeError,lambda :func({}))
236
 
 
237
 
    def check_foo_integer8(self, level=1):
238
 
        i = int64(2)
239
 
        e = int64(3)
240
 
        func = m.fooint8
241
 
        assert isinstance(i,int64),`type(i)`
242
 
        r = func(i)
243
 
        assert isinstance(r,int64),`type(r)`
244
 
        assert i is not r,`id(i),id(r)`
245
 
        assert_equal(r,e)
246
 
 
247
 
        r = func(2)
248
 
        assert isinstance(r,int64),`type(r)`
249
 
        assert_equal(r,e)
250
 
 
251
 
        r = func(2.0)
252
 
        assert isinstance(r,int64),`type(r)`
253
 
        assert_equal(r,e)
254
 
 
255
 
        r = func(2.2)
256
 
        assert isinstance(r,int64),`type(r)`
257
 
        assert_equal(r,e)
258
 
 
259
 
        for intx in [int8,int16,int32]:
260
 
            r = func(intx(2))
261
 
            assert isinstance(r,int64),`type(r)`
262
 
            assert_equal(r,e)
263
 
 
264
 
        r = func([2])
265
 
        assert isinstance(r,int64),`type(r)`
266
 
        assert_equal(r,e)
267
 
 
268
 
        self.assertRaises(TypeError,lambda :func(2.2j))
269
 
        self.assertRaises(TypeError,lambda :func([2,1]))
270
 
        self.assertRaises(TypeError,lambda :func({}))
271
 
 
272
 
    def check_foo_real4(self, level=1):
273
 
        i = float32(2)
274
 
        e = float32(3)
275
 
        func = m.foofloat4
276
 
        assert isinstance(i,float32),`type(i)`
277
 
        r = func(i)
278
 
        assert isinstance(r,float32),`type(r)`
279
 
        assert i is not r,`id(i),id(r)`
280
 
        assert_equal(r,e)
281
 
 
282
 
        r = func(2)
283
 
        assert isinstance(r,float32),`type(r)`
284
 
        assert_equal(r,e)
285
 
 
286
 
        r = func(2.0)
287
 
        assert isinstance(r,float32),`type(r)`
288
 
        assert_equal(r,e)
289
 
 
290
 
        r = func(2.2)
291
 
        assert isinstance(r,float32),`type(r)`
292
 
        assert_equal(r,e+float32(0.2))
293
 
 
294
 
        r = func(float64(2.0))
295
 
        assert isinstance(r,float32),`type(r)`
296
 
        assert_equal(r,e)
297
 
 
298
 
        r = func([2])
299
 
        assert isinstance(r,float32),`type(r)`
300
 
        assert_equal(r,e)
301
 
 
302
 
        self.assertRaises(TypeError,lambda :func(2.2j))
303
 
        self.assertRaises(TypeError,lambda :func([2,1]))
304
 
        self.assertRaises(TypeError,lambda :func({}))
305
 
 
306
 
    def check_foo_real8(self, level=1):
307
 
        i = float64(2)
308
 
        e = float64(3)
309
 
        func = m.foofloat8
310
 
        assert isinstance(i,float64),`type(i)`
311
 
        r = func(i)
312
 
        assert isinstance(r,float64),`type(r)`
313
 
        assert i is not r,`id(i),id(r)`
314
 
        assert_equal(r,e)
315
 
 
316
 
        r = func(2)
317
 
        assert isinstance(r,float64),`type(r)`
318
 
        assert_equal(r,e)
319
 
 
320
 
        r = func(2.0)
321
 
        assert isinstance(r,float64),`type(r)`
322
 
        assert_equal(r,e)
323
 
 
324
 
        r = func(2.2)
325
 
        assert isinstance(r,float64),`type(r)`
326
 
        assert_equal(r,e+float64(0.2))
327
 
 
328
 
        r = func(float32(2.0))
329
 
        assert isinstance(r,float64),`type(r)`
330
 
        assert_equal(r,e)
331
 
 
332
 
        r = func([2])
333
 
        assert isinstance(r,float64),`type(r)`
334
 
        assert_equal(r,e)
335
 
 
336
 
        self.assertRaises(TypeError,lambda :func(2.2j))
337
 
        self.assertRaises(TypeError,lambda :func([2,1]))
338
 
        self.assertRaises(TypeError,lambda :func({}))
339
 
 
340
 
    def check_foo_complex8(self, level=1):
341
 
        i = complex64(2)
342
 
        e = complex64(3)
343
 
        func = m.foocomplex8
344
 
        assert isinstance(i,complex64),`type(i)`
345
 
        r = func(i)
346
 
        assert isinstance(r,complex64),`type(r)`
347
 
        assert i is not r,`id(i),id(r)`
348
 
        assert_equal(r,e)
349
 
 
350
 
        r = func(2)
351
 
        assert isinstance(r,complex64),`type(r)`
352
 
        assert_equal(r,e)
353
 
 
354
 
        r = func(2.0)
355
 
        assert isinstance(r,complex64),`type(r)`
356
 
        assert_equal(r,e)
357
 
 
358
 
        r = func(2.2)
359
 
        assert isinstance(r,complex64),`type(r)`
360
 
        assert_equal(r,e+complex64(0.2))
361
 
 
362
 
        r = func(2+1j)
363
 
        assert isinstance(r,complex64),`type(r)`
364
 
        assert_equal(r,e+complex64(1j))
365
 
 
366
 
        r = func(complex128(2.0))
367
 
        assert isinstance(r,complex64),`type(r)`
368
 
        assert_equal(r,e)
369
 
 
370
 
        r = func([2])
371
 
        assert isinstance(r,complex64),`type(r)`
372
 
        assert_equal(r,e)
373
 
 
374
 
        r = func([2,3])
375
 
        assert isinstance(r,complex64),`type(r)`
376
 
        assert_equal(r,e+complex64(3j))
377
 
 
378
 
        self.assertRaises(TypeError,lambda :func([2,1,3]))
379
 
        self.assertRaises(TypeError,lambda :func({}))
380
 
 
381
 
    def check_foo_complex16(self, level=1):
382
 
        i = complex128(2)
383
 
        e = complex128(3)
384
 
        func = m.foocomplex16
385
 
        assert isinstance(i,complex128),`type(i)`
386
 
        r = func(i)
387
 
        assert isinstance(r,complex128),`type(r)`
388
 
        assert i is not r,`id(i),id(r)`
389
 
        assert_equal(r,e)
390
 
 
391
 
        r = func(2)
392
 
        assert isinstance(r,complex128),`type(r)`
393
 
        assert_equal(r,e)
394
 
 
395
 
        r = func(2.0)
396
 
        assert isinstance(r,complex128),`type(r)`
397
 
        assert_equal(r,e)
398
 
 
399
 
        r = func(2.2)
400
 
        assert isinstance(r,complex128),`type(r)`
401
 
        assert_equal(r,e+complex128(0.2))
402
 
 
403
 
        r = func(2+1j)
404
 
        assert isinstance(r,complex128),`type(r)`
405
 
        assert_equal(r,e+complex128(1j))
406
 
 
407
 
        r = func([2])
408
 
        assert isinstance(r,complex128),`type(r)`
409
 
        assert_equal(r,e)
410
 
 
411
 
        r = func([2,3])
412
 
        assert isinstance(r,complex128),`type(r)`
413
 
        assert_equal(r,e+complex128(3j))
414
 
 
415
 
        r = func(complex64(2.0))
416
 
        assert isinstance(r,complex128),`type(r)`
417
 
        assert_equal(r,e)
418
 
 
419
 
        self.assertRaises(TypeError,lambda :func([2,1,3]))
420
 
        self.assertRaises(TypeError,lambda :func({}))
421
 
 
422
 
    def check_foo_bool1(self, level=1):
423
 
        i = bool8(True)
424
 
        e = bool8(False)
425
 
        func = m.foobool1
426
 
        assert isinstance(i,bool8),`type(i)`
427
 
        r = func(i)
428
 
        assert isinstance(r,bool8),`type(r)`
429
 
        assert i is not r,`id(i),id(r)`
430
 
        assert_equal(r,e)
431
 
 
432
 
        for tv in [1,2,2.1,-1j,[0],True]:
433
 
            r = func(tv)
434
 
            assert isinstance(r,bool8),`type(r)`
435
 
            assert_equal(r,e)
436
 
 
437
 
        for fv in [0,0.0,0j,False,(),{},[]]:
438
 
            r = func(fv)
439
 
            assert isinstance(r,bool8),`type(r)`
440
 
            assert_equal(r,not e)
441
 
 
442
 
    def check_foo_bool2(self, level=1):
443
 
        i = bool8(True)
444
 
        e = bool8(False)
445
 
        func = m.foobool2
446
 
        assert isinstance(i,bool8),`type(i)`
447
 
        r = func(i)
448
 
        assert isinstance(r,bool8),`type(r)`
449
 
        assert i is not r,`id(i),id(r)`
450
 
        assert_equal(r,e)
451
 
 
452
 
        for tv in [1,2,2.1,-1j,[0],True]:
453
 
            r = func(tv)
454
 
            assert isinstance(r,bool8),`type(r)`
455
 
            assert_equal(r,e)
456
 
 
457
 
        for fv in [0,0.0,0j,False,(),{},[]]:
458
 
            r = func(fv)
459
 
            assert isinstance(r,bool8),`type(r)`
460
 
            assert_equal(r,not e)
461
 
 
462
 
    def check_foo_bool4(self, level=1):
463
 
        i = bool8(True)
464
 
        e = bool8(False)
465
 
        func = m.foobool4
466
 
        assert isinstance(i,bool8),`type(i)`
467
 
        r = func(i)
468
 
        assert isinstance(r,bool8),`type(r)`
469
 
        assert i is not r,`id(i),id(r)`
470
 
        assert_equal(r,e)
471
 
 
472
 
        for tv in [1,2,2.1,-1j,[0],True]:
473
 
            r = func(tv)
474
 
            assert isinstance(r,bool8),`type(r)`
475
 
            assert_equal(r,e)
476
 
 
477
 
        for fv in [0,0.0,0j,False,(),{},[]]:
478
 
            r = func(fv)
479
 
            assert isinstance(r,bool8),`type(r)`
480
 
            assert_equal(r,not e)
481
 
 
482
 
    def check_foo_bool8(self, level=1):
483
 
        i = bool8(True)
484
 
        e = bool8(False)
485
 
        func = m.foobool8
486
 
        assert isinstance(i,bool8),`type(i)`
487
 
        r = func(i)
488
 
        assert isinstance(r,bool8),`type(r)`
489
 
        assert i is not r,`id(i),id(r)`
490
 
        assert_equal(r,e)
491
 
 
492
 
        for tv in [1,2,2.1,-1j,[0],True]:
493
 
            r = func(tv)
494
 
            assert isinstance(r,bool8),`type(r)`
495
 
            assert_equal(r,e)
496
 
 
497
 
        for fv in [0,0.0,0j,False,(),{},[]]:
498
 
            r = func(fv)
499
 
            assert isinstance(r,bool8),`type(r)`
500
 
            assert_equal(r,not e)
501
 
 
502
 
    def check_foo_string1(self, level=1):
503
 
        i = string0('a')
504
 
        e = string0('1')
505
 
        func = m.foostring1
506
 
        assert isinstance(i,string0),`type(i)`
507
 
        r = func(i)
508
 
        assert isinstance(r,string0),`type(r)`
509
 
        assert i is not r,`id(i),id(r)`
510
 
        assert_equal(r,e)
511
 
 
512
 
        r = func('ab')
513
 
        assert isinstance(r,string0),`type(r)`
514
 
        assert_equal(r,e)
515
 
 
516
 
        r = func('')
517
 
        assert isinstance(r,string0),`type(r)`
518
 
        assert_equal(r,e)
519
 
 
520
 
    def check_foo_string5(self, level=1):
521
 
        i = string0('abcde')
522
 
        e = string0('12cde')
523
 
        func = m.foostring5
524
 
        assert isinstance(i,string0),`type(i)`
525
 
        r = func(i)
526
 
        assert isinstance(r,string0),`type(r)`
527
 
        assert i is not r,`id(i),id(r)`
528
 
        assert_equal(r,e)
529
 
 
530
 
        r = func('abc')
531
 
        assert isinstance(r,string0),`type(r)`
532
 
        assert_equal(r,'12c  ')
533
 
 
534
 
        r = func('abcdefghi')
535
 
        assert isinstance(r,string0),`type(r)`
536
 
        assert_equal(r,'12cde')
537
 
 
538
 
        r = func([1])
539
 
        assert isinstance(r,string0),`type(r)`
540
 
        assert_equal(r,'12]  ')
541
 
 
542
 
    def check_foo_string0(self, level=1):
543
 
        i = string0('abcde')
544
 
        e = string0('12cde')
545
 
        func = m.foostringstar
546
 
        r = func('abcde')
547
 
        assert_equal(r,'1bcde')
548
 
        r = func('')
549
 
        assert_equal(r,'')
550
 
        
551
 
if __name__ == "__main__":
552
 
    NumpyTest().run()