def test_pack_unpack(repeat): """Test gmpy2.pack and gmpy2.unpack.""" r = gmpy2.random_state(42) for counter in range(repeat): for t in (10, 1000, 2000, 10000, 100000): v = gmpy2.mpz_rrandomb(r, t) for b in range(1, max(1001, t)): temp = gmpy2.unpack(v, b) u = gmpy2.pack(temp, b) assert u == v
def test_pack_unpack(bits = 200, chunk = 500, terms = 50): """Test gmpy2.pack and gmpy2.unpack.""" for t in range(2, terms): for b in range(1, bits): # Test with all bits set to 1. v = [ 2**b - 1 ] * t for c in range(b, chunk): temp = gmpy2.pack(v, c) u = gmpy2.unpack(temp, c) assert u == v, (v, temp, u, (t, b, c))
def test_pack_unpack(repeat): """Test gmpy2.pack and gmpy2.unpack.""" r = gmpy2.random_state(42) for counter in range(repeat): for t in (10, 1000, 2000, 10000, 100000): v = gmpy2.mpz_rrandomb(r, t) for b in range(1, max(1001,t)): temp = gmpy2.unpack(v, b) u = gmpy2.pack(temp, b) assert u == v
def test(repeat=1): """Test gmpy2.pack and gmpy2.unpack.""" r = gmpy2.random_state(42) try: for counter in range(repeat): for t in (10, 30, 60, 500, 1000, 2000, 10000, 100000): v = gmpy2.mpz_rrandomb(r, t) for b in range(1, max(1001,t)): temp = gmpy2.unpack(v, b) u = gmpy2.pack(temp, b) if u != v: raise ValueError return True except ValueError: return False
def apply_hash_actor(frame): """ Reads the data stored by apply_hash_initalizer and applies cropping and hashing to each of the frames passed to this function. Returns a HashedFrame() with the results. """ global mp_data hash_function, hash_args, hash_window_size, tolerance = mp_data data = ImageTool.crop_image_only_outside(frame.frame, tolerance, hash_window_size, hash_window_size) hashed_frame = HashedFrame() hashed_frame.hash = hash_function(data, *hash_args) hashed_frame.hash = pack( hashed_frame.hash.astype(int).flatten().tolist(), 1) hashed_frame.position = frame.position hashed_frame.filename = frame.filename return hashed_frame