Skip to content

Commit

Permalink
Unified solution on dotnetcore2.1
Browse files Browse the repository at this point in the history
Made NumSharp.csproj, NumSharp.Benchmark.csproj, and NumSharp.UnitTest.csproj use the same settings. This is in preparation for Span<T>.

Fixed a warning in NdArray with GetHashCode.
  • Loading branch information
fdncred committed Nov 4, 2018
1 parent 74c4ff8 commit d1bed10
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 53 deletions.
16 changes: 7 additions & 9 deletions src/NumSharp/Extensions/NdArray.Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,11 +16,12 @@ public static NDArray<TData> Array<TData>(this NDArray<TData> np, IEnumerable<TD

return np;
}
public static NDArray<Byte> Array(this NDArray<Byte> np, Bitmap image )

public static NDArray<Byte> Array(this NDArray<Byte> np, System.Drawing.Bitmap image )
{
NDArray<Byte> imageArray = new NDArray<byte>();

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];
Expand All @@ -35,13 +31,15 @@ public static NDArray<Byte> Array(this NDArray<Byte> np, Bitmap image )
imageArray.Shape = new int[] { bmpd.Height, bmpd.Width, 3 };

return imageArray;
}
}

public static NDArray<TData[]> Array<TData>(this NDArray<TData[]> np, TData[][] array )
{
np.Data = array;

return np;
}

public static NDArray<TData> Array<TData>(this NDArray<TData> np, TData[] array)
{
np.Data = array;
Expand Down
12 changes: 12 additions & 0 deletions src/NumSharp/NdArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TCast>()
{
dynamic dotNetArray = null;
Expand Down
96 changes: 56 additions & 40 deletions src/NumSharp/NumSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,46 +1,62 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>Haiping Chen</Authors>
<Description>NumPy port in C#</Description>
<PackageProjectUrl>https://github.com/Oceania2018/NumSharp</PackageProjectUrl>
<Copyright>Apache 2.0</Copyright>
<RepositoryUrl>https://github.com/Oceania2018/NumSharp</RepositoryUrl>
<PackageReleaseNotes>Implemented arange, reshape, max, min, normalize.</PackageReleaseNotes>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
<FileVersion>0.1.0.0</FileVersion>
<RepositoryType>git</RepositoryType>
<PackageTags>NumPy, NumSharp, MachineLearning, Math, Scientific, Numeric</PackageTags>
<Version>0.1.0</Version>
<PackageLicenseUrl>https://raw.githubusercontent.com/Oceania2018/NumSharp/master/LICENSE</PackageLicenseUrl>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net472'">
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^net\d'))">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>Haiping Chen, Christian Kahr, Darren Schroeder</Authors>
<Description>NumPy port in C#</Description>
<PackageProjectUrl>https://github.com/Oceania2018/NumSharp</PackageProjectUrl>
<Copyright>Apache 2.0</Copyright>
<RepositoryUrl>https://github.com/Oceania2018/NumSharp</RepositoryUrl>
<PackageReleaseNotes>Implemented arange, reshape, max, min, normalize.</PackageReleaseNotes>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
<FileVersion>0.1.0.0</FileVersion>
<RepositoryType>git</RepositoryType>
<PackageTags>NumPy, NumSharp, MachineLearning, Math, Scientific, Numeric</PackageTags>
<Version>0.1.0</Version>
<PackageLicenseUrl>https://raw.githubusercontent.com/Oceania2018/NumSharp/master/LICENSE</PackageLicenseUrl>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^net\d'))">
<DefineConstants>NETFRAMEWORK</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netstandard\d'))">
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netstandard\d'))">
<DefineConstants>NETSTANDARD</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netcoreapp\d'))">
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netcoreapp\d'))">
<DefineConstants>NETCORE</DefineConstants>
</PropertyGroup>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^net\d'))">
<PackageReference Include="System.Drawing" Version="4.0.0" />
</ItemGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netstandard\d'))">
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.1" />
</ItemGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netcoreapp\d'))">
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.1" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="System.Memory" Version="4.5.1" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
<Target Name="LogDebugInfo">
<Message Text="Building for $(TargetFramework) on $(OS)" Importance="High" />
</Target>

</Project>
</Project>
41 changes: 41 additions & 0 deletions test/NumSharp.Benchmark/NumSharp.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,45 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^net\d'))">
<DefineConstants>NETFRAMEWORK</DefineConstants>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netstandard\d'))">
<DefineConstants>NETSTANDARD</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netcoreapp\d'))">
<DefineConstants>NETCORE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^net\d'))">
<PackageReference Include="System.Drawing" Version="4.0.0" />
</ItemGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netstandard\d'))">
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.1" />
</ItemGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netcoreapp\d'))">
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.1" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="System.Memory" Version="4.5.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>

<Target Name="LogDebugInfo">
<Message Text="Building for $(TargetFramework) on $(OS)" Importance="High" />
</Target>

</Project>
3 changes: 1 addition & 2 deletions test/NumSharp.UnitTest/Extensions/NdArray.Array.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>().Array(image);

Assert.IsTrue(imageNDArray[0,0,0] == 255);
Assert.IsTrue(imageNDArray[0,0,1] == 253);
Assert.IsTrue(imageNDArray[0,0,2] == 252);
Expand Down
43 changes: 41 additions & 2 deletions test/NumSharp.UnitTest/NumSharp.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,54 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^net\d'))">
<DefineConstants>NETFRAMEWORK</DefineConstants>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netstandard\d'))">
<DefineConstants>NETSTANDARD</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netcoreapp\d'))">
<DefineConstants>NETCORE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^net\d'))">
<PackageReference Include="System.Drawing" Version="4.0.0" />
</ItemGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netstandard\d'))">
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.1" />
</ItemGroup>

<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFramework)', '^netcoreapp\d'))">
<PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.1" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="System.Memory" Version="4.5.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>

<Target Name="LogDebugInfo">
<Message Text="Building for $(TargetFramework) on $(OS)" Importance="High" />
</Target>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down

1 comment on commit d1bed10

@Oceania2018
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just include System.Memory package, we can keep using netstandard2.0

Please sign in to comment.