示例#1
0
  /**
   * Discrete fourier transform 2d
   *
   * @param input the input to transform
   * @param rows the number of rows in the transformed output matrix
   * @param cols the number of columns in the transformed output matrix
   * @return the discrete fourier transform of the input
   */
  public static ComplexDoubleMatrix complexDisceteFourierTransform(
      ComplexDoubleMatrix input, int rows, int cols) {
    ComplexDoubleMatrix base;

    // pad
    if (input.rows < rows || input.columns < cols)
      base = MatrixUtil.complexPadWithZeros(input, rows, cols);
    // truncation
    else if (input.rows > rows || input.columns > cols) {
      base = input.dup();
      base =
          base.get(
              MatrixUtil.toIndices(RangeUtils.interval(0, rows)),
              MatrixUtil.toIndices(RangeUtils.interval(0, cols)));
    } else base = input.dup();

    ComplexDoubleMatrix temp = new ComplexDoubleMatrix(base.rows, base.columns);
    ComplexDoubleMatrix ret = new ComplexDoubleMatrix(base.rows, base.columns);
    for (int i = 0; i < base.columns; i++) {
      ComplexDoubleMatrix column = base.getColumn(i);
      temp.putColumn(i, complexDiscreteFourierTransform1d(column));
    }

    for (int i = 0; i < ret.rows; i++) {
      ComplexDoubleMatrix row = temp.getRow(i);
      ret.putRow(i, complexDiscreteFourierTransform1d(row));
    }
    return ret;
  }
示例#2
0
  /**
   * Compute the singular values of a complex matrix.
   *
   * @param A ComplexDoubleMatrix of dimension m * n
   * @return A real-valued (!) min(m, n) vector of singular values.
   */
  public static DoubleMatrix SVDValues(ComplexDoubleMatrix A) {
    int m = A.rows;
    int n = A.columns;
    DoubleMatrix S = new DoubleMatrix(min(m, n));
    double[] rwork = new double[5 * min(m, n)];

    int info =
        NativeBlas.zgesvd(
            'N',
            'N',
            m,
            n,
            A.dup().data,
            0,
            m,
            S.data,
            0,
            null,
            0,
            1,
            null,
            0,
            min(m, n),
            rwork,
            0);

    if (info > 0) {
      throw new LapackConvergenceException(
          "GESVD", info + " superdiagonals of an intermediate bidiagonal form failed to converge.");
    }

    return S;
  }
示例#3
0
  /**
   * Compute a singular-value decomposition of A.
   *
   * @return A ComplexDoubleMatrix[3] array of U, S, V such that A = U * diag(S) * V'
   */
  public static ComplexDoubleMatrix[] fullSVD(ComplexDoubleMatrix A) {
    int m = A.rows;
    int n = A.columns;

    ComplexDoubleMatrix U = new ComplexDoubleMatrix(m, m);
    DoubleMatrix S = new DoubleMatrix(min(m, n));
    ComplexDoubleMatrix V = new ComplexDoubleMatrix(n, n);

    double[] rwork = new double[5 * min(m, n)];

    int info =
        NativeBlas.zgesvd(
            'A', 'A', m, n, A.dup().data, 0, m, S.data, 0, U.data, 0, m, V.data, 0, n, rwork, 0);

    if (info > 0) {
      throw new LapackConvergenceException(
          "GESVD", info + " superdiagonals of an intermediate bidiagonal form failed to converge.");
    }

    return new ComplexDoubleMatrix[] {U, new ComplexDoubleMatrix(S), V.hermitian()};
  }