Skip to content

Commit 7787758

Browse files
committed
overload np.asarray
support all kind of value type and string
1 parent 7f623ac commit 7787758

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/NumSharp.Core/Creation/np.asarray.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,32 @@ namespace NumSharp.Core
99
{
1010
public static partial class np
1111
{
12-
public static NDArray asarray(double[] data, int ndim = 1)
12+
public static NDArray asarray(string data)
1313
{
14-
var nd = new NDArray(typeof(double), data.Length);
15-
nd.Storage.SetData(data);
14+
var nd = new NDArray(typeof(string), new int[0]);
15+
nd.Storage.SetData(new string[] { data });
1616
return nd;
1717
}
1818

19-
public static NDArray asarray(float data)
19+
public static NDArray asarray<T>(T data) where T : struct
2020
{
21-
return new NDArray(new float[] { data });
21+
var nd = new NDArray(typeof(T), new int[0]);
22+
nd.Storage.SetData(new T[] { data });
23+
return nd;
2224
}
2325

24-
public static NDArray asarray(float[] data, int ndim = 1)
26+
public static NDArray asarray(string[] data, int ndim = 1)
2527
{
26-
var nd = new NDArray(typeof(float), data.Length);
28+
var nd = new NDArray(typeof(string), data.Length);
2729
nd.Storage.SetData(data);
2830
return nd;
2931
}
30-
/*
31-
public static NDArray asarray(matrix mx, int ndim = 1)
32+
33+
public static NDArray asarray<T>(T[] data, int ndim = 1) where T : struct
3234
{
33-
var nd = new NDArray(mx.dtype, mx.shape);
34-
nd.Storage = mx.Storage;
35+
var nd = new NDArray(typeof(T), data.Length);
36+
nd.Storage.SetData(data);
3537
return nd;
3638
}
37-
*/
3839
}
3940
}

0 commit comments

Comments
 (0)