Skip to content

Commit 137b368

Browse files
committed
Merge branch 'master' of https://github.com/Oceania2018/NumSharp
2 parents 835e8c3 + ebaa50f commit 137b368

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/NumSharp.Core/LinearAlgebra/NdArray.Dot.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ public NDArray dot(NDArray nd2)
2323
// in case must do a reshape
2424
var oldStorage1 = this.Storage;
2525
var oldStorage2 = nd2.Storage;
26+
if ((this.ndim == 0) & (nd2.ndim == 0))
27+
{
28+
if (this.dtype == typeof(int))
29+
{
30+
var ret = this.Data<int>()[0] * nd2.Data<int>()[0];
31+
return new NDArray(new int[] { ret }).reshape();
32+
}
33+
34+
}
2635

2736
if ((this.ndim == 1 ) & (nd2.ndim == 1))
2837
if (this.shape[0] != nd2.shape[0])

src/NumSharp.Core/NumSharp.Core.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,23 @@ Add T randn&lt;T&gt;()</PackageReleaseNotes>
7575
<Content CopyToOutputDirectory="PreserveNewest" Include="./runtimes/linux-x64/native/lapack.so" Link="lapack.so" Pack="true" PackagePath="runtimes/linux-x64/native/lapack.so" />
7676
</ItemGroup>
7777

78+
<ItemGroup>
79+
<None Update="Operations\NdArray.ElementsWise.tt">
80+
<Generator>TextTemplatingFileGenerator</Generator>
81+
<LastGenOutput>NdArray.ElementsWise.cs</LastGenOutput>
82+
</None>
83+
</ItemGroup>
84+
85+
<ItemGroup>
86+
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
87+
</ItemGroup>
88+
89+
<ItemGroup>
90+
<Compile Update="Operations\NdArray.ElementsWise.cs">
91+
<DesignTime>True</DesignTime>
92+
<AutoGen>True</AutoGen>
93+
<DependentUpon>NdArray.ElementsWise.tt</DependentUpon>
94+
</Compile>
95+
</ItemGroup>
96+
7897
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


test/NumSharp.UnitTest/LinearAlgebra/NdArray.Dot.Test.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,24 @@ public void DotTwo1Int()
3131

3232
var yArray = y.Storage.GetData<int>();
3333

34+
3435
Assert.AreEqual(yArray[0], 5);
3536
Assert.AreEqual(yArray[1], 8);
3637
Assert.AreEqual(yArray[2], 10);
3738
Assert.AreEqual(yArray[3], 13);
3839
}
3940

41+
[TestMethod]
42+
public void DotTwoScalar()
43+
{
44+
45+
int sca1 = 2;
46+
int sca2 = 3;
47+
var sca3 = np.dot(sca1, sca2);
48+
49+
Assert.AreEqual(sca3.Data<int>()[0], 6);
50+
}
51+
4052
[TestMethod]
4153
public void DotTwo1DDouble()
4254
{

0 commit comments

Comments
 (0)