Skip to content

Commit d7c59c5

Browse files
committed
fix benchmark project build failure.
1 parent 10d526c commit d7c59c5

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public static NDArray asarray(double[] data, int ndim = 1)
1616
return nd;
1717
}
1818

19+
public static NDArray asarray(float data)
20+
{
21+
return new NDArray(new float[] { data });
22+
}
23+
1924
public static NDArray asarray(float[] data, int ndim = 1)
2025
{
2126
var nd = new NDArray(typeof(float), data.Length);

test/NumSharp.Benchmark/NDArrayTester1D.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,30 @@ namespace NumSharp.Benchmark
1515
[HtmlExporter]
1616
public class NDArrayTester1D
1717
{
18-
public NDArrayGeneric<double> np1;
19-
public NDArrayGeneric<double> np2;
20-
public NDArrayGeneric<double> np3;
18+
public NDArray np1;
19+
public NDArray np2;
20+
public NDArray np3;
2121
public double[] np1Double;
2222
public double[] np2Double;
2323
public double[] np3Double;
2424
[GlobalSetup]
2525
public void Setup()
2626
{
2727
// first array
28-
np1 = new NDArrayGeneric<double>();
29-
np1.Data = new double[100000].Select((x,idx) => x + idx ).ToArray();
30-
np1.Shape = new Shape(np1.Data.Length);
28+
np1 = new NDArray(new double[100000].Select((x, idx) => x + idx).ToArray());
29+
np1Double = np1.Storage.GetData<double>();
3130

32-
np1Double = np1.Data;
33-
3431
// second array
35-
np2 = new NDArrayGeneric<double>();
36-
np2.Data = new double[100000].Select((x,idx) => x + idx ).ToArray();
37-
np2.Shape = new Shape(np2.Data.Length);
38-
39-
np2Double = np2.Data;
32+
np2 = new NDArray(new double[100000].Select((x, idx) => x + idx).ToArray());
33+
np2Double = np2.Storage.GetData<double>();
4034

4135
// result array
42-
np3 = new NDArrayGeneric<double>();
43-
np3.Data = new double[100000];
44-
45-
np3Double = np3.Data;
36+
np3 = new NDArray(new double[100000]);
37+
np3Double = np3.Storage.GetData<double>();
4638

4739
// result array
48-
np3 = new NDArrayGeneric<double>();
49-
np3.Data = new double[100000];
50-
51-
np3Double = np3.Data;
40+
np3 = new NDArray(new double[100000]);
41+
np3Double = np3.Storage.GetData<double>();
5242
}
5343
[Benchmark]
5444
public void DirectAddition1D()

test/NumSharp.Benchmark/np.index.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public class npindex
2020
public void Setup()
2121
{
2222
shape = new Shape(1000, 1000);
23-
nd = np.arange(1000 * 1000 * 1.0).reshape(shape.Shapes.ToArray());
23+
nd = np.arange(1000 * 1000 * 1.0).reshape(shape);
2424
}
2525

2626
[Benchmark]
2727
public void accessInDtype()
2828
{
2929
double a = 0;
3030

31-
for (int d1 = 0; d1 < shape[0]; d1++)
31+
for (int d1 = 0; d1 < shape.Dimensions[0]; d1++)
3232
{
33-
for (int d2 = 0; d2 < shape[1]; d2++)
33+
for (int d2 = 0; d2 < shape.Dimensions[1]; d2++)
3434
{
3535
a = (double)nd[d1, d2];
3636
}
@@ -42,11 +42,11 @@ public void accessInGeneric()
4242
{
4343
double a = 0;
4444

45-
for (int d1 = 0; d1 < shape[0]; d1++)
45+
for (int d1 = 0; d1 < shape.Dimensions[0]; d1++)
4646
{
47-
for (int d2 = 0; d2 < shape[1]; d2++)
47+
for (int d2 = 0; d2 < shape.Dimensions[1]; d2++)
4848
{
49-
a = nd.Data<double>(d1, d2);
49+
a = nd.Storage.GetData<double>(d1, d2);
5050
}
5151
}
5252
}
@@ -56,9 +56,9 @@ public void accessInObject()
5656
{
5757
object a = 0;
5858

59-
for (int d1 = 0; d1 < shape[0]; d1++)
59+
for (int d1 = 0; d1 < shape.Dimensions[0]; d1++)
6060
{
61-
for (int d2 = 0; d2 < shape[1]; d2++)
61+
for (int d2 = 0; d2 < shape.Dimensions[1]; d2++)
6262
{
6363
a = nd[d1, d2];
6464
}

0 commit comments

Comments
 (0)