~inkscape.dev/inkscape-devlibs/trunk

« back to all changes in this revision

Viewing changes to python/Lib/site-packages/numpy/core/tests/test_multiarray.py

  • Committer: Eduard Braun
  • Date: 2016-10-22 16:54:41 UTC
  • Revision ID: eduard.braun2@gmx.de-20161022165441-gfp6agtut9nh4p22
Update Python to version 2.7.12

Included modules:
  coverage 4.2
  lxml 3.6.4
  numpy 1.11.2
  scour 0.35
  six 1.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
564
564
        arr = np.array([], dtype='V')
565
565
        assert_equal(arr.dtype.kind, 'V')
566
566
 
 
567
    def test_too_big_error(self):
 
568
        # 45341 is the smallest integer greater than sqrt(2**31 - 1).
 
569
        # 3037000500 is the smallest integer greater than sqrt(2**63 - 1).
 
570
        # We want to make sure that the square byte array with those dimensions
 
571
        # is too big on 32 or 64 bit systems respectively.
 
572
        if np.iinfo('intp').max == 2**31 - 1:
 
573
            shape = (46341, 46341)
 
574
        elif np.iinfo('intp').max == 2**63 - 1:
 
575
            shape = (3037000500, 3037000500)
 
576
        else:
 
577
            return
 
578
        assert_raises(ValueError, np.empty, shape, dtype=np.int8)
 
579
        assert_raises(ValueError, np.zeros, shape, dtype=np.int8)
 
580
        assert_raises(ValueError, np.ones, shape, dtype=np.int8)
 
581
 
567
582
    def test_zeros(self):
568
583
        types = np.typecodes['AllInteger'] + np.typecodes['AllFloat']
569
584
        for dt in types:
730
745
        d = A([1,2,3])
731
746
        assert_equal(len(np.array(d)), 3)
732
747
 
 
748
    def test_array_too_big(self):
 
749
        # Test that array creation succeeds for arrays addressable by intp
 
750
        # on the byte level and fails for too large arrays.
 
751
        buf = np.zeros(100)
 
752
 
 
753
        max_bytes = np.iinfo(np.intp).max
 
754
        for dtype in ["intp", "S20", "b"]:
 
755
            dtype = np.dtype(dtype)
 
756
            itemsize = dtype.itemsize
 
757
 
 
758
            np.ndarray(buffer=buf, strides=(0,),
 
759
                       shape=(max_bytes//itemsize,), dtype=dtype)
 
760
            assert_raises(ValueError, np.ndarray, buffer=buf, strides=(0,),
 
761
                          shape=(max_bytes//itemsize + 1,), dtype=dtype)
 
762
 
733
763
 
734
764
class TestStructured(TestCase):
735
765
    def test_subarray_field_access(self):
1266
1296
        msg = 'test empty array sort with axis=None'
1267
1297
        assert_equal(np.sort(a, axis=None), a.ravel(), msg)
1268
1298
 
 
1299
        # test generic class with bogus ordering,
 
1300
        # should not segfault.
 
1301
        class Boom(object):
 
1302
            def __lt__(self, other):
 
1303
                return True
 
1304
 
 
1305
        a = np.array([Boom()]*100, dtype=object)
 
1306
        for kind in ['q', 'm', 'h']:
 
1307
            msg = "bogus comparison object sort, kind=%s" % kind
 
1308
            c.sort(kind=kind)
 
1309
 
1269
1310
    def test_copy(self):
1270
1311
        def assert_fortran(arr):
1271
1312
            assert_(arr.flags.fortran)
3396
3437
        x = val.clip(max=4)
3397
3438
        assert_(np.all(x <= 4))
3398
3439
 
 
3440
    def test_nan(self):
 
3441
        input_arr = np.array([-2., np.nan, 0.5, 3., 0.25, np.nan])
 
3442
        result = input_arr.clip(-1, 1)
 
3443
        expected = np.array([-1., np.nan, 0.5, 1., 0.25, np.nan])
 
3444
        assert_array_equal(result, expected)
 
3445
 
3399
3446
 
3400
3447
class TestCompress(TestCase):
3401
3448
    def test_axis(self):
3558
3605
            u, v = np.array(u, dtype='object'), np.array(v, dtype='object')
3559
3606
            assert_array_equal(idx, np.lexsort((u, v)))
3560
3607
 
 
3608
    def test_invalid_axis(self): # gh-7528
 
3609
        x = np.linspace(0., 1., 42*3).reshape(42, 3)
 
3610
        assert_raises(ValueError, np.lexsort, x, axis=2)
3561
3611
 
3562
3612
class TestIO(object):
3563
3613
    """Test tofile, fromfile, tobytes, and fromstring"""
5872
5922
        """ticket #2046, should not seqfault, raise AttributeError"""
5873
5923
        a = np.ones(2)
5874
5924
        attr = ['shape', 'strides', 'data', 'dtype', 'real', 'imag', 'flat']
5875
 
        for s in attr:
5876
 
            assert_raises(AttributeError, delattr, a, s)
 
5925
        with warnings.catch_warnings():
 
5926
            warnings.simplefilter('ignore')
 
5927
            for s in attr:
 
5928
                assert_raises(AttributeError, delattr, a, s)
5877
5929
 
5878
5930
    def test_multiarray_not_writable_attributes_deletion(self):
5879
5931
        a = np.ones(2)