示例#1
0
def spear(x,y,idx,idy,sigma,tau,lags,wids,scales,symm=None,set_pmap=False) :
    """
    Clean version without multithreading. Used when multiprocessing is on (e.g., 
    in emcee MCMC sampling).

    set_pmap needs to be turned on for the Pmap_Model.
    """
    if (sigma<0. or tau<0.) :
        raise ValueError, 'The amp and scale parameters must be positive.'
    if (symm is None) :
        symm = (x is y) and (idx is idy)
    x = regularize_array(x)
    y = regularize_array(y)
    nx = x.shape[0]
    ny = y.shape[0]
    if np.isscalar(idx) :
        idx = np.ones(nx, dtype="int", order="F")*idx
    if np.isscalar(idy) :
        idy = np.ones(nx, dtype="int", order="F")*idy
    # Allocate the matrix
    C = np.asmatrix(np.empty((nx,ny),dtype=float,order='F'))
    if set_pmap :
        SCF.covmatpmap_bit(C,x,y,idx,idy,sigma,tau,lags,wids,scales,0,-1,symm)
    else :
        SCF.covmat_bit(C,x,y,idx,idy,sigma,tau,lags,wids,scales,0,-1,symm)
    if symm:
        isotropic_cov_funs.symmetrize(C)
    return(C)
示例#2
0
def spear_threading(x,y,idx,idy,sigma,tau,lags,wids,scales,symm=None,set_pmap=False,blocksize=10000) :
    """
    threaded version, divide matrix into subblocks with *blocksize* 
    elements each. Do not use it when multiprocessing is on (e.g., in emcee MCMC
    sampling).

    set_pmap needs to be turned on for the Pmap_Model.
    """
    if (sigma<0. or tau<0.) :
        raise ValueError, 'The amp and scale parameters must be positive.'
    if (symm is None) :
        symm = (x is y) and (idx is idy)
    x = regularize_array(x)
    y = regularize_array(y)
    nx = x.shape[0]
    ny = y.shape[0]
    if np.isscalar(idx) :
        idx = np.ones(nx, dtype="int", order="F")*idx
    if np.isscalar(idy) :
        idy = np.ones(nx, dtype="int", order="F")*idy
    # Figure out how to divide job up between threads (along y)
    n_threads = min(get_threadpool_size(), nx*ny/blocksize)
    if n_threads > 1 :
        if not symm:
            # divide ny evenly if x is not y
            bounds = np.linspace(0,ny,n_threads+1)
        else :
            # divide ny*ny evenly in quadrature if x is y
            bounds = np.array(np.sqrt(np.linspace(0,ny*ny,n_threads+1)),dtype=int)
    # Allocate the matrix
    C = np.asmatrix(np.empty((nx,ny),dtype=float,order='F'))
    if set_pmap :
        def targ(C,x,y,idx,idy,cmin,cmax,symm) :
            SCF.covmatpmap_bit(C,x,y,idx,idy,sigma,tau,lags,wids,scales,cmin,cmax,symm)
    else :
        def targ(C,x,y,idx,idy,cmin,cmax,symm) :
            SCF.covmat_bit(C,x,y,idx,idy,sigma,tau,lags,wids,scales,cmin,cmax,symm)
    if n_threads <= 1 :
        targ(C,x,y,idx,idy,0,-1,symm)
    else :
        thread_args = [(C,x,y,idx,idy,bounds[i],bounds[i+1],symm) for i in xrange(n_threads)]
        map_noreturn(targ, thread_args)
    if symm:
        isotropic_cov_funs.symmetrize(C)
    return(C)
示例#3
0
def spear(x,
          y,
          idx,
          idy,
          sigma,
          tau,
          lags,
          wids,
          scales,
          symm=None,
          set_pmap=False,
          set_dpmap=False):
    """ Clean version without multithreading. Used when multiprocessing is on
    (e.g., in emcee MCMC sampling).

    set_pmap needs to be turned on for the Pmap_Model.
    """
    if (sigma < 0. or tau < 0.):
        raise ValueError, 'The amp and scale parameters must be positive.'
    if (symm is None):
        symm = (x is y) and (idx is idy)
    x = regularize_array(x)
    y = regularize_array(y)
    nx = x.shape[0]
    ny = y.shape[0]
    if np.isscalar(idx):
        idx = np.ones(nx, dtype="int", order="F") * idx
    if np.isscalar(idy):
        idy = np.ones(nx, dtype="int", order="F") * idy
    # Allocate the matrix
    C = np.asmatrix(np.empty((nx, ny), dtype=float, order='F'))
    if set_pmap:
        SCF.covmatpmap_bit(C, x, y, idx, idy, sigma, tau, lags, wids, scales,
                           0, -1, symm)
    elif set_dpmap:
        SCF.covmatdpmap_bit(C, x, y, idx, idy, sigma, tau, lags, wids, scales,
                            0, -1, symm)
    else:
        SCF.covmat_bit(C, x, y, idx, idy, sigma, tau, lags, wids, scales, 0,
                       -1, symm)
    if symm:
        isotropic_cov_funs.symmetrize(C)
    return (C)
示例#4
0
def spear_threading(x,
                    y,
                    idx,
                    idy,
                    sigma,
                    tau,
                    lags,
                    wids,
                    scales,
                    symm=None,
                    set_pmap=False,
                    blocksize=10000):
    """
    threaded version, divide matrix into subblocks with *blocksize*
    elements each. Do not use it when multiprocessing is on (e.g., in emcee MCMC
    sampling).

    set_pmap needs to be turned on for the Pmap_Model.
    """
    if (sigma < 0. or tau < 0.):
        raise ValueError, 'The amp and scale parameters must be positive.'
    if (symm is None):
        symm = (x is y) and (idx is idy)
    x = regularize_array(x)
    y = regularize_array(y)
    nx = x.shape[0]
    ny = y.shape[0]
    if np.isscalar(idx):
        idx = np.ones(nx, dtype="int", order="F") * idx
    if np.isscalar(idy):
        idy = np.ones(nx, dtype="int", order="F") * idy
    # Figure out how to divide job up between threads (along y)
    n_threads = min(get_threadpool_size(), nx * ny / blocksize)
    if n_threads > 1:
        if not symm:
            # divide ny evenly if x is not y
            bounds = np.linspace(0, ny, n_threads + 1)
        else:
            # divide ny*ny evenly in quadrature if x is y
            bounds = np.array(np.sqrt(np.linspace(0, ny * ny, n_threads + 1)),
                              dtype=int)
    # Allocate the matrix
    C = np.asmatrix(np.empty((nx, ny), dtype=float, order='F'))
    if set_pmap:

        def targ(C, x, y, idx, idy, cmin, cmax, symm):
            SCF.covmatpmap_bit(C, x, y, idx, idy, sigma, tau, lags, wids,
                               scales, cmin, cmax, symm)
    else:

        def targ(C, x, y, idx, idy, cmin, cmax, symm):
            SCF.covmat_bit(C, x, y, idx, idy, sigma, tau, lags, wids, scales,
                           cmin, cmax, symm)

    if n_threads <= 1:
        targ(C, x, y, idx, idy, 0, -1, symm)
    else:
        thread_args = [(C, x, y, idx, idy, bounds[i], bounds[i + 1], symm)
                       for i in xrange(n_threads)]
        map_noreturn(targ, thread_args)
    if symm:
        isotropic_cov_funs.symmetrize(C)
    return (C)