Skip to content

Commit db26353

Browse files
author
dotchris90
committed
Merge remote-tracking branch 'upstream/master'
2 parents 08f0364 + 351e6ce commit db26353

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

src/NumSharp.Core/Casting/Implicit/NdArray.Implicit.ValueTypes.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public static implicit operator NDArray(double d)
4646
return ndArray;
4747
}
4848

49+
public static implicit operator NDArray(short d)
50+
{
51+
var ndArray = new NDArray(typeof(short), new int[0]);
52+
ndArray.Storage.SetData(new short[] { d });
53+
54+
return ndArray;
55+
}
56+
4957
public static implicit operator NDArray(int d)
5058
{
5159
var ndArray = new NDArray(typeof(int),new int[0]);

src/NumSharp.Core/NDStorage.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using NumSharp.Core;
44
using System;
55
using System.Linq;
6+
using System.Runtime.InteropServices;
67

78
namespace NumSharp.Core
89
{
@@ -177,17 +178,7 @@ public int DTypeSize
177178
{
178179
get
179180
{
180-
switch (_DType.Name)
181-
{
182-
case "Int32":
183-
return sizeof(int);
184-
case "Single":
185-
return sizeof(float);
186-
case "Double":
187-
return sizeof(double);
188-
default:
189-
return 0;
190-
}
181+
return Marshal.SizeOf(_DType);
191182
}
192183
}
193184
/// <summary>

src/NumSharp.Core/NumSharp.Core.csproj

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
<Description>NumSharp is the fundamental package for scientific computing with dot NET. It has implemented the arange, array, max, min, reshape, normalize, unique and random interfaces and so on. More and more interfaces will be added to the library gradually. If you want to use .NET to get started with machine learning, NumSharp will be your best tool library.</Description>
1111
<PackageProjectUrl>https://github.com/SciSharp</PackageProjectUrl>
1212
<Copyright>Apache 2.0</Copyright>
13-
<RepositoryUrl>https://github.com/Oceania2018/NumSharp</RepositoryUrl>
14-
<PackageReleaseNotes>Added ReShape interface for Shape.
15-
Added the water equation example.
16-
Added np.mgrid API.
17-
Add axis arg in ndarray.roll.</PackageReleaseNotes>
18-
<AssemblyVersion>0.6.2.0</AssemblyVersion>
19-
<FileVersion>0.6.2.0</FileVersion>
13+
<RepositoryUrl>https://github.com/SciSharp/NumSharp</RepositoryUrl>
14+
<PackageReleaseNotes>Add public static implicit operator NDArray(short d)
15+
Add T randn&lt;T&gt;()</PackageReleaseNotes>
16+
<AssemblyVersion>0.6.4.0</AssemblyVersion>
17+
<FileVersion>0.6.4.0</FileVersion>
2018
<RepositoryType>git</RepositoryType>
2119
<PackageTags>NumPy, NumSharp, MachineLearning, Math, Scientific, Numeric</PackageTags>
22-
<Version>0.6.2</Version>
20+
<Version>0.6.4</Version>
2321
<PackageLicenseUrl>LICENSE</PackageLicenseUrl>
2422
<LangVersion>latest</LangVersion>
2523
<PackageIconUrl>https://avatars3.githubusercontent.com/u/44989469?s=200&amp;v=4</PackageIconUrl>

src/NumSharp.Core/Random/np.random.randn.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ public NDArray randn(params int[] size)
1616
return stardard_normal(size);
1717
}
1818

19+
/// <summary>
20+
/// Scalar value
21+
/// </summary>
22+
/// <typeparam name="T"></typeparam>
23+
/// <returns></returns>
24+
public T randn<T>()
25+
{
26+
var nd = stardard_normal();
27+
switch (typeof(T).Name)
28+
{
29+
case "Double":
30+
return (T)Convert.ChangeType(nd.Data<double>()[0], typeof(T));
31+
default:
32+
throw new NotImplementedException("randn");
33+
}
34+
}
35+
1936
/// <summary>
2037
/// Draw random samples from a normal (Gaussian) distribution.
2138
/// </summary>
@@ -25,8 +42,6 @@ public NDArray randn(params int[] size)
2542
/// <returns></returns>
2643
public NDArray normal(double loc, double scale, params int[] dims)
2744
{
28-
if (dims.Length == 0)
29-
throw new Exception("d cannot be empty.");
3045
var array = new NDArray(typeof(double), new Shape(dims));
3146
Random rand = new Random(); //reuse this if you are generating many
3247

0 commit comments

Comments
 (0)