Using `ndraws` Monte Carlo draws, estimate the volume of the
        *union* of ellipsoids. If `return_overlap=True`, also returns the
        estimated fractional overlap with the unit cube.
487434
def monte_carlo_vol(self, ndraws=10000, rstate=None,
                        return_overlap=True):
        """"""

        if rstate is None:
            rstate = np.random

        # Estimate volume using Monte Carlo integration.
        samples = [self.sample(rstate=rstate, return_q=True)
                   for i in range(ndraws)]
        qsum = sum([q for (x, idx, q) in samples])
        vol = 1. * ndraws / qsum * self.vol_tot

        if return_overlap:
            # Estimate the fractional amount of overlap with the
            # unit cube using the same set of samples.
            qin = sum([q * unitcheck(x) for (x, idx, q) in samples])
            overlap = 1. * qin / qsum
            return vol, overlap
        else:
            return vol
234863
def propose_unif(self):
        """"""

        while True:
            # Sample a point from the ellipsoid.
            u = self.ell.sample(rstate=self.rstate)

            # Check if `u` is within the unit cube.
            if unitcheck(u, self.nonperiodic):
                break  # if it is, we're done!

        return u, self.ell.axes
1357713
def cublasCgeru(handle, m, n, alpha, x, incx, y, incy, A, lda):
    

    status = _libcublas.cublasCgeru_v2(handle,
                                       m, n, ctypes.byref(cuda.cuFloatComplex(alpha.real,
                                                                              alpha.imag)),
                                       int(x), incx, int(y), incy, int(A), lda)
    cublasCheckStatus(status)
418224
def unitcube_overlap(self, ndraws=10000, rstate=None):
        """"""

        if rstate is None:
            rstate = np.random

        samples = [self.sample(rstate=rstate) for i in range(ndraws)]
        nin = sum([unitcheck(x) for x in samples])

        return 1. * nin / ndraws
6969
def cublasZhpmv(handle, uplo, n, alpha, AP, x, incx, beta, y, incy):
    
    
    status = _libcublas.cublasZhpmv_v2(handle,
                                       _CUBLAS_FILL_MODE[uplo], 
                                       n, ctypes.byref(cuda.cuDoubleComplex(alpha.real,
                                                                            alpha.imag)),
                                       int(AP), int(x), incx,
                                       ctypes.byref(cuda.cuDoubleComplex(beta.real, 
                                                                         beta.imag)),
                                       int(y), incy)
    cublasCheckStatus(status)
1163565
def _estimate_delta(ntriangles, area):
    
    return np.sqrt(4./np.sqrt(3) * float(area) / float(ntriangles))
94002
def iou(box1, box2):
        
        int_box = Box.intersection_box(box1, box2)
        int_area = int_box.area()
        union_area = box1.area() + box2.area() - int_area

        result = 0.0
        if union_area > 0:
            result = float(int_area) / float(union_area)

        return result
996221
def cublasSspr(handle, uplo, n, alpha, x, incx, AP):
    
    
    status = _libcublas.cublasSspr_v2(handle, 
                                      _CUBLAS_FILL_MODE[uplo], n,                                       
                                      ctypes.byref(ctypes.c_float(alpha)), 
                                      int(x), incx, int(AP))                                      
    cublasCheckStatus(status)
836508
def bounds_overlap(bound1, bound2):
    ''''''
    (x1,y1,w1,h1) = bound1
    (x2,y2,w2,h2) = bound2
    if x1+w1 < x2:
        return False
    if x2+w2 < x1:
        return False
    if y1+h1 < y2:
        return False
    if y2+h2 < y1:
        return False
    return True
84759
public static double overlap(SpatialComparable box1, SpatialComparable box2) {
    final int dim = assertSameDimensionality(box1, box2);

    // the maximal and minimal value of the overlap box.
    double omax, omin;

    // the overlap volume
    double overlap = 1.;

    for(int i = 0; i < dim; i++) {
      // The maximal value of that overlap box in the current
      // dimension is the minimum of the max values.
      omax = Math.min(box1.getMax(i), box2.getMax(i));
      // The minimal value is the maximum of the min values.
      omin = Math.max(box1.getMin(i), box2.getMin(i));

      // if omax <= omin in any dimension, the overlap box has a volume of zero
      if(omax <= omin) {
        return 0.;
      }

      overlap *= omax - omin;
    }

    return overlap;
  }
501334
def _real(coords1, charges1, coords2, charges2, rcut, alpha, box):
    
    n = coords1.shape[0]
    m = coords2.shape[0]
    # Unit vectors
    a = box[0]
    b = box[1]
    c = box[2]
    
    
    # This is helpful to add the correct number of boxes
    l_max = int(np.ceil(2.0 * rcut / np.min(np.trace(box))))
    result = np.zeros(n)
    
    
    for i in range(n):
        q_i = charges1[i]
        r_i = coords1[i]

        for j in range(m):
            q_j = charges2[j]
            r_j = coords2[j]

            for l_i in range(-l_max, l_max + 1):
                for l_j in range(-l_max, l_max + 1):
                    for l_k in range(-l_max, l_max + 1):
                        nv = l_i * a + l_j * b + l_k * c
                        r_j_n = r_j + nv
                        
                        r_ij = _dist(r_i, r_j_n)
                        if r_ij < 1e-10 or r_ij > rcut:
                            continue
                        value = q_i * q_j * math.erfc(alpha * r_ij) / r_ij
                        result[i] += value

    return result
212810
def cublasZtrsm(handle, side, uplo, transa, diag, m, n, alpha, A, lda, B, ldb):
    
    
    status = _libcublas.cublasZtrsm_v2(handle, 
                                       _CUBLAS_SIDE_MODE[side], 
                                       _CUBLAS_FILL_MODE[uplo], 
                                       _CUBLAS_OP[trans], 
                                       _CUBLAS_DIAG[diag], 
                                       m, n, ctypes.byref(cuda.cuDoubleComplex(alpha.real,                    
                                                                               alpha.imag)),
                                       int(A), lda, int(B), ldb)
    cublasCheckStatus(status)
721486
def propose_unif(self):
        """"""

        # Initialize a K-D Tree to assist nearest neighbor searches.
        if self.use_kdtree:
            kdtree = spatial.KDTree(self.live_u)
        else:
            kdtree = None

        while True:
            # Sample a point `u` from the union of N-spheres along with the
            # number of overlapping spheres `q` at point `u`.
            u, q = self.radfriends.sample(self.live_u, rstate=self.rstate,
                                          return_q=True, kdtree=kdtree)

            # Check if our sample is within the unit cube.
            if unitcheck(u, self.nonperiodic):
                # Accept the point with probability 1/q to account for
                # overlapping balls.
                if q == 1 or self.rstate.rand() < 1.0 / q:
                    break  # if successful, we're done!

        # Define the axes of the N-sphere.
        ax = np.identity(self.npdim) * self.radfriends.radius

        return u, ax
332477
def click_estimate_curvature():
    

    c1 = _pylab.ginput()
    if len(c1)==0:
        return None

    c2 = _pylab.ginput()
    if len(c2)==0:
        return None

    return 2*(c2[0][1]-c1[0][1])/(c2[0][0]-c1[0][0])**2
1214607
def on_separate_dimensions(self):
        
        if np.any([isinstance(k.active_dims, slice) for k in self.kernels]):
            # Be conservative in the case of a slice object
            return False
        else:
            dimlist = [k.active_dims for k in self.kernels]
            overlapping = False
            for i, dims_i in enumerate(dimlist):
                for dims_j in dimlist[i + 1:]:
                    if np.any(dims_i.reshape(-1, 1) == dims_j.reshape(1, -1)):
                        overlapping = True
            return not overlapping
1374559
def get_1D_overlap(eclusters, depth=1):
    
    overlap_set = set()
    active = set()

    ends = []
    for i, (chr, left, right) in enumerate(eclusters):
        ends.append((chr, left, 0, i))  # 0/1 for left/right-ness
        ends.append((chr, right, 1, i))
    ends.sort()

    chr_last = ""
    for chr, pos, left_right, i in ends:
        if chr != chr_last:
            active.clear()
        if left_right == 0:
            active.add(i)
        else:
            active.remove(i)

        if len(active) > depth:
            overlap_set.add(tuple(sorted(active)))

        chr_last = chr

    return overlap_set
454437
def overlap(self, x, ctrs, kdtree=None):
        """"""

        q = len(self.within(x, ctrs, kdtree=kdtree))

        return q