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

Method check_unary_fuzz

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

Source from the content-addressed store, hash-verified

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

Calls 6

iter_random_view_pairsFunction · 0.85
assert_copy_equivalentFunction · 0.85
astypeMethod · 0.80
reshapeMethod · 0.80
nextFunction · 0.50
copyMethod · 0.45

Tested by

no test coverage detected