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

« back to all changes in this revision

Viewing changes to numpy/core/tests/test_numeric.orig

  • 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
 
from numpy.core import *
2
 
from numpy.random import rand, randint
3
 
from numpy.testing import *
4
 
from numpy.core.multiarray import dot as dot_
5
 
 
6
 
class Vec:
7
 
    def __init__(self,sequence=None):
8
 
        if sequence is None:
9
 
            sequence=[]
10
 
        self.array=array(sequence)    
11
 
    def __add__(self,other):
12
 
        out=Vec()
13
 
        out.array=self.array+other.array
14
 
        return out
15
 
    def __sub__(self,other):
16
 
        out=Vec()
17
 
        out.array=self.array-other.array
18
 
        return out
19
 
    def __mul__(self,other): # with scalar
20
 
        out=Vec(self.array.copy())
21
 
        out.array*=other
22
 
        return out
23
 
    def __rmul__(self,other):
24
 
        return self*other
25
 
    def __abs__(self):
26
 
        out=Vec()
27
 
        out.array=abs(self.array)
28
 
        return out
29
 
    def __repr__(self):
30
 
        return "Vec("+repr(self.array.tolist())+")"
31
 
    __str__=__repr__
32
 
 
33
 
class test_dot(NumpyTestCase):
34
 
    def setUp(self):
35
 
        self.A = rand(10,8)
36
 
        self.b1 = rand(8,1)
37
 
        self.b2 = rand(8)
38
 
        self.b3 = rand(1,8)
39
 
        self.b4 = rand(10)
40
 
        self.N = 14
41
 
 
42
 
    def check_matmat(self):
43
 
        A = self.A
44
 
        c1 = dot(A.transpose(), A)
45
 
        c2 = dot_(A.transpose(), A)
46
 
        assert_almost_equal(c1, c2, decimal=self.N)
47
 
 
48
 
    def check_matvec(self):
49
 
        A, b1 = self.A, self.b1
50
 
        c1 = dot(A, b1)
51
 
        c2 = dot_(A, b1)
52
 
        assert_almost_equal(c1, c2, decimal=self.N)
53
 
 
54
 
    def check_matvec2(self):
55
 
        A, b2 = self.A, self.b2
56
 
        c1 = dot(A, b2)
57
 
        c2 = dot_(A, b2)
58
 
        assert_almost_equal(c1, c2, decimal=self.N)
59
 
 
60
 
    def check_vecmat(self):
61
 
        A, b4 = self.A, self.b4
62
 
        c1 = dot(b4, A)
63
 
        c2 = dot_(b4, A)
64
 
        assert_almost_equal(c1, c2, decimal=self.N)
65
 
 
66
 
    def check_vecmat2(self):
67
 
        b3, A = self.b3, self.A
68
 
        c1 = dot(b3, A.transpose())
69
 
        c2 = dot_(b3, A.transpose())
70
 
        assert_almost_equal(c1, c2, decimal=self.N)
71
 
 
72
 
    def check_vecmat3(self):
73
 
        A, b4 = self.A, self.b4
74
 
        c1 = dot(A.transpose(),b4)
75
 
        c2 = dot_(A.transpose(),b4)
76
 
        assert_almost_equal(c1, c2, decimal=self.N)
77
 
 
78
 
    def check_vecvecouter(self):
79
 
        b1, b3 = self.b1, self.b3
80
 
        c1 = dot(b1, b3)
81
 
        c2 = dot_(b1, b3)
82
 
        assert_almost_equal(c1, c2, decimal=self.N)
83
 
 
84
 
    def check_vecvecinner(self):
85
 
        b1, b3 = self.b1, self.b3
86
 
        c1 = dot(b3, b1)
87
 
        c2 = dot_(b3, b1)
88
 
        assert_almost_equal(c1, c2, decimal=self.N)
89
 
 
90
 
    def check_matscalar(self):
91
 
        b1 = matrix(ones((3,3),dtype=complex))
92
 
        assert_equal(b1*1.0, b1)
93
 
 
94
 
    def check_columnvect(self):
95
 
        b1 = ones((3,1))
96
 
        b2 = [5.3]
97
 
        c1 = dot(b1,b2)
98
 
        c2 = dot_(b1,b2)
99
 
        assert_almost_equal(c1, c2, decimal=self.N)
100
 
 
101
 
    def check_columnvect(self):
102
 
        b1 = ones((3,1)).transpose()
103
 
        b2 = [6.2]
104
 
        c1 = dot(b2,b1)
105
 
        c2 = dot_(b2,b1)
106
 
        assert_almost_equal(c1, c2, decimal=self.N)
107
 
 
108
 
    def check_vecscalar(self):
109
 
        b1 = rand(1,1)
110
 
        b2 = rand(1,8)
111
 
        c1 = dot(b1,b2)
112
 
        c2 = dot_(b1,b2)
113
 
        assert_almost_equal(c1, c2, decimal=self.N)
114
 
 
115
 
    def check_vecscalar2(self):
116
 
        b1 = rand(8,1)
117
 
        b2 = rand(1,1)
118
 
        c1 = dot(b1,b2)
119
 
        c2 = dot_(b1,b2)
120
 
        assert_almost_equal(c1, c2, decimal=self.N)        
121
 
 
122
 
    def check_all(self):
123
 
        dims = [(),(1,),(1,1)]
124
 
        for dim1 in dims:
125
 
            for dim2 in dims:
126
 
                arg1 = rand(*dim1)
127
 
                arg2 = rand(*dim2)
128
 
                c1 = dot(arg1, arg2)
129
 
                c2 = dot_(arg1, arg2)
130
 
                assert (c1.shape == c2.shape)
131
 
                assert_almost_equal(c1, c2, decimal=self.N)
132
 
 
133
 
    def check_vecobject(self):
134
 
        U_non_cont = transpose([[1.,1.],[1.,2.]])
135
 
        U_cont = ascontiguousarray(U_non_cont)
136
 
        x = array([Vec([1.,0.]),Vec([0.,1.])])
137
 
        zeros = array([Vec([0.,0.]),Vec([0.,0.])])
138
 
        zeros_test = dot(U_cont,x) - dot(U_non_cont,x)
139
 
        assert_equal(zeros[0].array, zeros_test[0].array)
140
 
        assert_equal(zeros[1].array, zeros_test[1].array)
141
 
 
142
 
 
143
 
class test_bool_scalar(NumpyTestCase):
144
 
    def test_logical(self):
145
 
        f = False_
146
 
        t = True_
147
 
        s = "xyz"
148
 
        self.failUnless((t and s) is s)
149
 
        self.failUnless((f and s) is f)
150
 
 
151
 
    def test_bitwise_or(self):
152
 
        f = False_
153
 
        t = True_
154
 
        self.failUnless((t | t) is t)
155
 
        self.failUnless((f | t) is t)
156
 
        self.failUnless((t | f) is t)
157
 
        self.failUnless((f | f) is f)
158
 
 
159
 
    def test_bitwise_and(self):
160
 
        f = False_
161
 
        t = True_
162
 
        self.failUnless((t & t) is t)
163
 
        self.failUnless((f & t) is f)
164
 
        self.failUnless((t & f) is f)
165
 
        self.failUnless((f & f) is f)
166
 
 
167
 
    def test_bitwise_xor(self):
168
 
        f = False_
169
 
        t = True_
170
 
        self.failUnless((t ^ t) is f)
171
 
        self.failUnless((f ^ t) is t)
172
 
        self.failUnless((t ^ f) is t)
173
 
        self.failUnless((f ^ f) is f)
174
 
 
175
 
 
176
 
class test_seterr(NumpyTestCase):
177
 
    def test_set(self):
178
 
        err = seterr()
179
 
        old = seterr(divide='warn')
180
 
        self.failUnless(err == old)
181
 
        new = seterr()
182
 
        self.failUnless(new['divide'] == 'warn')
183
 
        seterr(over='raise')
184
 
        self.failUnless(geterr()['over'] == 'raise')
185
 
        self.failUnless(new['divide'] == 'warn')
186
 
        seterr(**old)
187
 
        self.failUnless(geterr() == old)
188
 
    def test_divideerr(self):
189
 
        seterr(divide='raise')
190
 
        try:
191
 
            array([1.]) / array([0.])
192
 
        except FloatingPointError:
193
 
            pass
194
 
        else:
195
 
            self.fail()
196
 
        seterr(divide='ignore')
197
 
        array([1.]) / array([0.])
198
 
        
199
 
        
200
 
class test_fromiter(NumpyTestCase):
201
 
    
202
 
    def makegen(self):
203
 
        for x in xrange(24):
204
 
            yield x**2
205
 
            
206
 
    def test_types(self):
207
 
        ai32 = fromiter(self.makegen(), int32)
208
 
        ai64 = fromiter(self.makegen(), int64)
209
 
        af = fromiter(self.makegen(), float)
210
 
        self.failUnless(ai32.dtype == dtype(int32))
211
 
        self.failUnless(ai64.dtype == dtype(int64))
212
 
        self.failUnless(af.dtype == dtype(float))
213
 
 
214
 
    def test_lengths(self):
215
 
        expected = array(list(self.makegen()))
216
 
        a = fromiter(self.makegen(), int)
217
 
        a20 = fromiter(self.makegen(), int, 20)
218
 
        self.failUnless(len(a) == len(expected))
219
 
        self.failUnless(len(a20) == 20)
220
 
        try:
221
 
            fromiter(self.makegen(), int, len(expected) + 10)
222
 
        except ValueError:
223
 
            pass
224
 
        else:
225
 
            self.fail()
226
 
 
227
 
    def test_values(self):
228
 
        expected = array(list(self.makegen()))
229
 
        a = fromiter(self.makegen(), int)
230
 
        a20 = fromiter(self.makegen(), int, 20)
231
 
        self.failUnless(alltrue(a == expected))
232
 
        self.failUnless(alltrue(a20 == expected[:20]))
233
 
 
234
 
class test_index(NumpyTestCase):
235
 
    def test_boolean(self):
236
 
        a = rand(3,5,8)
237
 
        V = rand(5,8)
238
 
        g1 = randint(0,5,size=15)
239
 
        g2 = randint(0,8,size=15)
240
 
        V[g1,g2] = -V[g1,g2]
241
 
        assert (array([a[0][V>0],a[1][V>0],a[2][V>0]]) == a[:,V>0]).all()
242
 
 
243
 
class test_binary_repr(NumpyTestCase):
244
 
    def test_zero(self):
245
 
        assert_equal(binary_repr(0),'0')
246
 
 
247
 
    def test_large(self):
248
 
        assert_equal(binary_repr(10736848),'101000111101010011010000')
249
 
 
250
 
if __name__ == '__main__':
251
 
    NumpyTest().run()