From b540acb3fe8584c57d08ec2428189616e8a67318 Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Mon, 16 Nov 2009 16:21:40 +0800 Subject: [PATCH] adding dot product --- .../Atlas/AtlasLinearAlgebraProvider.cs | 156 ++++++++++++------ .../LinearAlgebra/Atlas/SafeNativeMethods.cs | 14 +- .../ILinearAlgebraProviderOfT.cs | 16 +- .../Mkl/MklLinearAlgebraProvider.cs | 156 ++++++++++++------ .../LinearAlgebra/Mkl/SafeNativeMethods.cs | 14 +- .../NativeAlgebraProvider.include | 152 +++++++++++------ .../LinearAlgebra/SafeNativeMethods.include | 12 ++ src/Numerics/Properties/Resources.Designer.cs | 11 +- 8 files changed, 365 insertions(+), 166 deletions(-) diff --git a/src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs b/src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs index ccb25f89..4ede1bc8 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs @@ -24,7 +24,11 @@ /* This file is automatically generated - do not modify it. Change NativeLinearAlgebraProvider.include instead. +<<<<<<< HEAD:src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs Last generated on: 14/11/2009 20:09:22 +======= + Last generated on: 11/13/2009 9:49:35 AM +>>>>>>> c1c4de3... adding dot product:src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs */ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas { @@ -36,7 +40,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// public class AtlasLinearAlgebraProvider : ILinearAlgebraProvider { - #region ILinearAlgebraProvider Members + #region ILinearAlgebraProvider Members /// /// Adds a scaled vector to another: y += alpha*x. @@ -78,6 +82,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(double alpha, double[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha == 1.0) { return; @@ -86,20 +95,6 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas SafeNativeMethods.d_scale(x.Length, alpha, x); } - /// - /// 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. - /// - public int QueryWorkspaceBlockSize(string methodName) - { - throw new NotImplementedException(); - } - /// /// Computes the dot product of x and y. /// @@ -109,7 +104,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the DOT BLAS routine. public double DotProduct(double[] x, double[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.d_dot_product(x.Length, x, y); } /// @@ -261,8 +271,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(double[] a, double[] work) @@ -276,8 +285,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(double[] a, int[] ipiv, double[] work) @@ -393,8 +401,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(double[] r, double[] q, double[] work) { @@ -427,8 +434,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, double[] r, double[] q, double[] b, double[] x, double[] work) { @@ -572,6 +578,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(float alpha, float[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha == 1.0) { return; @@ -589,7 +600,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the DOT BLAS routine. public float DotProduct(float[] x, float[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.s_dot_product(x.Length, x, y); } /// @@ -741,8 +767,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(float[] a, float[] work) @@ -756,8 +781,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(float[] a, int[] ipiv, float[] work) @@ -873,8 +897,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(float[] r, float[] q, float[] work) { @@ -907,8 +930,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, float[] r, float[] q, float[] b, float[] x, float[] work) { @@ -1052,6 +1074,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(Complex alpha, Complex[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha.IsOne) { return; @@ -1069,7 +1096,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the DOT BLAS routine. public Complex DotProduct(Complex[] x, Complex[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.z_dot_product(x.Length, x, y); } /// @@ -1221,8 +1263,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(Complex[] a, Complex[] work) @@ -1236,8 +1277,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(Complex[] a, int[] ipiv, Complex[] work) @@ -1353,8 +1393,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(Complex[] r, Complex[] q, Complex[] work) { @@ -1387,8 +1426,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, Complex[] r, Complex[] q, Complex[] b, Complex[] x, Complex[] work) { @@ -1532,6 +1570,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(Complex32 alpha, Complex32[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha.IsOne) { return; @@ -1549,7 +1592,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the DOT BLAS routine. public Complex32 DotProduct(Complex32[] x, Complex32[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.c_dot_product(x.Length, x, y); } /// @@ -1701,8 +1759,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(Complex32[] a, Complex32[] work) @@ -1716,8 +1773,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(Complex32[] a, int[] ipiv, Complex32[] work) @@ -1833,8 +1889,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(Complex32[] r, Complex32[] q, Complex32[] work) { @@ -1867,8 +1922,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, Complex32[] r, Complex32[] q, Complex32[] b, Complex32[] x, Complex32[] work) { diff --git a/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs b/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs index 3f71ad2c..df8d7a1c 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs @@ -28,7 +28,7 @@ /* This file is automatically generated - do not modify it. Change SafeNativeMethods.include instead. - Last generated on: 11/6/2009 2:44:00 PM + Last generated on: 11/13/2009 9:49:42 AM */ using System.Runtime.InteropServices; @@ -73,6 +73,18 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_scale(int n, ref 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); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern double d_dot_product(int n, double[] x, double[] y); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern Complex32 c_dot_product(int n, Complex32[] x, Complex32[] y); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y); + #endregion BLAS } } diff --git a/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProviderOfT.cs b/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProviderOfT.cs index c90e7be1..6327e3de 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProviderOfT.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProviderOfT.cs @@ -79,14 +79,14 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// Supported data types are double, single, , and . public interface ILinearAlgebraProvider where T : 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); + int QueryWorkspaceBlockSize(string methodName);*/ /// /// Adds a scaled vector to another: y += alpha*x. @@ -233,8 +233,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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, T[] work); @@ -245,8 +244,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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[] ipiv, T[] work); @@ -335,8 +333,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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[] r, T[] q, T[] work); @@ -364,8 +361,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. void QRSolve(int columnsOfB, T[] r, T[] q, T[] b, T[] x, T[] work); diff --git a/src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs b/src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs index 1deb0d4d..3d8ce29a 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs @@ -24,7 +24,11 @@ /* This file is automatically generated - do not modify it. Change NativeLinearAlgebraProvider.include instead. +<<<<<<< HEAD:src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs Last generated on: 14/11/2009 20:09:20 +======= + Last generated on: 11/6/2009 3:03:50 PM +>>>>>>> c1c4de3... adding dot product:src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs */ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl { @@ -36,7 +40,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// public class MklLinearAlgebraProvider : ILinearAlgebraProvider { - #region ILinearAlgebraProvider Members + #region ILinearAlgebraProvider Members /// /// Adds a scaled vector to another: y += alpha*x. @@ -78,6 +82,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(double alpha, double[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha == 1.0) { return; @@ -86,20 +95,6 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl SafeNativeMethods.d_scale(x.Length, alpha, x); } - /// - /// 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. - /// - public int QueryWorkspaceBlockSize(string methodName) - { - throw new NotImplementedException(); - } - /// /// Computes the dot product of x and y. /// @@ -109,7 +104,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the DOT BLAS routine. public double DotProduct(double[] x, double[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.d_dot_product(x.Length, x, y); } /// @@ -261,8 +271,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(double[] a, double[] work) @@ -276,8 +285,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(double[] a, int[] ipiv, double[] work) @@ -393,8 +401,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(double[] r, double[] q, double[] work) { @@ -427,8 +434,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, double[] r, double[] q, double[] b, double[] x, double[] work) { @@ -572,6 +578,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(float alpha, float[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha == 1.0) { return; @@ -589,7 +600,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the DOT BLAS routine. public float DotProduct(float[] x, float[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.s_dot_product(x.Length, x, y); } /// @@ -741,8 +767,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(float[] a, float[] work) @@ -756,8 +781,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(float[] a, int[] ipiv, float[] work) @@ -873,8 +897,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(float[] r, float[] q, float[] work) { @@ -907,8 +930,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, float[] r, float[] q, float[] b, float[] x, float[] work) { @@ -1052,6 +1074,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(Complex alpha, Complex[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha.IsOne) { return; @@ -1069,7 +1096,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the DOT BLAS routine. public Complex DotProduct(Complex[] x, Complex[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.z_dot_product(x.Length, x, y); } /// @@ -1221,8 +1263,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(Complex[] a, Complex[] work) @@ -1236,8 +1277,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(Complex[] a, int[] ipiv, Complex[] work) @@ -1353,8 +1393,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(Complex[] r, Complex[] q, Complex[] work) { @@ -1387,8 +1426,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, Complex[] r, Complex[] q, Complex[] b, Complex[] x, Complex[] work) { @@ -1532,6 +1570,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(Complex32 alpha, Complex32[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha.IsOne) { return; @@ -1549,7 +1592,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the DOT BLAS routine. public Complex32 DotProduct(Complex32[] x, Complex32[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.c_dot_product(x.Length, x, y); } /// @@ -1701,8 +1759,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(Complex32[] a, Complex32[] work) @@ -1716,8 +1773,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(Complex32[] a, int[] ipiv, Complex32[] work) @@ -1833,8 +1889,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(Complex32[] r, Complex32[] q, Complex32[] work) { @@ -1867,8 +1922,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, Complex32[] r, Complex32[] q, Complex32[] b, Complex32[] x, Complex32[] work) { diff --git a/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs b/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs index c44ca405..b3413960 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs @@ -28,7 +28,7 @@ /* This file is automatically generated - do not modify it. Change SafeNativeMethods.include instead. - Last generated on: 11/6/2009 2:44:03 PM + Last generated on: 11/13/2009 9:49:46 AM */ using System.Runtime.InteropServices; @@ -73,6 +73,18 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_scale(int n, ref 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); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern double d_dot_product(int n, double[] x, double[] y); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern Complex32 c_dot_product(int n, Complex32[] x, Complex32[] y); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y); + #endregion BLAS } } diff --git a/src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include b/src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include index addb970c..a916be82 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include +++ b/src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include @@ -36,7 +36,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// public class <#=library#>LinearAlgebraProvider : ILinearAlgebraProvider { - #region ILinearAlgebraProvider Members + #region ILinearAlgebraProvider Members /// /// Adds a scaled vector to another: y += alpha*x. @@ -78,6 +78,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(double alpha, double[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha == 1.0) { return; @@ -86,20 +91,6 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> SafeNativeMethods.d_scale(x.Length, alpha, x); } - /// - /// 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. - /// - public int QueryWorkspaceBlockSize(string methodName) - { - throw new NotImplementedException(); - } - /// /// Computes the dot product of x and y. /// @@ -109,7 +100,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the DOT BLAS routine. public double DotProduct(double[] x, double[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.d_dot_product(x.Length, x, y); } /// @@ -261,8 +267,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(double[] a, double[] work) @@ -276,8 +281,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(double[] a, int[] ipiv, double[] work) @@ -393,8 +397,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(double[] r, double[] q, double[] work) { @@ -427,8 +430,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, double[] r, double[] q, double[] b, double[] x, double[] work) { @@ -572,6 +574,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(float alpha, float[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha == 1.0) { return; @@ -589,7 +596,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the DOT BLAS routine. public float DotProduct(float[] x, float[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.s_dot_product(x.Length, x, y); } /// @@ -741,8 +763,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(float[] a, float[] work) @@ -756,8 +777,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(float[] a, int[] ipiv, float[] work) @@ -873,8 +893,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(float[] r, float[] q, float[] work) { @@ -907,8 +926,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, float[] r, float[] q, float[] b, float[] x, float[] work) { @@ -1052,6 +1070,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(Complex alpha, Complex[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha.IsOne) { return; @@ -1069,7 +1092,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the DOT BLAS routine. public Complex DotProduct(Complex[] x, Complex[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.z_dot_product(x.Length, x, y); } /// @@ -1221,8 +1259,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(Complex[] a, Complex[] work) @@ -1236,8 +1273,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(Complex[] a, int[] ipiv, Complex[] work) @@ -1353,8 +1389,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(Complex[] r, Complex[] q, Complex[] work) { @@ -1387,8 +1422,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, Complex[] r, Complex[] q, Complex[] b, Complex[] x, Complex[] work) { @@ -1532,6 +1566,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the SCAL BLAS routine. public void ScaleArray(Complex32 alpha, Complex32[] x) { + if (x == null) + { + throw new ArgumentNullException("x"); + } + if (alpha.IsOne) { return; @@ -1549,7 +1588,22 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the DOT BLAS routine. public Complex32 DotProduct(Complex32[] x, Complex32[] y) { - throw new NotImplementedException(); + if (y == null) + { + throw new ArgumentNullException("y"); + } + + if (x == null) + { + throw new ArgumentNullException("x"); + } + + if (x.Length != y.Length) + { + throw new ArgumentException(Resources.ArgumentArraysSameLength); + } + + return SafeNativeMethods.c_dot_product(x.Length, x, y); } /// @@ -1701,8 +1755,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// /// The N by N matrix to invert. Contains the inverse On exit. /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverse(Complex32[] a, Complex32[] work) @@ -1716,8 +1769,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// The LU factored N by N matrix. Contains the inverse On exit. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// 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. public void LUInverseFactored(Complex32[] a, int[] ipiv, Complex32[] work) @@ -1833,8 +1885,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRFactor(Complex32[] r, Complex32[] q, Complex32[] work) { @@ -1867,8 +1918,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// The B matrix. /// 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. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal + /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal /// work size value. public void QRSolve(int columnsOfB, Complex32[] r, Complex32[] q, Complex32[] b, Complex32[] x, Complex32[] work) { diff --git a/src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include b/src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include index 61dfc9d5..cf4605cc 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include +++ b/src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include @@ -73,6 +73,18 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#= namespaceSuffix #> [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern void z_scale(int n, ref 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); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern double d_dot_product(int n, double[] x, double[] y); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern Complex32 c_dot_product(int n, Complex32[] x, Complex32[] y); + + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y); + #endregion BLAS } } diff --git a/src/Numerics/Properties/Resources.Designer.cs b/src/Numerics/Properties/Resources.Designer.cs index 11addd24..6d990350 100644 --- a/src/Numerics/Properties/Resources.Designer.cs +++ b/src/Numerics/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.4200 +// Runtime Version:2.0.50727.4927 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -60,6 +60,15 @@ namespace MathNet.Numerics.Properties { } } + /// + /// Looks up a localized string similar to All arrays must have the same length.. + /// + internal static string ArgumentArraysSameLength { + get { + return ResourceManager.GetString("ArgumentArraysSameLength", resourceCulture); + } + } + /// /// Looks up a localized string similar to The argument must be between 0 and 1.. ///