MCPcopy Index your code
hub / github.com/numpy/numpy / test_subclasses

Function test_subclasses

numpy/lib/tests/test_stride_tricks.py:550–584  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

548
549
550def 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
587def test_writeable():

Callers

nothing calls this directly

Calls 7

assert_Function · 0.90
as_stridedFunction · 0.90
broadcast_arraysFunction · 0.90
broadcast_toFunction · 0.90
VerySimpleSubClassClass · 0.85
SimpleSubClassClass · 0.85
reshapeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…