Beispiel #1
0
 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)
Beispiel #2
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
Beispiel #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
Beispiel #4
0
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
Beispiel #5
0
 def test_igraycode(self):
     for i in range(10):
         assert utils.igraycode(utils.graycode(i)) == i
         assert utils.graycode(utils.igraycode(i)) == i
Beispiel #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