def testNumpyCorrelate(self): primes = num.array([1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31], dtype=num.int) n = 6 lines = [] have_flips, have_errs = False, False for ia in range(1, n + 1): for ib in range(1, n + 1): a = primes[:ia] b = primes[ia:ia + ib] for mode in 'full', 'valid', 'same': c1 = trace.numpy_correlate_emulate(a, b, mode=mode) c2 = trace.numpy_correlate_fixed(a, b, mode=mode) if a.size < b.size: sl = '<' elif a.size > b.size: sl = '>' else: sl = '=' assert c1.dtype == c2.dtype sa = '' if num.all(c1 == c1[::-1]): sa = ' (ambig)' if num.all(c1 == c2): sr = 'ok' + sa elif num.all(c1 == c2[::-1]): have_flips = True sr = 'flip' else: have_errs = True sr = 'err, %s != %s' % (c1, c2) kmin, kmax = trace.numpy_correlate_lag_range(a, b, mode=mode) lines.append( 'len(a) = %i, len(b) = %i, ' 'kmin = %2i, kmax = %2i, (%s), mode = %-6s %s' % (a.size, b.size, kmin, kmax, sl, mode + ', ', sr)) assert not have_flips and not have_errs, '\n'.join(lines)
def testNumpyCorrelate(self): primes = num.array( [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31], dtype=num.int) n = 6 lines = [] have_flips, have_errs = False, False for ia in range(1, n+1): for ib in range(1, n+1): a = primes[:ia] b = primes[ia:ia+ib] for mode in 'full', 'valid', 'same': c1 = trace.numpy_correlate_emulate(a, b, mode=mode) c2 = trace.numpy_correlate_fixed(a, b, mode=mode) if a.size < b.size: sl = '<' elif a.size > b.size: sl = '>' else: sl = '=' assert c1.dtype == c2.dtype sa = '' if num.all(c1 == c1[::-1]): sa = ' (ambig)' if num.all(c1 == c2): sr = 'ok' + sa elif num.all(c1 == c2[::-1]): have_flips = True sr = 'flip' else: have_errs = True sr = 'err, %s != %s' % (c1, c2) kmin, kmax = trace.numpy_correlate_lag_range( a, b, mode=mode) lines.append( 'len(a) = %i, len(b) = %i, ' 'kmin = %2i, kmax = %2i, (%s), mode = %-6s %s' % (a.size, b.size, kmin, kmax, sl, mode+', ', sr)) assert not have_flips and not have_errs, '\n'.join(lines)