From d1bed102119f861fece8309714afe9b3f7695109 Mon Sep 17 00:00:00 2001 From: Darren Schroeder Date: Sun, 4 Nov 2018 14:05:18 -0600 Subject: [PATCH] Unified solution on dotnetcore2.1 Made NumSharp.csproj, NumSharp.Benchmark.csproj, and NumSharp.UnitTest.csproj use the same settings. This is in preparation for Span. Fixed a warning in NdArray with GetHashCode. --- src/NumSharp/Extensions/NdArray.Array.cs | 16 ++-- src/NumSharp/NdArray.cs | 12 +++ src/NumSharp/NumSharp.csproj | 96 +++++++++++-------- .../NumSharp.Benchmark.csproj | 41 ++++++++ .../Extensions/NdArray.Array.Test.cs | 3 +- .../NumSharp.UnitTest.csproj | 43 ++++++++- 6 files changed, 158 insertions(+), 53 deletions(-) diff --git a/src/NumSharp/Extensions/NdArray.Array.cs b/src/NumSharp/Extensions/NdArray.Array.cs index a4241cc3..23280ff4 100644 --- a/src/NumSharp/Extensions/NdArray.Array.cs +++ b/src/NumSharp/Extensions/NdArray.Array.cs @@ -3,13 +3,8 @@ using System.ComponentModel; using System.Linq; using System.Text; -#if NETFRAMEWORK || NETSTANDARD using System.Drawing; -#endif -#if NETCORE -using System.Drawing.Common; -#endif - + namespace NumSharp { public static partial class NDArrayExtensions @@ -21,11 +16,12 @@ public static NDArray Array(this NDArray np, IEnumerable Array(this NDArray np, Bitmap image ) + + public static NDArray Array(this NDArray np, System.Drawing.Bitmap image ) { NDArray imageArray = new NDArray(); - var bmpd = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, image.PixelFormat); + var bmpd = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, image.PixelFormat); var dataSize = bmpd.Stride * bmpd.Height; imageArray.Data = new byte[dataSize]; @@ -35,13 +31,15 @@ public static NDArray Array(this NDArray np, Bitmap image ) imageArray.Shape = new int[] { bmpd.Height, bmpd.Width, 3 }; return imageArray; - } + } + public static NDArray Array(this NDArray np, TData[][] array ) { np.Data = array; return np; } + public static NDArray Array(this NDArray np, TData[] array) { np.Data = array; diff --git a/src/NumSharp/NdArray.cs b/src/NumSharp/NdArray.cs index e5c8f60a..bd7018d3 100644 --- a/src/NumSharp/NdArray.cs +++ b/src/NumSharp/NdArray.cs @@ -213,6 +213,18 @@ public override bool Equals(object obj) { return np.Data[0].Equals(obj); } + + public override int GetHashCode() + { + unchecked + { + var result = 1337; + result = (result * 397) ^ this.NDim; + result = (result * 397) ^ this.Size; + return result; + } + } + public TCast ToDotNetArray() { dynamic dotNetArray = null; diff --git a/src/NumSharp/NumSharp.csproj b/src/NumSharp/NumSharp.csproj index 23b9202c..620bc33b 100644 --- a/src/NumSharp/NumSharp.csproj +++ b/src/NumSharp/NumSharp.csproj @@ -1,46 +1,62 @@ - - - - netstandard2.0 - true - true - Haiping Chen - NumPy port in C# - https://github.com/Oceania2018/NumSharp - Apache 2.0 - https://github.com/Oceania2018/NumSharp - Implemented arange, reshape, max, min, normalize. - 0.1.0.0 - 0.1.0.0 - git - NumPy, NumSharp, MachineLearning, Math, Scientific, Numeric - 0.1.0 - https://raw.githubusercontent.com/Oceania2018/NumSharp/master/LICENSE - latest - - - - win-x86 - - - + + + netcoreapp2.1 + true + true + Haiping Chen, Christian Kahr, Darren Schroeder + NumPy port in C# + https://github.com/Oceania2018/NumSharp + Apache 2.0 + https://github.com/Oceania2018/NumSharp + Implemented arange, reshape, max, min, normalize. + 0.1.0.0 + 0.1.0.0 + git + NumPy, NumSharp, MachineLearning, Math, Scientific, Numeric + 0.1.0 + https://raw.githubusercontent.com/Oceania2018/NumSharp/master/LICENSE + latest + + + NETFRAMEWORK - - + win-x86 + + + NETSTANDARD - - + + + NETCORE - + + + + DEBUG;TRACE + + + + + + + + + + + + + + + + - - DEBUG;TRACE - + + + + - - - - - + + + - + \ No newline at end of file diff --git a/test/NumSharp.Benchmark/NumSharp.Benchmark.csproj b/test/NumSharp.Benchmark/NumSharp.Benchmark.csproj index 23df6047..6d39d6f3 100644 --- a/test/NumSharp.Benchmark/NumSharp.Benchmark.csproj +++ b/test/NumSharp.Benchmark/NumSharp.Benchmark.csproj @@ -5,4 +5,45 @@ netcoreapp2.1 + + NETFRAMEWORK + win-x86 + + + + NETSTANDARD + + + + NETCORE + + + + DEBUG;TRACE + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/NumSharp.UnitTest/Extensions/NdArray.Array.Test.cs b/test/NumSharp.UnitTest/Extensions/NdArray.Array.Test.cs index d610c1c6..794a8e5a 100644 --- a/test/NumSharp.UnitTest/Extensions/NdArray.Array.Test.cs +++ b/test/NumSharp.UnitTest/Extensions/NdArray.Array.Test.cs @@ -43,9 +43,8 @@ public void ArrayImage() var imagePath = System.IO.Path.Combine(pwd,"./data/image.jpg"); var image = new System.Drawing.Bitmap(imagePath); - var imageNDArray = new NDArray().Array(image); - + Assert.IsTrue(imageNDArray[0,0,0] == 255); Assert.IsTrue(imageNDArray[0,0,1] == 253); Assert.IsTrue(imageNDArray[0,0,2] == 252); diff --git a/test/NumSharp.UnitTest/NumSharp.UnitTest.csproj b/test/NumSharp.UnitTest/NumSharp.UnitTest.csproj index 2ae373e0..78010ae5 100644 --- a/test/NumSharp.UnitTest/NumSharp.UnitTest.csproj +++ b/test/NumSharp.UnitTest/NumSharp.UnitTest.csproj @@ -2,15 +2,54 @@ netcoreapp2.1 - false + + NETFRAMEWORK + win-x86 + + + + NETSTANDARD + + + + NETCORE + + + + DEBUG;TRACE + + + + + + + + + + + + + + + + + + + + + + + + + + -