|
|
|
@ -4,7 +4,7 @@ |
|
|
|
// http://github.com/mathnet/mathnet-numerics
|
|
|
|
// http://mathnetnumerics.codeplex.com
|
|
|
|
//
|
|
|
|
// Copyright (c) 2009-2010 Math.NET
|
|
|
|
// Copyright (c) 2009-2013 Math.NET
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person
|
|
|
|
// obtaining a copy of this software and associated documentation
|
|
|
|
@ -28,10 +28,9 @@ |
|
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
using System; |
|
|
|
using MathNet.Numerics.LinearAlgebra.Factorization; |
|
|
|
using MathNet.Numerics.Properties; |
|
|
|
using System; |
|
|
|
using MathNet.Numerics.Providers.LinearAlgebra; |
|
|
|
|
|
|
|
namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization |
|
|
|
{ |
|
|
|
@ -44,13 +43,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization |
|
|
|
/// <remarks>
|
|
|
|
/// The computation of the QR decomposition is done at construction time by modified Gram-Schmidt Orthogonalization.
|
|
|
|
/// </remarks>
|
|
|
|
public class DenseGramSchmidt : GramSchmidt |
|
|
|
public sealed class DenseGramSchmidt : GramSchmidt |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// used for QR solve
|
|
|
|
/// </summary>
|
|
|
|
private readonly ILinearAlgebraProvider _provider = new ManagedLinearAlgebraProvider(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="DenseGramSchmidt"/> class. This object creates an unitary matrix
|
|
|
|
/// using the modified Gram-Schmidt method.
|
|
|
|
@ -59,21 +53,23 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization |
|
|
|
/// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
|
|
|
|
/// <exception cref="ArgumentException">If <paramref name="matrix"/> row count is less then column count</exception>
|
|
|
|
/// <exception cref="ArgumentException">If <paramref name="matrix"/> is rank deficient</exception>
|
|
|
|
public DenseGramSchmidt(DenseMatrix matrix) |
|
|
|
public static DenseGramSchmidt Create(DenseMatrix matrix) |
|
|
|
{ |
|
|
|
if (matrix == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("matrix"); |
|
|
|
} |
|
|
|
|
|
|
|
if (matrix.RowCount < matrix.ColumnCount) |
|
|
|
{ |
|
|
|
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix); |
|
|
|
} |
|
|
|
|
|
|
|
Q = matrix.Clone(); |
|
|
|
MatrixR = matrix.CreateMatrix(matrix.ColumnCount, matrix.ColumnCount); |
|
|
|
Factorize(((DenseMatrix)Q).Values, Q.RowCount, Q.ColumnCount, ((DenseMatrix)MatrixR).Values); |
|
|
|
var q = (DenseMatrix)matrix.Clone(); |
|
|
|
var r = new DenseMatrix(matrix.ColumnCount, matrix.ColumnCount); |
|
|
|
Factorize(q.Values, q.RowCount, q.ColumnCount, r.Values); |
|
|
|
|
|
|
|
return new DenseGramSchmidt(q, r); |
|
|
|
} |
|
|
|
|
|
|
|
DenseGramSchmidt(Matrix<Complex32> q, Matrix<Complex32> rFull) |
|
|
|
: base(q, rFull) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -133,17 +129,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization |
|
|
|
/// <param name="result">The left hand side <see cref="Matrix{T}"/>, <b>X</b>.</param>
|
|
|
|
public override void Solve(Matrix<Complex32> input, Matrix<Complex32> result) |
|
|
|
{ |
|
|
|
// Check for proper arguments.
|
|
|
|
if (input == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("input"); |
|
|
|
} |
|
|
|
|
|
|
|
if (result == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("result"); |
|
|
|
} |
|
|
|
|
|
|
|
// The solution X should have the same number of columns as B
|
|
|
|
if (input.ColumnCount != result.ColumnCount) |
|
|
|
{ |
|
|
|
@ -174,7 +159,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization |
|
|
|
throw new NotSupportedException("Can only do GramSchmidt factorization for dense matrices at the moment."); |
|
|
|
} |
|
|
|
|
|
|
|
_provider.QRSolveFactored(((DenseMatrix)Q).Values, ((DenseMatrix)MatrixR).Values, Q.RowCount, MatrixR.ColumnCount, null, dinput.Values, input.ColumnCount, dresult.Values, QRMethod.Thin); |
|
|
|
Control.LinearAlgebraProvider.QRSolveFactored(((DenseMatrix)Q).Values, ((DenseMatrix)MatrixR).Values, Q.RowCount, MatrixR.ColumnCount, null, dinput.Values, input.ColumnCount, dresult.Values, QRMethod.Thin); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -184,16 +169,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization |
|
|
|
/// <param name="result">The left hand side <see cref="Matrix{T}"/>, <b>x</b>.</param>
|
|
|
|
public override void Solve(Vector<Complex32> input, Vector<Complex32> result) |
|
|
|
{ |
|
|
|
if (input == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("input"); |
|
|
|
} |
|
|
|
|
|
|
|
if (result == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("result"); |
|
|
|
} |
|
|
|
|
|
|
|
// Ax=b where A is an m x n matrix
|
|
|
|
// Check that b is a column vector with m entries
|
|
|
|
if (Q.RowCount != input.Count) |
|
|
|
@ -219,7 +194,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization |
|
|
|
throw new NotSupportedException("Can only do GramSchmidt factorization for dense vectors at the moment."); |
|
|
|
} |
|
|
|
|
|
|
|
_provider.QRSolveFactored(((DenseMatrix)Q).Values, ((DenseMatrix)MatrixR).Values, Q.RowCount, MatrixR.ColumnCount, null, dinput.Values, 1, dresult.Values, QRMethod.Thin); |
|
|
|
Control.LinearAlgebraProvider.QRSolveFactored(((DenseMatrix)Q).Values, ((DenseMatrix)MatrixR).Values, Q.RowCount, MatrixR.ColumnCount, null, dinput.Values, 1, dresult.Values, QRMethod.Thin); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|