()
| 533 | |
| 534 | |
| 535 | def test_subclasses(): |
| 536 | # test that subclass is preserved only if subok=True |
| 537 | a = VerySimpleSubClass([1, 2, 3, 4]) |
| 538 | assert_(type(a) is VerySimpleSubClass) |
| 539 | a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,)) |
| 540 | assert_(type(a_view) is np.ndarray) |
| 541 | a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,), subok=True) |
| 542 | assert_(type(a_view) is VerySimpleSubClass) |
| 543 | # test that if a subclass has __array_finalize__, it is used |
| 544 | a = SimpleSubClass([1, 2, 3, 4]) |
| 545 | a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,), subok=True) |
| 546 | assert_(type(a_view) is SimpleSubClass) |
| 547 | assert_(a_view.info == 'simple finalized') |
| 548 | |
| 549 | # similar tests for broadcast_arrays |
| 550 | b = np.arange(len(a)).reshape(-1, 1) |
| 551 | a_view, b_view = broadcast_arrays(a, b) |
| 552 | assert_(type(a_view) is np.ndarray) |
| 553 | assert_(type(b_view) is np.ndarray) |
| 554 | assert_(a_view.shape == b_view.shape) |
| 555 | a_view, b_view = broadcast_arrays(a, b, subok=True) |
| 556 | assert_(type(a_view) is SimpleSubClass) |
| 557 | assert_(a_view.info == 'simple finalized') |
| 558 | assert_(type(b_view) is np.ndarray) |
| 559 | assert_(a_view.shape == b_view.shape) |
| 560 | |
| 561 | # and for broadcast_to |
| 562 | shape = (2, 4) |
| 563 | a_view = broadcast_to(a, shape) |
| 564 | assert_(type(a_view) is np.ndarray) |
| 565 | assert_(a_view.shape == shape) |
| 566 | a_view = broadcast_to(a, shape, subok=True) |
| 567 | assert_(type(a_view) is SimpleSubClass) |
| 568 | assert_(a_view.info == 'simple finalized') |
| 569 | assert_(a_view.shape == shape) |
| 570 | |
| 571 | |
| 572 | def test_writeable(): |
nothing calls this directly
no test coverage detected