MCPcopy Create free account
hub / github.com/numpy/numpy / test_contiguous_flags

Function test_contiguous_flags

numpy/core/tests/test_api.py:542–572  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

540 check_copy_result(res, c, ccontig=False, fcontig=False, strides=True)
541
542def test_contiguous_flags():
543 a = np.ones((4, 4, 1))[::2,:,:]
544 a.strides = a.strides[:2] + (-123,)
545 b = np.ones((2, 2, 1, 2, 2)).swapaxes(3, 4)
546
547 def check_contig(a, ccontig, fcontig):
548 assert_(a.flags.c_contiguous == ccontig)
549 assert_(a.flags.f_contiguous == fcontig)
550
551 # Check if new arrays are correct:
552 check_contig(a, False, False)
553 check_contig(b, False, False)
554 check_contig(np.empty((2, 2, 0, 2, 2)), True, True)
555 check_contig(np.array([[[1], [2]]], order='F'), True, True)
556 check_contig(np.empty((2, 2)), True, False)
557 check_contig(np.empty((2, 2), order='F'), False, True)
558
559 # Check that np.array creates correct contiguous flags:
560 check_contig(np.array(a, copy=False), False, False)
561 check_contig(np.array(a, copy=False, order='C'), True, False)
562 check_contig(np.array(a, ndmin=4, copy=False, order='F'), False, True)
563
564 # Check slicing update of flags and :
565 check_contig(a[0], True, True)
566 check_contig(a[None, ::4, ..., None], True, True)
567 check_contig(b[0, 0, ...], False, True)
568 check_contig(b[:, :, 0:0, :, :], True, True)
569
570 # Test ravel and squeeze.
571 check_contig(a.ravel(), True, True)
572 check_contig(np.ones((1, 3, 1)).squeeze(), True, True)
573
574def test_broadcast_arrays():
575 # Test user defined dtypes

Callers

nothing calls this directly

Calls 3

check_contigFunction · 0.85
ravelMethod · 0.45
squeezeMethod · 0.45

Tested by

no test coverage detected