From 207a08eb9e7e9990b1b5125481d63555521da15e Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sat, 17 Aug 2013 12:35:29 +0200 Subject: [PATCH] LA Provider: maintain excluded ACML & GotoBLAS providers, minor cleanup --- src/Numerics/Numerics.csproj | 1 - .../Acml/AcmlLinearAlgebraProvider.Complex.cs | 117 ++-- .../AcmlLinearAlgebraProvider.Complex32.cs | 145 +++-- .../Acml/AcmlLinearAlgebraProvider.double.cs | 145 +++-- .../Acml/AcmlLinearAlgebraProvider.float.cs | 143 +++-- .../LinearAlgebra/Acml/SafeNativeMethods.cs | 42 +- .../GotoBlasLinearAlgebraProvider.Common.cs | 50 +- .../GotoBlasLinearAlgebraProvider.Complex.cs | 147 +++-- ...GotoBlasLinearAlgebraProvider.Complex32.cs | 145 +++-- .../GotoBlasLinearAlgebraProvider.double.cs | 145 +++-- .../GotoBlasLinearAlgebraProvider.float.cs | 141 +++-- .../GotoBlas/SafeNativeMethods.cs | 42 +- .../LinearAlgebra/ILinearAlgebraProvider.cs | 503 ++++++++++++++++- .../ILinearAlgebraProviderOfT.cs | 533 ------------------ .../ManagedLinearAlgebraProvider.Complex.cs | 20 +- .../ManagedLinearAlgebraProvider.Complex32.cs | 520 ++++++++--------- .../ManagedLinearAlgebraProvider.Double.cs | 509 ++++++++--------- .../ManagedLinearAlgebraProvider.Single.cs | 496 ++++++++-------- .../Mkl/MklLinearAlgebraProvider.Common.cs | 40 +- .../Mkl/MklLinearAlgebraProvider.Complex.cs | 136 ++--- .../LinearAlgebra/Mkl/SafeNativeMethods.cs | 58 +- 21 files changed, 2019 insertions(+), 2059 deletions(-) delete mode 100644 src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProviderOfT.cs diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 95e2d318..eebfdbcf 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -101,7 +101,6 @@ - diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex.cs index 82745147..ff50ee1c 100644 --- a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex.cs +++ b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex.cs @@ -27,14 +27,13 @@ #if NATIVEACML using MathNet.Numerics.LinearAlgebra.Factorization; +using MathNet.Numerics.Properties; +using System; +using System.Numerics; +using System.Security; namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { - using System; - using System.Numerics; - using System.Security; - using Properties; - /// /// AMD Core Math Library (ACML) linear algebra provider. /// @@ -189,7 +188,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB; - if (c.Length != m * n) + if (c.Length != m*n) { throw new ArgumentException(Resources.ArgumentMatrixDimensions); } @@ -224,7 +223,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -251,7 +250,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -280,7 +279,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -311,7 +310,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -352,7 +351,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -391,12 +390,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -431,7 +430,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -441,7 +440,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -474,7 +473,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentMustBePositive, "order"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -509,7 +508,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -543,7 +542,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -581,7 +580,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -591,12 +590,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = new Complex[columnsR * Control.BlockSize]; + var work = new Complex[columnsR*Control.BlockSize]; SafeNativeMethods.z_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length); } @@ -633,7 +632,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -643,14 +642,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - if (work.Length < columnsR * Control.BlockSize) + if (work.Length < columnsR*Control.BlockSize) { - work[0] = columnsR * Control.BlockSize; + work[0] = columnsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -667,7 +666,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// The number of columns of B. /// On exit, the solution matrix. /// Rows must be greater or equal to columns. - public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x) + public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x, QRMethod method = QRMethod.Full) { if (a == null) { @@ -684,17 +683,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("x"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -704,7 +703,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.RowsLessThanColumns); } - var work = new Complex[columns * Control.BlockSize]; + var work = new Complex[columns*Control.BlockSize]; QRSolve(a, rows, columns, b, columnsB, x, work); } @@ -721,7 +720,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x, Complex[] work) + public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x, Complex[] work, QRMethod method = QRMethod.Full) { if (a == null) { @@ -743,17 +742,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -765,7 +764,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (work.Length < 1) { - work[0] = rows * Control.BlockSize; + work[0] = rows*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -786,7 +785,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// On exit, the solution matrix. /// Rows must be greater or equal to columns. [SecuritySafeCritical] - public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x) + public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x, QRMethod method = QRMethod.Full) { if (r == null) { @@ -808,22 +807,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -833,7 +832,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.RowsLessThanColumns); } - var work = new Complex[columnsR * Control.BlockSize]; + var work = new Complex[columnsR*Control.BlockSize]; QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work); } @@ -854,7 +853,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x, Complex[] work) + public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x, Complex[] work, QRMethod method = QRMethod.Full) { if (r == null) { @@ -881,22 +880,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -908,7 +907,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (work.Length < 1) { - work[0] = rowsR * Control.BlockSize; + work[0] = rowsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -951,12 +950,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -966,7 +965,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - var work = new Complex[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work); } @@ -996,20 +995,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - var work = new Complex[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; var s = new Complex[Math.Min(rowsA, columnsA)]; - var u = new Complex[rowsA * rowsA]; - var vt = new Complex[columnsA * columnsA]; + var u = new Complex[rowsA*rowsA]; + var vt = new Complex[columnsA*columnsA]; var clone = new Complex[a.Length]; a.Copy(clone); @@ -1061,12 +1060,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -1081,9 +1080,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "work"); } - if (work.Length < (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) + if (work.Length < (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) { - work[0] = (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); + work[0] = (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex32.cs index 1ca1b70b..1eb29d01 100644 --- a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex32.cs +++ b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex32.cs @@ -31,13 +31,12 @@ #if NATIVEACML using MathNet.Numerics.LinearAlgebra.Factorization; +using MathNet.Numerics.Properties; +using System; +using System.Security; namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { - using System; - using System.Security; - using Properties; - /// /// AMD Core Math Library (ACML) linear algebra provider. /// @@ -70,7 +69,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml return SafeNativeMethods.c_dot_product(x.Length, x, y); } - + /// /// Adds a scaled vector to another: result = y + alpha*x. /// @@ -123,8 +122,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (x == null) { throw new ArgumentNullException("x"); - } - + } + if (!ReferenceEquals(x, result)) { Array.Copy(x, 0, result, 0, x.Length); @@ -192,9 +191,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB; - if (c.Length != m * n) + if (c.Length != m*n) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw new ArgumentException(Resources.ArgumentMatrixDimensions); } if (k != l) @@ -227,7 +226,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -236,7 +235,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - + SafeNativeMethods.c_lu_factor(order, data, ipiv); } @@ -254,13 +253,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } var work = new Complex32[order]; - SafeNativeMethods.c_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.c_lu_inverse(order, a, work, work.Length); } /// @@ -283,7 +282,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -294,7 +293,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml } var work = new Complex32[order]; - SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -314,7 +313,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -329,7 +328,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.c_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.c_lu_inverse(order, a, work, work.Length); } /// @@ -355,7 +354,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -375,7 +374,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -394,22 +393,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - + if (ReferenceEquals(a, b)) { throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.c_lu_solve(order, columnsOfB, a, b); + SafeNativeMethods.c_lu_solve(order, columnsOfB, a, b); } /// @@ -434,7 +433,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -444,7 +443,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -454,7 +453,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.c_lu_solve_factored(order, columnsOfB, a, ipiv, b); + SafeNativeMethods.c_lu_solve_factored(order, columnsOfB, a, ipiv, b); } /// @@ -477,7 +476,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentMustBePositive, "order"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -512,7 +511,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -522,7 +521,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.c_cholesky_solve(orderA, columnsB, a, b); + SafeNativeMethods.c_cholesky_solve(orderA, columnsB, a, b); } /// @@ -546,7 +545,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -556,7 +555,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.c_cholesky_solve_factored(orderA, columnsB, a, b); + SafeNativeMethods.c_cholesky_solve_factored(orderA, columnsB, a, b); } /// @@ -584,7 +583,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -594,12 +593,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = new Complex32[columnsR * Control.BlockSize]; + var work = new Complex32[columnsR*Control.BlockSize]; SafeNativeMethods.c_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length); } @@ -636,7 +635,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -646,14 +645,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - if (work.Length < columnsR * Control.BlockSize) + if (work.Length < columnsR*Control.BlockSize) { - work[0] = columnsR * Control.BlockSize; + work[0] = columnsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -670,7 +669,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// The number of columns of B. /// On exit, the solution matrix. /// Rows must be greater or equal to columns. - public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x) + public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x, QRMethod method = QRMethod.Full) { if (a == null) { @@ -687,17 +686,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("x"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -707,7 +706,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.RowsLessThanColumns); } - var work = new Complex32[columns * Control.BlockSize]; + var work = new Complex32[columns*Control.BlockSize]; QRSolve(a, rows, columns, b, columnsB, x, work); } @@ -724,7 +723,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work) + public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work, QRMethod method = QRMethod.Full) { if (a == null) { @@ -746,17 +745,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -768,7 +767,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (work.Length < 1) { - work[0] = rows * Control.BlockSize; + work[0] = rows*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -789,7 +788,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// On exit, the solution matrix. /// Rows must be greater or equal to columns. [SecuritySafeCritical] - public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x) + public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x, QRMethod method = QRMethod.Full) { if (r == null) { @@ -811,22 +810,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -835,8 +834,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { throw new ArgumentException(Resources.RowsLessThanColumns); } - - var work = new Complex32[columnsR * Control.BlockSize]; + + var work = new Complex32[columnsR*Control.BlockSize]; QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work); } @@ -857,7 +856,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work) + public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work, QRMethod method = QRMethod.Full) { if (r == null) { @@ -884,22 +883,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -911,7 +910,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (work.Length < 1) { - work[0] = rowsR * Control.BlockSize; + work[0] = rowsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -954,12 +953,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -969,7 +968,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - var work = new Complex32[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex32[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work); } @@ -999,20 +998,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - var work = new Complex32[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex32[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; var s = new Complex32[Math.Min(rowsA, columnsA)]; - var u = new Complex32[rowsA * rowsA]; - var vt = new Complex32[columnsA * columnsA]; + var u = new Complex32[rowsA*rowsA]; + var vt = new Complex32[columnsA*columnsA]; var clone = new Complex32[a.Length]; a.Copy(clone); @@ -1064,12 +1063,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -1084,9 +1083,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "work"); } - if (work.Length < (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) + if (work.Length < (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) { - work[0] = (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); + work[0] = (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.double.cs b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.double.cs index f656ce52..77188b5a 100644 --- a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.double.cs +++ b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.double.cs @@ -31,13 +31,12 @@ #if NATIVEACML using MathNet.Numerics.LinearAlgebra.Factorization; +using MathNet.Numerics.Properties; +using System; +using System.Security; namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { - using System; - using System.Security; - using Properties; - /// /// AMD Core Math Library (ACML) linear algebra provider. /// @@ -70,7 +69,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml return SafeNativeMethods.d_dot_product(x.Length, x, y); } - + /// /// Adds a scaled vector to another: result = y + alpha*x. /// @@ -123,8 +122,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (x == null) { throw new ArgumentNullException("x"); - } - + } + if (!ReferenceEquals(x, result)) { Array.Copy(x, 0, result, 0, x.Length); @@ -192,9 +191,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB; - if (c.Length != m * n) + if (c.Length != m*n) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw new ArgumentException(Resources.ArgumentMatrixDimensions); } if (k != l) @@ -227,7 +226,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -236,7 +235,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - + SafeNativeMethods.d_lu_factor(order, data, ipiv); } @@ -254,13 +253,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } var work = new double[order]; - SafeNativeMethods.d_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.d_lu_inverse(order, a, work, work.Length); } /// @@ -283,7 +282,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -294,7 +293,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml } var work = new double[order]; - SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -314,7 +313,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -329,7 +328,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.d_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.d_lu_inverse(order, a, work, work.Length); } /// @@ -355,7 +354,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -375,7 +374,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -394,22 +393,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - + if (ReferenceEquals(a, b)) { throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.d_lu_solve(order, columnsOfB, a, b); + SafeNativeMethods.d_lu_solve(order, columnsOfB, a, b); } /// @@ -434,7 +433,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -444,7 +443,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -454,7 +453,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.d_lu_solve_factored(order, columnsOfB, a, ipiv, b); + SafeNativeMethods.d_lu_solve_factored(order, columnsOfB, a, ipiv, b); } /// @@ -477,7 +476,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentMustBePositive, "order"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -512,7 +511,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -522,7 +521,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.d_cholesky_solve(orderA, columnsB, a, b); + SafeNativeMethods.d_cholesky_solve(orderA, columnsB, a, b); } /// @@ -546,7 +545,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -556,7 +555,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.d_cholesky_solve_factored(orderA, columnsB, a, b); + SafeNativeMethods.d_cholesky_solve_factored(orderA, columnsB, a, b); } /// @@ -584,7 +583,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -594,12 +593,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = new double[columnsR * Control.BlockSize]; + var work = new double[columnsR*Control.BlockSize]; SafeNativeMethods.d_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length); } @@ -636,7 +635,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -646,14 +645,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - if (work.Length < columnsR * Control.BlockSize) + if (work.Length < columnsR*Control.BlockSize) { - work[0] = columnsR * Control.BlockSize; + work[0] = columnsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -670,7 +669,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// The number of columns of B. /// On exit, the solution matrix. /// Rows must be greater or equal to columns. - public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x) + public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x, QRMethod method = QRMethod.Full) { if (a == null) { @@ -687,17 +686,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("x"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -707,7 +706,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.RowsLessThanColumns); } - var work = new double[columns * Control.BlockSize]; + var work = new double[columns*Control.BlockSize]; QRSolve(a, rows, columns, b, columnsB, x, work); } @@ -724,7 +723,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x, double[] work) + public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x, double[] work, QRMethod method = QRMethod.Full) { if (a == null) { @@ -746,17 +745,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -768,7 +767,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (work.Length < 1) { - work[0] = rows * Control.BlockSize; + work[0] = rows*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -789,7 +788,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// On exit, the solution matrix. /// Rows must be greater or equal to columns. [SecuritySafeCritical] - public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x) + public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x, QRMethod method = QRMethod.Full) { if (r == null) { @@ -811,22 +810,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -835,8 +834,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { throw new ArgumentException(Resources.RowsLessThanColumns); } - - var work = new double[columnsR * Control.BlockSize]; + + var work = new double[columnsR*Control.BlockSize]; QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work); } @@ -857,7 +856,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x, double[] work) + public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x, double[] work, QRMethod method = QRMethod.Full) { if (r == null) { @@ -884,22 +883,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -911,7 +910,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (work.Length < 1) { - work[0] = rowsR * Control.BlockSize; + work[0] = rowsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -954,12 +953,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -969,7 +968,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - var work = new double[Math.Max((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5 * Math.Min(rowsA, columnsA))]; + var work = new double[Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA))]; SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work); } @@ -999,20 +998,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - var work = new double[Math.Max((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5 * Math.Min(rowsA, columnsA))]; + var work = new double[Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA))]; var s = new double[Math.Min(rowsA, columnsA)]; - var u = new double[rowsA * rowsA]; - var vt = new double[columnsA * columnsA]; + var u = new double[rowsA*rowsA]; + var vt = new double[columnsA*columnsA]; var clone = new double[a.Length]; a.Copy(clone); @@ -1064,12 +1063,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -1084,9 +1083,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "work"); } - if (work.Length < Math.Max((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5 * Math.Min(rowsA, columnsA))) + if (work.Length < Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA))) { - work[0] = Math.Max((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5 * Math.Min(rowsA, columnsA)); + work[0] = Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA)); throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.float.cs b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.float.cs index 0f9f7186..57ee2606 100644 --- a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.float.cs +++ b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.float.cs @@ -31,13 +31,12 @@ #if NATIVEACML using MathNet.Numerics.LinearAlgebra.Factorization; +using MathNet.Numerics.Properties; +using System; +using System.Security; namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { - using System; - using System.Security; - using Properties; - /// /// AMD Core Math Library (ACML) linear algebra provider. /// @@ -70,7 +69,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml return SafeNativeMethods.s_dot_product(x.Length, x, y); } - + /// /// Adds a scaled vector to another: result = y + alpha*x. /// @@ -123,8 +122,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (x == null) { throw new ArgumentNullException("x"); - } - + } + if (!ReferenceEquals(x, result)) { Array.Copy(x, 0, result, 0, x.Length); @@ -192,9 +191,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB; - if (c.Length != m * n) + if (c.Length != m*n) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw new ArgumentException(Resources.ArgumentMatrixDimensions); } if (k != l) @@ -227,7 +226,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -236,7 +235,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - + SafeNativeMethods.s_lu_factor(order, data, ipiv); } @@ -254,13 +253,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } var work = new float[order]; - SafeNativeMethods.s_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.s_lu_inverse(order, a, work, work.Length); } /// @@ -283,7 +282,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -314,7 +313,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -328,8 +327,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - - SafeNativeMethods.s_lu_inverse(order, a, work, work.Length); + + SafeNativeMethods.s_lu_inverse(order, a, work, work.Length); } /// @@ -355,7 +354,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -394,22 +393,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - + if (ReferenceEquals(a, b)) { throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.s_lu_solve(order, columnsOfB, a, b); + SafeNativeMethods.s_lu_solve(order, columnsOfB, a, b); } /// @@ -434,7 +433,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -444,7 +443,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -454,7 +453,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.s_lu_solve_factored(order, columnsOfB, a, ipiv, b); + SafeNativeMethods.s_lu_solve_factored(order, columnsOfB, a, ipiv, b); } /// @@ -477,7 +476,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentMustBePositive, "order"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -512,7 +511,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -522,7 +521,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.s_cholesky_solve(orderA, columnsB, a, b); + SafeNativeMethods.s_cholesky_solve(orderA, columnsB, a, b); } /// @@ -546,7 +545,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -556,7 +555,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.s_cholesky_solve_factored(orderA, columnsB, a, b); + SafeNativeMethods.s_cholesky_solve_factored(orderA, columnsB, a, b); } /// @@ -584,7 +583,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -594,12 +593,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = new float[columnsR * Control.BlockSize]; + var work = new float[columnsR*Control.BlockSize]; SafeNativeMethods.s_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length); } @@ -636,7 +635,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -646,14 +645,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - if (work.Length < columnsR * Control.BlockSize) + if (work.Length < columnsR*Control.BlockSize) { - work[0] = columnsR * Control.BlockSize; + work[0] = columnsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -670,7 +669,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// The number of columns of B. /// On exit, the solution matrix. /// Rows must be greater or equal to columns. - public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x) + public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x, QRMethod method = QRMethod.Full) { if (a == null) { @@ -687,17 +686,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("x"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -707,7 +706,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.RowsLessThanColumns); } - var work = new float[columns * Control.BlockSize]; + var work = new float[columns*Control.BlockSize]; QRSolve(a, rows, columns, b, columnsB, x, work); } @@ -724,7 +723,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x, float[] work) + public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x, float[] work, QRMethod method = QRMethod.Full) { if (a == null) { @@ -746,17 +745,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -768,7 +767,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (work.Length < 1) { - work[0] = rows * Control.BlockSize; + work[0] = rows*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -789,7 +788,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// On exit, the solution matrix. /// Rows must be greater or equal to columns. [SecuritySafeCritical] - public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x) + public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x, QRMethod method = QRMethod.Full) { if (r == null) { @@ -811,22 +810,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -835,8 +834,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml { throw new ArgumentException(Resources.RowsLessThanColumns); } - - var work = new float[columnsR * Control.BlockSize]; + + var work = new float[columnsR*Control.BlockSize]; QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work); } @@ -857,7 +856,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x, float[] work) + public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x, float[] work, QRMethod method = QRMethod.Full) { if (r == null) { @@ -884,22 +883,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -911,7 +910,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml if (work.Length < 1) { - work[0] = rowsR * Control.BlockSize; + work[0] = rowsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -954,12 +953,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -969,7 +968,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - var work = new float[Math.Max(((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5 * Math.Min(rowsA, columnsA))]; + var work = new float[Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA))]; SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work); } @@ -999,20 +998,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - var work = new float[Math.Max(((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5 * Math.Min(rowsA, columnsA))]; + var work = new float[Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA))]; var s = new float[Math.Min(rowsA, columnsA)]; - var u = new float[rowsA * rowsA]; - var vt = new float[columnsA * columnsA]; + var u = new float[rowsA*rowsA]; + var vt = new float[columnsA*columnsA]; var clone = new float[a.Length]; a.Copy(clone); @@ -1064,12 +1063,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -1084,9 +1083,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "work"); } - if (work.Length < Math.Max(((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5 * Math.Min(rowsA, columnsA))) + if (work.Length < Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA))) { - work[0] = Math.Max((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5 * Math.Min(rowsA, columnsA)); + work[0] = Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA)); throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/SafeNativeMethods.cs b/src/Numerics/Providers/LinearAlgebra/Acml/SafeNativeMethods.cs index aa05e495..60f3f394 100644 --- a/src/Numerics/Providers/LinearAlgebra/Acml/SafeNativeMethods.cs +++ b/src/Numerics/Providers/LinearAlgebra/Acml/SafeNativeMethods.cs @@ -44,10 +44,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml /// /// Name of the native DLL. /// - private const string DllName = "MathNET.Numerics.ACML.dll"; + const string DllName = "MathNET.Numerics.ACML.dll"; + + #region BLAS -#region BLAS - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void s_axpy(int n, float alpha, float[] x, [In, Out] float[] y); @@ -59,7 +59,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_axpy(int n, Complex alpha, Complex[] x, [In, Out] Complex[] y); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void s_scale(int n, float alpha, [Out] float[] x); @@ -71,7 +71,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_scale(int n, Complex alpha, [In, Out] Complex[] x); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern float s_dot_product(int n, float[] x, float[] y); @@ -83,22 +83,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void s_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, float alpha, float[] x, float[] y, float beta, [In, Out]float[] c); - + internal static extern void s_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, float alpha, float[] x, float[] y, float beta, [In, Out] float[] c); + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void d_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, double alpha, double[] x, double[] y, double beta, [In, Out]double[] c); + internal static extern void d_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, double alpha, double[] x, double[] y, double beta, [In, Out] double[] c); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void c_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex32 alpha, Complex32[] x, Complex32[] y, Complex32 beta, [In, Out]Complex32[] c); + internal static extern void c_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex32 alpha, Complex32[] x, Complex32[] y, Complex32 beta, [In, Out] Complex32[] c); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void z_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex alpha, Complex[] x, Complex[] y, Complex beta, [In, Out]Complex[] c); + internal static extern void z_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex alpha, Complex[] x, Complex[] y, Complex beta, [In, Out] Complex[] c); -#endregion BLAS - -#region LAPACK + #endregion BLAS + + #region LAPACK [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern float s_matrix_norm(byte norm, int rows, int columns, [In] float[] a, [In, Out] float[] work); @@ -123,7 +123,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int z_cholesky_factor(int n, [In, Out] Complex[] a); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int s_lu_factor(int n, [In, Out] float[] a, [In, Out] int[] ipiv); @@ -153,15 +153,15 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int d_lu_inverse_factored(int n, [In, Out] double[] a, [In, Out] int[] ipiv, [In, Out] double[] work, int lwork); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int c_lu_inverse_factored(int n, [In, Out] Complex32[] a, [In, Out] int[] ipiv, [In, Out] Complex32[] work, int lwork); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int z_lu_inverse_factored(int n, [In, Out] Complex[] a, [In, Out] int[] ipiv, [In, Out] Complex[] work, int lwork); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int s_lu_solve_factored(int n, int nrhs, float[] a, [In, Out]int[] ipiv, [In, Out] float[] b); + internal static extern int s_lu_solve_factored(int n, int nrhs, float[] a, [In, Out] int[] ipiv, [In, Out] float[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int d_lu_solve_factored(int n, int nrhs, double[] a, [In, Out] int[] ipiv, [In, Out] double[] b); @@ -170,7 +170,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml internal static extern int c_lu_solve_factored(int n, int nrhs, Complex32[] a, [In, Out] int[] ipiv, [In, Out] Complex32[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int z_lu_solve_factored(int n, int nrhs, Complex[] a, [In, Out]int[] ipiv, [In, Out] Complex[] b); + internal static extern int z_lu_solve_factored(int n, int nrhs, Complex[] a, [In, Out] int[] ipiv, [In, Out] Complex[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int s_lu_solve(int n, int nrhs, float[] a, [In, Out] float[] b); @@ -182,7 +182,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml internal static extern int c_lu_solve(int n, int nrhs, Complex32[] a, [In, Out] Complex32[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int z_lu_solve(int n, int nrhs, Complex[] a, [In, Out] Complex[] b); + internal static extern int z_lu_solve(int n, int nrhs, Complex[] a, [In, Out] Complex[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int s_cholesky_solve(int n, int nrhs, float[] a, [In, Out] float[] b); @@ -256,7 +256,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Acml [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int z_svd_factor(bool computeVectors, int m, int n, [In, Out] Complex[] a, [In, Out] Complex[] s, [In, Out] Complex[] u, [In, Out] Complex[] v, [In, Out] Complex[] work, int len); -#endregion LAPACK + #endregion LAPACK } } diff --git a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Common.cs b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Common.cs index 4e31a85a..726cd67e 100644 --- a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Common.cs +++ b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Common.cs @@ -30,13 +30,13 @@ #if NATIVEGOTO +using MathNet.Numerics.Properties; +using System; +using System.Numerics; +using System.Security; + namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { - using System; - using System.Numerics; - using System.Security; - using Properties; - /// /// GotoBLAS2 linear algebra provider. /// @@ -70,9 +70,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } var work = new float[rows]; @@ -109,9 +109,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } if (work.Length < rows) @@ -119,7 +119,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work"); } - return SafeNativeMethods.s_matrix_norm((byte)norm, rows, columns, matrix, work); + return SafeNativeMethods.s_matrix_norm((byte) norm, rows, columns, matrix, work); } /// @@ -150,9 +150,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } var work = new double[rows]; @@ -189,9 +189,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } if (work.Length < rows) @@ -199,7 +199,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work"); } - return SafeNativeMethods.d_matrix_norm((byte)norm, rows, columns, matrix, work); + return SafeNativeMethods.d_matrix_norm((byte) norm, rows, columns, matrix, work); } /// @@ -230,9 +230,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } var work = new float[rows]; @@ -269,9 +269,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } if (work.Length < rows) @@ -279,7 +279,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work"); } - return SafeNativeMethods.c_matrix_norm((byte)norm, rows, columns, matrix, work); + return SafeNativeMethods.c_matrix_norm((byte) norm, rows, columns, matrix, work); } /// @@ -310,9 +310,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } var work = new double[rows]; @@ -349,9 +349,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } if (work.Length < rows) @@ -359,7 +359,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work"); } - return SafeNativeMethods.z_matrix_norm((byte)norm, rows, columns, matrix, work); + return SafeNativeMethods.z_matrix_norm((byte) norm, rows, columns, matrix, work); } } } diff --git a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Complex.cs index 429672b5..efa55565 100644 --- a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Complex.cs +++ b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Complex.cs @@ -31,14 +31,13 @@ #if NATIVEGOTO using MathNet.Numerics.LinearAlgebra.Factorization; +using MathNet.Numerics.Properties; +using System; +using System.Numerics; +using System.Security; namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { - using System; - using System.Numerics; - using System.Security; - using Properties; - /// /// GotoBLAS2 linear algebra provider. /// @@ -96,8 +95,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (x == null) { throw new ArgumentNullException("x"); - } - + } + if (!ReferenceEquals(x, result)) { Array.Copy(x, 0, result, 0, x.Length); @@ -165,9 +164,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB; - if (c.Length != m * n) + if (c.Length != m*n) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw new ArgumentException(Resources.ArgumentMatrixDimensions); } if (k != l) @@ -200,7 +199,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -209,7 +208,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - + SafeNativeMethods.z_lu_factor(order, data, ipiv); } @@ -227,13 +226,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } var work = new Complex[order]; - SafeNativeMethods.z_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.z_lu_inverse(order, a, work, work.Length); } /// @@ -256,7 +255,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -267,7 +266,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas } var work = new Complex[order]; - SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -287,7 +286,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -302,7 +301,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.z_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.z_lu_inverse(order, a, work, work.Length); } /// @@ -328,7 +327,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -348,7 +347,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -367,22 +366,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - + if (ReferenceEquals(a, b)) { throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.z_lu_solve(order, columnsOfB, a, b); + SafeNativeMethods.z_lu_solve(order, columnsOfB, a, b); } /// @@ -407,7 +406,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -417,7 +416,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -427,7 +426,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.z_lu_solve_factored(order, columnsOfB, a, ipiv, b); + SafeNativeMethods.z_lu_solve_factored(order, columnsOfB, a, ipiv, b); } /// @@ -450,7 +449,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "order"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -485,7 +484,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -495,7 +494,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.z_cholesky_solve(orderA, columnsB, a, b); + SafeNativeMethods.z_cholesky_solve(orderA, columnsB, a, b); } /// @@ -519,7 +518,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -529,7 +528,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.z_cholesky_solve_factored(orderA, columnsB, a, b); + SafeNativeMethods.z_cholesky_solve_factored(orderA, columnsB, a, b); } /// @@ -545,7 +544,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// to be used by the QR solve routine. /// This is similar to the GEQRF and ORGQR LAPACK routines. [SecuritySafeCritical] - public override void QRFactor(Complex[] r, int rowsR, int columnsR, Complex[] q, Complex[] tau, QRMethod method = QRMethod.Full) + public override void QRFactor(Complex[] r, int rowsR, int columnsR, Complex[] q, Complex[] tau) { if (r == null) { @@ -557,7 +556,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -567,12 +566,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = new Complex[columnsR * Control.BlockSize]; + var work = new Complex[columnsR*Control.BlockSize]; SafeNativeMethods.z_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length); } @@ -609,7 +608,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -619,14 +618,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - if (work.Length < columnsR * Control.BlockSize) + if (work.Length < columnsR*Control.BlockSize) { - work[0] = columnsR * Control.BlockSize; + work[0] = columnsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -643,7 +642,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// The number of columns of B. /// On exit, the solution matrix. /// Rows must be greater or equal to columns. - public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x) + public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x, QRMethod method = QRMethod.Full) { if (a == null) { @@ -660,17 +659,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("x"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -680,7 +679,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.RowsLessThanColumns); } - var work = new Complex[columns * Control.BlockSize]; + var work = new Complex[columns*Control.BlockSize]; QRSolve(a, rows, columns, b, columnsB, x, work); } @@ -697,7 +696,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x, Complex[] work) + public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x, Complex[] work, QRMethod method = QRMethod.Full) { if (a == null) { @@ -719,17 +718,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -741,7 +740,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (work.Length < 1) { - work[0] = rows * Control.BlockSize; + work[0] = rows*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -762,7 +761,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// On exit, the solution matrix. /// Rows must be greater or equal to columns. [SecuritySafeCritical] - public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x) + public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x, QRMethod method = QRMethod.Full) { if (r == null) { @@ -784,22 +783,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -808,8 +807,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { throw new ArgumentException(Resources.RowsLessThanColumns); } - - var work = new Complex[columnsR * Control.BlockSize]; + + var work = new Complex[columnsR*Control.BlockSize]; QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work); } @@ -830,7 +829,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x, Complex[] work) + public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x, Complex[] work, QRMethod method = QRMethod.Full) { if (r == null) { @@ -857,22 +856,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -884,7 +883,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (work.Length < 1) { - work[0] = rowsR * Control.BlockSize; + work[0] = rowsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -927,12 +926,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -942,7 +941,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - var work = new Complex[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work); } @@ -972,20 +971,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - var work = new Complex[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; var s = new Complex[Math.Min(rowsA, columnsA)]; - var u = new Complex[rowsA * rowsA]; - var vt = new Complex[columnsA * columnsA]; + var u = new Complex[rowsA*rowsA]; + var vt = new Complex[columnsA*columnsA]; var clone = new Complex[a.Length]; a.Copy(clone); @@ -1037,12 +1036,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -1057,9 +1056,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "work"); } - if (work.Length < (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) + if (work.Length < (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) { - work[0] = (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); + work[0] = (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } diff --git a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Complex32.cs index c9deb438..e5de77d7 100644 --- a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Complex32.cs +++ b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.Complex32.cs @@ -31,13 +31,12 @@ #if NATIVEGOTO using MathNet.Numerics.LinearAlgebra.Factorization; +using MathNet.Numerics.Properties; +using System; +using System.Security; namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { - using System; - using System.Security; - using Properties; - /// /// GotoBLAS2 linear algebra provider. /// @@ -95,8 +94,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (x == null) { throw new ArgumentNullException("x"); - } - + } + if (!ReferenceEquals(x, result)) { Array.Copy(x, 0, result, 0, x.Length); @@ -164,9 +163,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB; - if (c.Length != m * n) + if (c.Length != m*n) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw new ArgumentException(Resources.ArgumentMatrixDimensions); } if (k != l) @@ -199,7 +198,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -208,7 +207,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - + SafeNativeMethods.c_lu_factor(order, data, ipiv); } @@ -226,13 +225,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } var work = new Complex32[order]; - SafeNativeMethods.c_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.c_lu_inverse(order, a, work, work.Length); } /// @@ -255,7 +254,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -266,7 +265,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas } var work = new Complex32[order]; - SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -286,7 +285,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -301,7 +300,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.c_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.c_lu_inverse(order, a, work, work.Length); } /// @@ -327,7 +326,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -347,7 +346,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -366,22 +365,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - + if (ReferenceEquals(a, b)) { throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.c_lu_solve(order, columnsOfB, a, b); + SafeNativeMethods.c_lu_solve(order, columnsOfB, a, b); } /// @@ -406,7 +405,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -416,7 +415,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -426,7 +425,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.c_lu_solve_factored(order, columnsOfB, a, ipiv, b); + SafeNativeMethods.c_lu_solve_factored(order, columnsOfB, a, ipiv, b); } /// @@ -449,7 +448,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "order"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -484,7 +483,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -494,7 +493,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.c_cholesky_solve(orderA, columnsB, a, b); + SafeNativeMethods.c_cholesky_solve(orderA, columnsB, a, b); } /// @@ -518,7 +517,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -528,7 +527,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.c_cholesky_solve_factored(orderA, columnsB, a, b); + SafeNativeMethods.c_cholesky_solve_factored(orderA, columnsB, a, b); } /// @@ -544,7 +543,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// to be used by the QR solve routine. /// This is similar to the GEQRF and ORGQR LAPACK routines. [SecuritySafeCritical] - public override void QRFactor(Complex32[] r, int rowsR, int columnsR, Complex32[] q, Complex32[] tau, QRMethod method = QRMethod.Full) + public override void QRFactor(Complex32[] r, int rowsR, int columnsR, Complex32[] q, Complex32[] tau) { if (r == null) { @@ -556,7 +555,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -566,12 +565,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = new Complex32[columnsR * Control.BlockSize]; + var work = new Complex32[columnsR*Control.BlockSize]; SafeNativeMethods.c_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length); } @@ -608,7 +607,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -618,14 +617,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - if (work.Length < columnsR * Control.BlockSize) + if (work.Length < columnsR*Control.BlockSize) { - work[0] = columnsR * Control.BlockSize; + work[0] = columnsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -642,7 +641,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// The number of columns of B. /// On exit, the solution matrix. /// Rows must be greater or equal to columns. - public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x) + public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x, QRMethod method = QRMethod.Full) { if (a == null) { @@ -659,17 +658,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("x"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -679,7 +678,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.RowsLessThanColumns); } - var work = new Complex32[columns * Control.BlockSize]; + var work = new Complex32[columns*Control.BlockSize]; QRSolve(a, rows, columns, b, columnsB, x, work); } @@ -696,7 +695,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work) + public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work, QRMethod method = QRMethod.Full) { if (a == null) { @@ -718,17 +717,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -740,7 +739,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (work.Length < 1) { - work[0] = rows * Control.BlockSize; + work[0] = rows*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -761,7 +760,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// On exit, the solution matrix. /// Rows must be greater or equal to columns. [SecuritySafeCritical] - public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x) + public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x, QRMethod method = QRMethod.Full) { if (r == null) { @@ -783,22 +782,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -807,8 +806,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { throw new ArgumentException(Resources.RowsLessThanColumns); } - - var work = new Complex32[columnsR * Control.BlockSize]; + + var work = new Complex32[columnsR*Control.BlockSize]; QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work); } @@ -829,7 +828,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work) + public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work, QRMethod method = QRMethod.Full) { if (r == null) { @@ -856,22 +855,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -883,7 +882,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (work.Length < 1) { - work[0] = rowsR * Control.BlockSize; + work[0] = rowsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -926,12 +925,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -941,7 +940,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - var work = new Complex32[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex32[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work); } @@ -971,20 +970,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - var work = new Complex32[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex32[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; var s = new Complex32[Math.Min(rowsA, columnsA)]; - var u = new Complex32[rowsA * rowsA]; - var vt = new Complex32[columnsA * columnsA]; + var u = new Complex32[rowsA*rowsA]; + var vt = new Complex32[columnsA*columnsA]; var clone = new Complex32[a.Length]; a.Copy(clone); @@ -1036,12 +1035,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -1056,9 +1055,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "work"); } - if (work.Length < (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) + if (work.Length < (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) { - work[0] = (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); + work[0] = (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } diff --git a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.double.cs b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.double.cs index b57583df..b3d2cf45 100644 --- a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.double.cs +++ b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.double.cs @@ -31,13 +31,12 @@ #if NATIVEGOTO using MathNet.Numerics.LinearAlgebra.Factorization; +using MathNet.Numerics.Properties; +using System; +using System.Security; namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { - using System; - using System.Security; - using Properties; - /// /// GotoBLAS2 linear algebra provider. /// @@ -95,8 +94,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (x == null) { throw new ArgumentNullException("x"); - } - + } + if (!ReferenceEquals(x, result)) { Array.Copy(x, 0, result, 0, x.Length); @@ -164,9 +163,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB; - if (c.Length != m * n) + if (c.Length != m*n) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw new ArgumentException(Resources.ArgumentMatrixDimensions); } if (k != l) @@ -199,7 +198,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -208,7 +207,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - + SafeNativeMethods.d_lu_factor(order, data, ipiv); } @@ -226,13 +225,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } var work = new double[order]; - SafeNativeMethods.d_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.d_lu_inverse(order, a, work, work.Length); } /// @@ -255,7 +254,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -266,7 +265,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas } var work = new double[order]; - SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -286,7 +285,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -301,7 +300,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.d_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.d_lu_inverse(order, a, work, work.Length); } /// @@ -327,7 +326,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -347,7 +346,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -366,22 +365,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - + if (ReferenceEquals(a, b)) { throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.d_lu_solve(order, columnsOfB, a, b); + SafeNativeMethods.d_lu_solve(order, columnsOfB, a, b); } /// @@ -406,7 +405,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -416,7 +415,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -426,7 +425,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.d_lu_solve_factored(order, columnsOfB, a, ipiv, b); + SafeNativeMethods.d_lu_solve_factored(order, columnsOfB, a, ipiv, b); } /// @@ -449,7 +448,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "order"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -484,7 +483,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -494,7 +493,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.d_cholesky_solve(orderA, columnsB, a, b); + SafeNativeMethods.d_cholesky_solve(orderA, columnsB, a, b); } /// @@ -518,7 +517,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -528,7 +527,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.d_cholesky_solve_factored(orderA, columnsB, a, b); + SafeNativeMethods.d_cholesky_solve_factored(orderA, columnsB, a, b); } /// @@ -544,7 +543,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// to be used by the QR solve routine. /// This is similar to the GEQRF and ORGQR LAPACK routines. [SecuritySafeCritical] - public override void QRFactor(double[] r, int rowsR, int columnsR, double[] q, double[] tau, QRMethod method = QRMethod.Full) + public override void QRFactor(double[] r, int rowsR, int columnsR, double[] q, double[] tau) { if (r == null) { @@ -556,7 +555,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -566,12 +565,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = new double[columnsR * Control.BlockSize]; + var work = new double[columnsR*Control.BlockSize]; SafeNativeMethods.d_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length); } @@ -608,7 +607,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -618,14 +617,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - if (work.Length < columnsR * Control.BlockSize) + if (work.Length < columnsR*Control.BlockSize) { - work[0] = columnsR * Control.BlockSize; + work[0] = columnsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -642,7 +641,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// The number of columns of B. /// On exit, the solution matrix. /// Rows must be greater or equal to columns. - public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x) + public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x, QRMethod method = QRMethod.Full) { if (a == null) { @@ -659,17 +658,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("x"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -679,7 +678,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.RowsLessThanColumns); } - var work = new double[columns * Control.BlockSize]; + var work = new double[columns*Control.BlockSize]; QRSolve(a, rows, columns, b, columnsB, x, work); } @@ -696,7 +695,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x, double[] work) + public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x, double[] work, QRMethod method = QRMethod.Full) { if (a == null) { @@ -718,17 +717,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -740,7 +739,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (work.Length < 1) { - work[0] = rows * Control.BlockSize; + work[0] = rows*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -761,7 +760,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// On exit, the solution matrix. /// Rows must be greater or equal to columns. [SecuritySafeCritical] - public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x) + public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x, QRMethod method = QRMethod.Full) { if (r == null) { @@ -783,22 +782,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -807,8 +806,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { throw new ArgumentException(Resources.RowsLessThanColumns); } - - var work = new double[columnsR * Control.BlockSize]; + + var work = new double[columnsR*Control.BlockSize]; QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work); } @@ -829,7 +828,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x, double[] work) + public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x, double[] work, QRMethod method = QRMethod.Full) { if (r == null) { @@ -856,22 +855,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -883,7 +882,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (work.Length < 1) { - work[0] = rowsR * Control.BlockSize; + work[0] = rowsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -926,12 +925,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -941,7 +940,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - var work = new double[Math.Max((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5 * Math.Min(rowsA, columnsA))]; + var work = new double[Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA))]; SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work); } @@ -971,20 +970,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - var work = new double[Math.Max((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5 * Math.Min(rowsA, columnsA))]; + var work = new double[Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA))]; var s = new double[Math.Min(rowsA, columnsA)]; - var u = new double[rowsA * rowsA]; - var vt = new double[columnsA * columnsA]; + var u = new double[rowsA*rowsA]; + var vt = new double[columnsA*columnsA]; var clone = new double[a.Length]; a.Copy(clone); @@ -1036,12 +1035,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -1056,9 +1055,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "work"); } - if (work.Length < Math.Max((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5 * Math.Min(rowsA, columnsA))) + if (work.Length < Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA))) { - work[0] = Math.Max((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5 * Math.Min(rowsA, columnsA)); + work[0] = Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA)); throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } diff --git a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.float.cs b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.float.cs index 8f9038e6..5df844ba 100644 --- a/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.float.cs +++ b/src/Numerics/Providers/LinearAlgebra/GotoBlas/GotoBlasLinearAlgebraProvider.float.cs @@ -31,13 +31,12 @@ #if NATIVEGOTO using MathNet.Numerics.LinearAlgebra.Factorization; +using MathNet.Numerics.Properties; +using System; +using System.Security; namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { - using System; - using System.Security; - using Properties; - /// /// GotoBLAS2 linear algebra provider. /// @@ -95,8 +94,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (x == null) { throw new ArgumentNullException("x"); - } - + } + if (!ReferenceEquals(x, result)) { Array.Copy(x, 0, result, 0, x.Length); @@ -164,9 +163,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB; - if (c.Length != m * n) + if (c.Length != m*n) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw new ArgumentException(Resources.ArgumentMatrixDimensions); } if (k != l) @@ -199,7 +198,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -208,7 +207,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - + SafeNativeMethods.s_lu_factor(order, data, ipiv); } @@ -226,13 +225,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } var work = new float[order]; - SafeNativeMethods.s_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.s_lu_inverse(order, a, work, work.Length); } /// @@ -255,7 +254,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -286,7 +285,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -301,7 +300,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.s_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.s_lu_inverse(order, a, work, work.Length); } /// @@ -327,7 +326,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -366,22 +365,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - + if (ReferenceEquals(a, b)) { throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.s_lu_solve(order, columnsOfB, a, b); + SafeNativeMethods.s_lu_solve(order, columnsOfB, a, b); } /// @@ -406,7 +405,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -416,7 +415,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -426,7 +425,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.s_lu_solve_factored(order, columnsOfB, a, ipiv, b); + SafeNativeMethods.s_lu_solve_factored(order, columnsOfB, a, ipiv, b); } /// @@ -449,7 +448,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentMustBePositive, "order"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -484,7 +483,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -494,7 +493,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.s_cholesky_solve(orderA, columnsB, a, b); + SafeNativeMethods.s_cholesky_solve(orderA, columnsB, a, b); } /// @@ -518,7 +517,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -528,7 +527,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.s_cholesky_solve_factored(orderA, columnsB, a, b); + SafeNativeMethods.s_cholesky_solve_factored(orderA, columnsB, a, b); } /// @@ -544,7 +543,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// to be used by the QR solve routine. /// This is similar to the GEQRF and ORGQR LAPACK routines. [SecuritySafeCritical] - public override void QRFactor(float[] r, int rowsR, int columnsR, float[] q, float[] tau, QRMethod method = QRMethod.Full) + public override void QRFactor(float[] r, int rowsR, int columnsR, float[] q, float[] tau) { if (r == null) { @@ -556,7 +555,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -566,12 +565,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = new float[columnsR * Control.BlockSize]; + var work = new float[columnsR*Control.BlockSize]; SafeNativeMethods.s_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length); } @@ -608,7 +607,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -618,14 +617,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - if (work.Length < columnsR * Control.BlockSize) + if (work.Length < columnsR*Control.BlockSize) { - work[0] = columnsR * Control.BlockSize; + work[0] = columnsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -642,7 +641,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// The number of columns of B. /// On exit, the solution matrix. /// Rows must be greater or equal to columns. - public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x) + public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x, QRMethod method = QRMethod.Full) { if (a == null) { @@ -659,17 +658,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("x"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -679,7 +678,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.RowsLessThanColumns); } - var work = new float[columns * Control.BlockSize]; + var work = new float[columns*Control.BlockSize]; QRSolve(a, rows, columns, b, columnsB, x, work); } @@ -696,7 +695,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x, float[] work) + public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x, float[] work, QRMethod method = QRMethod.Full) { if (a == null) { @@ -718,17 +717,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -740,7 +739,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (work.Length < 1) { - work[0] = rows * Control.BlockSize; + work[0] = rows*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -761,7 +760,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// On exit, the solution matrix. /// Rows must be greater or equal to columns. [SecuritySafeCritical] - public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x) + public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x, QRMethod method = QRMethod.Full) { if (r == null) { @@ -783,22 +782,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -807,8 +806,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas { throw new ArgumentException(Resources.RowsLessThanColumns); } - - var work = new float[columnsR * Control.BlockSize]; + + var work = new float[columnsR*Control.BlockSize]; QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work); } @@ -829,7 +828,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. /// Rows must be greater or equal to columns. - public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x, float[] work) + public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x, float[] work, QRMethod method = QRMethod.Full) { if (r == null) { @@ -856,22 +855,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "r"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "q"); } - if (b.Length != rowsR * columnsB) + if (b.Length != rowsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsR * columnsB) + if (x.Length != columnsR*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -883,7 +882,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas if (work.Length < 1) { - work[0] = rowsR * Control.BlockSize; + work[0] = rowsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -926,12 +925,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -941,7 +940,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - var work = new float[Math.Max(((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5 * Math.Min(rowsA, columnsA))]; + var work = new float[Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA))]; SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work); } @@ -971,20 +970,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - var work = new float[Math.Max(((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5 * Math.Min(rowsA, columnsA))]; + var work = new float[Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA))]; var s = new float[Math.Min(rowsA, columnsA)]; - var u = new float[rowsA * rowsA]; - var vt = new float[columnsA * columnsA]; + var u = new float[rowsA*rowsA]; + var vt = new float[columnsA*columnsA]; var clone = new float[a.Length]; a.Copy(clone); @@ -1036,12 +1035,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -1056,9 +1055,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "work"); } - if (work.Length < Math.Max(((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5 * Math.Min(rowsA, columnsA))) + if (work.Length < Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA))) { - work[0] = Math.Max(((3 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5 * Math.Min(rowsA, columnsA)); + work[0] = Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA)); throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } diff --git a/src/Numerics/Providers/LinearAlgebra/GotoBlas/SafeNativeMethods.cs b/src/Numerics/Providers/LinearAlgebra/GotoBlas/SafeNativeMethods.cs index 9426f5b7..6ed47e53 100644 --- a/src/Numerics/Providers/LinearAlgebra/GotoBlas/SafeNativeMethods.cs +++ b/src/Numerics/Providers/LinearAlgebra/GotoBlas/SafeNativeMethods.cs @@ -44,10 +44,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas /// /// Name of the native DLL. /// - private const string DllName = "MathNET.Numerics.GotoBLAS2.dll"; + const string DllName = "MathNET.Numerics.GotoBLAS2.dll"; + + #region BLAS -#region BLAS - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void s_axpy(int n, float alpha, float[] x, [In, Out] float[] y); @@ -59,7 +59,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_axpy(int n, Complex alpha, Complex[] x, [In, Out] Complex[] y); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void s_scale(int n, float alpha, [Out] float[] x); @@ -71,7 +71,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_scale(int n, Complex alpha, [In, Out] Complex[] x); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern float s_dot_product(int n, float[] x, float[] y); @@ -83,22 +83,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void s_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, float alpha, float[] x, float[] y, float beta, [In, Out]float[] c); - + internal static extern void s_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, float alpha, float[] x, float[] y, float beta, [In, Out] float[] c); + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void d_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, double alpha, double[] x, double[] y, double beta, [In, Out]double[] c); + internal static extern void d_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, double alpha, double[] x, double[] y, double beta, [In, Out] double[] c); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void c_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex32 alpha, Complex32[] x, Complex32[] y, Complex32 beta, [In, Out]Complex32[] c); + internal static extern void c_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex32 alpha, Complex32[] x, Complex32[] y, Complex32 beta, [In, Out] Complex32[] c); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void z_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex alpha, Complex[] x, Complex[] y, Complex beta, [In, Out]Complex[] c); + internal static extern void z_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex alpha, Complex[] x, Complex[] y, Complex beta, [In, Out] Complex[] c); -#endregion BLAS - -#region LAPACK + #endregion BLAS + + #region LAPACK [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern float s_matrix_norm(byte norm, int rows, int columns, [In] float[] a, [In, Out] float[] work); @@ -123,7 +123,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int z_cholesky_factor(int n, [In, Out] Complex[] a); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int s_lu_factor(int n, [In, Out] float[] a, [In, Out] int[] ipiv); @@ -153,15 +153,15 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int d_lu_inverse_factored(int n, [In, Out] double[] a, [In, Out] int[] ipiv, [In, Out] double[] work, int lwork); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int c_lu_inverse_factored(int n, [In, Out] Complex32[] a, [In, Out] int[] ipiv, [In, Out] Complex32[] work, int lwork); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int z_lu_inverse_factored(int n, [In, Out] Complex[] a, [In, Out] int[] ipiv, [In, Out] Complex[] work, int lwork); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int s_lu_solve_factored(int n, int nrhs, float[] a, [In, Out]int[] ipiv, [In, Out] float[] b); + internal static extern int s_lu_solve_factored(int n, int nrhs, float[] a, [In, Out] int[] ipiv, [In, Out] float[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int d_lu_solve_factored(int n, int nrhs, double[] a, [In, Out] int[] ipiv, [In, Out] double[] b); @@ -170,7 +170,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas internal static extern int c_lu_solve_factored(int n, int nrhs, Complex32[] a, [In, Out] int[] ipiv, [In, Out] Complex32[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int z_lu_solve_factored(int n, int nrhs, Complex[] a, [In, Out]int[] ipiv, [In, Out] Complex[] b); + internal static extern int z_lu_solve_factored(int n, int nrhs, Complex[] a, [In, Out] int[] ipiv, [In, Out] Complex[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int s_lu_solve(int n, int nrhs, float[] a, [In, Out] float[] b); @@ -182,7 +182,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas internal static extern int c_lu_solve(int n, int nrhs, Complex32[] a, [In, Out] Complex32[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int z_lu_solve(int n, int nrhs, Complex[] a, [In, Out] Complex[] b); + internal static extern int z_lu_solve(int n, int nrhs, Complex[] a, [In, Out] Complex[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int s_cholesky_solve(int n, int nrhs, float[] a, [In, Out] float[] b); @@ -256,7 +256,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.GotoBlas [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int z_svd_factor(bool computeVectors, int m, int n, [In, Out] Complex[] a, [In, Out] Complex[] s, [In, Out] Complex[] u, [In, Out] Complex[] v, [In, Out] Complex[] work, int len); -#endregion LAPACK + #endregion LAPACK } } diff --git a/src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs b/src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs index cafb0070..a087911a 100644 --- a/src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs +++ b/src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs @@ -28,17 +28,518 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using MathNet.Numerics.LinearAlgebra.Factorization; + namespace MathNet.Numerics.Providers.LinearAlgebra { #if !NOSYSNUMERICS using Complex = System.Numerics.Complex; + #endif + /// + /// How to transpose a matrix. + /// + public enum Transpose + { + /// + /// Don't transpose a matrix. + /// + DontTranspose = 111, + + /// + /// Transpose a matrix. + /// + Transpose = 112, + + /// + /// Conjugate transpose a complex matrix. + /// + /// If a conjugate transpose is used with a real matrix, then the matrix is just transposed. + ConjugateTranspose = 113 + } + + /// + /// Types of matrix norms. + /// + public enum Norm : byte + { + /// + /// The 1-norm. + /// + OneNorm = (byte) '1', + + /// + /// The Frobenius norm. + /// + FrobeniusNorm = (byte) 'f', + + /// + /// The infinity norm. + /// + InfinityNorm = (byte) 'i', + + /// + /// The largest absolute value norm. + /// + LargestAbsoluteValue = (byte) 'm' + } + + /// + /// Interface to linear algebra algorithms that work off 1-D arrays. + /// + public interface ILinearAlgebraProvider : + ILinearAlgebraProvider, + ILinearAlgebraProvider, + ILinearAlgebraProvider, + ILinearAlgebraProvider + { + } + /// /// Interface to linear algebra algorithms that work off 1-D arrays. /// - public interface ILinearAlgebraProvider : ILinearAlgebraProvider, ILinearAlgebraProvider, ILinearAlgebraProvider, ILinearAlgebraProvider + /// Supported data types are double, single, Complex, and Complex32. + public interface ILinearAlgebraProvider + where T : struct + where TNorm : struct { + /*/// + /// Queries the provider for the optimal, workspace block size + /// for the given routine. + /// + /// Name of the method to query. + /// -1 if the provider cannot compute the workspace size; otherwise + /// the suggested block size. + int QueryWorkspaceBlockSize(string methodName);*/ + + /// + /// Adds a scaled vector to another: result = y + alpha*x. + /// + /// The vector to update. + /// The value to scale by. + /// The vector to add to . + /// The result of the addition. + /// This is similar to the AXPY BLAS routine. + void AddVectorToScaledVector(T[] y, T alpha, T[] x, T[] result); + + /// + /// Scales an array. Can be used to scale a vector and a matrix. + /// + /// The scalar. + /// The values to scale. + /// This result of the scaling. + /// This is similar to the SCAL BLAS routine. + void ScaleArray(T alpha, T[] x, T[] result); + + /// + /// Computes the dot product of x and y. + /// + /// The vector x. + /// The vector y. + /// The dot product of x and y. + /// This is equivalent to the DOT BLAS routine. + T DotProduct(T[] x, T[] y); + + /// + /// Does a point wise add of two arrays z = x + y. This can be used + /// to add vectors or matrices. + /// + /// The array x. + /// The array y. + /// The result of the addition. + /// There is no equivalent BLAS routine, but many libraries + /// provide optimized (parallel and/or vectorized) versions of this + /// routine. + void AddArrays(T[] x, T[] y, T[] result); + + /// + /// Does a point wise subtraction of two arrays z = x - y. This can be used + /// to subtract vectors or matrices. + /// + /// The array x. + /// The array y. + /// The result of the subtraction. + /// There is no equivalent BLAS routine, but many libraries + /// provide optimized (parallel and/or vectorized) versions of this + /// routine. + void SubtractArrays(T[] x, T[] y, T[] result); + + /// + /// Does a point wise multiplication of two arrays z = x * y. This can be used + /// to multiply elements of vectors or matrices. + /// + /// The array x. + /// The array y. + /// The result of the point wise multiplication. + /// There is no equivalent BLAS routine, but many libraries + /// provide optimized (parallel and/or vectorized) versions of this + /// routine. + void PointWiseMultiplyArrays(T[] x, T[] y, T[] result); + + /// + /// Does a point wise division of two arrays z = x / y. This can be used + /// to divide elements of vectors or matrices. + /// + /// The array x. + /// The array y. + /// The result of the point wise division. + /// There is no equivalent BLAS routine, but many libraries + /// provide optimized (parallel and/or vectorized) versions of this + /// routine. + void PointWiseDivideArrays(T[] x, T[] y, T[] result); + + /// + /// Computes the requested of the matrix. + /// + /// The type of norm to compute. + /// The number of rows. + /// The number of columns. + /// The matrix to compute the norm from. + /// + /// The requested of the matrix. + /// + T MatrixNorm(Norm norm, int rows, int columns, T[] matrix); + + /// + /// Computes the requested of the matrix. + /// + /// The type of norm to compute. + /// The number of rows. + /// The number of columns. + /// The matrix to compute the norm from. + /// The work array. Only used when + /// and needs to be have a length of at least M (number of rows of . + /// + /// The requested of the matrix. + /// + T MatrixNorm(Norm norm, int rows, int columns, T[] matrix, TNorm[] work); + + /// + /// Multiples two matrices. result = x * y + /// + /// The x matrix. + /// The number of rows in the x matrix. + /// The number of columns in the x matrix. + /// The y matrix. + /// The number of rows in the y matrix. + /// The number of columns in the y matrix. + /// Where to store the result of the multiplication. + /// This is a simplified version of the BLAS GEMM routine with alpha + /// set to 1.0 and beta set to 0.0, and x and y are not transposed. + void MatrixMultiply(T[] x, int rowsX, int columnsX, T[] y, int rowsY, int columnsY, T[] result); + + /// + /// Multiplies two matrices and updates another with the result. c = alpha*op(a)*op(b) + beta*c + /// + /// How to transpose the matrix. + /// How to transpose the matrix. + /// The value to scale matrix. + /// The a matrix. + /// The number of rows in the matrix. + /// The number of columns in the matrix. + /// The b matrix + /// The number of rows in the matrix. + /// The number of columns in the matrix. + /// The value to scale the matrix. + /// The c matrix. + void MatrixMultiplyWithUpdate(Transpose transposeA, Transpose transposeB, T alpha, T[] a, int rowsA, int columnsA, T[] b, int rowsB, int columnsB, T beta, T[] c); + + /// + /// Computes the LUP factorization of A. P*A = L*U. + /// + /// An by matrix. The matrix is overwritten with the + /// the LU factorization on exit. The lower triangular factor L is stored in under the diagonal of (the diagonal is always 1.0 + /// for the L factor). The upper triangular factor U is stored on and above the diagonal of . + /// The order of the square matrix . + /// On exit, it contains the pivot indices. The size of the array must be . + /// This is equivalent to the GETRF LAPACK routine. + void LUFactor(T[] data, int order, int[] ipiv); + + /// + /// Computes the inverse of matrix using LU factorization. + /// + /// The N by N matrix to invert. Contains the inverse On exit. + /// The order of the square matrix . + /// This is equivalent to the GETRF and GETRI LAPACK routines. + void LUInverse(T[] a, int order); + + /// + /// Computes the inverse of a previously factored matrix. + /// + /// The LU factored N by N matrix. Contains the inverse On exit. + /// The order of the square matrix . + /// The pivot indices of . + /// This is equivalent to the GETRI LAPACK routine. + void LUInverseFactored(T[] a, int order, int[] ipiv); + + /// + /// Computes the inverse of matrix using LU factorization. + /// + /// The N by N matrix to invert. Contains the inverse On exit. + /// The order of the square matrix . + /// The work array. The array must have a length of at least N, + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal + /// work size value. + /// This is equivalent to the GETRF and GETRI LAPACK routines. + void LUInverse(T[] a, int order, T[] work); + + /// + /// Computes the inverse of a previously factored matrix. + /// + /// The LU factored N by N matrix. Contains the inverse On exit. + /// The order of the square matrix . + /// The pivot indices of . + /// The work array. The array must have a length of at least N, + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal + /// work size value. + /// This is equivalent to the GETRI LAPACK routine. + void LUInverseFactored(T[] a, int order, int[] ipiv, T[] work); + + /// + /// Solves A*X=B for X using LU factorization. + /// + /// The number of columns of B. + /// The square matrix A. + /// The order of the square matrix . + /// On entry the B matrix; on exit the X matrix. + /// This is equivalent to the GETRF and GETRS LAPACK routines. + void LUSolve(int columnsOfB, T[] a, int order, T[] b); + + /// + /// Solves A*X=B for X using a previously factored A matrix. + /// + /// The number of columns of B. + /// The factored A matrix. + /// The order of the square matrix . + /// The pivot indices of . + /// On entry the B matrix; on exit the X matrix. + /// This is equivalent to the GETRS LAPACK routine. + void LUSolveFactored(int columnsOfB, T[] a, int order, int[] ipiv, T[] b); + + /// + /// Computes the Cholesky factorization of A. + /// + /// On entry, a square, positive definite matrix. On exit, the matrix is overwritten with the + /// the Cholesky factorization. + /// The number of rows or columns in the matrix. + /// This is equivalent to the POTRF LAPACK routine. + void CholeskyFactor(T[] a, int order); + + /// + /// Solves A*X=B for X using Cholesky factorization. + /// + /// The square, positive definite matrix A. + /// The number of rows and columns in A. + /// On entry the B matrix; on exit the X matrix. + /// The number of columns in the B matrix. + /// This is equivalent to the POTRF add POTRS LAPACK routines. + void CholeskySolve(T[] a, int orderA, T[] b, int columnsB); + + /// + /// Solves A*X=B for X using a previously factored A matrix. + /// + /// The square, positive definite matrix A. + /// The number of rows and columns in A. + /// On entry the B matrix; on exit the X matrix. + /// The number of columns in the B matrix. + /// This is equivalent to the POTRS LAPACK routine. + void CholeskySolveFactored(T[] a, int orderA, T[] b, int columnsB); + + /// + /// Computes the full QR factorization of A. + /// + /// On entry, it is the M by N A matrix to factor. On exit, + /// it is overwritten with the R matrix of the QR factorization. + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// On exit, A M by M matrix that holds the Q matrix of the + /// QR factorization. + /// A min(m,n) vector. On exit, contains additional information + /// to be used by the QR solve routine. + /// This is similar to the GEQRF and ORGQR LAPACK routines. + void QRFactor(T[] a, int rowsA, int columnsA, T[] q, T[] tau); + + /// + /// Computes the full QR factorization of A. + /// + /// On entry, it is the M by N A matrix to factor. On exit, + /// it is overwritten with the R matrix of the QR factorization. + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// On exit, A M by M matrix that holds the Q matrix of the + /// QR factorization. + /// A min(m,n) vector. On exit, contains additional information + /// to be used by the QR solve routine. + /// The work array. The array must have a length of at least N, + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal + /// work size value. + /// This is similar to the GEQRF and ORGQR LAPACK routines. + void QRFactor(T[] a, int rowsA, int columnsA, T[] q, T[] tau, T[] work); + + /// + /// Computes the thin QR factorization of A where M > N. + /// + /// On entry, it is the M by N A matrix to factor. On exit, + /// it is overwritten with the Q matrix of the QR factorization. + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// On exit, A N by N matrix that holds the R matrix of the + /// QR factorization. + /// A min(m,n) vector. On exit, contains additional information + /// to be used by the QR solve routine. + /// This is similar to the GEQRF and ORGQR LAPACK routines. + void ThinQRFactor(T[] a, int rowsA, int columnsA, T[] r, T[] tau); + + /// + /// Computes the thin QR factorization of A where M > N. + /// + /// On entry, it is the M by N A matrix to factor. On exit, + /// it is overwritten with the Q matrix of the QR factorization. + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// On exit, A N by N matrix that holds the R matrix of the + /// QR factorization. + /// A min(m,n) vector. On exit, contains additional information + /// to be used by the QR solve routine. + /// The work array. The array must have a length of at least N, + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal + /// work size value. + /// This is similar to the GEQRF and ORGQR LAPACK routines. + void ThinQRFactor(T[] a, int rowsA, int columnsA, T[] r, T[] tau, T[] work); + + /// + /// Solves A*X=B for X using QR factorization of A. + /// + /// The A matrix. + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// The B matrix. + /// The number of columns of B. + /// On exit, the solution matrix. + /// The type of QR factorization to perform. + /// Rows must be greater or equal to columns. + void QRSolve(T[] a, int rows, int columns, T[] b, int columnsB, T[] x, QRMethod method = QRMethod.Full); + + /// + /// Solves A*X=B for X using QR factorization of A. + /// + /// The A matrix. + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// On entry the B matrix; on exit the X matrix. + /// The number of columns of B. + /// On exit, the solution matrix. + /// The work array. The array must have a length of at least N, + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal + /// work size value. + /// The type of QR factorization to perform. + /// Rows must be greater or equal to columns. + void QRSolve(T[] a, int rows, int columns, T[] b, int columnsB, T[] x, T[] work, QRMethod method = QRMethod.Full); + + /// + /// Solves A*X=B for X using a previously QR factored matrix. + /// + /// The Q matrix obtained by QR factor. This is only used for the managed provider and can be + /// null for the native provider. The native provider uses the Q portion stored in the R matrix. + /// The R matrix obtained by calling . + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// Contains additional information on Q. Only used for the native solver + /// and can be null for the managed provider. + /// On entry the B matrix; on exit the X matrix. + /// The number of columns of B. + /// On exit, the solution matrix. + /// Rows must be greater or equal to columns. + /// The type of QR factorization to perform. + void QRSolveFactored(T[] q, T[] r, int rowsA, int columnsA, T[] tau, T[] b, int columnsB, T[] x, QRMethod method = QRMethod.Full); + + /// + /// Solves A*X=B for X using a previously QR factored matrix. + /// + /// The Q matrix obtained by QR factor. This is only used for the managed provider and can be + /// null for the native provider. The native provider uses the Q portion stored in the R matrix. + /// The R matrix obtained by calling . + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// Contains additional information on Q. Only used for the native solver + /// and can be null for the managed provider. + /// On entry the B matrix; on exit the X matrix. + /// The number of columns of B. + /// On exit, the solution matrix. + /// The work array - only used in the native provider. The array must have a length of at least N, + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal + /// work size value. + /// Rows must be greater or equal to columns. + /// The type of QR factorization to perform. + void QRSolveFactored(T[] q, T[] r, int rowsA, int columnsA, T[] tau, T[] b, int columnsB, T[] x, T[] work, QRMethod method = QRMethod.Full); + + /// + /// Computes the singular value decomposition of A. + /// + /// Compute the singular U and VT vectors or not. + /// On entry, the M by N matrix to decompose. On exit, A may be overwritten. + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// The singular values of A in ascending value. + /// If is true, on exit U contains the left + /// singular vectors. + /// If is true, on exit VT contains the transposed + /// right singular vectors. + /// This is equivalent to the GESVD LAPACK routine. + void SingularValueDecomposition(bool computeVectors, T[] a, int rowsA, int columnsA, T[] s, T[] u, T[] vt); + + /// + /// Computes the singular value decomposition of A. + /// + /// Compute the singular U and VT vectors or not. + /// On entry, the M by N matrix to decompose. On exit, A may be overwritten. + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// The singular values of A in ascending value. + /// If is true, on exit U contains the left + /// singular vectors. + /// If is true, on exit VT contains the transposed + /// right singular vectors. + /// The work array. On exit, work[0] contains the optimal work size value. + /// + /// This is equivalent to the GESVD LAPACK routine. + void SingularValueDecomposition(bool computeVectors, T[] a, int rowsA, int columnsA, T[] s, T[] u, T[] vt, T[] work); + + /// + /// Solves A*X=B for X using the singular value decomposition of A. + /// + /// On entry, the M by N matrix to decompose. + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// The B matrix. + /// The number of columns of B. + /// On exit, the solution matrix. + void SvdSolve(T[] a, int rowsA, int columnsA, T[] b, int columnsB, T[] x); + + /// + /// Solves A*X=B for X using a previously SVD decomposed matrix. + /// + /// The number of rows in the A matrix. + /// The number of columns in the A matrix. + /// The s values returned by . + /// The left singular vectors returned by . + /// The right singular vectors returned by . + /// The B matrix + /// The number of columns of B. + /// On exit, the solution matrix. + void SvdSolveFactored(int rowsA, int columnsA, T[] s, T[] u, T[] vt, T[] b, int columnsB, T[] x); + + /// + /// Computes the eigenvalues and eigenvectors of a matrix. + /// + /// Wether the matrix is symmetric or not. + /// The order of the matrix. + /// The matrix to decompose. The lenth of the array must be order * order. + /// On output, the matrix contains the eigen vectors. The lenth of the array must be order * order. + /// On output, the eigen values (λ) of matrix in ascending value. The length of the arry must . + /// On output, the block diagonal eigenvalue matrix. The lenth of the array must be order * order. + void EigenDecomp(bool isSymmetric, int order, T[] matrix, T[] matrixEv, Complex[] vectorEv, T[] matrixD); } } diff --git a/src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProviderOfT.cs b/src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProviderOfT.cs deleted file mode 100644 index ce7e881a..00000000 --- a/src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProviderOfT.cs +++ /dev/null @@ -1,533 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://numerics.mathdotnet.com -// http://github.com/mathnet/mathnet-numerics -// http://mathnetnumerics.codeplex.com -// -// 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 -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -using MathNet.Numerics.LinearAlgebra.Factorization; - -namespace MathNet.Numerics.Providers.LinearAlgebra -{ - -#if !NOSYSNUMERICS - using Complex = System.Numerics.Complex; -#endif - - /// - /// How to transpose a matrix. - /// - public enum Transpose - { - /// - /// Don't transpose a matrix. - /// - DontTranspose = 111, - - /// - /// Transpose a matrix. - /// - Transpose = 112, - - /// - /// Conjugate transpose a complex matrix. - /// - /// If a conjugate transpose is used with a real matrix, then the matrix is just transposed. - ConjugateTranspose = 113 - } - - /// - /// Types of matrix norms. - /// - public enum Norm : byte - { - /// - /// The 1-norm. - /// - OneNorm = (byte)'1', - - /// - /// The Frobenius norm. - /// - FrobeniusNorm = (byte)'f', - - /// - /// The infinity norm. - /// - InfinityNorm = (byte)'i', - - /// - /// The largest absolute value norm. - /// - LargestAbsoluteValue = (byte)'m' - } - - /// - /// Interface to linear algebra algorithms that work off 1-D arrays. - /// - /// Supported data types are double, single, Complex, and Complex32. - public interface ILinearAlgebraProvider - where T : struct - where TNorm : struct - { - /*/// - /// Queries the provider for the optimal, workspace block size - /// for the given routine. - /// - /// Name of the method to query. - /// -1 if the provider cannot compute the workspace size; otherwise - /// the suggested block size. - int QueryWorkspaceBlockSize(string methodName);*/ - - /// - /// Adds a scaled vector to another: result = y + alpha*x. - /// - /// The vector to update. - /// The value to scale by. - /// The vector to add to . - /// The result of the addition. - /// This is similar to the AXPY BLAS routine. - void AddVectorToScaledVector(T[] y, T alpha, T[] x, T[] result); - - /// - /// Scales an array. Can be used to scale a vector and a matrix. - /// - /// The scalar. - /// The values to scale. - /// This result of the scaling. - /// This is similar to the SCAL BLAS routine. - void ScaleArray(T alpha, T[] x, T[] result); - - /// - /// Computes the dot product of x and y. - /// - /// The vector x. - /// The vector y. - /// The dot product of x and y. - /// This is equivalent to the DOT BLAS routine. - T DotProduct(T[] x, T[] y); - - /// - /// Does a point wise add of two arrays z = x + y. This can be used - /// to add vectors or matrices. - /// - /// The array x. - /// The array y. - /// The result of the addition. - /// There is no equivalent BLAS routine, but many libraries - /// provide optimized (parallel and/or vectorized) versions of this - /// routine. - void AddArrays(T[] x, T[] y, T[] result); - - /// - /// Does a point wise subtraction of two arrays z = x - y. This can be used - /// to subtract vectors or matrices. - /// - /// The array x. - /// The array y. - /// The result of the subtraction. - /// There is no equivalent BLAS routine, but many libraries - /// provide optimized (parallel and/or vectorized) versions of this - /// routine. - void SubtractArrays(T[] x, T[] y, T[] result); - - /// - /// Does a point wise multiplication of two arrays z = x * y. This can be used - /// to multiply elements of vectors or matrices. - /// - /// The array x. - /// The array y. - /// The result of the point wise multiplication. - /// There is no equivalent BLAS routine, but many libraries - /// provide optimized (parallel and/or vectorized) versions of this - /// routine. - void PointWiseMultiplyArrays(T[] x, T[] y, T[] result); - - /// - /// Does a point wise division of two arrays z = x / y. This can be used - /// to divide elements of vectors or matrices. - /// - /// The array x. - /// The array y. - /// The result of the point wise division. - /// There is no equivalent BLAS routine, but many libraries - /// provide optimized (parallel and/or vectorized) versions of this - /// routine. - void PointWiseDivideArrays(T[] x, T[] y, T[] result); - - /// - /// Computes the requested of the matrix. - /// - /// The type of norm to compute. - /// The number of rows. - /// The number of columns. - /// The matrix to compute the norm from. - /// - /// The requested of the matrix. - /// - T MatrixNorm(Norm norm, int rows, int columns, T[] matrix); - - /// - /// Computes the requested of the matrix. - /// - /// The type of norm to compute. - /// The number of rows. - /// The number of columns. - /// The matrix to compute the norm from. - /// The work array. Only used when - /// and needs to be have a length of at least M (number of rows of . - /// - /// The requested of the matrix. - /// - T MatrixNorm(Norm norm, int rows, int columns, T[] matrix, TNorm[] work); - - /// - /// Multiples two matrices. result = x * y - /// - /// The x matrix. - /// The number of rows in the x matrix. - /// The number of columns in the x matrix. - /// The y matrix. - /// The number of rows in the y matrix. - /// The number of columns in the y matrix. - /// Where to store the result of the multiplication. - /// This is a simplified version of the BLAS GEMM routine with alpha - /// set to 1.0 and beta set to 0.0, and x and y are not transposed. - void MatrixMultiply(T[] x, int rowsX, int columnsX, T[] y, int rowsY, int columnsY, T[] result); - - /// - /// Multiplies two matrices and updates another with the result. c = alpha*op(a)*op(b) + beta*c - /// - /// How to transpose the matrix. - /// How to transpose the matrix. - /// The value to scale matrix. - /// The a matrix. - /// The number of rows in the matrix. - /// The number of columns in the matrix. - /// The b matrix - /// The number of rows in the matrix. - /// The number of columns in the matrix. - /// The value to scale the matrix. - /// The c matrix. - void MatrixMultiplyWithUpdate(Transpose transposeA, Transpose transposeB, T alpha, T[] a, int rowsA, int columnsA, T[] b, int rowsB, int columnsB, T beta, T[] c); - - /// - /// Computes the LUP factorization of A. P*A = L*U. - /// - /// An by matrix. The matrix is overwritten with the - /// the LU factorization on exit. The lower triangular factor L is stored in under the diagonal of (the diagonal is always 1.0 - /// for the L factor). The upper triangular factor U is stored on and above the diagonal of . - /// The order of the square matrix . - /// On exit, it contains the pivot indices. The size of the array must be . - /// This is equivalent to the GETRF LAPACK routine. - void LUFactor(T[] data, int order, int[] ipiv); - - /// - /// Computes the inverse of matrix using LU factorization. - /// - /// The N by N matrix to invert. Contains the inverse On exit. - /// The order of the square matrix . - /// This is equivalent to the GETRF and GETRI LAPACK routines. - void LUInverse(T[] a, int order); - - /// - /// Computes the inverse of a previously factored matrix. - /// - /// The LU factored N by N matrix. Contains the inverse On exit. - /// The order of the square matrix . - /// The pivot indices of . - /// This is equivalent to the GETRI LAPACK routine. - void LUInverseFactored(T[] a, int order, int[] ipiv); - - /// - /// Computes the inverse of matrix using LU factorization. - /// - /// The N by N matrix to invert. Contains the inverse On exit. - /// The order of the square matrix . - /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal - /// work size value. - /// This is equivalent to the GETRF and GETRI LAPACK routines. - void LUInverse(T[] a, int order, T[] work); - - /// - /// Computes the inverse of a previously factored matrix. - /// - /// The LU factored N by N matrix. Contains the inverse On exit. - /// The order of the square matrix . - /// The pivot indices of . - /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal - /// work size value. - /// This is equivalent to the GETRI LAPACK routine. - void LUInverseFactored(T[] a, int order, int[] ipiv, T[] work); - - /// - /// Solves A*X=B for X using LU factorization. - /// - /// The number of columns of B. - /// The square matrix A. - /// The order of the square matrix . - /// On entry the B matrix; on exit the X matrix. - /// This is equivalent to the GETRF and GETRS LAPACK routines. - void LUSolve(int columnsOfB, T[] a, int order, T[] b); - - /// - /// Solves A*X=B for X using a previously factored A matrix. - /// - /// The number of columns of B. - /// The factored A matrix. - /// The order of the square matrix . - /// The pivot indices of . - /// On entry the B matrix; on exit the X matrix. - /// This is equivalent to the GETRS LAPACK routine. - void LUSolveFactored(int columnsOfB, T[] a, int order, int[] ipiv, T[] b); - - /// - /// Computes the Cholesky factorization of A. - /// - /// On entry, a square, positive definite matrix. On exit, the matrix is overwritten with the - /// the Cholesky factorization. - /// The number of rows or columns in the matrix. - /// This is equivalent to the POTRF LAPACK routine. - void CholeskyFactor(T[] a, int order); - - /// - /// Solves A*X=B for X using Cholesky factorization. - /// - /// The square, positive definite matrix A. - /// The number of rows and columns in A. - /// On entry the B matrix; on exit the X matrix. - /// The number of columns in the B matrix. - /// This is equivalent to the POTRF add POTRS LAPACK routines. - void CholeskySolve(T[] a, int orderA, T[] b, int columnsB); - - /// - /// Solves A*X=B for X using a previously factored A matrix. - /// - /// The square, positive definite matrix A. - /// The number of rows and columns in A. - /// On entry the B matrix; on exit the X matrix. - /// The number of columns in the B matrix. - /// This is equivalent to the POTRS LAPACK routine. - void CholeskySolveFactored(T[] a, int orderA, T[] b, int columnsB); - - /// - /// Computes the full QR factorization of A. - /// - /// On entry, it is the M by N A matrix to factor. On exit, - /// it is overwritten with the R matrix of the QR factorization. - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// On exit, A M by M matrix that holds the Q matrix of the - /// QR factorization. - /// A min(m,n) vector. On exit, contains additional information - /// to be used by the QR solve routine. - /// This is similar to the GEQRF and ORGQR LAPACK routines. - void QRFactor(T[] a, int rowsA, int columnsA, T[] q, T[] tau); - - /// - /// Computes the full QR factorization of A. - /// - /// On entry, it is the M by N A matrix to factor. On exit, - /// it is overwritten with the R matrix of the QR factorization. - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// On exit, A M by M matrix that holds the Q matrix of the - /// QR factorization. - /// A min(m,n) vector. On exit, contains additional information - /// to be used by the QR solve routine. - /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal - /// work size value. - /// This is similar to the GEQRF and ORGQR LAPACK routines. - void QRFactor(T[] a, int rowsA, int columnsA, T[] q, T[] tau, T[] work); - - /// - /// Computes the thin QR factorization of A where M > N. - /// - /// On entry, it is the M by N A matrix to factor. On exit, - /// it is overwritten with the Q matrix of the QR factorization. - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// On exit, A N by N matrix that holds the R matrix of the - /// QR factorization. - /// A min(m,n) vector. On exit, contains additional information - /// to be used by the QR solve routine. - /// This is similar to the GEQRF and ORGQR LAPACK routines. - void ThinQRFactor(T[] a, int rowsA, int columnsA, T[] r, T[] tau); - - /// - /// Computes the thin QR factorization of A where M > N. - /// - /// On entry, it is the M by N A matrix to factor. On exit, - /// it is overwritten with the Q matrix of the QR factorization. - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// On exit, A N by N matrix that holds the R matrix of the - /// QR factorization. - /// A min(m,n) vector. On exit, contains additional information - /// to be used by the QR solve routine. - /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal - /// work size value. - /// This is similar to the GEQRF and ORGQR LAPACK routines. - void ThinQRFactor(T[] a, int rowsA, int columnsA, T[] r, T[] tau, T[] work); - - /// - /// Solves A*X=B for X using QR factorization of A. - /// - /// The A matrix. - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// The B matrix. - /// The number of columns of B. - /// On exit, the solution matrix. - /// The type of QR factorization to perform. - /// Rows must be greater or equal to columns. - void QRSolve(T[] a, int rows, int columns, T[] b, int columnsB, T[] x, QRMethod method = QRMethod.Full); - - /// - /// Solves A*X=B for X using QR factorization of A. - /// - /// The A matrix. - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// On entry the B matrix; on exit the X matrix. - /// The number of columns of B. - /// On exit, the solution matrix. - /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal - /// work size value. - /// The type of QR factorization to perform. - /// Rows must be greater or equal to columns. - void QRSolve(T[] a, int rows, int columns, T[] b, int columnsB, T[] x, T[] work, QRMethod method = QRMethod.Full); - - /// - /// Solves A*X=B for X using a previously QR factored matrix. - /// - /// The Q matrix obtained by QR factor. This is only used for the managed provider and can be - /// null for the native provider. The native provider uses the Q portion stored in the R matrix. - /// The R matrix obtained by calling . - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// Contains additional information on Q. Only used for the native solver - /// and can be null for the managed provider. - /// On entry the B matrix; on exit the X matrix. - /// The number of columns of B. - /// On exit, the solution matrix. - /// Rows must be greater or equal to columns. - /// The type of QR factorization to perform. - void QRSolveFactored(T[] q, T[] r, int rowsA, int columnsA, T[] tau, T[] b, int columnsB, T[] x, QRMethod method = QRMethod.Full); - - /// - /// Solves A*X=B for X using a previously QR factored matrix. - /// - /// The Q matrix obtained by QR factor. This is only used for the managed provider and can be - /// null for the native provider. The native provider uses the Q portion stored in the R matrix. - /// The R matrix obtained by calling . - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// Contains additional information on Q. Only used for the native solver - /// and can be null for the managed provider. - /// On entry the B matrix; on exit the X matrix. - /// The number of columns of B. - /// On exit, the solution matrix. - /// The work array - only used in the native provider. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal - /// work size value. - /// Rows must be greater or equal to columns. - /// The type of QR factorization to perform. - void QRSolveFactored(T[] q, T[] r, int rowsA, int columnsA, T[] tau, T[] b, int columnsB, T[] x, T[] work, QRMethod method = QRMethod.Full); - - /// - /// Computes the singular value decomposition of A. - /// - /// Compute the singular U and VT vectors or not. - /// On entry, the M by N matrix to decompose. On exit, A may be overwritten. - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// The singular values of A in ascending value. - /// If is true, on exit U contains the left - /// singular vectors. - /// If is true, on exit VT contains the transposed - /// right singular vectors. - /// This is equivalent to the GESVD LAPACK routine. - void SingularValueDecomposition(bool computeVectors, T[] a, int rowsA, int columnsA, T[] s, T[] u, T[] vt); - - /// - /// Computes the singular value decomposition of A. - /// - /// Compute the singular U and VT vectors or not. - /// On entry, the M by N matrix to decompose. On exit, A may be overwritten. - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// The singular values of A in ascending value. - /// If is true, on exit U contains the left - /// singular vectors. - /// If is true, on exit VT contains the transposed - /// right singular vectors. - /// The work array. On exit, work[0] contains the optimal work size value. - /// - /// This is equivalent to the GESVD LAPACK routine. - void SingularValueDecomposition(bool computeVectors, T[] a, int rowsA, int columnsA, T[] s, T[] u, T[] vt, T[] work); - - /// - /// Solves A*X=B for X using the singular value decomposition of A. - /// - /// On entry, the M by N matrix to decompose. - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// The B matrix. - /// The number of columns of B. - /// On exit, the solution matrix. - void SvdSolve(T[] a, int rowsA, int columnsA, T[] b, int columnsB, T[] x); - - /// - /// Solves A*X=B for X using a previously SVD decomposed matrix. - /// - /// The number of rows in the A matrix. - /// The number of columns in the A matrix. - /// The s values returned by . - /// The left singular vectors returned by . - /// The right singular vectors returned by . - /// The B matrix - /// The number of columns of B. - /// On exit, the solution matrix. - void SvdSolveFactored(int rowsA, int columnsA, T[] s, T[] u, T[] vt, T[] b, int columnsB, T[] x); - - /// - /// Computes the eigenvalues and eigenvectors of a matrix. - /// - /// Wether the matrix is symmetric or not. - /// The order of the matrix. - /// The matrix to decompose. The lenth of the array must be order * order. - /// On output, the matrix contains the eigen vectors. The lenth of the array must be order * order. - /// On output, the eigen values (λ) of matrix in ascending value. The length of the arry must . - /// On output, the block diagonal eigenvalue matrix. The lenth of the array must be order * order. - void EigenDecomp(bool isSymmetric, int order, T[] matrix, T[] matrixEv, Complex[] vectorEv, T[] matrixD); - } -} diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs index c051ad82..f9111247 100644 --- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs +++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs @@ -1854,7 +1854,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra }); work[tmp] += 1.0; - var s = (1.0 / work[tmp]).SquareRoot(); + var s = (1.0/work[tmp]).SquareRoot(); CommonParallel.For(0, rowCount - row, 4096, (u, v) => { for (int i = u; i < v; i++) @@ -2110,7 +2110,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Fill result matrix for (var col = 0; col < columnsB; col++) { - Array.Copy(sol, col * rowsA, x, col * columnsA, columnsR); + Array.Copy(sol, col*rowsA, x, col*columnsA, columnsR); } } @@ -3013,9 +3013,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("matrix"); } - if (matrix.Length != order * order) + if (matrix.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrix"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrix"); } if (matrixEv == null) @@ -3023,9 +3023,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("matrixEv"); } - if (matrixEv.Length != order * order) + if (matrixEv.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrixEv"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrixEv"); } if (vectorEv == null) @@ -3043,9 +3043,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("matrixD"); } - if (matrixD.Length != order * order) + if (matrixD.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrixD"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrixD"); } var matrixCopy = new Complex[matrix.Length]; Array.Copy(matrix, matrixCopy, matrix.Length); @@ -3071,9 +3071,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra DenseEvd.NonsymmetricReduceHessenberToRealSchur(vectorEv, matrixEv, matrixCopy, order); } - for (var i = 0; i < order; i ++) + for (var i = 0; i < order; i++) { - matrixD[i * order + i] = vectorEv[i]; + matrixD[i*order + i] = vectorEv[i]; } } } diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs index f76465d1..a231fa01 100644 --- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs +++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs @@ -112,11 +112,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = y[index] + (alpha * x[index]); + result[index] = y[index] + (alpha*x[index]); } } } - + } /// @@ -157,7 +157,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = alpha * x[index]; + result[index] = alpha*x[index]; } } } @@ -191,7 +191,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var i = 0; i < y.Length; i++) { - d += y[i] * x[i]; + d += y[i]*x[i]; } return d; @@ -345,7 +345,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = x[index] * y[index]; + result[index] = x[index]*y[index]; } } } @@ -396,7 +396,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = x[index] / y[index]; + result[index] = x[index]/y[index]; } } } @@ -422,7 +422,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var s = 0.0; for (var i = 0; i < rows; i++) { - s += matrix[(j * rows) + i].Magnitude; + s += matrix[(j*rows) + i].Magnitude; } ret = Math.Max(ret, s); @@ -435,7 +435,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var j = 0; j < columns; j++) { - ret = Math.Max(matrix[(j * rows) + i].Magnitude, ret); + ret = Math.Max(matrix[(j*rows) + i].Magnitude, ret); } } @@ -446,7 +446,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var s = 0.0; for (var j = 0; j < columns; j++) { - s += matrix[(j * rows) + i].Magnitude; + s += matrix[(j*rows) + i].Magnitude; } ret = Math.Max(ret, s); @@ -454,12 +454,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra break; case Norm.FrobeniusNorm: - var aat = new Complex32[rows * rows]; + var aat = new Complex32[rows*rows]; MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.ConjugateTranspose, 1.0f, matrix, rows, columns, matrix, rows, columns, 0.0f, aat); for (var i = 0; i < rows; i++) { - ret += aat[(i * rows) + i].Magnitude; + ret += aat[(i*rows) + i].Magnitude; } ret = Math.Sqrt(ret); @@ -516,12 +516,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("result"); } - if (rowsX * columnsX != x.Length) + if (rowsX*columnsX != x.Length) { throw new ArgumentException("x.Length != xRows * xColumns"); } - if (rowsY * columnsY != y.Length) + if (rowsY*columnsY != y.Length) { throw new ArgumentException("y.Length != yRows * yColumns"); } @@ -531,7 +531,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException("xColumns != yRows"); } - if (rowsX * columnsY != result.Length) + if (rowsX*columnsY != result.Length) { throw new ArgumentException("xRows * yColumns != result.Length"); } @@ -542,7 +542,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra Complex32[] xdata; if (ReferenceEquals(x, result)) { - xdata = (Complex32[])x.Clone(); + xdata = (Complex32[]) x.Clone(); } else { @@ -552,7 +552,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra Complex32[] ydata; if (ReferenceEquals(y, result)) { - ydata = (Complex32[])y.Clone(); + ydata = (Complex32[]) y.Clone(); } else { @@ -593,14 +593,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if ((int)transposeA > 111 && (int)transposeB > 111) + if ((int) transposeA > 111 && (int) transposeB > 111) { if (rowsA != columnsB) { throw new ArgumentOutOfRangeException(); } - if (columnsA * rowsB != c.Length) + if (columnsA*rowsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -609,14 +609,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra n = rowsB; k = rowsA; } - else if ((int)transposeA > 111) + else if ((int) transposeA > 111) { if (rowsA != rowsB) { throw new ArgumentOutOfRangeException(); } - if (columnsA * columnsB != c.Length) + if (columnsA*columnsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -625,14 +625,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra n = columnsB; k = rowsA; } - else if ((int)transposeB > 111) + else if ((int) transposeB > 111) { if (columnsA != columnsB) { throw new ArgumentOutOfRangeException(); } - if (rowsA * rowsB != c.Length) + if (rowsA*rowsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -648,7 +648,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentOutOfRangeException(); } - if (rowsA * columnsB != c.Length) + if (rowsA*columnsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -670,7 +670,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra Complex32[] adata; if (ReferenceEquals(a, c)) { - adata = (Complex32[])a.Clone(); + adata = (Complex32[]) a.Clone(); } else { @@ -680,7 +680,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra Complex32[] bdata; if (ReferenceEquals(b, c)) { - bdata = (Complex32[])b.Clone(); + bdata = (Complex32[]) b.Clone(); } else { @@ -726,13 +726,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The constant number of columns of matrix op(B) and of the matrix C. /// The constant number of columns of matrix op(A) and the rows of the matrix op(B). /// Indicates if this is the first recursion. - private static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, Complex32 alpha, Complex32[] matrixA, int shiftArow, int shiftAcol, Complex32[] matrixB, int shiftBrow, int shiftBcol, Complex32[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first) + static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, Complex32 alpha, Complex32[] matrixA, int shiftArow, int shiftAcol, Complex32[] matrixB, int shiftBrow, int shiftBcol, Complex32[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first) { if (m + n <= Control.ParallelizeOrder) { - if ((int)transposeA > 111 && (int)transposeB > 111) + if ((int) transposeA > 111 && (int) transposeB > 111) { - if ((int)transposeA > 112 && (int)transposeB > 112) + if ((int) transposeA > 112 && (int) transposeB > 112) { for (var m1 = 0; m1 < m; m1++) { @@ -744,15 +744,15 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = Complex32.Zero; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol].Conjugate() * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos].Conjugate(); + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol].Conjugate()* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos].Conjugate(); } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } - else if ((int)transposeA > 112) + else if ((int) transposeA > 112) { for (var m1 = 0; m1 < m; m1++) { @@ -764,15 +764,15 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = Complex32.Zero; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol].Conjugate() * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos]; + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol].Conjugate()* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } - else if ((int)transposeB > 112) + else if ((int) transposeB > 112) { for (var m1 = 0; m1 < m; m1++) { @@ -784,11 +784,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = Complex32.Zero; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol] * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos].Conjugate(); + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol]* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos].Conjugate(); } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } @@ -804,18 +804,18 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = Complex32.Zero; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol] * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos]; + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol]* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } } - else if ((int)transposeA > 111) + else if ((int) transposeA > 111) { - if ((int)transposeA > 112) + if ((int) transposeA > 112) { for (var m1 = 0; m1 < m; m1++) { @@ -827,11 +827,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = Complex32.Zero; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol].Conjugate() * - matrixB[(matBcolPos * constK) + k1 + shiftBrow]; + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol].Conjugate()* + matrixB[(matBcolPos*constK) + k1 + shiftBrow]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } @@ -847,18 +847,18 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = Complex32.Zero; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol] * - matrixB[(matBcolPos * constK) + k1 + shiftBrow]; + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol]* + matrixB[(matBcolPos*constK) + k1 + shiftBrow]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } } - else if ((int)transposeB > 111) + else if ((int) transposeB > 111) { - if ((int)transposeB > 112) + if ((int) transposeB > 112) { for (var m1 = 0; m1 < m; m1++) { @@ -870,11 +870,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = Complex32.Zero; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[((k1 + shiftAcol) * constM) + matArowPos] * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos].Conjugate(); + sum += matrixA[((k1 + shiftAcol)*constM) + matArowPos]* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos].Conjugate(); } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } @@ -890,11 +890,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = Complex32.Zero; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[((k1 + shiftAcol) * constM) + matArowPos] * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos]; + sum += matrixA[((k1 + shiftAcol)*constM) + matArowPos]* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } @@ -911,11 +911,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = Complex32.Zero; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[((k1 + shiftAcol) * constM) + matArowPos] * - matrixB[(matBcolPos * constK) + k1 + shiftBrow]; + sum += matrixA[((k1 + shiftAcol)*constM) + matArowPos]* + matrixB[(matBcolPos*constK) + k1 + shiftBrow]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } @@ -923,7 +923,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra else { // divide and conquer - int m2 = m / 2, n2 = n / 2, k2 = k / 2; + int m2 = m/2, n2 = n/2, k2 = k/2; if (first) { @@ -977,7 +977,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -998,7 +998,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Outer loop. for (var j = 0; j < order; j++) { - var indexj = j * order; + var indexj = j*order; var indexjj = indexj + j; // Make a copy of the j-th column to localize references. @@ -1015,7 +1015,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var s = Complex32.Zero; for (var k = 0; k < kmax; k++) { - s += data[(k * order) + i] * vecLUcolj[k]; + s += data[(k*order) + i]*vecLUcolj[k]; } data[indexj + i] = vecLUcolj[i] -= s; @@ -1035,7 +1035,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var k = 0; k < order; k++) { - var indexk = k * order; + var indexk = k*order; var indexkp = indexk + p; var indexkj = indexk + j; var temp = data[indexkp]; @@ -1070,7 +1070,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -1099,7 +1099,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -1112,7 +1112,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var inverse = new Complex32[a.Length]; for (var i = 0; i < order; i++) { - inverse[i + (order * i)] = Complex32.One; + inverse[i + (order*i)] = Complex32.One; } LUSolveFactored(order, a, order, ipiv, inverse); @@ -1168,12 +1168,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != order * columnsOfB) + if (b.Length != order*columnsOfB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1216,7 +1216,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -1226,7 +1226,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != order * columnsOfB) + if (b.Length != order*columnsOfB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1247,7 +1247,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var p = ipiv[i]; for (var j = 0; j < columnsOfB; j++) { - var indexk = j * order; + var indexk = j*order; var indexkp = indexk + p; var indexkj = indexk + i; var temp = b[indexkp]; @@ -1259,13 +1259,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Solve L*Y = P*B for (var k = 0; k < order; k++) { - var korder = k * order; + var korder = k*order; for (var i = k + 1; i < order; i++) { for (var j = 0; j < columnsOfB; j++) { - var index = j * order; - b[i + index] -= b[k + index] * a[i + korder]; + var index = j*order; + b[i + index] -= b[k + index]*a[i + korder]; } } } @@ -1273,19 +1273,19 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Solve U*X = Y; for (var k = order - 1; k >= 0; k--) { - var korder = k + (k * order); + var korder = k + (k*order); for (var j = 0; j < columnsOfB; j++) { - b[k + (j * order)] /= a[korder]; + b[k + (j*order)] /= a[korder]; } - korder = k * order; + korder = k*order; for (var i = 0; i < k; i++) { for (var j = 0; j < columnsOfB; j++) { - var index = j * order; - b[i + index] -= b[k + index] * a[i + korder]; + var index = j*order; + b[i + index] -= b[k + index]*a[i + korder]; } } } @@ -1311,20 +1311,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var ij = 0; ij < order; ij++) { // "Pivot" element - var tmpVal = a[(ij * order) + ij]; + var tmpVal = a[(ij*order) + ij]; if (tmpVal.Real > 0.0) { tmpVal = tmpVal.SquareRoot(); - a[(ij * order) + ij] = tmpVal; + a[(ij*order) + ij] = tmpVal; tmpColumn[ij] = tmpVal; // Calculate multipliers and copy to local column // Current column, below the diagonal for (var i = ij + 1; i < order; i++) { - a[(ij * order) + i] /= tmpVal; - tmpColumn[i] = a[(ij * order) + i]; + a[(ij*order) + i] /= tmpVal; + tmpColumn[i] = a[(ij*order) + i]; } // Remaining columns, below the diagonal @@ -1337,7 +1337,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var i = ij + 1; i < order; i++) { - a[(i * order) + ij] = 0.0f; + a[(i*order) + ij] = 0.0f; } } } @@ -1351,14 +1351,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// Total columns /// Multipliers calculated previously /// Number of available processors - private static void DoCholeskyStep(Complex32[] data, int rowDim, int firstCol, int colLimit, Complex32[] multipliers, int availableCores) + static void DoCholeskyStep(Complex32[] data, int rowDim, int firstCol, int colLimit, Complex32[] multipliers, int availableCores) { var tmpColCount = colLimit - firstCol; if ((availableCores > 1) && (tmpColCount > Control.ParallelizeElements)) { - var tmpSplit = firstCol + (tmpColCount / 3); - var tmpCores = availableCores / 2; + var tmpSplit = firstCol + (tmpColCount/3); + var tmpCores = availableCores/2; CommonParallel.Invoke( () => DoCholeskyStep(data, rowDim, firstCol, tmpSplit, multipliers, tmpCores), @@ -1371,7 +1371,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var tmpVal = multipliers[j]; for (var i = j; i < rowDim; i++) { - data[(j * rowDim) + i] -= multipliers[i] * tmpVal.Conjugate(); + data[(j*rowDim) + i] -= multipliers[i]*tmpVal.Conjugate(); } } } @@ -1397,7 +1397,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1433,7 +1433,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1459,9 +1459,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The number of rows and columns in A. /// On entry the B matrix; on exit the X matrix. /// The column to solve for. - private static void DoCholeskySolve(Complex32[] a, int orderA, Complex32[] b, int index) + static void DoCholeskySolve(Complex32[] a, int orderA, Complex32[] b, int index) { - var cindex = index * orderA; + var cindex = index*orderA; // Solve L*Y = B; Complex32 sum; @@ -1470,23 +1470,23 @@ namespace MathNet.Numerics.Providers.LinearAlgebra sum = b[cindex + i]; for (var k = i - 1; k >= 0; k--) { - sum -= a[(k * orderA) + i] * b[cindex + k]; + sum -= a[(k*orderA) + i]*b[cindex + k]; } - b[cindex + i] = sum / a[(i * orderA) + i]; + b[cindex + i] = sum/a[(i*orderA) + i]; } // Solve L'*X = Y; for (var i = orderA - 1; i >= 0; i--) { sum = b[cindex + i]; - var iindex = i * orderA; + var iindex = i*orderA; for (var k = i + 1; k < orderA; k++) { - sum -= a[iindex + k].Conjugate() * b[cindex + k]; + sum -= a[iindex + k].Conjugate()*b[cindex + k]; } - b[cindex + i] = sum / a[iindex + i]; + b[cindex + i] = sum/a[iindex + i]; } } @@ -1514,7 +1514,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -1524,12 +1524,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = columnsR > rowsR ? new Complex32 [rowsR * rowsR] : new Complex32[rowsR * columnsR]; + var work = columnsR > rowsR ? new Complex32[rowsR*rowsR] : new Complex32[rowsR*columnsR]; QRFactor(r, rowsR, columnsR, q, tau, work); } @@ -1565,7 +1565,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -1575,24 +1575,24 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } if (columnsR > rowsR) { - if (work.Length < rowsR * rowsR) + if (work.Length < rowsR*rowsR) { - work[0] = rowsR * rowsR; + work[0] = rowsR*rowsR; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } } else { - if (work.Length < rowsR * columnsR) + if (work.Length < rowsR*columnsR) { - work[0] = rowsR * columnsR; + work[0] = rowsR*columnsR; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } } @@ -1617,7 +1617,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ComputeQR(work, i, q, i, rowsR, i, rowsR, Control.NumberOfParallelWorkerThreads); } - work[0] = columnsR > rowsR ? rowsR * rowsR : rowsR * columnsR; + work[0] = columnsR > rowsR ? rowsR*rowsR : rowsR*columnsR; } /// @@ -1644,7 +1644,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("a"); } - if (a.Length != rowsA * columnsA) + if (a.Length != rowsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "a"); } @@ -1654,12 +1654,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (r.Length != columnsA * columnsA) + if (r.Length != columnsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "columnsA * columnsA"), "r"); } - var work = new Complex32[rowsA * columnsA]; + var work = new Complex32[rowsA*columnsA]; ThinQRFactor(a, rowsA, columnsA, r, tau, work); } @@ -1695,7 +1695,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("q"); } - if (a.Length != rowsA * columnsA) + if (a.Length != rowsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "a"); } @@ -1705,14 +1705,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (r.Length != columnsA * columnsA) + if (r.Length != columnsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "columnsA * columnsA"), "r"); } - if (work.Length < rowsA * columnsA) + if (work.Length < rowsA*columnsA) { - work[0] = rowsA * columnsA; + work[0] = rowsA*columnsA; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -1726,8 +1726,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra //copy R for (var j = 0; j < columnsA; j++) { - var rIndex = j * columnsA; - var aIndex = j * rowsA; + var rIndex = j*columnsA; + var aIndex = j*rowsA; for (var i = 0; i < columnsA; i++) { r[rIndex + i] = a[aIndex + i]; @@ -1738,7 +1738,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra Array.Clear(a, 0, a.Length); for (var i = 0; i < columnsA; i++) { - a[i * rowsA + i] = Complex32.One; + a[i*rowsA + i] = Complex32.One; } for (var i = minmn - 1; i >= 0; i--) @@ -1746,7 +1746,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ComputeQR(work, i, a, i, rowsA, i, columnsA, Control.NumberOfParallelWorkerThreads); } - work[0] = rowsA * columnsA; + work[0] = rowsA*columnsA; } @@ -1763,7 +1763,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The first column /// The last column /// Number of available CPUs - private static void ComputeQR(Complex32[] work, int workIndex, Complex32[] a, int rowStart, int rowCount, int columnStart, int columnCount, int availableCores) + static void ComputeQR(Complex32[] work, int workIndex, Complex32[] a, int rowStart, int rowCount, int columnStart, int columnCount, int availableCores) { if (rowStart > rowCount || columnStart > columnCount) { @@ -1774,8 +1774,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if ((availableCores > 1) && (tmpColCount > 200)) { - var tmpSplit = columnStart + (tmpColCount / 2); - var tmpCores = availableCores / 2; + var tmpSplit = columnStart + (tmpColCount/2); + var tmpCores = availableCores/2; CommonParallel.Invoke( () => ComputeQR(work, workIndex, a, rowStart, rowCount, columnStart, tmpSplit, tmpCores), @@ -1788,12 +1788,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var scale = Complex32.Zero; for (var i = rowStart; i < rowCount; i++) { - scale += work[(workIndex * rowCount) + i - rowStart] * a[(j * rowCount) + i]; + scale += work[(workIndex*rowCount) + i - rowStart]*a[(j*rowCount) + i]; } for (var i = rowStart; i < rowCount; i++) { - a[(j * rowCount) + i] -= work[(workIndex * rowCount) + i - rowStart].Conjugate() * scale; + a[(j*rowCount) + i] -= work[(workIndex*rowCount) + i - rowStart].Conjugate()*scale; } } } @@ -1807,9 +1807,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The number of rows in matrix /// The first row /// Column index - private static void GenerateColumn(Complex32[] work, Complex32[] a, int rowCount, int row, int column) + static void GenerateColumn(Complex32[] work, Complex32[] a, int rowCount, int row, int column) { - var tmp = column * rowCount; + var tmp = column*rowCount; var index = tmp + row; CommonParallel.For(row, rowCount, (u, v) => @@ -1826,7 +1826,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var i = 0; i < rowCount - row; ++i) { var index1 = tmp + i; - norm += work[index1].Magnitude * work[index1].Magnitude; + norm += work[index1].Magnitude*work[index1].Magnitude; } norm = norm.SquareRoot(); @@ -1839,7 +1839,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (work[tmp].Magnitude != 0.0f) { - norm = norm.Magnitude * (work[tmp] / work[tmp].Magnitude); + norm = norm.Magnitude*(work[tmp]/work[tmp].Magnitude); } a[index] = -norm; @@ -1852,7 +1852,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra }); work[tmp] += 1.0f; - var s = (1.0f / work[tmp]).SquareRoot(); + var s = (1.0f/work[tmp]).SquareRoot(); CommonParallel.For(0, rowCount - row, 4096, (u, v) => { for (int i = u; i < v; i++) @@ -1877,7 +1877,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// Rows must be greater or equal to columns. public virtual void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x, QRMethod method = QRMethod.Full) { - var work = new Complex32[rows * columns]; + var work = new Complex32[rows*columns]; QRSolve(a, rows, columns, b, columnsB, x, work, method); } @@ -1917,17 +1917,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -1937,9 +1937,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(Resources.RowsLessThanColumns); } - if (work.Length < rows * columns) + if (work.Length < rows*columns) { - work[0] = rows * columns; + work[0] = rows*columns; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -1948,18 +1948,18 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (method == QRMethod.Full) { - var q = new Complex32[rows * rows]; + var q = new Complex32[rows*rows]; QRFactor(clone, rows, columns, q, work); QRSolveFactored(q, clone, rows, columns, null, b, columnsB, x, method); } else { - var r = new Complex32[columns * columns]; + var r = new Complex32[columns*columns]; ThinQRFactor(clone, rows, columns, r, work); QRSolveFactored(clone, r, rows, columns, null, b, columnsB, x, method); } - work[0] = rows * columns; + work[0] = rows*columns; } /// @@ -2067,7 +2067,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var column = new Complex32[rowsA]; for (var j = 0; j < columnsB; j++) { - var jm = j * rowsA; + var jm = j*rowsA; Array.Copy(sol, jm, column, 0, rowsA); CommonParallel.For(0, columnsA, (u, v) => { @@ -2108,7 +2108,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Fill result matrix for (var col = 0; col < columnsB; col++) { - Array.Copy(sol, col * rowsA, x, col * columnsA, columnsR); + Array.Copy(sol, col*rowsA, x, col*columnsA, columnsR); } } @@ -2147,12 +2147,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -2208,12 +2208,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -2264,24 +2264,24 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = 0.0f; for (i = l; i < rowsA; i++) { - sum += a[(l * rowsA) + i].Magnitude * a[(l * rowsA) + i].Magnitude; + sum += a[(l*rowsA) + i].Magnitude*a[(l*rowsA) + i].Magnitude; } - stemp[l] = (float)Math.Sqrt(sum); + stemp[l] = (float) Math.Sqrt(sum); if (stemp[l] != 0.0f) { - if (a[(l * rowsA) + l] != 0.0f) + if (a[(l*rowsA) + l] != 0.0f) { - stemp[l] = stemp[l].Magnitude * (a[(l * rowsA) + l] / a[(l * rowsA) + l].Magnitude); + stemp[l] = stemp[l].Magnitude*(a[(l*rowsA) + l]/a[(l*rowsA) + l].Magnitude); } // A part of column "l" of Matrix A from row "l" to end multiply by 1.0f / s[l] for (i = l; i < rowsA; i++) { - a[(l * rowsA) + i] = a[(l * rowsA) + i] * (1.0f / stemp[l]); + a[(l*rowsA) + i] = a[(l*rowsA) + i]*(1.0f/stemp[l]); } - a[(l * rowsA) + l] = 1.0f + a[(l * rowsA) + l]; + a[(l*rowsA) + l] = 1.0f + a[(l*rowsA) + l]; } stemp[l] = -stemp[l]; @@ -2297,21 +2297,21 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t = 0.0f; for (i = l; i < rowsA; i++) { - t += a[(l * rowsA) + i].Conjugate() * a[(j * rowsA) + i]; + t += a[(l*rowsA) + i].Conjugate()*a[(j*rowsA) + i]; } - t = -t / a[(l * rowsA) + l]; + t = -t/a[(l*rowsA) + l]; for (var ii = l; ii < rowsA; ii++) { - a[(j * rowsA) + ii] += t * a[(l * rowsA) + ii]; + a[(j*rowsA) + ii] += t*a[(l*rowsA) + ii]; } } } // Place the l-th row of matrix into "e" for the // subsequent calculation of the row transformation. - e[j] = a[(j * rowsA) + l].Conjugate(); + e[j] = a[(j*rowsA) + l].Conjugate(); } if (computeVectors && l < nct) @@ -2319,7 +2319,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Place the transformation in "u" for subsequent back multiplication. for (i = l; i < rowsA; i++) { - u[(l * rowsA) + i] = a[(l * rowsA) + i]; + u[(l*rowsA) + i] = a[(l*rowsA) + i]; } } @@ -2332,21 +2332,21 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var enorm = 0.0f; for (i = lp1; i < e.Length; i++) { - enorm += e[i].Magnitude * e[i].Magnitude; + enorm += e[i].Magnitude*e[i].Magnitude; } - e[l] = (float)Math.Sqrt(enorm); + e[l] = (float) Math.Sqrt(enorm); if (e[l] != 0.0f) { if (e[lp1] != 0.0f) { - e[l] = e[l].Magnitude * (e[lp1] / e[lp1].Magnitude); + e[l] = e[l].Magnitude*(e[lp1]/e[lp1].Magnitude); } // Scale vector "e" from "lp1" by 1.0f / e[l] for (i = lp1; i < e.Length; i++) { - e[i] = e[i] * (1.0f / e[l]); + e[i] = e[i]*(1.0f/e[l]); } e[lp1] = 1.0f + e[lp1]; @@ -2366,16 +2366,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var ii = lp1; ii < rowsA; ii++) { - work[ii] += e[j] * a[(j * rowsA) + ii]; + work[ii] += e[j]*a[(j*rowsA) + ii]; } } for (j = lp1; j < columnsA; j++) { - var ww = (-e[j] / e[lp1]).Conjugate(); + var ww = (-e[j]/e[lp1]).Conjugate(); for (var ii = lp1; ii < rowsA; ii++) { - a[(j * rowsA) + ii] += ww * work[ii]; + a[(j*rowsA) + ii] += ww*work[ii]; } } } @@ -2388,7 +2388,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Place the transformation in v for subsequent back multiplication. for (i = lp1; i < columnsA; i++) { - v[(l * columnsA) + i] = e[i]; + v[(l*columnsA) + i] = e[i]; } } @@ -2398,7 +2398,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var nrtp1 = nrt + 1; if (nct < columnsA) { - stemp[nctp1 - 1] = a[((nctp1 - 1) * rowsA) + (nctp1 - 1)]; + stemp[nctp1 - 1] = a[((nctp1 - 1)*rowsA) + (nctp1 - 1)]; } if (rowsA < m) @@ -2408,7 +2408,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (nrtp1 < m) { - e[nrtp1 - 1] = a[((m - 1) * rowsA) + (nrtp1 - 1)]; + e[nrtp1 - 1] = a[((m - 1)*rowsA) + (nrtp1 - 1)]; } e[m - 1] = 0.0f; @@ -2420,10 +2420,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (i = 0; i < rowsA; i++) { - u[(j * rowsA) + i] = 0.0f; + u[(j*rowsA) + i] = 0.0f; } - u[(j * rowsA) + j] = 1.0f; + u[(j*rowsA) + j] = 1.0f; } for (l = nct - 1; l >= 0; l--) @@ -2435,36 +2435,36 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t = 0.0f; for (i = l; i < rowsA; i++) { - t += u[(l * rowsA) + i].Conjugate() * u[(j * rowsA) + i]; + t += u[(l*rowsA) + i].Conjugate()*u[(j*rowsA) + i]; } - t = -t / u[(l * rowsA) + l]; + t = -t/u[(l*rowsA) + l]; for (var ii = l; ii < rowsA; ii++) { - u[(j * rowsA) + ii] += t * u[(l * rowsA) + ii]; + u[(j*rowsA) + ii] += t*u[(l*rowsA) + ii]; } } // A part of column "l" of matrix A from row "l" to end multiply by -1.0f for (i = l; i < rowsA; i++) { - u[(l * rowsA) + i] = u[(l * rowsA) + i] * -1.0f; + u[(l*rowsA) + i] = u[(l*rowsA) + i]*-1.0f; } - u[(l * rowsA) + l] = 1.0f + u[(l * rowsA) + l]; + u[(l*rowsA) + l] = 1.0f + u[(l*rowsA) + l]; for (i = 0; i < l; i++) { - u[(l * rowsA) + i] = 0.0f; + u[(l*rowsA) + i] = 0.0f; } } else { for (i = 0; i < rowsA; i++) { - u[(l * rowsA) + i] = 0.0f; + u[(l*rowsA) + i] = 0.0f; } - u[(l * rowsA) + l] = 1.0f; + u[(l*rowsA) + l] = 1.0f; } } } @@ -2484,13 +2484,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t = 0.0f; for (i = lp1; i < columnsA; i++) { - t += v[(l * columnsA) + i].Conjugate() * v[(j * columnsA) + i]; + t += v[(l*columnsA) + i].Conjugate()*v[(j*columnsA) + i]; } - t = -t / v[(l * columnsA) + lp1]; + t = -t/v[(l*columnsA) + lp1]; for (var ii = l; ii < columnsA; ii++) { - v[(j * columnsA) + ii] += t * v[(l * columnsA) + ii]; + v[(j*columnsA) + ii] += t*v[(l*columnsA) + ii]; } } } @@ -2498,10 +2498,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (i = 0; i < columnsA; i++) { - v[(l * columnsA) + i] = 0.0f; + v[(l*columnsA) + i] = 0.0f; } - v[(l * columnsA) + l] = 1.0f; + v[(l*columnsA) + l] = 1.0f; } } @@ -2512,11 +2512,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (stemp[i] != 0.0f) { t = stemp[i].Magnitude; - r = stemp[i] / t; + r = stemp[i]/t; stemp[i] = t; if (i < m - 1) { - e[i] = e[i] / r; + e[i] = e[i]/r; } if (computeVectors) @@ -2524,7 +2524,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // A part of column "i" of matrix U from row 0 to end multiply by r for (j = 0; j < rowsA; j++) { - u[(i * rowsA) + j] = u[(i * rowsA) + j] * r; + u[(i*rowsA) + j] = u[(i*rowsA) + j]*r; } } } @@ -2541,9 +2541,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra } t = e[i].Magnitude; - r = t / e[i]; + r = t/e[i]; e[i] = t; - stemp[i + 1] = stemp[i + 1] * r; + stemp[i + 1] = stemp[i + 1]*r; if (!computeVectors) { continue; @@ -2552,7 +2552,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // A part of column "i+1" of matrix VT from row 0 to end multiply by r for (j = 0; j < columnsA; j++) { - v[((i + 1) * columnsA) + j] = v[((i + 1) * columnsA) + j] * r; + v[((i + 1)*columnsA) + j] = v[((i + 1)*columnsA) + j]*r; } } @@ -2639,7 +2639,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float f; switch (kase) { - // Deflate negligible s[m]. + // Deflate negligible s[m]. case 1: f = e[m - 2].Real; e[m - 2] = 0.0f; @@ -2652,8 +2652,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra stemp[k] = t1; if (k != l) { - f = -sn * e[k - 1].Real; - e[k - 1] = cs * e[k - 1]; + f = -sn*e[k - 1].Real; + e[k - 1] = cs*e[k - 1]; } if (computeVectors) @@ -2661,16 +2661,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Rotate for (i = 0; i < columnsA; i++) { - var z = (cs * v[(k * columnsA) + i]) + (sn * v[((m - 1) * columnsA) + i]); - v[((m - 1) * columnsA) + i] = (cs * v[((m - 1) * columnsA) + i]) - (sn * v[(k * columnsA) + i]); - v[(k * columnsA) + i] = z; + var z = (cs*v[(k*columnsA) + i]) + (sn*v[((m - 1)*columnsA) + i]); + v[((m - 1)*columnsA) + i] = (cs*v[((m - 1)*columnsA) + i]) - (sn*v[(k*columnsA) + i]); + v[(k*columnsA) + i] = z; } } } break; - // Split at negligible s[l]. + // Split at negligible s[l]. case 2: f = e[l - 1].Real; e[l - 1] = 0.0f; @@ -2679,23 +2679,23 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t1 = stemp[k].Real; Drotg(ref t1, ref f, ref cs, ref sn); stemp[k] = t1; - f = -sn * e[k].Real; - e[k] = cs * e[k]; + f = -sn*e[k].Real; + e[k] = cs*e[k]; if (computeVectors) { // Rotate for (i = 0; i < rowsA; i++) { - var z = (cs * u[(k * rowsA) + i]) + (sn * u[((l - 1) * rowsA) + i]); - u[((l - 1) * rowsA) + i] = (cs * u[((l - 1) * rowsA) + i]) - (sn * u[(k * rowsA) + i]); - u[(k * rowsA) + i] = z; + var z = (cs*u[(k*rowsA) + i]) + (sn*u[((l - 1)*rowsA) + i]); + u[((l - 1)*rowsA) + i] = (cs*u[((l - 1)*rowsA) + i]) - (sn*u[(k*rowsA) + i]); + u[(k*rowsA) + i] = z; } } } break; - // Perform one qr step. + // Perform one qr step. case 3: // calculate the shift. var scale = 0.0f; @@ -2704,27 +2704,27 @@ namespace MathNet.Numerics.Providers.LinearAlgebra scale = Math.Max(scale, e[m - 2].Magnitude); scale = Math.Max(scale, stemp[l].Magnitude); scale = Math.Max(scale, e[l].Magnitude); - var sm = stemp[m - 1].Real / scale; - var smm1 = stemp[m - 2].Real / scale; - var emm1 = e[m - 2].Real / scale; - var sl = stemp[l].Real / scale; - var el = e[l].Real / scale; - var b = (((smm1 + sm) * (smm1 - sm)) + (emm1 * emm1)) / 2.0f; - var c = (sm * emm1) * (sm * emm1); + var sm = stemp[m - 1].Real/scale; + var smm1 = stemp[m - 2].Real/scale; + var emm1 = e[m - 2].Real/scale; + var sl = stemp[l].Real/scale; + var el = e[l].Real/scale; + var b = (((smm1 + sm)*(smm1 - sm)) + (emm1*emm1))/2.0f; + var c = (sm*emm1)*(sm*emm1); var shift = 0.0f; if (b != 0.0f || c != 0.0f) { - shift = (float)Math.Sqrt((b * b) + c); + shift = (float) Math.Sqrt((b*b) + c); if (b < 0.0f) { shift = -shift; } - shift = c / (b + shift); + shift = c/(b + shift); } - f = ((sl + sm) * (sl - sm)) + shift; - var g = sl * el; + f = ((sl + sm)*(sl - sm)) + shift; + var g = sl*el; // Chase zeros for (k = l; k < m - 1; k++) @@ -2735,33 +2735,33 @@ namespace MathNet.Numerics.Providers.LinearAlgebra e[k - 1] = f; } - f = (cs * stemp[k].Real) + (sn * e[k].Real); - e[k] = (cs * e[k]) - (sn * stemp[k]); - g = sn * stemp[k + 1].Real; - stemp[k + 1] = cs * stemp[k + 1]; + f = (cs*stemp[k].Real) + (sn*e[k].Real); + e[k] = (cs*e[k]) - (sn*stemp[k]); + g = sn*stemp[k + 1].Real; + stemp[k + 1] = cs*stemp[k + 1]; if (computeVectors) { for (i = 0; i < columnsA; i++) { - var z = (cs * v[(k * columnsA) + i]) + (sn * v[((k + 1) * columnsA) + i]); - v[((k + 1) * columnsA) + i] = (cs * v[((k + 1) * columnsA) + i]) - (sn * v[(k * columnsA) + i]); - v[(k * columnsA) + i] = z; + var z = (cs*v[(k*columnsA) + i]) + (sn*v[((k + 1)*columnsA) + i]); + v[((k + 1)*columnsA) + i] = (cs*v[((k + 1)*columnsA) + i]) - (sn*v[(k*columnsA) + i]); + v[(k*columnsA) + i] = z; } } Drotg(ref f, ref g, ref cs, ref sn); stemp[k] = f; - f = (cs * e[k].Real) + (sn * stemp[k + 1].Real); - stemp[k + 1] = -(sn * e[k]) + (cs * stemp[k + 1]); - g = sn * e[k + 1].Real; - e[k + 1] = cs * e[k + 1]; + f = (cs*e[k].Real) + (sn*stemp[k + 1].Real); + stemp[k + 1] = -(sn*e[k]) + (cs*stemp[k + 1]); + g = sn*e[k + 1].Real; + e[k + 1] = cs*e[k + 1]; if (computeVectors && k < rowsA) { for (i = 0; i < rowsA; i++) { - var z = (cs * u[(k * rowsA) + i]) + (sn * u[((k + 1) * rowsA) + i]); - u[((k + 1) * rowsA) + i] = (cs * u[((k + 1) * rowsA) + i]) - (sn * u[(k * rowsA) + i]); - u[(k * rowsA) + i] = z; + var z = (cs*u[(k*rowsA) + i]) + (sn*u[((k + 1)*rowsA) + i]); + u[((k + 1)*rowsA) + i] = (cs*u[((k + 1)*rowsA) + i]) - (sn*u[(k*rowsA) + i]); + u[(k*rowsA) + i] = z; } } } @@ -2770,7 +2770,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra iter = iter + 1; break; - // Convergence + // Convergence case 4: // Make the singular value positive @@ -2782,7 +2782,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // A part of column "l" of matrix VT from row 0 to end multiply by -1 for (i = 0; i < columnsA; i++) { - v[(l * columnsA) + i] = v[(l * columnsA) + i] * -1.0f; + v[(l*columnsA) + i] = v[(l*columnsA) + i]*-1.0f; } } } @@ -2803,9 +2803,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Swap columns l, l + 1 for (i = 0; i < columnsA; i++) { - var z = v[(l * columnsA) + i]; - v[(l * columnsA) + i] = v[((l + 1) * columnsA) + i]; - v[((l + 1) * columnsA) + i] = z; + var z = v[(l*columnsA) + i]; + v[(l*columnsA) + i] = v[((l + 1)*columnsA) + i]; + v[((l + 1)*columnsA) + i] = z; } } @@ -2814,9 +2814,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Swap columns l, l + 1 for (i = 0; i < rowsA; i++) { - var z = u[(l * rowsA) + i]; - u[(l * rowsA) + i] = u[((l + 1) * rowsA) + i]; - u[((l + 1) * rowsA) + i] = z; + var z = u[(l*rowsA) + i]; + u[(l*rowsA) + i] = u[((l + 1)*rowsA) + i]; + u[((l + 1)*rowsA) + i] = z; } } @@ -2836,7 +2836,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (j = 0; j < columnsA; j++) { - vt[(j * columnsA) + i] = v[(i * columnsA) + j].Conjugate(); + vt[(j*columnsA) + i] = v[(i*columnsA) + j].Conjugate(); } } } @@ -2848,7 +2848,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // On return the first element of the work array stores the min size of the work array could have been // work[0] = Math.Max(3 * Math.Min(aRows, aColumns) + Math.Max(aRows, aColumns), 5 * Math.Min(aRows, aColumns)); - work[0] = rowsA; + work[0] = rowsA; } /// @@ -2877,20 +2877,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } var work = new Complex32[rowsA]; var s = new Complex32[Math.Min(rowsA, columnsA)]; - var u = new Complex32[rowsA * rowsA]; - var vt = new Complex32[columnsA * columnsA]; + var u = new Complex32[rowsA*rowsA]; + var vt = new Complex32[columnsA*columnsA]; var clone = new Complex32[a.Length]; a.Copy(clone); @@ -2936,12 +2936,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("x"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -2951,12 +2951,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -2973,7 +2973,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var i = 0; i < rowsA; i++) { - value += u[(j * rowsA) + i].Conjugate() * b[(k * rowsA) + i]; + value += u[(j*rowsA) + i].Conjugate()*b[(k*rowsA) + i]; } value /= s[j]; @@ -2987,10 +2987,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var value = Complex32.Zero; for (var i = 0; i < columnsA; i++) { - value += vt[(j * columnsA) + i].Conjugate() * tmp[i]; + value += vt[(j*columnsA) + i].Conjugate()*tmp[i]; } - x[(k * columnsA) + j] = value; + x[(k*columnsA) + j] = value; } } } @@ -3006,27 +3006,27 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// On output, the block diagonal eigenvalue matrix. The lenth of the array must be order * order. public virtual void EigenDecomp(bool isSymmetric, int order, Complex32[] matrix, Complex32[] matrixEv, Complex[] vectorEv, Complex32[] matrixD) { - if (matrix == null) + if (matrix == null) { throw new ArgumentNullException("matrix"); } - if (matrix.Length != order * order ) + if (matrix.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrix"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrix"); } - - if (matrixEv == null) + + if (matrixEv == null) { throw new ArgumentNullException("matrixEv"); } - if (matrixEv.Length != order * order ) + if (matrixEv.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrixEv"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrixEv"); } - if (vectorEv == null) + if (vectorEv == null) { throw new ArgumentNullException("vectorEv"); } @@ -3036,14 +3036,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order), "vectorEv"); } - if (matrixD == null) + if (matrixD == null) { throw new ArgumentNullException("matrixD"); } - if (matrixD.Length != order * order ) + if (matrixD.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrixD"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrixD"); } var matrixCopy = new Complex32[matrix.Length]; @@ -3062,7 +3062,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var i = 0; i < order; i++) { vectorEv[i] = new Complex(d[i], e[i]); - matrixD[i * order + i] = new Complex32(d[i], e[i]); + matrixD[i*order + i] = new Complex32(d[i], e[i]); } } else @@ -3072,7 +3072,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var i = 0; i < order; i++) { vectorEv[i] = new Complex(v[i].Real, v[i].Imaginary); - matrixD[i * order + i] = v[i]; + matrixD[i*order + i] = v[i]; } } } diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs index 7c2a3390..e9e6b0b0 100644 --- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs +++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs @@ -110,7 +110,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = y[index] + (alpha * x[index]); + result[index] = y[index] + (alpha*x[index]); } } } @@ -154,7 +154,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = alpha * x[index]; + result[index] = alpha*x[index]; } } } @@ -188,7 +188,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var index = 0; index < y.Length; index++) { - sum += y[index] * x[index]; + sum += y[index]*x[index]; } return sum; @@ -342,7 +342,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = x[index] * y[index]; + result[index] = x[index]*y[index]; } } } @@ -393,7 +393,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = x[index] / y[index]; + result[index] = x[index]/y[index]; } } } @@ -419,7 +419,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var s = 0.0; for (var i = 0; i < rows; i++) { - s += Math.Abs(matrix[(j * rows) + i]); + s += Math.Abs(matrix[(j*rows) + i]); } ret = Math.Max(ret, s); @@ -427,12 +427,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra break; case Norm.LargestAbsoluteValue: - + for (var i = 0; i < rows; i++) { for (var j = 0; j < columns; j++) { - ret = Math.Max(Math.Abs(matrix[(j * rows) + i]), ret); + ret = Math.Max(Math.Abs(matrix[(j*rows) + i]), ret); } } @@ -443,7 +443,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var s = 0.0; for (var j = 0; j < columns; j++) { - s += Math.Abs(matrix[(j * rows) + i]); + s += Math.Abs(matrix[(j*rows) + i]); } ret = Math.Max(ret, s); @@ -451,12 +451,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra break; case Norm.FrobeniusNorm: - var aat = new double[rows * rows]; + var aat = new double[rows*rows]; MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.Transpose, 1.0, matrix, rows, columns, matrix, rows, columns, 0.0, aat); for (var i = 0; i < rows; i++) { - ret += Math.Abs(aat[(i * rows) + i]); + ret += Math.Abs(aat[(i*rows) + i]); } ret = Math.Sqrt(ret); @@ -512,12 +512,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("result"); } - if (rowsX * columnsX != x.Length) + if (rowsX*columnsX != x.Length) { throw new ArgumentException("x.Length != xRows * xColumns"); } - if (rowsY * columnsY != y.Length) + if (rowsY*columnsY != y.Length) { throw new ArgumentException("y.Length != yRows * yColumns"); } @@ -527,7 +527,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException("xColumns != yRows"); } - if (rowsX * columnsY != result.Length) + if (rowsX*columnsY != result.Length) { throw new ArgumentException("xRows * yColumns != result.Length"); } @@ -538,7 +538,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra double[] xdata; if (ReferenceEquals(x, result)) { - xdata = (double[])x.Clone(); + xdata = (double[]) x.Clone(); } else { @@ -548,7 +548,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra double[] ydata; if (ReferenceEquals(y, result)) { - ydata = (double[])y.Clone(); + ydata = (double[]) y.Clone(); } else { @@ -589,14 +589,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if ((int)transposeA > 111 && (int)transposeB > 111) + if ((int) transposeA > 111 && (int) transposeB > 111) { if (rowsA != columnsB) { throw new ArgumentOutOfRangeException(); } - if (columnsA * rowsB != c.Length) + if (columnsA*rowsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -605,14 +605,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra n = rowsB; k = rowsA; } - else if ((int)transposeA > 111) + else if ((int) transposeA > 111) { if (rowsA != rowsB) { throw new ArgumentOutOfRangeException(); } - if (columnsA * columnsB != c.Length) + if (columnsA*columnsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -621,14 +621,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra n = columnsB; k = rowsA; } - else if ((int)transposeB > 111) + else if ((int) transposeB > 111) { if (columnsA != columnsB) { throw new ArgumentOutOfRangeException(); } - if (rowsA * rowsB != c.Length) + if (rowsA*rowsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -644,7 +644,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentOutOfRangeException(); } - if (rowsA * columnsB != c.Length) + if (rowsA*columnsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -666,7 +666,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra double[] adata; if (ReferenceEquals(a, c)) { - adata = (double[])a.Clone(); + adata = (double[]) a.Clone(); } else { @@ -676,7 +676,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra double[] bdata; if (ReferenceEquals(b, c)) { - bdata = (double[])b.Clone(); + bdata = (double[]) b.Clone(); } else { @@ -722,11 +722,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The constant number of columns of matrix op(B) and of the matrix C. /// The constant number of columns of matrix op(A) and the rows of the matrix op(B). /// Indicates if this is the first recursion. - private static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, double alpha, double[] matrixA, int shiftArow, int shiftAcol, double[] matrixB, int shiftBrow, int shiftBcol, double[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first) + static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, double alpha, double[] matrixA, int shiftArow, int shiftAcol, double[] matrixB, int shiftBrow, int shiftBcol, double[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first) { if (m + n <= Control.ParallelizeOrder) { - if ((int)transposeA > 111 && (int)transposeB > 111) + if ((int) transposeA > 111 && (int) transposeB > 111) { for (var m1 = 0; m1 < m; m1++) { @@ -738,15 +738,15 @@ namespace MathNet.Numerics.Providers.LinearAlgebra double sum = 0; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol] * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos]; + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol]* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } - else if ((int)transposeA > 111) + else if ((int) transposeA > 111) { for (var m1 = 0; m1 < m; m1++) { @@ -758,15 +758,15 @@ namespace MathNet.Numerics.Providers.LinearAlgebra double sum = 0; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol] * - matrixB[(matBcolPos * constK) + k1 + shiftBrow]; + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol]* + matrixB[(matBcolPos*constK) + k1 + shiftBrow]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } - else if ((int)transposeB > 111) + else if ((int) transposeB > 111) { for (var m1 = 0; m1 < m; m1++) { @@ -778,11 +778,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra double sum = 0; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[((k1 + shiftAcol) * constM) + matArowPos] * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos]; + sum += matrixA[((k1 + shiftAcol)*constM) + matArowPos]* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } @@ -798,11 +798,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra double sum = 0; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[((k1 + shiftAcol) * constM) + matArowPos] * - matrixB[(matBcolPos * constK) + k1 + shiftBrow]; + sum += matrixA[((k1 + shiftAcol)*constM) + matArowPos]* + matrixB[(matBcolPos*constK) + k1 + shiftBrow]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } @@ -810,7 +810,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra else { // divide and conquer - int m2 = m / 2, n2 = n / 2, k2 = k / 2; + int m2 = m/2, n2 = n/2, k2 = k/2; if (first) { @@ -864,7 +864,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -885,7 +885,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Outer loop. for (var j = 0; j < order; j++) { - var indexj = j * order; + var indexj = j*order; var indexjj = indexj + j; // Make a copy of the j-th column to localize references. @@ -902,7 +902,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var s = 0.0; for (var k = 0; k < kmax; k++) { - s += data[(k * order) + i] * vecLUcolj[k]; + s += data[(k*order) + i]*vecLUcolj[k]; } data[indexj + i] = vecLUcolj[i] -= s; @@ -922,7 +922,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var k = 0; k < order; k++) { - var indexk = k * order; + var indexk = k*order; var indexkp = indexk + p; var indexkj = indexk + j; var temp = data[indexkp]; @@ -957,7 +957,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -986,7 +986,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -999,7 +999,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var inverse = new double[a.Length]; for (var i = 0; i < order; i++) { - inverse[i + (order * i)] = 1.0; + inverse[i + (order*i)] = 1.0; } LUSolveFactored(order, a, order, ipiv, inverse); @@ -1032,7 +1032,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// This is equivalent to the GETRI LAPACK routine. public virtual void LUInverseFactored(double[] a, int order, int[] ipiv, double[] work) { - LUInverseFactored(a, order, ipiv); + LUInverseFactored(a, order, ipiv); } /// @@ -1055,12 +1055,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != order * columnsOfB) + if (b.Length != order*columnsOfB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1103,7 +1103,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -1113,7 +1113,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != order * columnsOfB) + if (b.Length != order*columnsOfB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1134,7 +1134,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var p = ipiv[i]; for (var j = 0; j < columnsOfB; j++) { - var indexk = j * order; + var indexk = j*order; var indexkp = indexk + p; var indexkj = indexk + i; var temp = b[indexkp]; @@ -1146,13 +1146,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Solve L*Y = P*B for (var k = 0; k < order; k++) { - var korder = k * order; + var korder = k*order; for (var i = k + 1; i < order; i++) { for (var j = 0; j < columnsOfB; j++) { - var index = j * order; - b[i + index] -= b[k + index] * a[i + korder]; + var index = j*order; + b[i + index] -= b[k + index]*a[i + korder]; } } } @@ -1160,19 +1160,19 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Solve U*X = Y; for (var k = order - 1; k >= 0; k--) { - var korder = k + (k * order); + var korder = k + (k*order); for (var j = 0; j < columnsOfB; j++) { - b[k + (j * order)] /= a[korder]; + b[k + (j*order)] /= a[korder]; } - korder = k * order; + korder = k*order; for (var i = 0; i < k; i++) { for (var j = 0; j < columnsOfB; j++) { - var index = j * order; - b[i + index] -= b[k + index] * a[i + korder]; + var index = j*order; + b[i + index] -= b[k + index]*a[i + korder]; } } } @@ -1198,20 +1198,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (int ij = 0; ij < order; ij++) { // "Pivot" element - double tmpVal = a[(ij * order) + ij]; + double tmpVal = a[(ij*order) + ij]; if (tmpVal > 0.0) { tmpVal = Math.Sqrt(tmpVal); - a[(ij * order) + ij] = tmpVal; + a[(ij*order) + ij] = tmpVal; tmpColumn[ij] = tmpVal; // Calculate multipliers and copy to local column // Current column, below the diagonal for (int i = ij + 1; i < order; i++) { - a[(ij * order) + i] /= tmpVal; - tmpColumn[i] = a[(ij * order) + i]; + a[(ij*order) + i] /= tmpVal; + tmpColumn[i] = a[(ij*order) + i]; } // Remaining columns, below the diagonal @@ -1224,7 +1224,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (int i = ij + 1; i < order; i++) { - a[(i * order) + ij] = 0.0; + a[(i*order) + ij] = 0.0; } } } @@ -1238,14 +1238,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// Total columns /// Multipliers calculated previously /// Number of available processors - private static void DoCholeskyStep(double[] data, int rowDim, int firstCol, int colLimit, double[] multipliers, int availableCores) + static void DoCholeskyStep(double[] data, int rowDim, int firstCol, int colLimit, double[] multipliers, int availableCores) { var tmpColCount = colLimit - firstCol; if ((availableCores > 1) && (tmpColCount > Control.ParallelizeElements)) { - var tmpSplit = firstCol + (tmpColCount / 3); - var tmpCores = availableCores / 2; + var tmpSplit = firstCol + (tmpColCount/3); + var tmpCores = availableCores/2; CommonParallel.Invoke( () => DoCholeskyStep(data, rowDim, firstCol, tmpSplit, multipliers, tmpCores), @@ -1258,7 +1258,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var tmpVal = multipliers[j]; for (var i = j; i < rowDim; i++) { - data[(j * rowDim) + i] -= multipliers[i] * tmpVal; + data[(j*rowDim) + i] -= multipliers[i]*tmpVal; } } } @@ -1284,7 +1284,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1320,7 +1320,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1346,9 +1346,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The number of rows and columns in A. /// On entry the B matrix; on exit the X matrix. /// The column to solve for. - private static void DoCholeskySolve(double[] a, int orderA, double[] b, int index) + static void DoCholeskySolve(double[] a, int orderA, double[] b, int index) { - var cindex = index * orderA; + var cindex = index*orderA; // Solve L*Y = B; double sum; @@ -1357,23 +1357,23 @@ namespace MathNet.Numerics.Providers.LinearAlgebra sum = b[cindex + i]; for (var k = i - 1; k >= 0; k--) { - sum -= a[(k * orderA) + i] * b[cindex + k]; + sum -= a[(k*orderA) + i]*b[cindex + k]; } - b[cindex + i] = sum / a[(i * orderA) + i]; + b[cindex + i] = sum/a[(i*orderA) + i]; } // Solve L'*X = Y; for (var i = orderA - 1; i >= 0; i--) { sum = b[cindex + i]; - var iindex = i * orderA; + var iindex = i*orderA; for (var k = i + 1; k < orderA; k++) { - sum -= a[iindex + k] * b[cindex + k]; + sum -= a[iindex + k]*b[cindex + k]; } - b[cindex + i] = sum / a[iindex + i]; + b[cindex + i] = sum/a[iindex + i]; } } @@ -1401,7 +1401,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -1411,13 +1411,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = columnsR > rowsR ? new double[rowsR * rowsR] : new double[rowsR * columnsR]; + var work = columnsR > rowsR ? new double[rowsR*rowsR] : new double[rowsR*columnsR]; QRFactor(r, rowsR, columnsR, q, tau, work); } @@ -1453,7 +1453,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -1463,24 +1463,24 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } if (columnsR > rowsR) { - if (work.Length < rowsR * rowsR) + if (work.Length < rowsR*rowsR) { - work[0] = rowsR * rowsR; + work[0] = rowsR*rowsR; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } } else { - if (work.Length < rowsR * columnsR) + if (work.Length < rowsR*columnsR) { - work[0] = rowsR * columnsR; + work[0] = rowsR*columnsR; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } } @@ -1505,7 +1505,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ComputeQR(work, i, q, i, rowsR, i, rowsR, Control.NumberOfParallelWorkerThreads); } - work[0] = columnsR > rowsR ? rowsR * rowsR : rowsR * columnsR; + work[0] = columnsR > rowsR ? rowsR*rowsR : rowsR*columnsR; } /// @@ -1532,7 +1532,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("a"); } - if (a.Length != rowsA * columnsA) + if (a.Length != rowsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "a"); } @@ -1542,12 +1542,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (r.Length != columnsA * columnsA) + if (r.Length != columnsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "columnsA * columnsA"), "r"); } - var work = new double[rowsA * columnsA]; + var work = new double[rowsA*columnsA]; ThinQRFactor(a, rowsA, columnsA, r, tau, work); } @@ -1583,7 +1583,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("q"); } - if (a.Length != rowsA * columnsA) + if (a.Length != rowsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "a"); } @@ -1593,12 +1593,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (r.Length != columnsA * columnsA) + if (r.Length != columnsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "columnsA * columnsA"), "r"); } - if (work.Length < rowsA * columnsA) + if (work.Length < rowsA*columnsA) { work[0] = rowsA*columnsA; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); @@ -1612,21 +1612,21 @@ namespace MathNet.Numerics.Providers.LinearAlgebra } //copy R - for (var j = 0; j < columnsA; j++ ) + for (var j = 0; j < columnsA; j++) { - var rIndex = j * columnsA; - var aIndex = j * rowsA; + var rIndex = j*columnsA; + var aIndex = j*rowsA; for (var i = 0; i < columnsA; i++) { - r[rIndex + i] = a[aIndex+i]; + r[rIndex + i] = a[aIndex + i]; } } //clear A and set diagonals to 1 Array.Clear(a, 0, a.Length); - for (var i = 0; i < columnsA; i++ ) + for (var i = 0; i < columnsA; i++) { - a[i * rowsA + i] = 1.0; + a[i*rowsA + i] = 1.0; } for (var i = minmn - 1; i >= 0; i--) @@ -1634,7 +1634,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ComputeQR(work, i, a, i, rowsA, i, columnsA, Control.NumberOfParallelWorkerThreads); } - work[0] = rowsA * columnsA; + work[0] = rowsA*columnsA; } #region QR Factor Helper functions @@ -1650,7 +1650,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The first column /// The last column /// Number of available CPUs - private static void ComputeQR(double[] work, int workIndex, double[] a, int rowStart, int rowCount, int columnStart, int columnCount, int availableCores) + static void ComputeQR(double[] work, int workIndex, double[] a, int rowStart, int rowCount, int columnStart, int columnCount, int availableCores) { if (rowStart > rowCount || columnStart > columnCount) { @@ -1661,8 +1661,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if ((availableCores > 1) && (tmpColCount > 200)) { - var tmpSplit = columnStart + (tmpColCount / 2); - var tmpCores = availableCores / 2; + var tmpSplit = columnStart + (tmpColCount/2); + var tmpCores = availableCores/2; CommonParallel.Invoke( () => ComputeQR(work, workIndex, a, rowStart, rowCount, columnStart, tmpSplit, tmpCores), @@ -1673,14 +1673,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var j = columnStart; j < columnCount; j++) { var scale = 0.0; - for (var i = rowStart; i < rowCount; i++) + for (var i = rowStart; i < rowCount; i++) { - scale += work[(workIndex * rowCount) + i - rowStart] * a[(j * rowCount) + i]; + scale += work[(workIndex*rowCount) + i - rowStart]*a[(j*rowCount) + i]; } - - for (var i = rowStart; i < rowCount; i++) + + for (var i = rowStart; i < rowCount; i++) { - a[(j * rowCount) + i] -= work[(workIndex * rowCount) + i - rowStart] * scale; + a[(j*rowCount) + i] -= work[(workIndex*rowCount) + i - rowStart]*scale; } } } @@ -1694,9 +1694,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The number of rows in matrix /// The first row /// Column index - private static void GenerateColumn(double[] work, double[] a, int rowCount, int row, int column) + static void GenerateColumn(double[] work, double[] a, int rowCount, int row, int column) { - var tmp = column * rowCount; + var tmp = column*rowCount; var index = tmp + row; CommonParallel.For(row, rowCount, (u, v) => @@ -1713,24 +1713,24 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var i = 0; i < rowCount - row; ++i) { var iindex = tmp + i; - norm += work[iindex] * work[iindex]; + norm += work[iindex]*work[iindex]; } norm = Math.Sqrt(norm); - if (row == rowCount - 1 || norm == 0) + if (row == rowCount - 1 || norm == 0) { a[index] = -work[tmp]; work[tmp] = Math.Sqrt(2.0); return; } - var scale = 1.0 / norm; + var scale = 1.0/norm; if (work[tmp] < 0.0) { scale *= -1.0; } - a[index] = -1.0 / scale; + a[index] = -1.0/scale; CommonParallel.For(0, rowCount - row, 4096, (u, v) => { for (int i = u; i < v; i++) @@ -1740,7 +1740,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra }); work[tmp] += 1.0; - var s = Math.Sqrt(1.0 / work[tmp]); + var s = Math.Sqrt(1.0/work[tmp]); CommonParallel.For(0, rowCount - row, 4096, (u, v) => { for (int i = u; i < v; i++) @@ -1765,7 +1765,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// Rows must be greater or equal to columns. public virtual void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x, QRMethod method = QRMethod.Full) { - var work = new double[rows * columns]; + var work = new double[rows*columns]; QRSolve(a, rows, columns, b, columnsB, x, work, method); } @@ -1805,17 +1805,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -1825,28 +1825,29 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(Resources.RowsLessThanColumns); } - if (work.Length < rows * columns) + if (work.Length < rows*columns) { - work[0] = rows * columns; + work[0] = rows*columns; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } var clone = new double[a.Length]; a.Copy(clone); - if (method == QRMethod.Full) + if (method == QRMethod.Full) { - var q = new double[rows * rows]; + var q = new double[rows*rows]; QRFactor(clone, rows, columns, q, work); QRSolveFactored(q, clone, rows, columns, null, b, columnsB, x, method); - } else + } + else { - var r = new double[columns * columns]; + var r = new double[columns*columns]; ThinQRFactor(clone, rows, columns, r, work); QRSolveFactored(clone, r, rows, columns, null, b, columnsB, x, method); } - work[0] = rows * columns; + work[0] = rows*columns; } /// @@ -1954,7 +1955,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var column = new double[rowsA]; for (var j = 0; j < columnsB; j++) { - var jm = j * rowsA; + var jm = j*rowsA; Array.Copy(sol, jm, column, 0, rowsA); CommonParallel.For(0, columnsA, (u, v) => { @@ -2034,12 +2035,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -2095,12 +2096,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -2151,25 +2152,25 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = 0.0; for (var i1 = l; i1 < rowsA; i1++) { - sum += a[(l * rowsA) + i1] * a[(l * rowsA) + i1]; + sum += a[(l*rowsA) + i1]*a[(l*rowsA) + i1]; } stemp[l] = Math.Sqrt(sum); if (stemp[l] != 0.0) { - if (a[(l * rowsA) + l] != 0.0) + if (a[(l*rowsA) + l] != 0.0) { - stemp[l] = Math.Abs(stemp[l]) * (a[(l * rowsA) + l] / Math.Abs(a[(l * rowsA) + l])); + stemp[l] = Math.Abs(stemp[l])*(a[(l*rowsA) + l]/Math.Abs(a[(l*rowsA) + l])); } // A part of column "l" of Matrix A from row "l" to end multiply by 1.0 / s[l] for (i = l; i < rowsA; i++) { - a[(l * rowsA) + i] = a[(l * rowsA) + i] * (1.0 / stemp[l]); + a[(l*rowsA) + i] = a[(l*rowsA) + i]*(1.0/stemp[l]); } - a[(l * rowsA) + l] = 1.0 + a[(l * rowsA) + l]; + a[(l*rowsA) + l] = 1.0 + a[(l*rowsA) + l]; } stemp[l] = -stemp[l]; @@ -2185,21 +2186,21 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t = 0.0; for (i = l; i < rowsA; i++) { - t += a[(j * rowsA) + i] * a[(l * rowsA) + i]; + t += a[(j*rowsA) + i]*a[(l*rowsA) + i]; } - t = -t / a[(l * rowsA) + l]; + t = -t/a[(l*rowsA) + l]; for (var ii = l; ii < rowsA; ii++) { - a[(j * rowsA) + ii] += t * a[(l * rowsA) + ii]; + a[(j*rowsA) + ii] += t*a[(l*rowsA) + ii]; } } } // Place the l-th row of matrix into "e" for the // subsequent calculation of the row transformation. - e[j] = a[(j * rowsA) + l]; + e[j] = a[(j*rowsA) + l]; } if (computeVectors && l < nct) @@ -2207,7 +2208,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Place the transformation in "u" for subsequent back multiplication. for (i = l; i < rowsA; i++) { - u[(l * rowsA) + i] = a[(l * rowsA) + i]; + u[(l*rowsA) + i] = a[(l*rowsA) + i]; } } @@ -2220,7 +2221,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var enorm = 0.0; for (i = lp1; i < e.Length; i++) { - enorm += e[i] * e[i]; + enorm += e[i]*e[i]; } e[l] = Math.Sqrt(enorm); @@ -2228,13 +2229,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { if (e[lp1] != 0.0) { - e[l] = Math.Abs(e[l]) * (e[lp1] / Math.Abs(e[lp1])); + e[l] = Math.Abs(e[l])*(e[lp1]/Math.Abs(e[lp1])); } // Scale vector "e" from "lp1" by 1.0 / e[l] for (i = lp1; i < e.Length; i++) { - e[i] = e[i] * (1.0 / e[l]); + e[i] = e[i]*(1.0/e[l]); } e[lp1] = 1.0 + e[lp1]; @@ -2254,16 +2255,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var ii = lp1; ii < rowsA; ii++) { - work[ii] += e[j] * a[(j * rowsA) + ii]; + work[ii] += e[j]*a[(j*rowsA) + ii]; } } for (j = lp1; j < columnsA; j++) { - var ww = -e[j] / e[lp1]; + var ww = -e[j]/e[lp1]; for (var ii = lp1; ii < rowsA; ii++) { - a[(j * rowsA) + ii] += ww * work[ii]; + a[(j*rowsA) + ii] += ww*work[ii]; } } } @@ -2276,7 +2277,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Place the transformation in v for subsequent back multiplication. for (i = lp1; i < columnsA; i++) { - v[(l * columnsA) + i] = e[i]; + v[(l*columnsA) + i] = e[i]; } } @@ -2286,7 +2287,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var nrtp1 = nrt + 1; if (nct < columnsA) { - stemp[nctp1 - 1] = a[((nctp1 - 1) * rowsA) + (nctp1 - 1)]; + stemp[nctp1 - 1] = a[((nctp1 - 1)*rowsA) + (nctp1 - 1)]; } if (rowsA < m) @@ -2296,7 +2297,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (nrtp1 < m) { - e[nrtp1 - 1] = a[((m - 1) * rowsA) + (nrtp1 - 1)]; + e[nrtp1 - 1] = a[((m - 1)*rowsA) + (nrtp1 - 1)]; } e[m - 1] = 0.0; @@ -2308,10 +2309,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (i = 0; i < rowsA; i++) { - u[(j * rowsA) + i] = 0.0; + u[(j*rowsA) + i] = 0.0; } - u[(j * rowsA) + j] = 1.0; + u[(j*rowsA) + j] = 1.0; } for (l = nct - 1; l >= 0; l--) @@ -2323,37 +2324,37 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t = 0.0; for (i = l; i < rowsA; i++) { - t += u[(j * rowsA) + i] * u[(l * rowsA) + i]; + t += u[(j*rowsA) + i]*u[(l*rowsA) + i]; } - t = -t / u[(l * rowsA) + l]; + t = -t/u[(l*rowsA) + l]; for (var ii = l; ii < rowsA; ii++) { - u[(j * rowsA) + ii] += t * u[(l * rowsA) + ii]; + u[(j*rowsA) + ii] += t*u[(l*rowsA) + ii]; } } // A part of column "l" of matrix A from row "l" to end multiply by -1.0 for (i = l; i < rowsA; i++) { - u[(l * rowsA) + i] = u[(l * rowsA) + i] * -1.0; + u[(l*rowsA) + i] = u[(l*rowsA) + i]*-1.0; } - u[(l * rowsA) + l] = 1.0 + u[(l * rowsA) + l]; + u[(l*rowsA) + l] = 1.0 + u[(l*rowsA) + l]; for (i = 0; i < l; i++) { - u[(l * rowsA) + i] = 0.0; + u[(l*rowsA) + i] = 0.0; } } else { for (i = 0; i < rowsA; i++) { - u[(l * rowsA) + i] = 0.0; + u[(l*rowsA) + i] = 0.0; } - u[(l * rowsA) + l] = 1.0; + u[(l*rowsA) + l] = 1.0; } } } @@ -2373,13 +2374,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t = 0.0; for (i = lp1; i < columnsA; i++) { - t += v[(j * columnsA) + i] * v[(l * columnsA) + i]; + t += v[(j*columnsA) + i]*v[(l*columnsA) + i]; } - t = -t / v[(l * columnsA) + lp1]; + t = -t/v[(l*columnsA) + lp1]; for (var ii = l; ii < columnsA; ii++) { - v[(j * columnsA) + ii] += t * v[(l * columnsA) + ii]; + v[(j*columnsA) + ii] += t*v[(l*columnsA) + ii]; } } } @@ -2387,10 +2388,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (i = 0; i < columnsA; i++) { - v[(l * columnsA) + i] = 0.0; + v[(l*columnsA) + i] = 0.0; } - v[(l * columnsA) + l] = 1.0; + v[(l*columnsA) + l] = 1.0; } } @@ -2401,11 +2402,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (stemp[i] != 0.0) { t = stemp[i]; - r = stemp[i] / t; + r = stemp[i]/t; stemp[i] = t; if (i < m - 1) { - e[i] = e[i] / r; + e[i] = e[i]/r; } if (computeVectors) @@ -2413,7 +2414,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // A part of column "i" of matrix U from row 0 to end multiply by r for (j = 0; j < rowsA; j++) { - u[(i * rowsA) + j] = u[(i * rowsA) + j] * r; + u[(i*rowsA) + j] = u[(i*rowsA) + j]*r; } } } @@ -2430,9 +2431,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra } t = e[i]; - r = t / e[i]; + r = t/e[i]; e[i] = t; - stemp[i + 1] = stemp[i + 1] * r; + stemp[i + 1] = stemp[i + 1]*r; if (!computeVectors) { continue; @@ -2441,7 +2442,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // A part of column "i+1" of matrix VT from row 0 to end multiply by r for (j = 0; j < columnsA; j++) { - v[((i + 1) * columnsA) + j] = v[((i + 1) * columnsA) + j] * r; + v[((i + 1)*columnsA) + j] = v[((i + 1)*columnsA) + j]*r; } } @@ -2542,8 +2543,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra stemp[k] = t1; if (k != l) { - f = -sn * e[k - 1]; - e[k - 1] = cs * e[k - 1]; + f = -sn*e[k - 1]; + e[k - 1] = cs*e[k - 1]; } if (computeVectors) @@ -2551,16 +2552,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Rotate for (i = 0; i < columnsA; i++) { - var z = (cs * v[(k * columnsA) + i]) + (sn * v[((m - 1) * columnsA) + i]); - v[((m - 1) * columnsA) + i] = (cs * v[((m - 1) * columnsA) + i]) - (sn * v[(k * columnsA) + i]); - v[(k * columnsA) + i] = z; + var z = (cs*v[(k*columnsA) + i]) + (sn*v[((m - 1)*columnsA) + i]); + v[((m - 1)*columnsA) + i] = (cs*v[((m - 1)*columnsA) + i]) - (sn*v[(k*columnsA) + i]); + v[(k*columnsA) + i] = z; } } } break; - // Split at negligible s[l]. + // Split at negligible s[l]. case 2: f = e[l - 1]; e[l - 1] = 0.0; @@ -2569,16 +2570,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t1 = stemp[k]; Drotg(ref t1, ref f, ref cs, ref sn); stemp[k] = t1; - f = -sn * e[k]; - e[k] = cs * e[k]; + f = -sn*e[k]; + e[k] = cs*e[k]; if (computeVectors) { // Rotate for (i = 0; i < rowsA; i++) { - var z = (cs * u[(k * rowsA) + i]) + (sn * u[((l - 1) * rowsA) + i]); - u[((l - 1) * rowsA) + i] = (cs * u[((l - 1) * rowsA) + i]) - (sn * u[(k * rowsA) + i]); - u[(k * rowsA) + i] = z; + var z = (cs*u[(k*rowsA) + i]) + (sn*u[((l - 1)*rowsA) + i]); + u[((l - 1)*rowsA) + i] = (cs*u[((l - 1)*rowsA) + i]) - (sn*u[(k*rowsA) + i]); + u[(k*rowsA) + i] = z; } } } @@ -2595,27 +2596,27 @@ namespace MathNet.Numerics.Providers.LinearAlgebra scale = Math.Max(scale, Math.Abs(e[m - 2])); scale = Math.Max(scale, Math.Abs(stemp[l])); scale = Math.Max(scale, Math.Abs(e[l])); - var sm = stemp[m - 1] / scale; - var smm1 = stemp[m - 2] / scale; - var emm1 = e[m - 2] / scale; - var sl = stemp[l] / scale; - var el = e[l] / scale; - var b = (((smm1 + sm) * (smm1 - sm)) + (emm1 * emm1)) / 2.0; - var c = (sm * emm1) * (sm * emm1); + var sm = stemp[m - 1]/scale; + var smm1 = stemp[m - 2]/scale; + var emm1 = e[m - 2]/scale; + var sl = stemp[l]/scale; + var el = e[l]/scale; + var b = (((smm1 + sm)*(smm1 - sm)) + (emm1*emm1))/2.0; + var c = (sm*emm1)*(sm*emm1); var shift = 0.0; if (b != 0.0 || c != 0.0) { - shift = Math.Sqrt((b * b) + c); + shift = Math.Sqrt((b*b) + c); if (b < 0.0) { shift = -shift; } - shift = c / (b + shift); + shift = c/(b + shift); } - f = ((sl + sm) * (sl - sm)) + shift; - var g = sl * el; + f = ((sl + sm)*(sl - sm)) + shift; + var g = sl*el; // Chase zeros for (k = l; k < m - 1; k++) @@ -2626,33 +2627,33 @@ namespace MathNet.Numerics.Providers.LinearAlgebra e[k - 1] = f; } - f = (cs * stemp[k]) + (sn * e[k]); - e[k] = (cs * e[k]) - (sn * stemp[k]); - g = sn * stemp[k + 1]; - stemp[k + 1] = cs * stemp[k + 1]; + f = (cs*stemp[k]) + (sn*e[k]); + e[k] = (cs*e[k]) - (sn*stemp[k]); + g = sn*stemp[k + 1]; + stemp[k + 1] = cs*stemp[k + 1]; if (computeVectors) { for (i = 0; i < columnsA; i++) { - var z = (cs * v[(k * columnsA) + i]) + (sn * v[((k + 1) * columnsA) + i]); - v[((k + 1) * columnsA) + i] = (cs * v[((k + 1) * columnsA) + i]) - (sn * v[(k * columnsA) + i]); - v[(k * columnsA) + i] = z; + var z = (cs*v[(k*columnsA) + i]) + (sn*v[((k + 1)*columnsA) + i]); + v[((k + 1)*columnsA) + i] = (cs*v[((k + 1)*columnsA) + i]) - (sn*v[(k*columnsA) + i]); + v[(k*columnsA) + i] = z; } } Drotg(ref f, ref g, ref cs, ref sn); stemp[k] = f; - f = (cs * e[k]) + (sn * stemp[k + 1]); - stemp[k + 1] = -(sn * e[k]) + (cs * stemp[k + 1]); - g = sn * e[k + 1]; - e[k + 1] = cs * e[k + 1]; + f = (cs*e[k]) + (sn*stemp[k + 1]); + stemp[k + 1] = -(sn*e[k]) + (cs*stemp[k + 1]); + g = sn*e[k + 1]; + e[k + 1] = cs*e[k + 1]; if (computeVectors && k < rowsA) { for (i = 0; i < rowsA; i++) { - var z = (cs * u[(k * rowsA) + i]) + (sn * u[((k + 1) * rowsA) + i]); - u[((k + 1) * rowsA) + i] = (cs * u[((k + 1) * rowsA) + i]) - (sn * u[(k * rowsA) + i]); - u[(k * rowsA) + i] = z; + var z = (cs*u[(k*rowsA) + i]) + (sn*u[((k + 1)*rowsA) + i]); + u[((k + 1)*rowsA) + i] = (cs*u[((k + 1)*rowsA) + i]) - (sn*u[(k*rowsA) + i]); + u[(k*rowsA) + i] = z; } } } @@ -2673,7 +2674,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // A part of column "l" of matrix VT from row 0 to end multiply by -1 for (i = 0; i < columnsA; i++) { - v[(l * columnsA) + i] = v[(l * columnsA) + i] * -1.0; + v[(l*columnsA) + i] = v[(l*columnsA) + i]*-1.0; } } } @@ -2694,9 +2695,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Swap columns l, l + 1 for (i = 0; i < columnsA; i++) { - var z = v[(l * columnsA) + i]; - v[(l * columnsA) + i] = v[((l + 1) * columnsA) + i]; - v[((l + 1) * columnsA) + i] = z; + var z = v[(l*columnsA) + i]; + v[(l*columnsA) + i] = v[((l + 1)*columnsA) + i]; + v[((l + 1)*columnsA) + i] = z; } } @@ -2705,9 +2706,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Swap columns l, l + 1 for (i = 0; i < rowsA; i++) { - var z = u[(l * rowsA) + i]; - u[(l * rowsA) + i] = u[((l + 1) * rowsA) + i]; - u[((l + 1) * rowsA) + i] = z; + var z = u[(l*rowsA) + i]; + u[(l*rowsA) + i] = u[((l + 1)*rowsA) + i]; + u[((l + 1)*rowsA) + i] = z; } } @@ -2727,7 +2728,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (j = 0; j < columnsA; j++) { - vt[(j * columnsA) + i] = v[(i * columnsA) + j]; + vt[(j*columnsA) + i] = v[(i*columnsA) + j]; } } } @@ -2735,7 +2736,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Copy stemp to s with size adjustment. We are using ported copy of linpack's svd code and it uses // a singular vector of length rows+1 when rows < columns. The last element is not used and needs to be removed. // We should port lapack's svd routine to remove this problem. - Buffer.BlockCopy(stemp, 0, s, 0, Math.Min(rowsA, columnsA) * Constants.SizeOfDouble); + Buffer.BlockCopy(stemp, 0, s, 0, Math.Min(rowsA, columnsA)*Constants.SizeOfDouble); // On return the first element of the work array stores the min size of the work array could have been // work[0] = Math.Max(3 * Math.Min(aRows, aColumns) + Math.Max(aRows, aColumns), 5 * Math.Min(aRows, aColumns)); @@ -2751,7 +2752,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// Contains the parameter c associated with the Givens rotation /// Contains the parameter s associated with the Givens rotation /// This is equivalent to the DROTG LAPACK routine. - private static void Drotg(ref double da, ref double db, ref double c, ref double s) + static void Drotg(ref double da, ref double db, ref double c, ref double s) { double r, z; @@ -2773,16 +2774,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra } else { - var sda = da / scale; - var sdb = db / scale; - r = scale * Math.Sqrt((sda * sda) + (sdb * sdb)); + var sda = da/scale; + var sdb = db/scale; + r = scale*Math.Sqrt((sda*sda) + (sdb*sdb)); if (roe < 0.0) { r = -r; } - c = da / r; - s = db / r; + c = da/r; + s = db/r; z = 1.0; if (absda > absdb) { @@ -2791,7 +2792,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (absdb >= absda && c != 0.0) { - z = 1.0 / c; + z = 1.0/c; } } @@ -2825,23 +2826,23 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } var work = new double[rowsA]; var s = new double[Math.Min(rowsA, columnsA)]; - var u = new double[rowsA * rowsA]; - var vt = new double[columnsA * columnsA]; + var u = new double[rowsA*rowsA]; + var vt = new double[columnsA*columnsA]; var clone = new double[a.Length]; - Buffer.BlockCopy(a, 0, clone, 0, a.Length * Constants.SizeOfDouble); + Buffer.BlockCopy(a, 0, clone, 0, a.Length*Constants.SizeOfDouble); SingularValueDecomposition(true, clone, rowsA, columnsA, s, u, vt, work); SvdSolveFactored(rowsA, columnsA, s, u, vt, b, columnsB, x); } @@ -2884,12 +2885,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("x"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -2899,12 +2900,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -2921,7 +2922,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var i = 0; i < rowsA; i++) { - value += u[(j * rowsA) + i] * b[(k * rowsA) + i]; + value += u[(j*rowsA) + i]*b[(k*rowsA) + i]; } value /= s[j]; @@ -2935,10 +2936,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra double value = 0; for (var i = 0; i < columnsA; i++) { - value += vt[(j * columnsA) + i] * tmp[i]; + value += vt[(j*columnsA) + i]*tmp[i]; } - x[(k * columnsA) + j] = value; + x[(k*columnsA) + j] = value; } } } @@ -2954,27 +2955,27 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// On output, the block diagonal eigenvalue matrix. The lenth of the array must be order * order. public virtual void EigenDecomp(bool isSymmetric, int order, double[] matrix, double[] matrixEv, Complex[] vectorEv, double[] matrixD) { - if (matrix == null) + if (matrix == null) { throw new ArgumentNullException("matrix"); } - if (matrix.Length != order * order ) + if (matrix.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrix"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrix"); } - - if (matrixEv == null) + + if (matrixEv == null) { throw new ArgumentNullException("matrixEv"); } - if (matrixEv.Length != order * order ) + if (matrixEv.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrixEv"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrixEv"); } - if (vectorEv == null) + if (vectorEv == null) { throw new ArgumentNullException("vectorEv"); } @@ -2984,14 +2985,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order), "vectorEv"); } - if (matrixD == null) + if (matrixD == null) { throw new ArgumentNullException("matrixD"); } - if (matrixD.Length != order * order ) + if (matrixD.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrixD"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrixD"); } var d = new double[order]; @@ -2999,7 +3000,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (isSymmetric) { - Buffer.BlockCopy(matrix, 0, matrixEv, 0, matrix.Length * Constants.SizeOfDouble); + Buffer.BlockCopy(matrix, 0, matrixEv, 0, matrix.Length*Constants.SizeOfDouble); var om1 = order - 1; for (var i = 0; i < order; i++) { @@ -3012,7 +3013,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra else { var matrixH = new double[matrix.Length]; - Buffer.BlockCopy(matrix, 0, matrixH, 0, matrix.Length * Constants.SizeOfDouble); + Buffer.BlockCopy(matrix, 0, matrixH, 0, matrix.Length*Constants.SizeOfDouble); Numerics.LinearAlgebra.Double.Factorization.DenseEvd.NonsymmetricReduceToHessenberg(matrixEv, matrixH, order); Numerics.LinearAlgebra.Double.Factorization.DenseEvd.NonsymmetricReduceHessenberToRealSchur(matrixEv, matrixH, d, e, order); } @@ -3021,13 +3022,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { vectorEv[i] = new Complex(d[i], e[i]); - var io = i * order; + var io = i*order; matrixD[io + i] = d[i]; if (e[i] > 0) { matrixD[io + order + i] = e[i]; - matrixD[(i+1) * order + i] = e[i]; + matrixD[(i + 1)*order + i] = e[i]; } else if (e[i] < 0) { diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs index bcb62187..7a581001 100644 --- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs +++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs @@ -110,7 +110,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = y[index] + (alpha * x[index]); + result[index] = y[index] + (alpha*x[index]); } } } @@ -154,7 +154,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = alpha * x[index]; + result[index] = alpha*x[index]; } } } @@ -188,7 +188,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var index = 0; index < y.Length; index++) { - sum += y[index] * x[index]; + sum += y[index]*x[index]; } return sum; @@ -342,7 +342,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = x[index] * y[index]; + result[index] = x[index]*y[index]; } } } @@ -393,11 +393,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var index = 0; index < x.Length; index++) { - result[index] = x[index] / y[index]; + result[index] = x[index]/y[index]; } } } - + /// /// Computes the requested of the matrix. /// @@ -419,7 +419,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var s = 0.0; for (var i = 0; i < rows; i++) { - s += Math.Abs(matrix[(j * rows) + i]); + s += Math.Abs(matrix[(j*rows) + i]); } ret = Math.Max(ret, s); @@ -432,7 +432,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var j = 0; j < columns; j++) { - ret = Math.Max(Math.Abs(matrix[(j * rows) + i]), ret); + ret = Math.Max(Math.Abs(matrix[(j*rows) + i]), ret); } } @@ -443,7 +443,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var s = 0.0; for (var j = 0; j < columns; j++) { - s += Math.Abs(matrix[(j * rows) + i]); + s += Math.Abs(matrix[(j*rows) + i]); } ret = Math.Max(ret, s); @@ -451,12 +451,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra break; case Norm.FrobeniusNorm: - var aat = new float[rows * rows]; + var aat = new float[rows*rows]; MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.Transpose, 1.0f, matrix, rows, columns, matrix, rows, columns, 0.0f, aat); for (var i = 0; i < rows; i++) { - ret += Math.Abs(aat[(i * rows) + i]); + ret += Math.Abs(aat[(i*rows) + i]); } ret = Math.Sqrt(ret); @@ -465,7 +465,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra return Convert.ToSingle(ret); } - + /// /// Computes the requested of the matrix. /// @@ -513,12 +513,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("result"); } - if (rowsX * columnsX != x.Length) + if (rowsX*columnsX != x.Length) { throw new ArgumentException("x.Length != xRows * xColumns"); } - if (rowsY * columnsY != y.Length) + if (rowsY*columnsY != y.Length) { throw new ArgumentException("y.Length != yRows * yColumns"); } @@ -528,7 +528,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException("xColumns != yRows"); } - if (rowsX * columnsY != result.Length) + if (rowsX*columnsY != result.Length) { throw new ArgumentException("xRows * yColumns != result.Length"); } @@ -539,7 +539,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float[] xdata; if (ReferenceEquals(x, result)) { - xdata = (float[])x.Clone(); + xdata = (float[]) x.Clone(); } else { @@ -549,7 +549,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float[] ydata; if (ReferenceEquals(y, result)) { - ydata = (float[])y.Clone(); + ydata = (float[]) y.Clone(); } else { @@ -590,14 +590,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if ((int)transposeA > 111 && (int)transposeB > 111) + if ((int) transposeA > 111 && (int) transposeB > 111) { if (rowsA != columnsB) { throw new ArgumentOutOfRangeException(); } - if (columnsA * rowsB != c.Length) + if (columnsA*rowsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -606,14 +606,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra n = rowsB; k = rowsA; } - else if ((int)transposeA > 111) + else if ((int) transposeA > 111) { if (rowsA != rowsB) { throw new ArgumentOutOfRangeException(); } - if (columnsA * columnsB != c.Length) + if (columnsA*columnsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -622,14 +622,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra n = columnsB; k = rowsA; } - else if ((int)transposeB > 111) + else if ((int) transposeB > 111) { if (columnsA != columnsB) { throw new ArgumentOutOfRangeException(); } - if (rowsA * rowsB != c.Length) + if (rowsA*rowsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -645,7 +645,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentOutOfRangeException(); } - if (rowsA * columnsB != c.Length) + if (rowsA*columnsB != c.Length) { throw new ArgumentOutOfRangeException(); } @@ -667,7 +667,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float[] adata; if (ReferenceEquals(a, c)) { - adata = (float[])a.Clone(); + adata = (float[]) a.Clone(); } else { @@ -677,7 +677,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float[] bdata; if (ReferenceEquals(b, c)) { - bdata = (float[])b.Clone(); + bdata = (float[]) b.Clone(); } else { @@ -723,11 +723,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The constant number of columns of matrix op(B) and of the matrix C. /// The constant number of columns of matrix op(A) and the rows of the matrix op(B). /// Indicates if this is the first recursion. - private static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, float alpha, float[] matrixA, int shiftArow, int shiftAcol, float[] matrixB, int shiftBrow, int shiftBcol, float[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first) + static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, float alpha, float[] matrixA, int shiftArow, int shiftAcol, float[] matrixB, int shiftBrow, int shiftBcol, float[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first) { if (m + n <= Control.ParallelizeOrder) { - if ((int)transposeA > 111 && (int)transposeB > 111) + if ((int) transposeA > 111 && (int) transposeB > 111) { for (var m1 = 0; m1 < m; m1++) { @@ -739,15 +739,15 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float sum = 0; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol] * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos]; + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol]* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } - else if ((int)transposeA > 111) + else if ((int) transposeA > 111) { for (var m1 = 0; m1 < m; m1++) { @@ -759,15 +759,15 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float sum = 0; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[(matArowPos * constK) + k1 + shiftAcol] * - matrixB[(matBcolPos * constK) + k1 + shiftBrow]; + sum += matrixA[(matArowPos*constK) + k1 + shiftAcol]* + matrixB[(matBcolPos*constK) + k1 + shiftBrow]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } - else if ((int)transposeB > 111) + else if ((int) transposeB > 111) { for (var m1 = 0; m1 < m; m1++) { @@ -779,11 +779,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float sum = 0; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[((k1 + shiftAcol) * constM) + matArowPos] * - matrixB[((k1 + shiftBrow) * constN) + matBcolPos]; + sum += matrixA[((k1 + shiftAcol)*constM) + matArowPos]* + matrixB[((k1 + shiftBrow)*constN) + matBcolPos]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } @@ -799,11 +799,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float sum = 0; for (var k1 = 0; k1 < k; ++k1) { - sum += matrixA[((k1 + shiftAcol) * constM) + matArowPos] * - matrixB[(matBcolPos * constK) + k1 + shiftBrow]; + sum += matrixA[((k1 + shiftAcol)*constM) + matArowPos]* + matrixB[(matBcolPos*constK) + k1 + shiftBrow]; } - result[((n1 + shiftCcol) * constM) + matCrowPos] += alpha * sum; + result[((n1 + shiftCcol)*constM) + matCrowPos] += alpha*sum; } } } @@ -811,7 +811,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra else { // divide and conquer - int m2 = m / 2, n2 = n / 2, k2 = k / 2; + int m2 = m/2, n2 = n/2, k2 = k/2; if (first) { @@ -865,7 +865,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -886,7 +886,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Outer loop. for (var j = 0; j < order; j++) { - var indexj = j * order; + var indexj = j*order; var indexjj = indexj + j; // Make a copy of the j-th column to localize references. @@ -903,7 +903,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var s = 0.0f; for (var k = 0; k < kmax; k++) { - s += data[(k * order) + i] * vecLUcolj[k]; + s += data[(k*order) + i]*vecLUcolj[k]; } data[indexj + i] = vecLUcolj[i] -= s; @@ -923,7 +923,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var k = 0; k < order; k++) { - var indexk = k * order; + var indexk = k*order; var indexkp = indexk + p; var indexkj = indexk + j; var temp = data[indexkp]; @@ -958,7 +958,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -987,7 +987,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -1000,7 +1000,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var inverse = new float[a.Length]; for (var i = 0; i < order; i++) { - inverse[i + (order * i)] = 1.0f; + inverse[i + (order*i)] = 1.0f; } LUSolveFactored(order, a, order, ipiv, inverse); @@ -1056,12 +1056,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != order * columnsOfB) + if (b.Length != order*columnsOfB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1104,7 +1104,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -1114,11 +1114,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != order * columnsOfB) + if (b.Length != order*columnsOfB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - + if (ReferenceEquals(a, b)) { throw new ArgumentException(Resources.ArgumentReferenceDifferent); @@ -1135,7 +1135,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var p = ipiv[i]; for (var j = 0; j < columnsOfB; j++) { - var indexk = j * order; + var indexk = j*order; var indexkp = indexk + p; var indexkj = indexk + i; var temp = b[indexkp]; @@ -1147,13 +1147,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Solve L*Y = P*B for (var k = 0; k < order; k++) { - var korder = k * order; + var korder = k*order; for (var i = k + 1; i < order; i++) { for (var j = 0; j < columnsOfB; j++) { - var index = j * order; - b[i + index] -= b[k + index] * a[i + korder]; + var index = j*order; + b[i + index] -= b[k + index]*a[i + korder]; } } } @@ -1161,19 +1161,19 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Solve U*X = Y; for (var k = order - 1; k >= 0; k--) { - var korder = k + (k * order); + var korder = k + (k*order); for (var j = 0; j < columnsOfB; j++) { - b[k + (j * order)] /= a[korder]; + b[k + (j*order)] /= a[korder]; } - korder = k * order; + korder = k*order; for (var i = 0; i < k; i++) { for (var j = 0; j < columnsOfB; j++) { - var index = j * order; - b[i + index] -= b[k + index] * a[i + korder]; + var index = j*order; + b[i + index] -= b[k + index]*a[i + korder]; } } } @@ -1199,20 +1199,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var ij = 0; ij < order; ij++) { // "Pivot" element - var tmpVal = a[(ij * order) + ij]; + var tmpVal = a[(ij*order) + ij]; if (tmpVal > 0.0) { - tmpVal = (float)Math.Sqrt(tmpVal); - a[(ij * order) + ij] = tmpVal; + tmpVal = (float) Math.Sqrt(tmpVal); + a[(ij*order) + ij] = tmpVal; tmpColumn[ij] = tmpVal; // Calculate multipliers and copy to local column // Current column, below the diagonal for (var i = ij + 1; i < order; i++) { - a[(ij * order) + i] /= tmpVal; - tmpColumn[i] = a[(ij * order) + i]; + a[(ij*order) + i] /= tmpVal; + tmpColumn[i] = a[(ij*order) + i]; } // Remaining columns, below the diagonal @@ -1225,7 +1225,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (int i = ij + 1; i < order; i++) { - a[(i * order) + ij] = 0.0f; + a[(i*order) + ij] = 0.0f; } } } @@ -1239,14 +1239,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// Total columns /// Multipliers calculated previously /// Number of available processors - private static void DoCholeskyStep(float[] data, int rowDim, int firstCol, int colLimit, float[] multipliers, int availableCores) + static void DoCholeskyStep(float[] data, int rowDim, int firstCol, int colLimit, float[] multipliers, int availableCores) { var tmpColCount = colLimit - firstCol; if ((availableCores > 1) && (tmpColCount > Control.ParallelizeElements)) { - var tmpSplit = firstCol + (tmpColCount / 3); - var tmpCores = availableCores / 2; + var tmpSplit = firstCol + (tmpColCount/3); + var tmpCores = availableCores/2; CommonParallel.Invoke( () => DoCholeskyStep(data, rowDim, firstCol, tmpSplit, multipliers, tmpCores), @@ -1259,7 +1259,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var tmpVal = multipliers[j]; for (var i = j; i < rowDim; i++) { - data[(j * rowDim) + i] -= multipliers[i] * tmpVal; + data[(j*rowDim) + i] -= multipliers[i]*tmpVal; } } } @@ -1285,7 +1285,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1321,7 +1321,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -1347,9 +1347,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The number of rows and columns in A. /// On entry the B matrix; on exit the X matrix. /// The column to solve for. - private static void DoCholeskySolve(float[] a, int orderA, float[] b, int index) + static void DoCholeskySolve(float[] a, int orderA, float[] b, int index) { - var cindex = index * orderA; + var cindex = index*orderA; // Solve L*Y = B; float sum; @@ -1358,23 +1358,23 @@ namespace MathNet.Numerics.Providers.LinearAlgebra sum = b[cindex + i]; for (var k = i - 1; k >= 0; k--) { - sum -= a[(k * orderA) + i] * b[cindex + k]; + sum -= a[(k*orderA) + i]*b[cindex + k]; } - b[cindex + i] = sum / a[(i * orderA) + i]; + b[cindex + i] = sum/a[(i*orderA) + i]; } // Solve L'*X = Y; for (var i = orderA - 1; i >= 0; i--) { sum = b[cindex + i]; - var iindex = i * orderA; + var iindex = i*orderA; for (var k = i + 1; k < orderA; k++) { - sum -= a[iindex + k] * b[cindex + k]; + sum -= a[iindex + k]*b[cindex + k]; } - b[cindex + i] = sum / a[iindex + i]; + b[cindex + i] = sum/a[iindex + i]; } } @@ -1402,7 +1402,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -1412,12 +1412,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = columnsR > rowsR ? new float[rowsR * rowsR] : new float[rowsR * columnsR]; + var work = columnsR > rowsR ? new float[rowsR*rowsR] : new float[rowsR*columnsR]; QRFactor(r, rowsR, columnsR, q, tau, work); } @@ -1453,7 +1453,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -1463,24 +1463,24 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } if (columnsR > rowsR) { - if (work.Length < rowsR * rowsR) + if (work.Length < rowsR*rowsR) { - work[0] = rowsR * rowsR; + work[0] = rowsR*rowsR; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } } else { - if (work.Length < rowsR * columnsR) + if (work.Length < rowsR*columnsR) { - work[0] = rowsR * columnsR; + work[0] = rowsR*columnsR; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } } @@ -1505,7 +1505,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ComputeQR(work, i, q, i, rowsR, i, rowsR, Control.NumberOfParallelWorkerThreads); } - work[0] = columnsR > rowsR ? rowsR * rowsR : rowsR * columnsR; + work[0] = columnsR > rowsR ? rowsR*rowsR : rowsR*columnsR; } /// @@ -1532,7 +1532,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("a"); } - if (a.Length != rowsA * columnsA) + if (a.Length != rowsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "a"); } @@ -1542,12 +1542,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (r.Length != columnsA * columnsA) + if (r.Length != columnsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "columnsA * columnsA"), "r"); } - var work = new float[rowsA * columnsA]; + var work = new float[rowsA*columnsA]; ThinQRFactor(a, rowsA, columnsA, r, tau, work); } @@ -1583,7 +1583,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("q"); } - if (a.Length != rowsA * columnsA) + if (a.Length != rowsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "a"); } @@ -1593,14 +1593,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (r.Length != columnsA * columnsA) + if (r.Length != columnsA*columnsA) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "columnsA * columnsA"), "r"); } - if (work.Length < rowsA * columnsA) + if (work.Length < rowsA*columnsA) { - work[0] = rowsA * columnsA; + work[0] = rowsA*columnsA; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -1614,8 +1614,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra //copy R for (var j = 0; j < columnsA; j++) { - var rIndex = j * columnsA; - var aIndex = j * rowsA; + var rIndex = j*columnsA; + var aIndex = j*rowsA; for (var i = 0; i < columnsA; i++) { r[rIndex + i] = a[aIndex + i]; @@ -1626,7 +1626,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra Array.Clear(a, 0, a.Length); for (var i = 0; i < columnsA; i++) { - a[i * rowsA + i] = 1.0f; + a[i*rowsA + i] = 1.0f; } for (var i = minmn - 1; i >= 0; i--) @@ -1634,7 +1634,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra ComputeQR(work, i, a, i, rowsA, i, columnsA, Control.NumberOfParallelWorkerThreads); } - work[0] = rowsA * columnsA; + work[0] = rowsA*columnsA; } @@ -1651,7 +1651,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The first column /// The last column /// Number of available CPUs - private static void ComputeQR(float[] work, int workIndex, float[] a, int rowStart, int rowCount, int columnStart, int columnCount, int availableCores) + static void ComputeQR(float[] work, int workIndex, float[] a, int rowStart, int rowCount, int columnStart, int columnCount, int availableCores) { if (rowStart > rowCount || columnStart > columnCount) { @@ -1662,8 +1662,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if ((availableCores > 1) && (tmpColCount > 200)) { - var tmpSplit = columnStart + (tmpColCount / 2); - var tmpCores = availableCores / 2; + var tmpSplit = columnStart + (tmpColCount/2); + var tmpCores = availableCores/2; CommonParallel.Invoke( () => ComputeQR(work, workIndex, a, rowStart, rowCount, columnStart, tmpSplit, tmpCores), @@ -1676,12 +1676,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var scale = 0.0f; for (var i = rowStart; i < rowCount; i++) { - scale += work[(workIndex * rowCount) + i - rowStart] * a[(j * rowCount) + i]; + scale += work[(workIndex*rowCount) + i - rowStart]*a[(j*rowCount) + i]; } for (var i = rowStart; i < rowCount; i++) { - a[(j * rowCount) + i] -= work[(workIndex * rowCount) + i - rowStart] * scale; + a[(j*rowCount) + i] -= work[(workIndex*rowCount) + i - rowStart]*scale; } } } @@ -1695,9 +1695,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// The number of rows in matrix /// The first row /// Column index - private static void GenerateColumn(float[] work, float[] a, int rowCount, int row, int column) + static void GenerateColumn(float[] work, float[] a, int rowCount, int row, int column) { - var tmp = column * rowCount; + var tmp = column*rowCount; var index = tmp + row; CommonParallel.For(row, rowCount, (u, v) => @@ -1714,24 +1714,24 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (var i = 0; i < rowCount - row; ++i) { var iindex = tmp + i; - norm += work[iindex] * work[iindex]; + norm += work[iindex]*work[iindex]; } norm = Math.Sqrt(norm); if (row == rowCount - 1 || norm == 0) { a[index] = -work[tmp]; - work[tmp] = (float)Math.Sqrt(2.0); + work[tmp] = (float) Math.Sqrt(2.0); return; } - var scale = 1.0f / (float)norm; + var scale = 1.0f/(float) norm; if (work[tmp] < 0.0) { scale *= -1.0f; } - a[index] = -1.0f / scale; + a[index] = -1.0f/scale; CommonParallel.For(0, rowCount - row, 4096, (u, v) => { for (int i = u; i < v; i++) @@ -1741,7 +1741,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra }); work[tmp] += 1.0f; - var s = (float)Math.Sqrt(1.0 / work[tmp]); + var s = (float) Math.Sqrt(1.0/work[tmp]); CommonParallel.For(0, rowCount - row, 4096, (u, v) => { for (int i = u; i < v; i++) @@ -1766,7 +1766,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// Rows must be greater or equal to columns. public virtual void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x, QRMethod method = QRMethod.Full) { - var work = new float[rows * columns]; + var work = new float[rows*columns]; QRSolve(a, rows, columns, b, columnsB, x, work, method); } @@ -1806,17 +1806,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -1826,9 +1826,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(Resources.RowsLessThanColumns); } - if (work.Length < rows * columns) + if (work.Length < rows*columns) { - work[0] = rows * columns; + work[0] = rows*columns; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -1837,18 +1837,18 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (method == QRMethod.Full) { - var q = new float[rows * rows]; + var q = new float[rows*rows]; QRFactor(clone, rows, columns, q, work); QRSolveFactored(q, clone, rows, columns, null, b, columnsB, x, method); } else { - var r = new float[columns * columns]; + var r = new float[columns*columns]; ThinQRFactor(clone, rows, columns, r, work); QRSolveFactored(clone, r, rows, columns, null, b, columnsB, x, method); } - work[0] = rows * columns; + work[0] = rows*columns; } /// @@ -1956,7 +1956,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var column = new float[rowsA]; for (var j = 0; j < columnsB; j++) { - var jm = j * rowsA; + var jm = j*rowsA; Array.Copy(sol, jm, column, 0, rowsA); CommonParallel.For(0, columnsA, (u, v) => { @@ -1997,7 +1997,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Fill result matrix for (var col = 0; col < columnsB; col++) { - Array.Copy(sol, col * rowsA, x, col * columnsA, columnsR); + Array.Copy(sol, col*rowsA, x, col*columnsA, columnsR); } } @@ -2036,12 +2036,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -2096,12 +2096,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -2154,25 +2154,25 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var sum = 0.0f; for (var i1 = l; i1 < rowsA; i1++) { - sum += a[(l1 * rowsA) + i1] * a[(l1 * rowsA) + i1]; + sum += a[(l1*rowsA) + i1]*a[(l1*rowsA) + i1]; } - - stemp[l] = (float)Math.Sqrt(sum); + + stemp[l] = (float) Math.Sqrt(sum); if (stemp[l] != 0.0) { - if (a[(l * rowsA) + l] != 0.0) + if (a[(l*rowsA) + l] != 0.0) { - stemp[l] = Math.Abs(stemp[l]) * (a[(l * rowsA) + l] / Math.Abs(a[(l * rowsA) + l])); + stemp[l] = Math.Abs(stemp[l])*(a[(l*rowsA) + l]/Math.Abs(a[(l*rowsA) + l])); } // A part of column "l" of Matrix A from row "l" to end multiply by 1.0 / s[l] for (i = l; i < rowsA; i++) { - a[(l * rowsA) + i] = a[(l * rowsA) + i] * (1.0f / stemp[l]); + a[(l*rowsA) + i] = a[(l*rowsA) + i]*(1.0f/stemp[l]); } - a[(l * rowsA) + l] = 1.0f + a[(l * rowsA) + l]; + a[(l*rowsA) + l] = 1.0f + a[(l*rowsA) + l]; } stemp[l] = -stemp[l]; @@ -2188,21 +2188,21 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t = 0.0f; for (i = l; i < rowsA; i++) { - t += a[(j * rowsA) + i] * a[(l * rowsA) + i]; + t += a[(j*rowsA) + i]*a[(l*rowsA) + i]; } - t = -t / a[(l * rowsA) + l]; + t = -t/a[(l*rowsA) + l]; for (var ii = l; ii < rowsA; ii++) { - a[(j * rowsA) + ii] += t * a[(l * rowsA) + ii]; + a[(j*rowsA) + ii] += t*a[(l*rowsA) + ii]; } } } // Place the l-th row of matrix into "e" for the // subsequent calculation of the row transformation. - e[j] = a[(j * rowsA) + l]; + e[j] = a[(j*rowsA) + l]; } if (computeVectors && l < nct) @@ -2210,7 +2210,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Place the transformation in "u" for subsequent back multiplication. for (i = l; i < rowsA; i++) { - u[(l * rowsA) + i] = a[(l * rowsA) + i]; + u[(l*rowsA) + i] = a[(l*rowsA) + i]; } } @@ -2223,21 +2223,21 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var enorm = 0.0; for (i = lp1; i < e.Length; i++) { - enorm += e[i] * e[i]; + enorm += e[i]*e[i]; } - e[l] = (float)Math.Sqrt(enorm); + e[l] = (float) Math.Sqrt(enorm); if (e[l] != 0.0) { if (e[lp1] != 0.0) { - e[l] = Math.Abs(e[l]) * (e[lp1] / Math.Abs(e[lp1])); + e[l] = Math.Abs(e[l])*(e[lp1]/Math.Abs(e[lp1])); } // Scale vector "e" from "lp1" by 1.0 / e[l] for (i = lp1; i < e.Length; i++) { - e[i] = e[i] * (1.0f / e[l]); + e[i] = e[i]*(1.0f/e[l]); } e[lp1] = 1.0f + e[lp1]; @@ -2257,16 +2257,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var ii = lp1; ii < rowsA; ii++) { - work[ii] += e[j] * a[(j * rowsA) + ii]; + work[ii] += e[j]*a[(j*rowsA) + ii]; } } for (j = lp1; j < columnsA; j++) { - var ww = -e[j] / e[lp1]; + var ww = -e[j]/e[lp1]; for (var ii = lp1; ii < rowsA; ii++) { - a[(j * rowsA) + ii] += ww * work[ii]; + a[(j*rowsA) + ii] += ww*work[ii]; } } } @@ -2279,7 +2279,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Place the transformation in v for subsequent back multiplication. for (i = lp1; i < columnsA; i++) { - v[(l * columnsA) + i] = e[i]; + v[(l*columnsA) + i] = e[i]; } } @@ -2289,7 +2289,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra var nrtp1 = nrt + 1; if (nct < columnsA) { - stemp[nctp1 - 1] = a[((nctp1 - 1) * rowsA) + (nctp1 - 1)]; + stemp[nctp1 - 1] = a[((nctp1 - 1)*rowsA) + (nctp1 - 1)]; } if (rowsA < m) @@ -2299,7 +2299,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (nrtp1 < m) { - e[nrtp1 - 1] = a[((m - 1) * rowsA) + (nrtp1 - 1)]; + e[nrtp1 - 1] = a[((m - 1)*rowsA) + (nrtp1 - 1)]; } e[m - 1] = 0.0f; @@ -2311,10 +2311,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (i = 0; i < rowsA; i++) { - u[(j * rowsA) + i] = 0.0f; + u[(j*rowsA) + i] = 0.0f; } - u[(j * rowsA) + j] = 1.0f; + u[(j*rowsA) + j] = 1.0f; } for (l = nct - 1; l >= 0; l--) @@ -2326,37 +2326,37 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t = 0.0f; for (i = l; i < rowsA; i++) { - t += u[(j * rowsA) + i] * u[(l * rowsA) + i]; + t += u[(j*rowsA) + i]*u[(l*rowsA) + i]; } - t = -t / u[(l * rowsA) + l]; + t = -t/u[(l*rowsA) + l]; for (var ii = l; ii < rowsA; ii++) { - u[(j * rowsA) + ii] += t * u[(l * rowsA) + ii]; + u[(j*rowsA) + ii] += t*u[(l*rowsA) + ii]; } } // A part of column "l" of matrix A from row "l" to end multiply by -1.0 for (i = l; i < rowsA; i++) { - u[(l * rowsA) + i] = u[(l * rowsA) + i] * -1.0f; + u[(l*rowsA) + i] = u[(l*rowsA) + i]*-1.0f; } - u[(l * rowsA) + l] = 1.0f + u[(l * rowsA) + l]; + u[(l*rowsA) + l] = 1.0f + u[(l*rowsA) + l]; for (i = 0; i < l; i++) { - u[(l * rowsA) + i] = 0.0f; + u[(l*rowsA) + i] = 0.0f; } } else { for (i = 0; i < rowsA; i++) { - u[(l * rowsA) + i] = 0.0f; + u[(l*rowsA) + i] = 0.0f; } - u[(l * rowsA) + l] = 1.0f; + u[(l*rowsA) + l] = 1.0f; } } } @@ -2376,13 +2376,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t = 0.0f; for (i = lp1; i < columnsA; i++) { - t += v[(j * columnsA) + i] * v[(l * columnsA) + i]; + t += v[(j*columnsA) + i]*v[(l*columnsA) + i]; } - t = -t / v[(l * columnsA) + lp1]; + t = -t/v[(l*columnsA) + lp1]; for (var ii = l; ii < columnsA; ii++) { - v[(j * columnsA) + ii] += t * v[(l * columnsA) + ii]; + v[(j*columnsA) + ii] += t*v[(l*columnsA) + ii]; } } } @@ -2390,10 +2390,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra for (i = 0; i < columnsA; i++) { - v[(l * columnsA) + i] = 0.0f; + v[(l*columnsA) + i] = 0.0f; } - v[(l * columnsA) + l] = 1.0f; + v[(l*columnsA) + l] = 1.0f; } } @@ -2404,11 +2404,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (stemp[i] != 0.0) { t = stemp[i]; - r = stemp[i] / t; + r = stemp[i]/t; stemp[i] = t; if (i < m - 1) { - e[i] = e[i] / r; + e[i] = e[i]/r; } if (computeVectors) @@ -2416,7 +2416,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // A part of column "i" of matrix U from row 0 to end multiply by r for (j = 0; j < rowsA; j++) { - u[(i * rowsA) + j] = u[(i * rowsA) + j] * r; + u[(i*rowsA) + j] = u[(i*rowsA) + j]*r; } } } @@ -2433,9 +2433,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra } t = e[i]; - r = t / e[i]; + r = t/e[i]; e[i] = t; - stemp[i + 1] = stemp[i + 1] * r; + stemp[i + 1] = stemp[i + 1]*r; if (!computeVectors) { continue; @@ -2444,7 +2444,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // A part of column "i+1" of matrix VT from row 0 to end multiply by r for (j = 0; j < columnsA; j++) { - v[((i + 1) * columnsA) + j] = v[((i + 1) * columnsA) + j] * r; + v[((i + 1)*columnsA) + j] = v[((i + 1)*columnsA) + j]*r; } } @@ -2545,8 +2545,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra stemp[k] = t1; if (k != l) { - f = -sn * e[k - 1]; - e[k - 1] = cs * e[k - 1]; + f = -sn*e[k - 1]; + e[k - 1] = cs*e[k - 1]; } if (computeVectors) @@ -2554,16 +2554,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Rotate for (i = 0; i < columnsA; i++) { - var z = (cs * v[(k * columnsA) + i]) + (sn * v[((m - 1) * columnsA) + i]); - v[((m - 1) * columnsA) + i] = (cs * v[((m - 1) * columnsA) + i]) - (sn * v[(k * columnsA) + i]); - v[(k * columnsA) + i] = z; + var z = (cs*v[(k*columnsA) + i]) + (sn*v[((m - 1)*columnsA) + i]); + v[((m - 1)*columnsA) + i] = (cs*v[((m - 1)*columnsA) + i]) - (sn*v[(k*columnsA) + i]); + v[(k*columnsA) + i] = z; } } } break; - // Split at negligible s[l]. + // Split at negligible s[l]. case 2: f = e[l - 1]; e[l - 1] = 0.0f; @@ -2572,16 +2572,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra t1 = stemp[k]; Drotg(ref t1, ref f, ref cs, ref sn); stemp[k] = t1; - f = -sn * e[k]; - e[k] = cs * e[k]; + f = -sn*e[k]; + e[k] = cs*e[k]; if (computeVectors) { // Rotate for (i = 0; i < rowsA; i++) { - var z = (cs * u[(k * rowsA) + i]) + (sn * u[((l - 1) * rowsA) + i]); - u[((l - 1) * rowsA) + i] = (cs * u[((l - 1) * rowsA) + i]) - (sn * u[(k * rowsA) + i]); - u[(k * rowsA) + i] = z; + var z = (cs*u[(k*rowsA) + i]) + (sn*u[((l - 1)*rowsA) + i]); + u[((l - 1)*rowsA) + i] = (cs*u[((l - 1)*rowsA) + i]) - (sn*u[(k*rowsA) + i]); + u[(k*rowsA) + i] = z; } } } @@ -2598,27 +2598,27 @@ namespace MathNet.Numerics.Providers.LinearAlgebra scale = Math.Max(scale, Math.Abs(e[m - 2])); scale = Math.Max(scale, Math.Abs(stemp[l])); scale = Math.Max(scale, Math.Abs(e[l])); - var sm = stemp[m - 1] / scale; - var smm1 = stemp[m - 2] / scale; - var emm1 = e[m - 2] / scale; - var sl = stemp[l] / scale; - var el = e[l] / scale; - var b = (((smm1 + sm) * (smm1 - sm)) + (emm1 * emm1)) / 2.0f; - var c = (sm * emm1) * (sm * emm1); + var sm = stemp[m - 1]/scale; + var smm1 = stemp[m - 2]/scale; + var emm1 = e[m - 2]/scale; + var sl = stemp[l]/scale; + var el = e[l]/scale; + var b = (((smm1 + sm)*(smm1 - sm)) + (emm1*emm1))/2.0f; + var c = (sm*emm1)*(sm*emm1); var shift = 0.0f; if (b != 0.0 || c != 0.0) { - shift = (float)Math.Sqrt((b * b) + c); + shift = (float) Math.Sqrt((b*b) + c); if (b < 0.0) { shift = -shift; } - shift = c / (b + shift); + shift = c/(b + shift); } - f = ((sl + sm) * (sl - sm)) + shift; - var g = sl * el; + f = ((sl + sm)*(sl - sm)) + shift; + var g = sl*el; // Chase zeros for (k = l; k < m - 1; k++) @@ -2629,33 +2629,33 @@ namespace MathNet.Numerics.Providers.LinearAlgebra e[k - 1] = f; } - f = (cs * stemp[k]) + (sn * e[k]); - e[k] = (cs * e[k]) - (sn * stemp[k]); - g = sn * stemp[k + 1]; - stemp[k + 1] = cs * stemp[k + 1]; + f = (cs*stemp[k]) + (sn*e[k]); + e[k] = (cs*e[k]) - (sn*stemp[k]); + g = sn*stemp[k + 1]; + stemp[k + 1] = cs*stemp[k + 1]; if (computeVectors) { for (i = 0; i < columnsA; i++) { - var z = (cs * v[(k * columnsA) + i]) + (sn * v[((k + 1) * columnsA) + i]); - v[((k + 1) * columnsA) + i] = (cs * v[((k + 1) * columnsA) + i]) - (sn * v[(k * columnsA) + i]); - v[(k * columnsA) + i] = z; + var z = (cs*v[(k*columnsA) + i]) + (sn*v[((k + 1)*columnsA) + i]); + v[((k + 1)*columnsA) + i] = (cs*v[((k + 1)*columnsA) + i]) - (sn*v[(k*columnsA) + i]); + v[(k*columnsA) + i] = z; } } Drotg(ref f, ref g, ref cs, ref sn); stemp[k] = f; - f = (cs * e[k]) + (sn * stemp[k + 1]); - stemp[k + 1] = -(sn * e[k]) + (cs * stemp[k + 1]); - g = sn * e[k + 1]; - e[k + 1] = cs * e[k + 1]; + f = (cs*e[k]) + (sn*stemp[k + 1]); + stemp[k + 1] = -(sn*e[k]) + (cs*stemp[k + 1]); + g = sn*e[k + 1]; + e[k + 1] = cs*e[k + 1]; if (computeVectors && k < rowsA) { for (i = 0; i < rowsA; i++) { - var z = (cs * u[(k * rowsA) + i]) + (sn * u[((k + 1) * rowsA) + i]); - u[((k + 1) * rowsA) + i] = (cs * u[((k + 1) * rowsA) + i]) - (sn * u[(k * rowsA) + i]); - u[(k * rowsA) + i] = z; + var z = (cs*u[(k*rowsA) + i]) + (sn*u[((k + 1)*rowsA) + i]); + u[((k + 1)*rowsA) + i] = (cs*u[((k + 1)*rowsA) + i]) - (sn*u[(k*rowsA) + i]); + u[(k*rowsA) + i] = z; } } } @@ -2676,7 +2676,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // A part of column "l" of matrix VT from row 0 to end multiply by -1 for (i = 0; i < columnsA; i++) { - v[(l * columnsA) + i] = v[(l * columnsA) + i] * -1.0f; + v[(l*columnsA) + i] = v[(l*columnsA) + i]*-1.0f; } } } @@ -2697,9 +2697,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Swap columns l, l + 1 for (i = 0; i < columnsA; i++) { - var z = v[(l * columnsA) + i]; - v[(l * columnsA) + i] = v[((l + 1) * columnsA) + i]; - v[((l + 1) * columnsA) + i] = z; + var z = v[(l*columnsA) + i]; + v[(l*columnsA) + i] = v[((l + 1)*columnsA) + i]; + v[((l + 1)*columnsA) + i] = z; } } @@ -2708,9 +2708,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Swap columns l, l + 1 for (i = 0; i < rowsA; i++) { - var z = u[(l * rowsA) + i]; - u[(l * rowsA) + i] = u[((l + 1) * rowsA) + i]; - u[((l + 1) * rowsA) + i] = z; + var z = u[(l*rowsA) + i]; + u[(l*rowsA) + i] = u[((l + 1)*rowsA) + i]; + u[((l + 1)*rowsA) + i] = z; } } @@ -2730,7 +2730,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (j = 0; j < columnsA; j++) { - vt[(j * columnsA) + i] = v[(i * columnsA) + j]; + vt[(j*columnsA) + i] = v[(i*columnsA) + j]; } } } @@ -2738,7 +2738,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra // Copy stemp to s with size adjustment. We are using ported copy of linpack's svd code and it uses // a singular vector of length rows+1 when rows < columns. The last element is not used and needs to be removed. // We should port lapack's svd routine to remove this problem. - Buffer.BlockCopy(stemp, 0, s, 0, Math.Min(rowsA, columnsA) * Constants.SizeOfFloat); + Buffer.BlockCopy(stemp, 0, s, 0, Math.Min(rowsA, columnsA)*Constants.SizeOfFloat); // On return the first element of the work array stores the min size of the work array could have been // work[0] = Math.Max(3 * Math.Min(aRows, aColumns) + Math.Max(aRows, aColumns), 5 * Math.Min(aRows, aColumns)); @@ -2754,7 +2754,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra /// Contains the parameter c associated with the Givens rotation /// Contains the parameter s associated with the Givens rotation /// This is equivalent to the DROTG LAPACK routine. - private static void Drotg(ref float da, ref float db, ref float c, ref float s) + static void Drotg(ref float da, ref float db, ref float c, ref float s) { float r, z; @@ -2776,16 +2776,16 @@ namespace MathNet.Numerics.Providers.LinearAlgebra } else { - var sda = da / scale; - var sdb = db / scale; - r = scale * (float)Math.Sqrt((sda * sda) + (sdb * sdb)); + var sda = da/scale; + var sdb = db/scale; + r = scale*(float) Math.Sqrt((sda*sda) + (sdb*sdb)); if (roe < 0.0) { r = -r; } - c = da / r; - s = db / r; + c = da/r; + s = db/r; z = 1.0f; if (absda > absdb) { @@ -2794,7 +2794,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (absdb >= absda && c != 0.0) { - z = 1.0f / c; + z = 1.0f/c; } } @@ -2828,23 +2828,23 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } var work = new float[rowsA]; var s = new float[Math.Min(rowsA, columnsA)]; - var u = new float[rowsA * rowsA]; - var vt = new float[columnsA * columnsA]; + var u = new float[rowsA*rowsA]; + var vt = new float[columnsA*columnsA]; var clone = new float[a.Length]; - Buffer.BlockCopy(a, 0, clone, 0, a.Length * Constants.SizeOfFloat); + Buffer.BlockCopy(a, 0, clone, 0, a.Length*Constants.SizeOfFloat); SingularValueDecomposition(true, clone, rowsA, columnsA, s, u, vt, work); SvdSolveFactored(rowsA, columnsA, s, u, vt, b, columnsB, x); } @@ -2887,12 +2887,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("x"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -2902,12 +2902,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -2924,7 +2924,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { for (var i = 0; i < rowsA; i++) { - value += u[(j * rowsA) + i] * b[(k * rowsA) + i]; + value += u[(j*rowsA) + i]*b[(k*rowsA) + i]; } value /= s[j]; @@ -2938,10 +2938,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra float value = 0; for (var i = 0; i < columnsA; i++) { - value += vt[(j * columnsA) + i] * tmp[i]; + value += vt[(j*columnsA) + i]*tmp[i]; } - x[(k * columnsA) + j] = value; + x[(k*columnsA) + j] = value; } } } @@ -2962,9 +2962,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("matrix"); } - if (matrix.Length != order * order) + if (matrix.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrix"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrix"); } if (matrixEv == null) @@ -2972,9 +2972,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("matrixEv"); } - if (matrixEv.Length != order * order) + if (matrixEv.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrixEv"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrixEv"); } if (vectorEv == null) @@ -2992,9 +2992,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra throw new ArgumentNullException("matrixD"); } - if (matrixD.Length != order * order) + if (matrixD.Length != order*order) { - throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order * order), "matrixD"); + throw new ArgumentException(String.Format(Resources.ArgumentArrayWrongLength, order*order), "matrixD"); } var d = new float[order]; @@ -3002,11 +3002,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra if (isSymmetric) { - Buffer.BlockCopy(matrix, 0, matrixEv, 0, matrix.Length * Constants.SizeOfFloat); + Buffer.BlockCopy(matrix, 0, matrixEv, 0, matrix.Length*Constants.SizeOfFloat); var om1 = order - 1; for (var i = 0; i < order; i++) { - d[i] = matrixEv[i * order + om1]; + d[i] = matrixEv[i*order + om1]; } Numerics.LinearAlgebra.Single.Factorization.DenseEvd.SymmetricTridiagonalize(matrixEv, d, e, order); @@ -3015,7 +3015,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra else { var matrixH = new float[matrix.Length]; - Buffer.BlockCopy(matrix, 0, matrixH, 0, matrix.Length * Constants.SizeOfFloat); + Buffer.BlockCopy(matrix, 0, matrixH, 0, matrix.Length*Constants.SizeOfFloat); Numerics.LinearAlgebra.Single.Factorization.DenseEvd.NonsymmetricReduceToHessenberg(matrixEv, matrixH, order); Numerics.LinearAlgebra.Single.Factorization.DenseEvd.NonsymmetricReduceHessenberToRealSchur(matrixEv, matrixH, d, e, order); } @@ -3024,7 +3024,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra { vectorEv[i] = new Complex(d[i], e[i]); - var io = i * order; + var io = i*order; matrixD[io + i] = d[i]; if (e[i] > 0) diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Common.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Common.cs index 75d979ae..e20200c5 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Common.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Common.cs @@ -70,9 +70,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } var work = new float[rows]; @@ -109,9 +109,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } if (work.Length < rows) @@ -119,7 +119,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work"); } - return SafeNativeMethods.s_matrix_norm((byte)norm, rows, columns, matrix, work); + return SafeNativeMethods.s_matrix_norm((byte) norm, rows, columns, matrix, work); } /// @@ -150,9 +150,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } var work = new double[rows]; @@ -189,9 +189,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } if (work.Length < rows) @@ -199,7 +199,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work"); } - return SafeNativeMethods.d_matrix_norm((byte)norm, rows, columns, matrix, work); + return SafeNativeMethods.d_matrix_norm((byte) norm, rows, columns, matrix, work); } /// @@ -230,9 +230,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } var work = new float[rows]; @@ -269,9 +269,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } if (work.Length < rows) @@ -279,7 +279,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work"); } - return SafeNativeMethods.c_matrix_norm((byte)norm, rows, columns, matrix, work); + return SafeNativeMethods.c_matrix_norm((byte) norm, rows, columns, matrix, work); } /// @@ -310,9 +310,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } var work = new double[rows]; @@ -349,9 +349,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentMustBePositive, "columns"); } - if (matrix.Length < rows * columns) + if (matrix.Length < rows*columns) { - throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix"); + throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix"); } if (work.Length < rows) @@ -359,7 +359,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work"); } - return SafeNativeMethods.z_matrix_norm((byte)norm, rows, columns, matrix, work); + return SafeNativeMethods.z_matrix_norm((byte) norm, rows, columns, matrix, work); } } } diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs index 858a38e9..40478892 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs @@ -70,7 +70,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl return SafeNativeMethods.z_dot_product(x.Length, x, y); } - + /// /// Adds a scaled vector to another: result = y + alpha*x. /// @@ -123,8 +123,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl if (x == null) { throw new ArgumentNullException("x"); - } - + } + if (!ReferenceEquals(x, result)) { Array.Copy(x, 0, result, 0, x.Length); @@ -192,9 +192,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB; - if (c.Length != m * n) + if (c.Length != m*n) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw new ArgumentException(Resources.ArgumentMatrixDimensions); } if (k != l) @@ -227,7 +227,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("ipiv"); } - if (data.Length != order * order) + if (data.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "data"); } @@ -236,7 +236,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl { throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - + SafeNativeMethods.z_lu_factor(order, data, ipiv); } @@ -254,13 +254,13 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } var work = new Complex[order]; - SafeNativeMethods.z_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.z_lu_inverse(order, a, work, work.Length); } /// @@ -283,7 +283,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -294,7 +294,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl } var work = new Complex[order]; - SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -314,7 +314,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -329,7 +329,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.z_lu_inverse(order, a, work, work.Length); + SafeNativeMethods.z_lu_inverse(order, a, work, work.Length); } /// @@ -355,7 +355,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -375,7 +375,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } - SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order); + SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order); } /// @@ -394,22 +394,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("a"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - + if (ReferenceEquals(a, b)) { throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.z_lu_solve(order, columnsOfB, a, b); + SafeNativeMethods.z_lu_solve(order, columnsOfB, a, b); } /// @@ -434,7 +434,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("ipiv"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -444,7 +444,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentArraysSameLength, "ipiv"); } - if (b.Length != columnsOfB * order) + if (b.Length != columnsOfB*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -454,7 +454,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.z_lu_solve_factored(order, columnsOfB, a, ipiv, b); + SafeNativeMethods.z_lu_solve_factored(order, columnsOfB, a, ipiv, b); } /// @@ -477,7 +477,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentMustBePositive, "order"); } - if (a.Length != order * order) + if (a.Length != order*order) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } @@ -512,7 +512,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -522,7 +522,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.z_cholesky_solve(orderA, columnsB, a, b); + SafeNativeMethods.z_cholesky_solve(orderA, columnsB, a, b); } /// @@ -546,7 +546,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("b"); } - if (b.Length != orderA * columnsB) + if (b.Length != orderA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } @@ -556,7 +556,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentReferenceDifferent); } - SafeNativeMethods.z_cholesky_solve_factored(orderA, columnsB, a, b); + SafeNativeMethods.z_cholesky_solve_factored(orderA, columnsB, a, b); } /// @@ -584,7 +584,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("q"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -594,12 +594,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - var work = new Complex[columnsR * Control.BlockSize]; + var work = new Complex[columnsR*Control.BlockSize]; SafeNativeMethods.z_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length); } @@ -636,7 +636,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("work"); } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r"); } @@ -646,14 +646,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau"); } - if (q.Length != rowsR * rowsR) + if (q.Length != rowsR*rowsR) { throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q"); } - if (work.Length < columnsR * Control.BlockSize) + if (work.Length < columnsR*Control.BlockSize) { - work[0] = columnsR * Control.BlockSize; + work[0] = columnsR*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -674,7 +674,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl [SecuritySafeCritical] public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x, QRMethod method = QRMethod.Full) { - var work = new Complex[columns * Control.BlockSize]; + var work = new Complex[columns*Control.BlockSize]; QRSolve(a, rows, columns, b, columnsB, x, work, method); } @@ -715,17 +715,17 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("work"); } - if (a.Length != rows * columns) + if (a.Length != rows*columns) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "a"); } - if (b.Length != rows * columnsB) + if (b.Length != rows*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columns * columnsB) + if (x.Length != columns*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "x"); } @@ -737,7 +737,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl if (work.Length < 1) { - work[0] = rows * Control.BlockSize; + work[0] = rows*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -761,7 +761,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl [SecuritySafeCritical] public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x, QRMethod method = QRMethod.Full) { - var work = new Complex[columnsR * Control.BlockSize]; + var work = new Complex[columnsR*Control.BlockSize]; QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work, method); } @@ -823,29 +823,29 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl columnsQ = rowsR = columnsR = columnsA; } - if (r.Length != rowsR * columnsR) + if (r.Length != rowsR*columnsR) { - throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, rowsR * columnsR), "r"); + throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, rowsR*columnsR), "r"); } - if (q.Length != rowsQ * columnsQ) + if (q.Length != rowsQ*columnsQ) { - throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, rowsQ * columnsQ), "q"); + throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, rowsQ*columnsQ), "q"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { - throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, rowsA * columnsB), "b"); + throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, rowsA*columnsB), "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { - throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, columnsA * columnsB), "x"); + throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, columnsA*columnsB), "x"); } if (work.Length < 1) { - work[0] = rowsA * Control.BlockSize; + work[0] = rowsA*Control.BlockSize; throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -897,12 +897,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("vt"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -912,7 +912,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentArraysSameLength, "s"); } - var work = new Complex[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work); } @@ -942,20 +942,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("x"); } - if (b.Length != rowsA * columnsB) + if (b.Length != rowsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - if (x.Length != columnsA * columnsB) + if (x.Length != columnsA*columnsB) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "b"); } - var work = new Complex[(2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; + var work = new Complex[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)]; var s = new Complex[Math.Min(rowsA, columnsA)]; - var u = new Complex[rowsA * rowsA]; - var vt = new Complex[columnsA * columnsA]; + var u = new Complex[rowsA*rowsA]; + var vt = new Complex[columnsA*columnsA]; var clone = new Complex[a.Length]; a.Copy(clone); @@ -1007,12 +1007,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentNullException("work"); } - if (u.Length != rowsA * rowsA) + if (u.Length != rowsA*rowsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "u"); } - if (vt.Length != columnsA * columnsA) + if (vt.Length != columnsA*columnsA) { throw new ArgumentException(Resources.ArgumentArraysSameLength, "vt"); } @@ -1027,9 +1027,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl throw new ArgumentException(Resources.ArgumentSingleDimensionArray, "work"); } - if (work.Length < (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) + if (work.Length < (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)) { - work[0] = (2 * Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); + work[0] = (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA); throw new ArgumentException(Resources.WorkArrayTooSmall, "work"); } @@ -1062,7 +1062,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl { throw new ArgumentException(Resources.ArgumentArraysSameLength); } - + if (x.Length != result.Length) { throw new ArgumentException(Resources.ArgumentArraysSameLength); @@ -1097,12 +1097,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl { throw new ArgumentException(Resources.ArgumentArraysSameLength); } - + if (x.Length != result.Length) { throw new ArgumentException(Resources.ArgumentArraysSameLength); } - + SafeNativeMethods.z_vector_subtract(x.Length, x, y, result); } @@ -1132,12 +1132,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl { throw new ArgumentException(Resources.ArgumentArraysSameLength); } - + if (x.Length != result.Length) { throw new ArgumentException(Resources.ArgumentArraysSameLength); } - + SafeNativeMethods.z_vector_multiply(x.Length, x, y, result); } @@ -1167,12 +1167,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl { throw new ArgumentException(Resources.ArgumentArraysSameLength); } - + if (x.Length != result.Length) { throw new ArgumentException(Resources.ArgumentArraysSameLength); } - + SafeNativeMethods.z_vector_divide(x.Length, x, y, result); } } diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs index 7bf3ec2c..78fc835b 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs @@ -44,10 +44,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl /// /// Name of the native DLL. /// - private const string DllName = "MathNet.Numerics.MKL.dll"; + const string DllName = "MathNet.Numerics.MKL.dll"; + + #region BLAS -#region BLAS - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void s_axpy(int n, float alpha, float[] x, [In, Out] float[] y); @@ -59,7 +59,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_axpy(int n, Complex alpha, Complex[] x, [In, Out] Complex[] y); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void s_scale(int n, float alpha, [Out] float[] x); @@ -71,7 +71,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_scale(int n, Complex alpha, [In, Out] Complex[] x); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern float s_dot_product(int n, float[] x, float[] y); @@ -83,22 +83,22 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void s_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, float alpha, float[] x, float[] y, float beta, [In, Out]float[] c); - + internal static extern void s_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, float alpha, float[] x, float[] y, float beta, [In, Out] float[] c); + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void d_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, double alpha, double[] x, double[] y, double beta, [In, Out]double[] c); + internal static extern void d_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, double alpha, double[] x, double[] y, double beta, [In, Out] double[] c); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void c_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex32 alpha, Complex32[] x, Complex32[] y, Complex32 beta, [In, Out]Complex32[] c); + internal static extern void c_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex32 alpha, Complex32[] x, Complex32[] y, Complex32 beta, [In, Out] Complex32[] c); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void z_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex alpha, Complex[] x, Complex[] y, Complex beta, [In, Out]Complex[] c); + internal static extern void z_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex alpha, Complex[] x, Complex[] y, Complex beta, [In, Out] Complex[] c); + + #endregion BLAS -#endregion BLAS - -#region LAPACK + #region LAPACK [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern float s_matrix_norm(byte norm, int rows, int columns, [In] float[] a, [In, Out] float[] work); @@ -123,7 +123,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int z_cholesky_factor(int n, [In, Out] Complex[] a); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int s_lu_factor(int n, [In, Out] float[] a, [In, Out] int[] ipiv); @@ -153,15 +153,15 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int d_lu_inverse_factored(int n, [In, Out] double[] a, [In, Out] int[] ipiv, [In, Out] double[] work, int lwork); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int c_lu_inverse_factored(int n, [In, Out] Complex32[] a, [In, Out] int[] ipiv, [In, Out] Complex32[] work, int lwork); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int z_lu_inverse_factored(int n, [In, Out] Complex[] a, [In, Out] int[] ipiv, [In, Out] Complex[] work, int lwork); - + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int s_lu_solve_factored(int n, int nrhs, float[] a, [In, Out]int[] ipiv, [In, Out] float[] b); + internal static extern int s_lu_solve_factored(int n, int nrhs, float[] a, [In, Out] int[] ipiv, [In, Out] float[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int d_lu_solve_factored(int n, int nrhs, double[] a, [In, Out] int[] ipiv, [In, Out] double[] b); @@ -170,7 +170,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl internal static extern int c_lu_solve_factored(int n, int nrhs, Complex32[] a, [In, Out] int[] ipiv, [In, Out] Complex32[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int z_lu_solve_factored(int n, int nrhs, Complex[] a, [In, Out]int[] ipiv, [In, Out] Complex[] b); + internal static extern int z_lu_solve_factored(int n, int nrhs, Complex[] a, [In, Out] int[] ipiv, [In, Out] Complex[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int s_lu_solve(int n, int nrhs, float[] a, [In, Out] float[] b); @@ -182,7 +182,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl internal static extern int c_lu_solve(int n, int nrhs, Complex32[] a, [In, Out] Complex32[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int z_lu_solve(int n, int nrhs, Complex[] a, [In, Out] Complex[] b); + internal static extern int z_lu_solve(int n, int nrhs, Complex[] a, [In, Out] Complex[] b); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern int s_cholesky_solve(int n, int nrhs, float[] a, [In, Out] float[] b); @@ -272,18 +272,18 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl internal static extern int s_eigen(bool isSymmetric, int n, [In] float[] a, [In, Out] float[] vectors, [In, Out] Complex[] values, [In, Out] float[] d); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int d_eigen(bool isSymmetric, int n, [In] double[] a, [In, Out] double[] vectors, [In, Out] Complex[] values, [In, Out] double[] d); + internal static extern int d_eigen(bool isSymmetric, int n, [In] double[] a, [In, Out] double[] vectors, [In, Out] Complex[] values, [In, Out] double[] d); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int c_eigen(bool isSymmetric, int n, [In] Complex32[] a, [In, Out] Complex32[] vectors, [In, Out] Complex[] values, [In, Out] Complex32[] d); + internal static extern int c_eigen(bool isSymmetric, int n, [In] Complex32[] a, [In, Out] Complex32[] vectors, [In, Out] Complex[] values, [In, Out] Complex32[] d); [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern int z_eigen(bool isSymmetric, int n, [In] Complex[] a, [In, Out] Complex[] vectors, [In, Out] Complex[] values, [In, Out] Complex[] d); - -#endregion LAPACK + internal static extern int z_eigen(bool isSymmetric, int n, [In] Complex[] a, [In, Out] Complex[] vectors, [In, Out] Complex[] values, [In, Out] Complex[] d); + + #endregion LAPACK + + #region Vector Functions -#region Vector Functions - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void s_vector_add(int n, float[] x, float[] y, [In, Out] float[] result); @@ -331,8 +331,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_vector_divide(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result); - -#endregion Vector Functions + + #endregion Vector Functions } }