Ejemplo n.º 1
0
        /// <summary>Performs the QR factorization.</summary>
        protected override void InternalCompute()
        {
            int m = matrix.RowCount;
            int n = matrix.ColumnCount;

#if MANAGED
            int minmn = m < n ? m : n;
            r_ = new DoubleMatrix(matrix); // create a copy
            var u = new DoubleVector[minmn];
            for (int i = 0; i < minmn; i++)
            {
                u[i] = Householder.GenerateColumn(r_, i, m - 1, i);
                Householder.UA(u[i], r_, i, m - 1, i + 1, n - 1);
            }
            q_ = DoubleMatrix.CreateIdentity(m);
            for (int i = minmn - 1; i >= 0; i--)
            {
                Householder.UA(u[i], q_, i, m - 1, i, m - 1);
            }
#else
            qr = new double[matrix.data.Length];
            Array.Copy(matrix.data, qr, matrix.data.Length);
            jpvt    = new int[n];
            jpvt[0] = 1;
            Lapack.Geqp3.Compute(m, n, qr, m, jpvt, out tau);
            r_ = new DoubleMatrix(m, n);
            // Populate R
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i <= j)
                    {
                        r_.data[j * m + i] = qr[(jpvt[j] - 1) * m + i];
                    }
                    else
                    {
                        r_.data[j * m + i] = 0.0;
                    }
                }
            }
            q_ = new DoubleMatrix(m, m);
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (j < n)
                    {
                        q_.data[j * m + i] = qr[j * m + i];
                    }
                    else
                    {
                        q_.data[j * m + i] = 0.0;
                    }
                }
            }

            if (m < n)
            {
                Lapack.Orgqr.Compute(m, m, m, q_.data, m, tau);
            }
            else
            {
                Lapack.Orgqr.Compute(m, m, n, q_.data, m, tau);
            }
#endif
            for (int i = 0; i < m; i++)
            {
                if (q_[i, i] == 0)
                {
                    isFullRank = false;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>Performs the QR factorization.</summary>
        protected override void InternalCompute()
        {
            int m = matrix.Rows;
            int n = matrix.Columns;

#if MANAGED
            int minmn = m < n ? m : n;
            r_ = new ComplexFloatMatrix(matrix); // create a copy
            ComplexFloatVector[] u = new ComplexFloatVector[minmn];
            for (int i = 0; i < minmn; i++)
            {
                u[i] = Householder.GenerateColumn(r_, i, m - 1, i);
                Householder.UA(u[i], r_, i, m - 1, i + 1, n - 1);
            }
            q_ = ComplexFloatMatrix.CreateIdentity(m);
            for (int i = minmn - 1; i >= 0; i--)
            {
                Householder.UA(u[i], q_, i, m - 1, i, m - 1);
            }
#else
            qr      = ComplexFloatMatrix.ToLinearComplexArray(matrix);
            jpvt    = new int[n];
            jpvt[0] = 1;
            Lapack.Geqp3.Compute(m, n, qr, m, jpvt, out tau);
            r_ = new ComplexFloatMatrix(m, n);
            // Populate R

            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i <= j)
                    {
                        r_.data[j * m + i] = qr[(jpvt[j] - 1) * m + i];
                    }
                    else
                    {
                        r_.data[j * m + i] = ComplexFloat.Zero;
                    }
                }
            }

            q_ = new ComplexFloatMatrix(m, m);
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (j < n)
                    {
                        q_.data[j * m + i] = qr[j * m + i];
                    }
                    else
                    {
                        q_.data[j * m + i] = ComplexFloat.Zero;
                    }
                }
            }
            if (m < n)
            {
                Lapack.Ungqr.Compute(m, m, m, q_.data, m, tau);
            }
            else
            {
                Lapack.Ungqr.Compute(m, m, n, q_.data, m, tau);
            }
#endif
            for (int i = 0; i < m; i++)
            {
                if (q_[i, i] == 0)
                {
                    isFullRank = false;
                }
            }
        }