|
4 | 4 | import platform
|
5 | 5 | from decimal import Decimal
|
6 | 6 | import warnings
|
| 7 | +import itertools |
7 | 8 |
|
8 | 9 | import numpy as np
|
9 | 10 | from numpy.core import *
|
@@ -1493,45 +1494,49 @@ def test_basic(self):
|
1493 | 1494 |
|
1494 | 1495 |
|
1495 | 1496 | class TestCreationFuncs(TestCase):
|
1496 |
| - |
1497 |
| - '''Test ones, zeros, empty and filled''' |
| 1497 | + #Test ones, zeros, empty and filled |
1498 | 1498 |
|
1499 | 1499 | def setUp(self):
|
1500 | 1500 | self.dtypes = ('b', 'i', 'u', 'f', 'c', 'S', 'a', 'U', 'V')
|
1501 | 1501 | self.orders = {'C': 'c_contiguous', 'F': 'f_contiguous'}
|
1502 | 1502 | self.ndims = 10
|
1503 | 1503 |
|
1504 | 1504 | def check_function(self, func, fill_value=None):
|
| 1505 | + par = ( |
| 1506 | + (0, 1, 2), |
| 1507 | + range(self.ndims), |
| 1508 | + self.orders, |
| 1509 | + self.dtypes, |
| 1510 | + 2**np.arange(9) |
| 1511 | + ) |
1505 | 1512 | fill_kwarg = {}
|
1506 | 1513 | if fill_value is not None:
|
1507 | 1514 | fill_kwarg = {'fill_value': fill_value}
|
1508 |
| - for size in (0, 1, 2): # size in one dimension |
1509 |
| - for ndims in range(self.ndims): # [], [size], [size, size] etc. |
| 1515 | + with warnings.catch_warnings(): |
| 1516 | + warnings.simplefilter('ignore', DeprecationWarning) |
| 1517 | + for size, ndims, order, type, bytes in itertools.product(*par): |
1510 | 1518 | shape = ndims * [size]
|
1511 |
| - for order in self.orders: # C, F |
1512 |
| - for type in self.dtypes: # bool, int, float etc. |
1513 |
| - for bytes in 2**np.arange(9): # byte size for type |
1514 |
| - try: |
1515 |
| - dtype = np.dtype('{0}{1}'.format(type, bytes)) |
1516 |
| - except TypeError: # dtype combination does not exist |
1517 |
| - continue |
1518 |
| - else: |
1519 |
| - # do not fill void type |
1520 |
| - if fill_value is not None and type in 'V': |
1521 |
| - continue |
1522 |
| - |
1523 |
| - arr = func(shape, order=order, dtype=dtype, |
1524 |
| - **fill_kwarg) |
1525 |
| - |
1526 |
| - assert arr.dtype == dtype |
1527 |
| - assert getattr(arr.flags, self.orders[order]) |
1528 |
| - |
1529 |
| - if fill_value is not None: |
1530 |
| - if dtype.str.startswith('|S'): |
1531 |
| - val = str(fill_value) |
1532 |
| - else: |
1533 |
| - val = fill_value |
1534 |
| - assert_equal(arr, dtype.type(val)) |
| 1519 | + try: |
| 1520 | + dtype = np.dtype('{0}{1}'.format(type, bytes)) |
| 1521 | + except TypeError: # dtype combination does not exist |
| 1522 | + continue |
| 1523 | + else: |
| 1524 | + # do not fill void type |
| 1525 | + if fill_value is not None and type in 'V': |
| 1526 | + continue |
| 1527 | + |
| 1528 | + arr = func(shape, order=order, dtype=dtype, |
| 1529 | + **fill_kwarg) |
| 1530 | + |
| 1531 | + assert_(arr.dtype == dtype) |
| 1532 | + assert_(getattr(arr.flags, self.orders[order])) |
| 1533 | + |
| 1534 | + if fill_value is not None: |
| 1535 | + if dtype.str.startswith('|S'): |
| 1536 | + val = str(fill_value) |
| 1537 | + else: |
| 1538 | + val = fill_value |
| 1539 | + assert_equal(arr, dtype.type(val)) |
1535 | 1540 |
|
1536 | 1541 | def test_zeros(self):
|
1537 | 1542 | self.check_function(np.zeros)
|
|
0 commit comments