def test_get_active_register_indices_raises(self):
     s = AnySketch(
         SketchConfig([
             IndexSpecification(UniformDistribution(2), 'uniform'),
             IndexSpecification(UniformDistribution(4), 'uniform')
         ],
                      num_hashes=1,
                      value_functions=[SumFunction()]), 84)
     s.add(1)
     with self.assertRaises(AssertionError):
         s.get_active_register_indices()
Example #2
0
 def test_incompatible_different_configs_value_function(self):
   # S1 and S2 have different value function in sketch config.
   s1 = AnySketch(
       SketchConfig([IndexSpecification(UniformDistribution(10), 'uniform')],
                    num_hashes=1,
                    value_functions=[SumFunction()]), 42)
   s2 = AnySketch(
       SketchConfig([IndexSpecification(UniformDistribution(10), 'uniform')],
                    num_hashes=1,
                    value_functions=[BitwiseOrFunction()]), 42)
   with self.assertRaises(AssertionError):
     s1.assert_compatible(s2)
Example #3
0
 def test_incompatible_different_hashes(self):
   # S1 and S2 will have default and therefore different random seeds.
   s1 = AnySketch(
       SketchConfig([IndexSpecification(UniformDistribution(10), 'uniform')],
                    num_hashes=2,
                    value_functions=[SumFunction()]))
   s2 = AnySketch(
       SketchConfig([IndexSpecification(UniformDistribution(10), 'uniform')],
                    num_hashes=2,
                    value_functions=[SumFunction()]))
   with self.assertRaises(AssertionError):
     s1.assert_compatible(s2)
Example #4
0
 def test_run_through_compatible_sketches(self):
   # S1 and S2 are compatible.
   s1 = AnySketch(
       SketchConfig([IndexSpecification(UniformDistribution(10), 'uniform')],
                    num_hashes=1,
                    value_functions=[SumFunction()]), 42)
   s2 = AnySketch(
       SketchConfig([IndexSpecification(UniformDistribution(10), 'uniform')],
                    num_hashes=1,
                    value_functions=[SumFunction()]), 42)
   self.assertTrue(
       s1.assert_compatible(s2),
       'Two sketches are compatible, yet raises error.')
Example #5
0
 def test_basic_capabilities(self):
   s = AnySketch(
       SketchConfig([IndexSpecification(UniformDistribution(10), 'uniform')],
                    num_hashes=1,
                    value_functions=[SumFunction()]))
   s.add_ids([1, 1])
   self.assertIn(1, s)
   self.assertEqual(s.max_size(), 10)
   self.assertTrue(s.assert_compatible(s))
 def test_get_active_register_indices(self):
     s = AnySketch(
         SketchConfig(
             [IndexSpecification(UniformDistribution(2), 'uniform')],
             num_hashes=1,
             value_functions=[SumFunction()]), 42)
     s.add(1)
     expected = np.array([1])
     np.testing.assert_equal(s.get_active_register_indices(), expected)
Example #7
0
  def test_with_custom_hash_function(self):

    class TestHash(object):

      def __init__(self, seed):
        self.seed = seed

      def __call__(self, x):
        return 1

    s1 = AnySketch(
        SketchConfig([IndexSpecification(UniformDistribution(2), 'uniform'),
                      IndexSpecification(UniformDistribution(4), 'uniform')],
                     num_hashes=3,
                     value_functions=[SumFunction()]), 42, TestHash)
    s1.add(1)
    expected = np.array([[0, 0, 0, 0], [0, 3, 0, 0]])
    self.assertLen(s1.sketch, len(expected))
    for i, sketch in enumerate(expected):
      np.testing.assert_equal(s1.sketch[i], sketch)