Return the distance of chess piece X and Y (Chebyshev Distance)
964444
def distance(self, piecex, piecey):
        ''''''
        return max(abs(piecex[0] - piecey[0]), abs(piecex[1], piecey[1]))
850145
def distance(self, x, y):
        
        if scipy.sparse.issparse(x):
            return numpy.sum(numpy.absolute((x-y).toarray().ravel()))
        else:
            return numpy.sum(numpy.absolute(x-y))
476901
def levenshtein_distance(self, a, b):
        '''
        '''

        n, m = len(a), len(b)
        if n > m:
            a,b = b,a
            n,m = m,n
        current = range(n+1)
        for i in range(1,m+1):
            previous, current = current, [i]+[0]*n
            for j in range(1,n+1):
                add, delete = previous[j]+1, current[j-1]+1
                change = previous[j-1]
                if a[j-1] != b[i-1]:
                    change = change + 1
                current[j] = min(add, delete, change)
        return current[n]
1048504
def distance(self, other):
        """"""
        return math.acos(self._pos3d.dot(other.vector))
721015
def _jit_pairwise_distances(pos1, pos2):
        
        n1 = pos1.shape[0]
        n2 = pos2.shape[0]
        D = np.empty((n1, n2))

        for i in range(n1):
            for j in range(n2):
                D[i, j] = np.sqrt(((pos1[i] - pos2[j])**2).sum())
        return D
1145865
function getDistanceMatrices(areas, sets, setids) {
        // initialize an empty distance matrix between all the points
        var distances = zerosM(sets.length, sets.length),
            constraints = zerosM(sets.length, sets.length);

        // compute required distances between all the sets such that
        // the areas match
        areas.filter(function(x) { return x.sets.length == 2; })
            .map(function(current) {
            var left = setids[current.sets[0]],
                right = setids[current.sets[1]],
                r1 = Math.sqrt(sets[left].size / Math.PI),
                r2 = Math.sqrt(sets[right].size / Math.PI),
                distance$$1 = distanceFromIntersectArea(r1, r2, current.size);

            distances[left][right] = distances[right][left] = distance$$1;

            // also update constraints to indicate if its a subset or disjoint
            // relationship
            var c = 0;
            if (current.size + 1e-10 >= Math.min(sets[left].size,
                                                 sets[right].size)) {
                c = 1;
            } else if (current.size <= 1e-10) {
                c = -1;
            }
            constraints[left][right] = constraints[right][left] = c;
        });

        return {distances: distances, constraints: constraints};
    }
1084639
public static int hammingDistance(long[] x, long[] y) {
    final int lx = x.length, ly = y.length;
    final int min = (lx < ly) ? lx : ly;
    int i = 0, h = 0;
    for(; i < min; i++) {
      h += Long.bitCount(x[i] ^ y[i]);
    }
    for(; i < lx; i++) {
      h += Long.bitCount(x[i]);
    }
    for(; i < ly; i++) {
      h += Long.bitCount(y[i]);
    }
    return h;
  }
157065
public static int distanceSq (int x1, int y1, int x2, int y2) {
        x2 -= x1;
        y2 -= y1;
        return x2 * x2 + y2 * y2;
    }
981486
def distance(a, b, metric="cosine"):
    
    if metric == "cosine":
        return np.dot(a, b.T)
    raise Exception("Unknown metric '{metric}'".format(metric=metric))
1143750
def distance_to_closest(self, ps: Union["Units", List["Point2"], Set["Point2"]]) -> Union[int, float]:
        
        assert ps
        closest_distance_squared = math.inf
        for p2 in ps:
            if not isinstance(p2, Point2):
                p2 = p2.position
            distance = (self[0] - p2[0]) ** 2 + (self[1] - p2[1]) ** 2
            if distance < closest_distance_squared:
                closest_distance_squared = distance
        return closest_distance_squared ** 0.5
792009
def distance_to(self, *args):
        """"""
        if not len(args) > 0:
            raise ValueError("at least one parameter must be given")

        x = args[0]
        if len(args) > 1:
            unit = args[1]
        else:
            unit = "px"
        u = {"px": (1.,1.), "in": (1.,72.), "cm": (2.54, 72.),
             "mm": (25.4, 72.)}
        f = u[unit][0] / u[unit][1]
        if type(x) is Point:
            return abs(self - x) * f

# from here on, x is a rectangle
# as a safeguard, make a finite copy of it
        r = Rect(x.top_left, x.top_left)
        r = r | x.bottom_right
        if self in r:
            return 0.0
        if self.x > r.x1:
            if self.y >= r.y1:
                return self.distance_to(r.bottom_right, unit)
            elif self.y <= r.y0:
                return self.distance_to(r.top_right, unit)
            else:
                return (self.x - r.x1) * f
        elif r.x0 <= self.x <= r.x1:
            if self.y >= r.y1:
                return (self.y - r.y1) * f
            else:
                return (r.y0 - self.y) * f
        else:
            if self.y >= r.y1:
                return self.distance_to(r.bottom_left, unit)
            elif self.y <= r.y0:
                return self.distance_to(r.top_left, unit)
            else:
                return (r.x0 - self.x) * f
900044
def square_distance(a: Square, b: Square) -> int:
    
    return max(abs(square_file(a) - square_file(b)), abs(square_rank(a) - square_rank(b)))
222154
def _manhattan_distance(vec_a, vec_b):
    """"""
    if len(vec_a) != len(vec_b):
        raise ValueError('len(vec_a) must equal len(vec_b)')
    return sum(map(lambda a, b: abs(a - b), vec_a, vec_b))
685209
function getCoefedDistance(box1, box2) {
            var xMin, xMax, yMin, yMax, xDist, yDist, dist, cx, cy;
            xMin = min(box1.left, box2.left);
            xMax = max(box1.right, box2.right);
            yMin = min(box1.top, box2.top);
            yMax = max(box1.bottom, box2.bottom);

            xDist = xMax - xMin - box1.width - box2.width;
            yDist = yMax - yMin - box1.height - box2.height;

            if (xDist < 0) dist = yDist;
            else if (yDist < 0) dist = xDist;
            else dist = sqrt(xDist * xDist + yDist * yDist);

            var node1 = box1.node;
            var node2 = box2.node;

            // sibling
            if (node1.parent == node2.parent) {
                dist /= 10;
            }
            // parent
            if (node2.parent == node1) {
                dist /= 5;
            }

            return dist;
        }
568897
def vector_distance(v1, v2):
    """"""
    dist = 0
    for dim in v1:
        for x in v1[dim]:
            dd = int(v1[dim][x]) - int(v2[dim][x])
            dist = dist + dd**2
    return dist
1372341
def get_distance(a, b, xaxis=True):
    
    if xaxis:
        arange = ("0", a.qstart, a.qstop, a.orientation)  # 0 is the dummy chromosome
        brange = ("0", b.qstart, b.qstop, b.orientation)
    else:
        arange = ("0", a.sstart, a.sstop, a.orientation)
        brange = ("0", b.sstart, b.sstop, b.orientation)

    dist, oo = range_distance(arange, brange, distmode="ee")
    dist = abs(dist)

    return dist
415289
def within(self, x, j=None):
        """"""

        # Loop through distance calculations if there aren't too many.
        idxs = np.where([self.ells[i].contains(x) if i != j else True
                         for i in range(self.nells)])[0]

        return idxs