| 1673 | assert_raises(AxisError, a.any, axis=-2) |
| 1674 | |
| 1675 | def test_scalar_reduction(self): |
| 1676 | # The functions 'sum', 'prod', etc allow specifying axis=0 |
| 1677 | # even for scalars |
| 1678 | assert_equal(np.sum(3, axis=0), 3) |
| 1679 | assert_equal(np.prod(3.5, axis=0), 3.5) |
| 1680 | assert_equal(np.any(True, axis=0), True) |
| 1681 | assert_equal(np.all(False, axis=0), False) |
| 1682 | assert_equal(np.max(3, axis=0), 3) |
| 1683 | assert_equal(np.min(2.5, axis=0), 2.5) |
| 1684 | |
| 1685 | # Check scalar behaviour for ufuncs without an identity |
| 1686 | assert_equal(np.power.reduce(3), 3) |
| 1687 | |
| 1688 | # Make sure that scalars are coming out from this operation |
| 1689 | assert_(type(np.prod(np.float32(2.5), axis=0)) is np.float32) |
| 1690 | assert_(type(np.sum(np.float32(2.5), axis=0)) is np.float32) |
| 1691 | assert_(type(np.max(np.float32(2.5), axis=0)) is np.float32) |
| 1692 | assert_(type(np.min(np.float32(2.5), axis=0)) is np.float32) |
| 1693 | |
| 1694 | # check if scalars/0-d arrays get cast |
| 1695 | assert_(type(np.any(0, axis=0)) is np.bool) |
| 1696 | |
| 1697 | # assert that 0-d arrays get wrapped |
| 1698 | class MyArray(np.ndarray): |
| 1699 | pass |
| 1700 | a = np.array(1).view(MyArray) |
| 1701 | assert_(type(np.any(a)) is MyArray) |
| 1702 | |
| 1703 | def test_casting_out_param(self): |
| 1704 | # Test that it's possible to do casts on output |