()
| 548 | |
| 549 | |
| 550 | def test_subclasses(): |
| 551 | # test that subclass is preserved only if subok=True |
| 552 | a = VerySimpleSubClass([1, 2, 3, 4]) |
| 553 | assert_(type(a) is VerySimpleSubClass) |
| 554 | a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,)) |
| 555 | assert_(type(a_view) is np.ndarray) |
| 556 | a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,), subok=True) |
| 557 | assert_(type(a_view) is VerySimpleSubClass) |
| 558 | # test that if a subclass has __array_finalize__, it is used |
| 559 | a = SimpleSubClass([1, 2, 3, 4]) |
| 560 | a_view = as_strided(a, shape=(2,), strides=(2 * a.itemsize,), subok=True) |
| 561 | assert_(type(a_view) is SimpleSubClass) |
| 562 | assert_(a_view.info == 'simple finalized') |
| 563 | |
| 564 | # similar tests for broadcast_arrays |
| 565 | b = np.arange(len(a)).reshape(-1, 1) |
| 566 | a_view, b_view = broadcast_arrays(a, b) |
| 567 | assert_(type(a_view) is np.ndarray) |
| 568 | assert_(type(b_view) is np.ndarray) |
| 569 | assert_(a_view.shape == b_view.shape) |
| 570 | a_view, b_view = broadcast_arrays(a, b, subok=True) |
| 571 | assert_(type(a_view) is SimpleSubClass) |
| 572 | assert_(a_view.info == 'simple finalized') |
| 573 | assert_(type(b_view) is np.ndarray) |
| 574 | assert_(a_view.shape == b_view.shape) |
| 575 | |
| 576 | # and for broadcast_to |
| 577 | shape = (2, 4) |
| 578 | a_view = broadcast_to(a, shape) |
| 579 | assert_(type(a_view) is np.ndarray) |
| 580 | assert_(a_view.shape == shape) |
| 581 | a_view = broadcast_to(a, shape, subok=True) |
| 582 | assert_(type(a_view) is SimpleSubClass) |
| 583 | assert_(a_view.info == 'simple finalized') |
| 584 | assert_(a_view.shape == shape) |
| 585 | |
| 586 | |
| 587 | def test_writeable(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…