Ejemplo n.º 1
0
def iddp_asvd(eps, A):
  """
  Compute SVD of a real matrix to a specified relative precision using random
  sampling.

  :param eps:
    Relative precision.
  :type eps: float
  :param A:
    Matrix.
  :type A: :class:`numpy.ndarray`

  :return:
    Left singular vectors.
  :rtype: :class:`numpy.ndarray`
  :return:
    Right singular vectors.
  :rtype: :class:`numpy.ndarray`
  :return:
    Singular values.
  :rtype: :class:`numpy.ndarray`
  """
  A = np.asfortranarray(A)
  m, n = A.shape
  n2, winit = _id.idd_frmi(m)
  w = np.empty(max((min(m,n) + 1)*(3*m + 5*n + 1) + 25*min(m,n)**2,
                   (2*n + 1)*(n2 + 1)),
               order='F')
  k, iU, iV, iS, w, ier = _id.iddp_asvd(eps, A, winit, w)
  if ier != 0: raise _RETCODE_ERROR
  U = w[iU-1:iU+m*k-1].reshape((m, k), order='F')
  V = w[iV-1:iV+n*k-1].reshape((n, k), order='F')
  S = w[iS-1:iS+k-1]
  return U, V, S
Ejemplo n.º 2
0
def iddp_asvd(eps, A):
    """
  Compute SVD of a real matrix to a specified relative precision using random
  sampling.

  :param eps:
    Relative precision.
  :type eps: float
  :param A:
    Matrix.
  :type A: :class:`numpy.ndarray`

  :return:
    Left singular vectors.
  :rtype: :class:`numpy.ndarray`
  :return:
    Right singular vectors.
  :rtype: :class:`numpy.ndarray`
  :return:
    Singular values.
  :rtype: :class:`numpy.ndarray`
  """
    A = np.asfortranarray(A)
    m, n = A.shape
    n2, winit = _id.idd_frmi(m)
    w = np.empty(max((min(m, n) + 1) * (3 * m + 5 * n + 1) + 25 * min(m, n)**2,
                     (2 * n + 1) * (n2 + 1)),
                 order='F')
    k, iU, iV, iS, w, ier = _id.iddp_asvd(eps, A, winit, w)
    if ier != 0: raise _RETCODE_ERROR
    U = w[iU - 1:iU + m * k - 1].reshape((m, k), order='F')
    V = w[iV - 1:iV + n * k - 1].reshape((n, k), order='F')
    S = w[iS - 1:iS + k - 1]
    return U, V, S
Ejemplo n.º 3
0
def idd_frmi(m):
  """
  Initialize data for :func:`idd_frm`.

  :param m:
    Length of vector to be transformed.
  :type m: int

  :return:
    Greatest power-of-two integer `n` satisfying `n <= m`.
  :rtype: int
  :return:
    Initialization array to be used by :func:`idd_frm`.
  :rtype: :class:`numpy.ndarray`
  """
  return _id.idd_frmi(m)
Ejemplo n.º 4
0
def idd_frmi(m):
    """
  Initialize data for :func:`idd_frm`.

  :param m:
    Length of vector to be transformed.
  :type m: int

  :return:
    Greatest power-of-two integer `n` satisfying `n <= m`.
  :rtype: int
  :return:
    Initialization array to be used by :func:`idd_frm`.
  :rtype: :class:`numpy.ndarray`
  """
    return _id.idd_frmi(m)