| 1481 | assert_raises(np.AxisError, a.any, axis=-2) |
| 1482 | |
| 1483 | def test_scalar_reduction(self): |
| 1484 | # The functions 'sum', 'prod', etc allow specifying axis=0 |
| 1485 | # even for scalars |
| 1486 | assert_equal(np.sum(3, axis=0), 3) |
| 1487 | assert_equal(np.prod(3.5, axis=0), 3.5) |
| 1488 | assert_equal(np.any(True, axis=0), True) |
| 1489 | assert_equal(np.all(False, axis=0), False) |
| 1490 | assert_equal(np.max(3, axis=0), 3) |
| 1491 | assert_equal(np.min(2.5, axis=0), 2.5) |
| 1492 | |
| 1493 | # Check scalar behaviour for ufuncs without an identity |
| 1494 | assert_equal(np.power.reduce(3), 3) |
| 1495 | |
| 1496 | # Make sure that scalars are coming out from this operation |
| 1497 | assert_(type(np.prod(np.float32(2.5), axis=0)) is np.float32) |
| 1498 | assert_(type(np.sum(np.float32(2.5), axis=0)) is np.float32) |
| 1499 | assert_(type(np.max(np.float32(2.5), axis=0)) is np.float32) |
| 1500 | assert_(type(np.min(np.float32(2.5), axis=0)) is np.float32) |
| 1501 | |
| 1502 | # check if scalars/0-d arrays get cast |
| 1503 | assert_(type(np.any(0, axis=0)) is np.bool_) |
| 1504 | |
| 1505 | # assert that 0-d arrays get wrapped |
| 1506 | class MyArray(np.ndarray): |
| 1507 | pass |
| 1508 | a = np.array(1).view(MyArray) |
| 1509 | assert_(type(np.any(a)) is MyArray) |
| 1510 | |
| 1511 | def test_casting_out_param(self): |
| 1512 | # Test that it's possible to do casts on output |