コード例 #1
0
def itransform(entry, direction, width, x):
    """
        Inverse transform - we simply reverse the operations in transform.
    """
    assert x < 2**width
    assert entry < 2**width
    return utils.lrot(x, direction + 1, width) ^ entry
コード例 #2
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def itransform(entry, direction, width, x):
    """
        Inverse transform - we simply reverse the operations in transform.
    """
    assert x < 2**width
    assert entry < 2**width
    return utils.lrot(x, direction+1, width)^entry
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def hilbert_point(dimension, order, h):
    """
        Convert an index on the Hilbert curve of the specified dimension and
        order to a set of point coordinates.
    """
    #    The bit widths in this function are:
    #        p[*]  - order
    #        h     - order*dimension
    #        l     - dimension
    #        e     - dimension
    hwidth = order*dimension
    e, d = 0, 0
    p = [0]*dimension
    for i in range(order):
        w = utils.bitrange(h, hwidth, i*dimension, i*dimension+dimension)
        l = utils.graycode(w)
        l = itransform(e, d, dimension, l)
        for j in range(dimension):
            b = utils.bitrange(l, dimension, j, j+1)
            p[j] = utils.setbit(p[j], order, i, b)
        e = e ^ utils.lrot(entry(w), d+1, dimension)
        d = (d + direction(w, dimension) + 1)%dimension
    return p
コード例 #7
0
def hilbert_point(dimension, order, h):
    """
        Convert an index on the Hilbert curve of the specified dimension and
        order to a set of point coordinates.
    """
    #    The bit widths in this function are:
    #        p[*]  - order
    #        h     - order*dimension
    #        l     - dimension
    #        e     - dimension
    hwidth = order * dimension
    e, d = 0, 0
    p = [0] * dimension
    for i in range(order):
        w = utils.bitrange(h, hwidth, i * dimension, i * dimension + dimension)
        l = utils.graycode(w)
        l = itransform(e, d, dimension, l)
        for j in range(dimension):
            b = utils.bitrange(l, dimension, j, j + 1)
            p[j] = utils.setbit(p[j], order, i, b)
        e = e ^ utils.lrot(entry(w), d + 1, dimension)
        d = (d + direction(w, dimension) + 1) % dimension
    return p
コード例 #8
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def rotpair(self, left, right, i, width):
     assert utils.rrot(left, i, width) == right
     assert utils.lrot(right, i, width) == left
     assert utils.lrot(left, i, width) == utils.rrot(left, width-i, width)
コード例 #9
0
 def rotpair(self, left, right, i, width):
     assert utils.rrot(left, i, width) == right
     assert utils.lrot(right, i, width) == left
     assert utils.lrot(left, i, width) == utils.rrot(left, width - i, width)