Skip to content

Commit 314069e

Browse files
author
dotchris90
committed
Merge remote-tracking branch 'upstream/master'
2 parents 4ddfb2f + 137b368 commit 314069e

File tree

6 files changed

+70
-3
lines changed

6 files changed

+70
-3
lines changed

src/NumSharp.Core/Casting/NdArray.ToString.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,27 @@ public partial class NDArray
1111
public override string ToString()
1212
{
1313
string output = "";
14-
15-
if (this.ndim == 2)
14+
if (this.ndim == 0)
15+
{
16+
switch (dtype.Name)
17+
{
18+
case "Int16":
19+
output = Data<short>()[0].ToString();
20+
break;
21+
case "Int32":
22+
output = Data<int>()[0].ToString();
23+
break;
24+
case "Double":
25+
output = Data<double>()[0].ToString();
26+
break;
27+
case "String":
28+
output = Data<string>()[0].ToString();
29+
break;
30+
default:
31+
throw new NotImplementedException("NDArray ToString()");
32+
}
33+
}
34+
else if (this.ndim == 2)
1635
{
1736
output = this._ToMatrixString();
1837
}

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/NDStorage.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ public int DTypeSize
178178
{
179179
get
180180
{
181-
return Marshal.SizeOf(_DType);
181+
if(_DType == typeof(string))
182+
{
183+
return 0;
184+
}
185+
else
186+
{
187+
return Marshal.SizeOf(_DType);
188+
}
182189
}
183190
}
184191
/// <summary>

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)