From aa570de15aba6222fb1372565a0141847cc2276e Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 26 Jan 2019 10:34:28 -0600 Subject: [PATCH] add NDArray to ValueType --- .../Implicit/NdArray.Implicit.ValueTypes.cs | 47 +++++++++++++++---- src/NumSharp.Core/NumSharp.Core.csproj | 8 ++-- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/NumSharp.Core/Casting/Implicit/NdArray.Implicit.ValueTypes.cs b/src/NumSharp.Core/Casting/Implicit/NdArray.Implicit.ValueTypes.cs index 63f8a7df..c7579d2c 100644 --- a/src/NumSharp.Core/Casting/Implicit/NdArray.Implicit.ValueTypes.cs +++ b/src/NumSharp.Core/Casting/Implicit/NdArray.Implicit.ValueTypes.cs @@ -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) @@ -38,20 +45,20 @@ public static implicit operator float(NDArray nd) return nd.Data(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(0); } public static implicit operator NDArray(short d) @@ -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(0); + } + public static implicit operator NDArray(int d) { var ndArray = new NDArray(typeof(int),new int[0]); @@ -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(0); + } + public static implicit operator NDArray(long d) { var ndArray = new NDArray(typeof(Int64),new int[0]); @@ -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(0); + } + public static implicit operator NDArray(Complex d) { var ndArray = new NDArray(typeof(Complex),new int[0]); diff --git a/src/NumSharp.Core/NumSharp.Core.csproj b/src/NumSharp.Core/NumSharp.Core.csproj index 93606a1e..5c117d65 100644 --- a/src/NumSharp.Core/NumSharp.Core.csproj +++ b/src/NumSharp.Core/NumSharp.Core.csproj @@ -11,12 +11,12 @@ https://github.com/SciSharp Apache 2.0 https://github.com/SciSharp/NumSharp - Improvements - 0.6.5.0 - 0.6.5.0 + add NDArray to ValueType + 0.6.6.0 + 0.6.6.0 git NumPy, NumSharp, MachineLearning, Math, Scientific, Numeric - 0.6.5 + 0.6.6 LICENSE latest https://avatars3.githubusercontent.com/u/44989469?s=200&v=4