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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-10-07 10:19:13 UTC
  • mfrom: (7.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20101007101913-8b1kmt8ho4upcl9s
Tags: 1:1.4.1-5
* debian/patches/10_use_local_python.org_object.inv_sphinx.diff
  - fixed small typo in description
* debian/patches/changeset_r8364.diff
  - fix memory corruption (double free); thanks to Joseph Barillari for the
    report and to Michael Gilbert for pushing resolution; Closes: #581058

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import sys
 
2
from decimal import Decimal
 
3
 
 
4
import numpy as np
2
5
from numpy.core import *
3
6
from numpy.random import rand, randint, randn
4
7
from numpy.testing import *
82
85
        c2 = dot_(b3, b1)
83
86
        assert_almost_equal(c1, c2, decimal=self.N)
84
87
 
85
 
    def test_matscalar(self):
86
 
        b1 = matrix(ones((3,3),dtype=complex))
87
 
        assert_equal(b1*1.0, b1)
88
 
 
89
88
    def test_columnvect1(self):
90
89
        b1 = ones((3,1))
91
90
        b2 = [5.3]
884
883
            assert dz.shape == dshape
885
884
            assert dz.dtype.type == dtype
886
885
 
 
886
class _TestCorrelate(TestCase):
 
887
    def _setup(self, dt):
 
888
        self.x = np.array([1, 2, 3, 4, 5], dtype=dt)
 
889
        self.y = np.array([-1, -2, -3], dtype=dt)
 
890
        self.z1 = np.array([ -3.,  -8., -14., -20., -26., -14.,  -5.], dtype=dt)
 
891
        self.z2 = np.array([ -5.,  -14., -26., -20., -14., -8.,  -3.], dtype=dt)
 
892
 
 
893
    def test_float(self):
 
894
        self._setup(np.float)
 
895
        z = np.correlate(self.x, self.y, 'full', old_behavior=self.old_behavior)
 
896
        assert_array_almost_equal(z, self.z1)
 
897
        z = np.correlate(self.y, self.x, 'full', old_behavior=self.old_behavior)
 
898
        assert_array_almost_equal(z, self.z2)
 
899
 
 
900
    def test_object(self):
 
901
        self._setup(Decimal)
 
902
        z = np.correlate(self.x, self.y, 'full', old_behavior=self.old_behavior)
 
903
        assert_array_almost_equal(z, self.z1)
 
904
        z = np.correlate(self.y, self.x, 'full', old_behavior=self.old_behavior)
 
905
        assert_array_almost_equal(z, self.z2)
 
906
 
 
907
class TestCorrelate(_TestCorrelate):
 
908
    old_behavior = True
 
909
    def _setup(self, dt):
 
910
        # correlate uses an unconventional definition so that correlate(a, b)
 
911
        # == correlate(b, a), so force the corresponding outputs to be the same
 
912
        # as well
 
913
        _TestCorrelate._setup(self, dt)
 
914
        self.z2 = self.z1
 
915
 
 
916
    @dec.deprecated()
 
917
    def test_complex(self):
 
918
        x = np.array([1, 2, 3, 4+1j], dtype=np.complex)
 
919
        y = np.array([-1, -2j, 3+1j], dtype=np.complex)
 
920
        r_z = np.array([3+1j, 6, 8-1j, 9+1j, -1-8j, -4-1j], dtype=np.complex)
 
921
        z = np.correlate(x, y, 'full')
 
922
        assert_array_almost_equal(z, r_z)
 
923
 
 
924
    @dec.deprecated()
 
925
    def test_float(self):
 
926
        _TestCorrelate.test_float(self)
 
927
 
 
928
    @dec.deprecated()
 
929
    def test_object(self):
 
930
        _TestCorrelate.test_object(self)
 
931
 
 
932
class TestCorrelateNew(_TestCorrelate):
 
933
    old_behavior = False
 
934
    def test_complex(self):
 
935
        x = np.array([1, 2, 3, 4+1j], dtype=np.complex)
 
936
        y = np.array([-1, -2j, 3+1j], dtype=np.complex)
 
937
        r_z = np.array([3-1j, 6, 8+1j, 11+5j, -5+8j, -4-1j], dtype=np.complex)
 
938
        #z = np.acorrelate(x, y, 'full')
 
939
        #assert_array_almost_equal(z, r_z)
 
940
 
 
941
        r_z = r_z[::-1].conjugate()
 
942
        z = np.correlate(y, x, 'full', old_behavior=self.old_behavior)
 
943
        assert_array_almost_equal(z, r_z)
 
944
 
 
945
class TestArgwhere:
 
946
    def test_2D(self):
 
947
        x = np.arange(6).reshape((2, 3))
 
948
        assert_array_equal(np.argwhere(x > 1),
 
949
                           [[0, 2],
 
950
                            [1, 0],
 
951
                            [1, 1],
 
952
                            [1, 2]])
 
953
 
 
954
    def test_list(self):
 
955
        assert_equal(np.argwhere([4, 0, 2, 1, 3]), [[0], [2], [3], [4]])
887
956
 
888
957
if __name__ == "__main__":
889
958
    run_module_suite()