Пример #1
0
 def testSameBuckets(self):
     d = 100
     c = 20
     r = 5
     h = 0
     a = CSVec(d, c, r, **self.csvecArgs)
     vec = torch.randn(d)
     a += vec
     b = TopHCS(h=h, d=d, c=c, r=r, **self.csvecArgs)
     b.store(vec)
     self.assertTrue(torch.allclose(a.table, b.csvec.table))
Пример #2
0
        def testStoreVec3(self):
            # store randn tensor, recover all
            d = 100
            c = 20
            r = 5
            h = d
            
            a = TopHCS(h, d, c, r, **self.csvecArgs)
            vec = torch.randn(d)
            a.store(vec)

            self.assertTrue(torch.allclose(a.topH, vec))
Пример #3
0
        def testStoreVec2(self):
            # store vec [1, 100], recover all
            d = 100
            c = 20
            r = 5
            h = d
            
            a = TopHCS(h, d, c, r, **self.csvecArgs)
            vec = torch.arange(1, d+1, dtype=torch.float, device=self.device)
            a.store(vec)

            self.assertTrue(torch.allclose(a.topH, vec))
Пример #4
0
        def testStoreVec1(self):
            # store vec [1, 100], recover 1
            d = 100
            c = 20
            r = 5
            h = 1
            
            a = TopHCS(h, d, c, r, **self.csvecArgs)
            vec = torch.arange(1, d+1, dtype=torch.float, device=self.device)
            a.store(vec)
            
            expected = torch.zeros(d, dtype=torch.float, device=self.device)
            expected[d-1] = d

            self.assertTrue(torch.allclose(a.topH, expected))
            self.assertTrue(torch.allclose(a.bottomH, vec - expected))
Пример #5
0
        def testTopKSum(self):
            d = 10
            c = 10000
            r = 20
            h = d

            a = TopHCS(h, d, c, r, **self.csvecArgs) 
            b = TopHCS(h, d, c, r, **self.csvecArgs) 
            zerosHalf = torch.zeros(d//2, dtype=torch.float, device=self.device) 
            vec = torch.cat((torch.randn(d//2, device=self.device), zerosHalf), 0)
            vec2 = torch.cat((zerosHalf, torch.randn(d//2, device=self.device)), 0)
            a.store(vec)
            b.store(vec2)

            result = TopHCS.topKSum([a, b], d) 
            expected = vec + vec2
            self.assertTrue(torch.equal(expected, result))
Пример #6
0
        def testTopKSum2(self):
            d = 10
            c = 10000
            r = 20
            h = d

            a = TopHCS(h, d, c, r, **self.csvecArgs) 
            b = TopHCS(h, d, c, r, **self.csvecArgs) 
            c = TopHCS(h, d, c, r, **self.csvecArgs) 
            vec = torch.randn(d, device=self.device)
            vec2 = torch.randn(d, device=self.device)
            vec3 = torch.randn(d, device=self.device)
            a.store(vec)
            b.store(vec2)
            c.store(vec3)

            result = TopHCS.topKSum([a, b, c], d) 
            expected = vec + vec2 + vec3
            self.assertTrue(torch.equal(expected, result))