def testStringToHashBucketsStrongInvalidKey(self): with self.cached_session(): input_string = constant_op.constant(['a', 'b', 'c']) with self.assertRaisesOpError('Key must have 2 elements'): string_ops.string_to_hash_bucket_strong(input_string, 10, key=[98765]).eval()
def testStringToOneHashBucketStrongOneHashBucket(self): with self.cached_session(): input_string = constant_op.constant(['a', 'b', 'c']) output = string_ops.string_to_hash_bucket_strong(input_string, 1, key=[123, 345]) self.assertAllEqual([0, 0, 0], self.evaluate(output))
def testStringToHashBucketsStrong(self): with self.cached_session(): input_string = constant_op.constant(['a', 'b', 'c']) output = string_ops.string_to_hash_bucket_strong( input_string, 10, key=[98765, 132]) # key = [98765, 132] # StrongKeyedHash(key, 'a') -> 7157389809176466784 -> mod 10 -> 4 # StrongKeyedHash(key, 'b') -> 15805638358933211562 -> mod 10 -> 2 # StrongKeyedHash(key, 'c') -> 18100027895074076528 -> mod 10 -> 8 self.assertAllEqual([4, 2, 8], self.evaluate(output))
def testStringToHashBucketsStrongInvalidKey(self): with self.cached_session(): input_string = constant_op.constant(['a', 'b', 'c']) with self.assertRaisesOpError('Key must have 2 elements'): string_ops.string_to_hash_bucket_strong( input_string, 10, key=[98765]).eval()
def testStringToOneHashBucketStrongOneHashBucket(self): with self.cached_session(): input_string = constant_op.constant(['a', 'b', 'c']) output = string_ops.string_to_hash_bucket_strong( input_string, 1, key=[123, 345]) self.assertAllEqual([0, 0, 0], self.evaluate(output))