Skip to content

Commit ac3dfa7

Browse files
committed
update ToString to adopt Scalar value
1 parent 351e6ce commit ac3dfa7

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-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
if(dtype == typeof(int))
1837
{

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>

0 commit comments

Comments
 (0)