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

Method check_unary_fuzz

numpy/_core/tests/test_mem_overlap.py:605–665  ·  view source on GitHub ↗
(self, operation, get_out_axis_size, dtype=np.int16,
                             count=5000)

Source from the content-addressed store, hash-verified

603 """
604
605 def check_unary_fuzz(self, operation, get_out_axis_size, dtype=np.int16,
606 count=5000):
607 shapes = [7, 13, 8, 21, 29, 32]
608
609 rng = np.random.RandomState(1234)
610
611 for ndim in range(1, 6):
612 x = rng.randint(0, 2**16, size=shapes[:ndim]).astype(dtype)
613
614 it = iter_random_view_pairs(x, same_steps=False, equal_size=True)
615
616 min_count = count // (ndim + 1)**2
617
618 overlapping = 0
619 while overlapping < min_count:
620 a, b = next(it)
621
622 a_orig = a.copy()
623 b_orig = b.copy()
624
625 if get_out_axis_size is None:
626 assert_copy_equivalent(operation, [a], out=b)
627
628 if np.shares_memory(a, b):
629 overlapping += 1
630 else:
631 for axis in itertools.chain(range(ndim), [None]):
632 a[...] = a_orig
633 b[...] = b_orig
634
635 # Determine size for reduction axis (None if scalar)
636 outsize, scalarize = get_out_axis_size(a, b, axis)
637 if outsize == 'skip':
638 continue
639
640 # Slice b to get an output array of the correct size
641 sl = [slice(None)] * ndim
642 if axis is None:
643 if outsize is None:
644 sl = [slice(0, 1)] + [0] * (ndim - 1)
645 else:
646 sl = [slice(0, outsize)] + [0] * (ndim - 1)
647 elif outsize is None:
648 k = b.shape[axis] // 2
649 if ndim == 1:
650 sl[axis] = slice(k, k + 1)
651 else:
652 sl[axis] = k
653 else:
654 assert b.shape[axis] >= outsize
655 sl[axis] = slice(0, outsize)
656 b_out = b[tuple(sl)]
657
658 if scalarize:
659 b_out = b_out.reshape([])
660
661 if np.shares_memory(a, b_out):
662 overlapping += 1

Calls 6

iter_random_view_pairsFunction · 0.85
assert_copy_equivalentFunction · 0.85
sliceFunction · 0.85
astypeMethod · 0.80
reshapeMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected