Ejemplo n.º 1
0
def get_moments(v,m,n=100,use_fortran=use_fortran):
  """ Get the first n moments of a certain vector
  using the Chebychev recursion relations"""
  if use_fortran:
    from kpmf90 import get_momentsf90 # fortran routine
    mo = coo_matrix(m) # convert to coo matrix
    vo = v.todense() # convert to conventional vector
    vo = np.array([vo[i,0] for i in range(len(vo))])
# call the fortran routine
    mus = get_momentsf90(mo.row+1,mo.col+1,mo.data,vo,n) 
    return mus # return fortran result
  else:
    mus = np.array([0.0j for i in range(2*n)]) # empty arrray for the moments
    a = v.copy() # first vector
    am = v.copy() # zero vector
    a = m*v  # vector number 1
    bk = (np.transpose(np.conjugate(v))*v)[0,0] # scalar product
    bk1 = (np.transpose(np.conjugate(v))*a)[0,0] # scalar product
    mus[0] = bk  # mu0
    mus[1] = bk1 # mu1
    for i in range(1,n): 
      ap = 2*m*a - am # recursion relation
      bk = (np.transpose(np.conjugate(a))*a)[0,0] # scalar product
      bk1 = (np.transpose(np.conjugate(ap))*a)[0,0] # scalar product
      mus[2*i] = 2.*bk
      mus[2*i+1] = 2.*bk1
      am = a +0. # new variables
      a = ap+0. # new variables
    mu0 = mus[0] # first
    mu1 = mus[1] # second
    for i in range(1,n): 
      mus[2*i] +=  - mu0
      mus[2*i+1] += -mu1 
    return mus
Ejemplo n.º 2
0
Archivo: kpm.py Proyecto: woal777/pygra
def get_moments(v, m, n=100, use_fortran=use_fortran):
    """ Get the first n moments of a certain vector
  using the Chebychev recursion relations"""
    if use_fortran:
        from kpmf90 import get_momentsf90  # fortran routine
        mo = coo_matrix(m)  # convert to coo matrix
        vo = v.todense()  # convert to conventional vector
        vo = np.array([vo[i, 0] for i in range(len(vo))])
        # call the fortran routine
        mus = get_momentsf90(mo.row + 1, mo.col + 1, mo.data, vo, n)
        return mus  # return fortran result
    else:
        mus = np.array([0.0j
                        for i in range(2 * n)])  # empty arrray for the moments
        a = v.copy()  # first vector
        am = v.copy()  # zero vector
        a = m * v  # vector number 1
        bk = (np.transpose(np.conjugate(v)) * v)[0, 0]  # scalar product
        bk1 = (np.transpose(np.conjugate(v)) * a)[0, 0]  # scalar product
        mus[0] = bk  # mu0
        mus[1] = bk1  # mu1
        for i in range(1, n):
            ap = 2 * m * a - am  # recursion relation
            bk = (np.transpose(np.conjugate(a)) * a)[0, 0]  # scalar product
            bk1 = (np.transpose(np.conjugate(ap)) * a)[0, 0]  # scalar product
            mus[2 * i] = 2. * bk
            mus[2 * i + 1] = 2. * bk1
            am = a + 0.  # new variables
            a = ap + 0.  # new variables
        mu0 = mus[0]  # first
        mu1 = mus[1]  # second
        for i in range(1, n):
            mus[2 * i] += -mu0
            mus[2 * i + 1] += -mu1
        return mus
Ejemplo n.º 3
0
def get_moments(v, m, n=100, use_fortran=use_fortran, test=False):
    """ Get the first n moments of a certain vector
  using the Chebychev recursion relations"""
    if use_fortran:
        from kpmf90 import get_momentsf90  # fortran routine
        mo = coo_matrix(m)  # convert to coo matrix
        vo = v.todense()  # convert to conventional vector
        vo = np.array([vo[i, 0] for i in range(len(vo))])
        # call the fortran routine
        mus = get_momentsf90(mo.row + 1, mo.col + 1, mo.data, vo, n)
        return mus  # return fortran result
    else:
        if test: return python_kpm_moments_clear(v, m, n=n)
        else: return python_kpm_moments(v, m, n=n)
Ejemplo n.º 4
0
def get_moments(v,m,n=100,use_fortran=use_fortran,test=False):
  """ Get the first n moments of a certain vector
  using the Chebychev recursion relations"""
  if use_fortran:
    from kpmf90 import get_momentsf90 # fortran routine
    mo = coo_matrix(m) # convert to coo matrix
    vo = v.todense() # convert to conventional vector
    vo = np.array([vo[i,0] for i in range(len(vo))])
# call the fortran routine
    mus = get_momentsf90(mo.row+1,mo.col+1,mo.data,vo,n) 
    return mus # return fortran result
  else:
   if test: return python_kpm_moments_clear(v,m,n=n)
   else: return python_kpm_moments(v,m,n=n)