Skip to content

Commit

Permalink
add NDArray to ValueType
Browse files Browse the repository at this point in the history
  • Loading branch information
Oceania2018 committed Jan 26, 2019
1 parent af8b3a2 commit aa570de
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
47 changes: 39 additions & 8 deletions src/NumSharp.Core/Casting/Implicit/NdArray.Implicit.ValueTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@
using System.Text;
using System.Globalization;
using System.Collections;
using NumSharp.Core;
using System.Numerics;

namespace NumSharp.Core
{
public partial class NDArray
{
public static implicit operator NDArray(float d)
{
var ndArray = new NDArray(typeof(float), new int[0]);
ndArray.Storage.SetData(new float[] { d });

return ndArray;
}

public static implicit operator float(NDArray nd)
{
if (nd.ndim > 0)
Expand All @@ -38,20 +45,20 @@ public static implicit operator float(NDArray nd)
return nd.Data<float>(0);
}

public static implicit operator NDArray(float d)
public static implicit operator NDArray(double d)
{
var ndArray = new NDArray(typeof(float), new int[0]);
ndArray.Storage.SetData(new float[] { d });
var ndArray = new NDArray(typeof(double),new int[0]);
ndArray.Storage.SetData(new double[]{d});

return ndArray;
}

public static implicit operator NDArray(double d)
public static implicit operator double(NDArray nd)
{
var ndArray = new NDArray(typeof(double),new int[0]);
ndArray.Storage.SetData(new double[]{d});
if (nd.ndim > 0)
throw new IncorrectShapeException();

return ndArray;
return nd.Data<double>(0);
}

public static implicit operator NDArray(short d)
Expand All @@ -62,6 +69,14 @@ public static implicit operator NDArray(short d)
return ndArray;
}

public static implicit operator short(NDArray nd)
{
if (nd.ndim > 0)
throw new IncorrectShapeException();

return nd.Data<short>(0);
}

public static implicit operator NDArray(int d)
{
var ndArray = new NDArray(typeof(int),new int[0]);
Expand All @@ -70,6 +85,14 @@ public static implicit operator NDArray(int d)
return ndArray;
}

public static implicit operator int(NDArray nd)
{
if (nd.ndim > 0)
throw new IncorrectShapeException();

return nd.Data<int>(0);
}

public static implicit operator NDArray(long d)
{
var ndArray = new NDArray(typeof(Int64),new int[0]);
Expand All @@ -78,6 +101,14 @@ public static implicit operator NDArray(long d)
return ndArray;
}

public static implicit operator long(NDArray nd)
{
if (nd.ndim > 0)
throw new IncorrectShapeException();

return nd.Data<long>(0);
}

public static implicit operator NDArray(Complex d)
{
var ndArray = new NDArray(typeof(Complex),new int[0]);
Expand Down
8 changes: 4 additions & 4 deletions src/NumSharp.Core/NumSharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<PackageProjectUrl>https://github.com/SciSharp</PackageProjectUrl>
<Copyright>Apache 2.0</Copyright>
<RepositoryUrl>https://github.com/SciSharp/NumSharp</RepositoryUrl>
<PackageReleaseNotes>Improvements</PackageReleaseNotes>
<AssemblyVersion>0.6.5.0</AssemblyVersion>
<FileVersion>0.6.5.0</FileVersion>
<PackageReleaseNotes>add NDArray to ValueType</PackageReleaseNotes>
<AssemblyVersion>0.6.6.0</AssemblyVersion>
<FileVersion>0.6.6.0</FileVersion>
<RepositoryType>git</RepositoryType>
<PackageTags>NumPy, NumSharp, MachineLearning, Math, Scientific, Numeric</PackageTags>
<Version>0.6.5</Version>
<Version>0.6.6</Version>
<PackageLicenseUrl>LICENSE</PackageLicenseUrl>
<LangVersion>latest</LangVersion>
<PackageIconUrl>https://avatars3.githubusercontent.com/u/44989469?s=200&amp;v=4</PackageIconUrl>
Expand Down

0 comments on commit aa570de

Please sign in to comment.