diff --git a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs index 7d87b6d5..de2828c7 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -33,7 +33,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// /// The managed linear algebra provider. /// - public partial class ManagedLinearAlgebraProvider : ILinearAlgebraProvider + public partial class ManagedLinearAlgebraProvider { /// /// Adds a scaled vector to another: y += alpha*x. @@ -1301,7 +1301,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Number of rows /// Column start /// Total columns - /// Multipliears calculated previously + /// Multipliers calculated previously /// Number of available processors private static void DoCholeskyStep(Complex[] data, int rowDim, int firstCol, int colLimit, Complex[] multipliers, int availableCores) { @@ -1535,7 +1535,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Perform calculation of Q or R /// /// Work array - /// Index of colunn in work array + /// Index of column in work array /// Q or R matrices /// The first row in /// The last row @@ -1584,7 +1584,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Work array /// Initial matrix /// The number of rows in matrix - /// The firts row + /// The first row /// Column index private static void GenerateColumn(Complex[] work, Complex[] a, int rowCount, int row, int column) { @@ -1871,9 +1871,9 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// This is equivalent to the GESVD LAPACK routine. public virtual void SingularValueDecomposition(bool computeVectors, Complex[] a, int rowsA, int columnsA, Complex[] s, Complex[] u, Complex[] vt) @@ -1926,9 +1926,9 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// The work array. For real matrices, the work array should be at least /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N). diff --git a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs index b00cc42a..e78397a7 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -26,14 +26,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra { using System; - using System.Numerics; using Properties; using Threading; /// /// The managed linear algebra provider. /// - public partial class ManagedLinearAlgebraProvider : ILinearAlgebraProvider + public partial class ManagedLinearAlgebraProvider { /// /// Adds a scaled vector to another: y += alpha*x. @@ -1308,7 +1307,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Number of rows /// Column start /// Total columns - /// Multipliears calculated previously + /// Multipliers calculated previously /// Number of available processors private static void DoCholeskyStep(Complex32[] data, int rowDim, int firstCol, int colLimit, Complex32[] multipliers, int availableCores) { @@ -1542,7 +1541,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Perform calculation of Q or R /// /// Work array - /// Index of colunn in work array + /// Index of column in work array /// Q or R matrices /// The first row in /// The last row @@ -1591,7 +1590,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Work array /// Initial matrix /// The number of rows in matrix - /// The firts row + /// The first row /// Column index private static void GenerateColumn(Complex32[] work, Complex32[] a, int rowCount, int row, int column) { @@ -1878,9 +1877,9 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// This is equivalent to the GESVD LAPACK routine. public virtual void SingularValueDecomposition(bool computeVectors, Complex32[] a, int rowsA, int columnsA, Complex32[] s, Complex32[] u, Complex32[] vt) @@ -1933,9 +1932,9 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// The work array. For real matrices, the work array should be at least /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N). diff --git a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs index 6b9c8d8b..88dfc4ba 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -1286,7 +1286,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Number of rows /// Column start /// Total columns - /// Multipliears calculated previously + /// Multipliers calculated previously /// Number of available processors private static void DoCholeskyStep(double[] data, int rowDim, int firstCol, int colLimit, double[] multipliers, int availableCores) { @@ -1520,7 +1520,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Perform calculation of Q or R /// /// Work array - /// Index of colunn in work array + /// Index of column in work array /// Q or R matrices /// The first row in /// The last row @@ -1569,7 +1569,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Work array /// Initial matrix /// The number of rows in matrix - /// The firts row + /// The first row /// Column index private static void GenerateColumn(double[] work, double[] a, int rowCount, int row, int column) { @@ -1857,9 +1857,9 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// This is equivalent to the GESVD LAPACK routine. public virtual void SingularValueDecomposition(bool computeVectors, double[] a, int rowsA, int columnsA, double[] s, double[] u, double[] vt) @@ -1912,9 +1912,9 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// The work array. For real matrices, the work array should be at least /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N). @@ -2590,7 +2590,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra } /// - /// Given the Cartesian coordinates (da, db) of a point p, these fucntion return the parameters da, db, c, and s + /// Given the Cartesian coordinates (da, db) of a point p, these function return the parameters da, db, c, and s /// associated with the Givens rotation that zeros the y-coordinate of the point. /// /// Provides the x-coordinate of the point p. On exit contains the parameter r associated with the Givens rotation diff --git a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs index df5ba92f..bb8ab9df 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics @@ -26,14 +26,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra { using System; - using System.Numerics; using Properties; using Threading; /// /// The managed linear algebra provider. /// - public partial class ManagedLinearAlgebraProvider : ILinearAlgebraProvider + public partial class ManagedLinearAlgebraProvider { /// /// Adds a scaled vector to another: y += alpha*x. @@ -1290,7 +1289,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Number of rows /// Column start /// Total columns - /// Multipliears calculated previously + /// Multipliers calculated previously /// Number of available processors private static void DoCholeskyStep(float[] data, int rowDim, int firstCol, int colLimit, float[] multipliers, int availableCores) { @@ -1524,7 +1523,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Perform calculation of Q or R /// /// Work array - /// Index of colunn in work array + /// Index of column in work array /// Q or R matrices /// The first row in /// The last row @@ -1573,7 +1572,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Work array /// Initial matrix /// The number of rows in matrix - /// The firts row + /// The first row /// Column index private static void GenerateColumn(float[] work, float[] a, int rowCount, int row, int column) { @@ -1861,9 +1860,9 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// This is equivalent to the GESVD LAPACK routine. public virtual void SingularValueDecomposition(bool computeVectors, float[] a, int rowsA, int columnsA, float[] s, float[] u, float[] vt) @@ -1916,9 +1915,9 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// The work array. For real matrices, the work array should be at least /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N). @@ -2594,7 +2593,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra } /// - /// Given the Cartesian coordinates (da, db) of a point p, these fucntion return the parameters da, db, c, and s + /// Given the Cartesian coordinates (da, db) of a point p, these function return the parameters da, db, c, and s /// associated with the Givens rotation that zeros the y-coordinate of the point. /// /// Provides the x-coordinate of the point p. On exit contains the parameter r associated with the Givens rotation diff --git a/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt b/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt index 75b9f980..bd1d4cf2 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt +++ b/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt @@ -3,46 +3,8 @@ <# string namespaceSuffix = "Mkl"; string library = "MKL"; #> -<#@ include file="..\SafeNativeMethods.include" #> +<#@ include file="..\safe.native.common.include" #> +<#@ include file="..\safe.native.vector.include" #> - #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); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void s_vector_subtract(int n, float[] x, float[] y, [In, Out] float[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void s_vector_multiply(int n, float[] x, float[] y, [In, Out] float[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void d_vector_add(int n, double[] x, double[] y, [In, Out] double[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void d_vector_subtract(int n, double[] x, double[] y, [In, Out] double[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void d_vector_multiply(int n, double[] x, double[] y, [In, Out] double[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void c_vector_add(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void c_vector_subtract(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void c_vector_multiply(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void z_vector_add(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void z_vector_subtract(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result); - - [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] - internal static extern void z_vector_multiply(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result); - - #endregion Vector Functions } } \ No newline at end of file diff --git a/src/Numerics/Algorithms/LinearAlgebra/native.common.include b/src/Numerics/Algorithms/LinearAlgebra/native.common.include index bd1019ed..d8632dd5 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/native.common.include +++ b/src/Numerics/Algorithms/LinearAlgebra/native.common.include @@ -82,17 +82,17 @@ /// 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 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. + /// 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 <#=one#> and beta set to <#=zero#>, and x and y are not transposed. - public override void MatrixMultiply(<#=dataType#>[] x, int xRows, int xColumns, <#=dataType#>[] y, int yRows, int yColumns, <#=dataType#>[] result) + public override void MatrixMultiply(<#=dataType#>[] x, int rowsX, int columnsX, <#=dataType#>[] y, int rowsY, int columnsY, <#=dataType#>[] result) { - MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, <#=one#>, x, xRows, xColumns, y, yRows, yColumns, <#=zero#>, result); + MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, <#=one#>, x, rowsX, columnsX, y, rowsY, columnsY, <#=zero#>, result); } /// @@ -102,15 +102,14 @@ /// 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 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 number of rows in the matrix. + /// The number of columns in the matrix. /// The value to scale the matrix. /// The c matrix. - public override void MatrixMultiplyWithUpdate(Transpose transposeA, Transpose transposeB, <#=dataType#> alpha, <#=dataType#>[] a, - int aRows, int aColumns, <#=dataType#>[] b, int bRows, int bColumns, <#=dataType#> beta, <#=dataType#>[] c) + public override void MatrixMultiplyWithUpdate(Transpose transposeA, Transpose transposeB, <#=dataType#> alpha, <#=dataType#>[] a, int rowsA, int columnsA, <#=dataType#>[] b, int rowsB, int columnsB, <#=dataType#> beta, <#=dataType#>[] c) { if (a == null) { @@ -127,16 +126,16 @@ throw new ArgumentNullException("c"); } - var m = transposeA == Transpose.DontTranspose ? aRows : aColumns; - var n = transposeB == Transpose.DontTranspose ? bColumns : bRows; - var k = transposeA == Transpose.DontTranspose ? aColumns : aRows; + var m = transposeA == Transpose.DontTranspose ? rowsA : columnsA; + var n = transposeB == Transpose.DontTranspose ? columnsB : rowsB; + var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA; - if( c.Length != aRows * bColumns) + if (c.Length != rowsA * columnsB) { throw new ArgumentException(Resources.ArgumentMatrixDimensions); } - if (aColumns != bRows) + if (columnsA != rowsB) { throw new ArgumentException(Resources.ArgumentMatrixDimensions); } @@ -144,7 +143,7 @@ SafeNativeMethods.<#=prefix#>_matrix_multiply(transposeA, transposeB, m, n, k, <#=reff#>alpha, a, b, <#=reff#>beta, c); } - /// + /// /// Computes the requested of the matrix. /// /// The type of norm to compute. @@ -176,8 +175,6 @@ throw new NotImplementedException(); } - - /// /// Computes the LUP factorization of A. P*A = L*U. /// @@ -326,13 +323,13 @@ /// Solves A*X=B for X using Cholesky factorization. /// /// The square, positive definite matrix A. - /// The number of rows and columns in A. + /// The number of rows and columns in A. /// The B matrix. - /// The number of rows in the B matrix. - /// The number of columns in the B matrix. + /// The number of rows in the B matrix. + /// The number of columns in the B matrix. /// This is equivalent to the POTRF add POTRS LAPACK routines. /// - public override void CholeskySolve(<#=dataType#>[] a, int aOrder, <#=dataType#>[] b, int bRows, int bColumns) + public override void CholeskySolve(<#=dataType#>[] a, int orderA, <#=dataType#>[] b, int rowsB, int columnsB) { throw new NotImplementedException(); } @@ -341,12 +338,12 @@ /// 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. + /// The number of rows and columns in A. /// The B matrix. - /// The number of rows in the B matrix. - /// The number of columns in the B matrix. + /// The number of rows in the B matrix. + /// The number of columns in the B matrix. /// This is equivalent to the POTRS LAPACK routine. - public override void CholeskySolveFactored(<#=dataType#>[] a, int aOrder, <#=dataType#>[] b, int bRows, int bColumns) + public override void CholeskySolveFactored(<#=dataType#>[] a, int orderA, <#=dataType#>[] b, int rowsB, int columnsB) { throw new NotImplementedException(); } @@ -356,12 +353,12 @@ /// /// 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. + /// 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. /// This is similar to the GEQRF and ORGQR LAPACK routines. - public override void QRFactor(<#=dataType#>[] r, int rRows, int rColumns, <#=dataType#>[] q) + public override void QRFactor(<#=dataType#>[] r, int rowsR, int columnsR, <#=dataType#>[] q) { throw new NotImplementedException(); } @@ -371,15 +368,15 @@ /// /// 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. + /// 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. /// 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. - public override void QRFactor(<#=dataType#>[] r, int rRows, int rColumns, <#=dataType#>[] q, <#=dataType#>[] work) + public override void QRFactor(<#=dataType#>[] r, int rowsR, int columnsR, <#=dataType#>[] q, <#=dataType#>[] work) { throw new NotImplementedException(); } @@ -389,14 +386,14 @@ /// /// 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. + /// 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. /// The B matrix. - /// The number of columns of B. + /// The number of columns of B. /// On exit, the solution matrix. - public override void QRSolve(<#=dataType#>[] r, int rRows, int rColumns, <#=dataType#>[] q, <#=dataType#>[] b, int bColumns, <#=dataType#>[] x) + public override void QRSolve(<#=dataType#>[] r, int rowsR, int columnsR, <#=dataType#>[] q, <#=dataType#>[] b, int columnsB, <#=dataType#>[] x) { throw new NotImplementedException(); } @@ -406,17 +403,17 @@ /// /// 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. + /// 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. /// The B matrix. - /// The number of columns of B. + /// 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. - public override void QRSolve(<#=dataType#>[] r, int rRows, int rColumns, <#=dataType#>[] q, <#=dataType#>[] b, int bColumns, <#=dataType#>[] x, <#=dataType#>[] work) + public override void QRSolve(<#=dataType#>[] r, int rowsR, int columnsR, <#=dataType#>[] q, <#=dataType#>[] b, int columnsB, <#=dataType#>[] x, <#=dataType#>[] work) { throw new NotImplementedException(); } @@ -426,12 +423,12 @@ /// /// The Q matrix obtained by calling . /// The R matrix obtained by calling . - /// The number of rows in the A matrix. - /// The number of columns in 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. + /// The number of columns of B. /// On exit, the solution matrix. - public override void QRSolveFactored(<#=dataType#>[] q, <#=dataType#>[] r, int rRows, int rColumns, <#=dataType#>[] b, int bColumns, <#=dataType#>[] x) + public override void QRSolveFactored(<#=dataType#>[] q, <#=dataType#>[] r, int rowsR, int columnsR, <#=dataType#>[] b, int columnsB, <#=dataType#>[] x) { throw new NotImplementedException(); } @@ -441,15 +438,15 @@ /// /// 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 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// This is equivalent to the GESVD LAPACK routine. - public override void SingularValueDecomposition(bool computeVectors, <#=dataType#>[] a, int aRows, int aColumns, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt) + public override void SingularValueDecomposition(bool computeVectors, <#=dataType#>[] a, int rowsA, int columnsA, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt) { throw new NotImplementedException(); } @@ -459,18 +456,18 @@ /// /// 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 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 + /// If is true, on exit U contains the left /// singular vectors. - /// If is true, on exit VT contains the transposed + /// If is true, on exit VT contains the transposed /// right singular vectors. /// The work array. For real matrices, the work array should be at least /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N). /// On exit, work[0] contains the optimal work size value. /// This is equivalent to the GESVD LAPACK routine. - public override void SingularValueDecomposition(bool computeVectors, <#=dataType#>[] a, int aRows, int aColumns, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt, <#=dataType#>[] work) + public override void SingularValueDecomposition(bool computeVectors, <#=dataType#>[] a, int rowsA, int columnsA, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt, <#=dataType#>[] work) { throw new NotImplementedException(); } @@ -479,15 +476,15 @@ /// Solves A*X=B for X using the singular value decomposition of A. /// /// 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 number of rows in the A matrix. + /// The number of columns in the A matrix. /// The singular values of A in ascending value. /// On exit U contains the left singular vectors. /// On exit VT contains the transposed right singular vectors. /// The B matrix. - /// The number of columns of B. + /// The number of columns of B. /// On exit, the solution matrix. - public override void SvdSolve(<#=dataType#>[] a, int aRows, int aColumns, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt, <#=dataType#>[] b, int bColumns, <#=dataType#>[] x) + public override void SvdSolve(<#=dataType#>[] a, int rowsA, int columnsA, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt, <#=dataType#>[] b, int columnsB, <#=dataType#>[] x) { throw new NotImplementedException(); } @@ -496,18 +493,18 @@ /// Solves A*X=B for X using the singular value decomposition of A. /// /// 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 number of rows in the A matrix. + /// The number of columns in the A matrix. /// The singular values of A in ascending value. /// On exit U contains the left singular vectors. /// On exit VT contains the transposed right singular vectors. /// The B matrix. - /// The number of columns of B. + /// The number of columns of B. /// On exit, the solution matrix. /// The work array. For real matrices, the work array should be at least /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N). /// On exit, work[0] contains the optimal work size value. - public override void SvdSolve(<#=dataType#>[] a, int aRows, int aColumns, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt, <#=dataType#>[] b, int bColumns, <#=dataType#>[] x, <#=dataType#>[] work) + public override void SvdSolve(<#=dataType#>[] a, int rowsA, int columnsA, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt, <#=dataType#>[] b, int columnsB, <#=dataType#>[] x, <#=dataType#>[] work) { throw new NotImplementedException(); } @@ -515,15 +512,15 @@ /// /// 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 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. + /// The number of columns of B. /// On exit, the solution matrix. - public override void SvdSolveFactored(int aRows, int aColumns, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt, <#=dataType#>[] b, int bColumns, <#=dataType#>[] x) + public override void SvdSolveFactored(int rowsA, int columnsA, <#=dataType#>[] s, <#=dataType#>[] u, <#=dataType#>[] vt, <#=dataType#>[] b, int columnsB, <#=dataType#>[] x) { throw new NotImplementedException(); } diff --git a/src/Numerics/Algorithms/LinearAlgebra/native.header.include b/src/Numerics/Algorithms/LinearAlgebra/native.header.include index 8ef87640..ca4dcae8 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/native.header.include +++ b/src/Numerics/Algorithms/LinearAlgebra/native.header.include @@ -35,11 +35,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> { using System; - using System.Numerics; + using System.Numerics; using Properties; - /// + /// /// <#=title#> linear algebra provider. /// public partial class <#=library#>LinearAlgebraProvider : ManagedLinearAlgebraProvider - { + { \ No newline at end of file diff --git a/src/Numerics/Algorithms/LinearAlgebra/native.vector.include b/src/Numerics/Algorithms/LinearAlgebra/native.vector.include index 505c15e8..2380fb44 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/native.vector.include +++ b/src/Numerics/Algorithms/LinearAlgebra/native.vector.include @@ -30,7 +30,7 @@ throw new ArgumentException(Resources.ArgumentArraysSameLength); } - SafeNativeMethods.<#=prefix#>_vector_add( x.Length, x, y, result ); + SafeNativeMethods.<#=prefix#>_vector_add(x.Length, x, y, result); } /// @@ -65,7 +65,7 @@ throw new ArgumentException(Resources.ArgumentArraysSameLength); } - SafeNativeMethods.<#=prefix#>_vector_subtract( x.Length, x, y, result ); + SafeNativeMethods.<#=prefix#>_vector_subtract(x.Length, x, y, result); } /// @@ -100,5 +100,40 @@ throw new ArgumentException(Resources.ArgumentArraysSameLength); } - SafeNativeMethods.<#=prefix#>_vector_multiply( x.Length, x, y, result ); + SafeNativeMethods.<#=prefix#>_vector_multiply(x.Length, x, y, 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. + public override void PointWiseDivideArrays(<#=dataType#>[] x, <#=dataType#>[] y, <#=dataType#>[] result) + { + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + if (x.Length != result.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + SafeNativeMethods.<#=prefix#>_vector_divide(x.Length, x, y, result); } \ No newline at end of file diff --git a/src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include b/src/Numerics/Algorithms/LinearAlgebra/safe.native.common.include similarity index 99% rename from src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include rename to src/Numerics/Algorithms/LinearAlgebra/safe.native.common.include index e90772a3..756685fb 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include +++ b/src/Numerics/Algorithms/LinearAlgebra/safe.native.common.include @@ -27,7 +27,6 @@ // /* This file is automatically generated - do not modify it. - Change SafeNativeMethods.include instead. Last generated on UTC <#=DateTime.UtcNow.ToString("u")#> */ diff --git a/src/Numerics/Algorithms/LinearAlgebra/safe.native.vector.include b/src/Numerics/Algorithms/LinearAlgebra/safe.native.vector.include new file mode 100644 index 00000000..29b0cc1f --- /dev/null +++ b/src/Numerics/Algorithms/LinearAlgebra/safe.native.vector.include @@ -0,0 +1,52 @@ + + #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); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void s_vector_subtract(int n, float[] x, float[] y, [In, Out] float[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void s_vector_multiply(int n, float[] x, float[] y, [In, Out] float[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void s_vector_divide(int n, float[] x, float[] y, [In, Out] float[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void d_vector_add(int n, double[] x, double[] y, [In, Out] double[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void d_vector_subtract(int n, double[] x, double[] y, [In, Out] double[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void d_vector_multiply(int n, double[] x, double[] y, [In, Out] double[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void d_vector_divide(int n, double[] x, double[] y, [In, Out] double[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void c_vector_add(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void c_vector_subtract(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void c_vector_multiply(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void c_vector_divide(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void z_vector_add(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void z_vector_subtract(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void z_vector_multiply(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result); + + [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 \ No newline at end of file diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 20dc4381..ca93c503 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -70,6 +70,9 @@ + + SafeNativeMethods.cs + @@ -456,7 +459,7 @@ MathNet.Numerics.snk - + SafeNativeMethods.cs