コード例 #1
0
ファイル: graycurve.py プロジェクト: todda/scurve
 def index(self, p):
     idx = 0
     iwidth = self.bits * self.dimension
     for i in range(iwidth):
         bitoff = self.bits-(i/self.dimension)-1
         poff = self.dimension-(i%self.dimension)-1
         b = utils.bitrange(p[poff], self.bits, bitoff, bitoff+1) << i
         idx |= b
     return utils.igraycode(idx)
コード例 #2
0
ファイル: hilbert.py プロジェクト: crabl/knn-algo
def hilbert_index(dimension, order, p):
    h, e, d = 0, 0, 0
    for i in range(order):
        l = 0
        for x in range(dimension):
            b = utils.bitrange(p[dimension - x - 1], order, i, i + 1)
            l |= b << x
        l = transform(e, d, dimension, l)
        w = utils.igraycode(l)
        e = e ^ utils.lrot(entry(w), d + 1, dimension)
        d = (d + direction(w, dimension) + 1) % dimension
        h = (h << dimension) | w
    return h
コード例 #3
0
def hilbert_index(dimension, order, p):
    h, e, d = 0, 0, 0
    for i in range(order):
        l = 0
        for x in range(dimension):
            b = utils.bitrange(p[dimension - x - 1], order, i, i + 1)
            l |= b << x
        l = transform(e, d, dimension, l)
        w = utils.igraycode(l)
        e = e ^ utils.lrot(entry(w), d + 1, dimension)
        d = (d + direction(w, dimension) + 1) % dimension
        h = (h << dimension) | w
    return h
コード例 #4
0
ファイル: hilbert.py プロジェクト: quag/scurve
def hilbert_index(dimension, order, p):
    # Hamilton's paper initialises d to 0, which appears to be an error.
    h, e, d = 0, 0, 1
    for i in range(order):
        l = 0
        for x in range(dimension):
            b = utils.bitrange(p[x], order, i, i+1)
            l |= b<<x
        l = transform(e, d, dimension, l)
        w = utils.igraycode(l)
        e = e ^ utils.lrot(entry(w), d+1, dimension)
        d = (d + direction(w, dimension) + 1)%dimension
        h = (h<<dimension)|w
    return h
コード例 #5
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def test_igraycode(self):
     for i in range(10):
         assert utils.igraycode(utils.graycode(i)) == i
         assert utils.graycode(utils.igraycode(i)) == i
コード例 #6
0
 def test_igraycode(self):
     for i in range(10):
         assert utils.igraycode(utils.graycode(i)) == i
         assert utils.graycode(utils.igraycode(i)) == i