From e2ef47c57478c942802f38cd31678b0efdec5ba1 Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Mon, 14 Feb 2011 20:53:37 +0800 Subject: [PATCH] fixed native scale bugs and added pointwise divide --- src/NativeWrappers/MKL/vector_functions.c | 16 ++++++++++++++++ .../MKLWrapper32Tests/MKLWrapper32Tests.csproj | 4 ++-- .../MKLWrapper64Tests/MKLWrapper64Tests.csproj | 2 +- .../LinearAlgebra/native.generic.include | 18 ++++++++++-------- .../LinearAlgebra/native.vector.include | 2 +- .../Double/LinearAlgebraProviderTests.cs | 15 +++++++++++++++ 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/NativeWrappers/MKL/vector_functions.c b/src/NativeWrappers/MKL/vector_functions.c index a8795930..080b641a 100644 --- a/src/NativeWrappers/MKL/vector_functions.c +++ b/src/NativeWrappers/MKL/vector_functions.c @@ -15,6 +15,10 @@ DLLEXPORT void s_vector_multiply( const int n, const float x[], const float y[], vsMul( n, x, y, result ); } +DLLEXPORT void s_vector_divide( const int n, const float x[], const float y[], float result[] ){ + vsDiv( n, x, y, result ); +} + DLLEXPORT void d_vector_add( const int n, const double x[], const double y[], double result[] ){ vdAdd( n, x, y, result ); } @@ -27,6 +31,10 @@ DLLEXPORT void d_vector_multiply( const int n, const double x[], const double y[ vdMul( n, x, y, result ); } +DLLEXPORT void d_vector_divide( const int n, const double x[], const double y[], double result[] ){ + vdDiv( n, x, y, result ); +} + DLLEXPORT void c_vector_add( const int n, const Complex8 x[], const Complex8 y[], Complex8 result[] ){ vcAdd( n, x, y, result ); } @@ -39,6 +47,10 @@ DLLEXPORT void c_vector_multiply( const int n, const Complex8 x[], const Complex vcMul( n, x, y, result ); } +DLLEXPORT void c_vector_divide( const int n, const Complex8 x[], const Complex8 y[], Complex8 result[] ){ + vcDiv( n, x, y, result ); +} + DLLEXPORT void z_vector_add( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){ vzAdd( n, x, y, result ); } @@ -50,3 +62,7 @@ DLLEXPORT void z_vector_subtract( const int n, const Complex16 x[], const Comple DLLEXPORT void z_vector_multiply( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){ vzMul( n, x, y, result ); } + +DLLEXPORT void z_vector_divide( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){ + vzDiv( n, x, y, result ); +} diff --git a/src/NativeWrappers/Windows/MKLWrapper32Tests/MKLWrapper32Tests.csproj b/src/NativeWrappers/Windows/MKLWrapper32Tests/MKLWrapper32Tests.csproj index c6be9618..be06bfa8 100644 --- a/src/NativeWrappers/Windows/MKLWrapper32Tests/MKLWrapper32Tests.csproj +++ b/src/NativeWrappers/Windows/MKLWrapper32Tests/MKLWrapper32Tests.csproj @@ -55,9 +55,9 @@ AllRules.ruleset - + False - ..\..\..\..\out\lib\Net40\MathNet.Numerics.dll + ..\..\..\..\out\debug\Net40\MathNet.Numerics.dll ..\..\..\..\lib\NUnit.2.5.9\nunit.framework.dll diff --git a/src/NativeWrappers/Windows/MKLWrapper64Tests/MKLWrapper64Tests.csproj b/src/NativeWrappers/Windows/MKLWrapper64Tests/MKLWrapper64Tests.csproj index 735bbfc3..31dda2c3 100644 --- a/src/NativeWrappers/Windows/MKLWrapper64Tests/MKLWrapper64Tests.csproj +++ b/src/NativeWrappers/Windows/MKLWrapper64Tests/MKLWrapper64Tests.csproj @@ -55,7 +55,7 @@ AllRules.ruleset - + False ..\..\..\..\out\debug\Net40\MathNet.Numerics.dll diff --git a/src/Numerics/Algorithms/LinearAlgebra/native.generic.include b/src/Numerics/Algorithms/LinearAlgebra/native.generic.include index 47fad92c..9406942d 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/native.generic.include +++ b/src/Numerics/Algorithms/LinearAlgebra/native.generic.include @@ -23,15 +23,16 @@ throw new ArgumentException(Resources.ArgumentVectorsSameLength); } + if (!ReferenceEquals(y, result)) + { + Array.Copy(y, 0, result, 0, y.Length); + } + if (alpha == <#=zero#>) { return; } - if (!ReferenceEquals(y, result)){ - Array.Copy(y, 0, result, 0, y.Length * 8); - } - SafeNativeMethods.<#=prefix#>_axpy(y.Length, <#=reff#>alpha, x, result); } @@ -49,15 +50,16 @@ throw new ArgumentNullException("x"); } + if (!ReferenceEquals(x, result)) + { + Array.Copy(x, 0, result, 0, x.Length); + } + if (alpha == <#=one#>) { return; } - if (!ReferenceEquals(x, result)){ - Array.Copy(x, 0, result, 0, x.Length * 8); - } - SafeNativeMethods.<#=prefix#>_scale(x.Length, <#=reff#>alpha, result); } diff --git a/src/Numerics/Algorithms/LinearAlgebra/native.vector.include b/src/Numerics/Algorithms/LinearAlgebra/native.vector.include index 2380fb44..f2885eb1 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/native.vector.include +++ b/src/Numerics/Algorithms/LinearAlgebra/native.vector.include @@ -103,7 +103,7 @@ 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. /// diff --git a/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs index f488b918..d98152c3 100644 --- a/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs +++ b/src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs @@ -181,6 +181,21 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double } } + /// + /// Can pointwise divide two arrays. + /// + [Test] + public void CanPointWiseDivideArrays() + { + var result = new double[_y.Length]; + Provider.PointWiseDivideArrays(_x, _y, result); + for (var i = 0; i < result.Length; i++) + { + Assert.AreEqual(_x[i] / _y[i], result[i]); + } + } + + /// /// Can compute L1 norm. ///