Skip to content

Commit e3a8b07

Browse files
committed
Turn NumPy to static class #155
1 parent 4634732 commit e3a8b07

55 files changed

Lines changed: 119 additions & 143 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/NumSharp.Core/Creation/NumPy.arange.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
using System.Linq;
55
using System.Numerics;
66
using System.Text;
7+
using np = NumSharp.Core.NumPy;
78

89
namespace NumSharp.Core
910
{
10-
public partial class NumPy
11+
public static partial class NumPy
1112
{
12-
public NDArray arange(double stop)
13+
public static NDArray arange(double stop)
1314
{
1415
return arange(0, stop, 1);
1516
}
1617

17-
public NDArray arange(double start, double stop, double step = 1)
18+
public static NDArray arange(double start, double stop, double step = 1)
1819
{
1920
if (start > stop)
2021
{
@@ -34,12 +35,12 @@ public NDArray arange(double start, double stop, double step = 1)
3435
return nd;
3536
}
3637

37-
public NDArray arange(int stop)
38+
public static NDArray arange(int stop)
3839
{
3940
return arange(0, stop, 1);
4041
}
4142

42-
public NDArray arange(int start, int stop, int step = 1)
43+
public static NDArray arange(int start, int stop, int step = 1)
4344
{
4445
if (start > stop)
4546
{
@@ -49,7 +50,7 @@ public NDArray arange(int start, int stop, int step = 1)
4950
int length = (int)Math.Ceiling((stop - start + 0.0) / step);
5051
int index = 0;
5152

52-
var nd = new NDArray(int32, new Shape(length));
53+
var nd = new NDArray(np.int32, new Shape(length));
5354

5455
if(nd.Data<int>() is int[] a)
5556
{

src/NumSharp.Core/Creation/NumPy.array.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace NumSharp.Core
99
{
10-
public partial class NumPy
10+
public static partial class NumPy
1111
{
12-
public NDArray array(Array array, Type dtype = null, int ndim = 1)
12+
public static NDArray array(Array array, Type dtype = null, int ndim = 1)
1313
{
1414
dtype = (dtype == null) ? array.GetType().GetElementType() : dtype;
1515

@@ -28,7 +28,7 @@ public NDArray array(Array array, Type dtype = null, int ndim = 1)
2828
return nd;
2929
}
3030

31-
public NDArray array(System.Drawing.Bitmap image)
31+
public static NDArray array(System.Drawing.Bitmap image)
3232
{
3333
var imageArray = new NDArray(typeof(Byte));
3434

@@ -45,7 +45,7 @@ public NDArray array(System.Drawing.Bitmap image)
4545
return imageArray;
4646
}
4747

48-
public NDArray array<T>(T[][] data)
48+
public static NDArray array<T>(T[][] data)
4949
{
5050
int size = data.Length * data[0].Length;
5151
var all = new T[size];

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77

88
namespace NumSharp.Core
99
{
10-
public partial class NumPy
10+
public static partial class NumPy
1111
{
12-
public NDArray asarray(double[] data, int ndim = 1)
12+
public static NDArray asarray(double[] data, int ndim = 1)
1313
{
1414
var nd = new NDArray(typeof(double), data.Length);
1515
nd.Storage.Set(data);
1616
return nd;
1717
}
1818

19-
public NDArray asarray(float[] data, int ndim = 1)
19+
public static NDArray asarray(float[] data, int ndim = 1)
2020
{
2121
var nd = new NDArray(typeof(float), data.Length);
2222
nd.Storage.Set(data);
2323
return nd;
2424
}
2525

26-
public NDArray asarray(matrix mx, int ndim = 1)
26+
public static NDArray asarray(matrix mx, int ndim = 1)
2727
{
2828
var nd = new NDArray(mx.dtype, mx.shape);
2929
nd.Storage = mx.Storage;

src/NumSharp.Core/Creation/NumPy.asmatrix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace NumSharp.Core
77
{
8-
public partial class NumPy
8+
public static partial class NumPy
99
{
10-
public matrix asmatrix(NDArray nd)
10+
public static matrix asmatrix(NDArray nd)
1111
{
1212
return nd.AsMatrix();
1313
}

src/NumSharp.Core/Creation/NumPy.linspace.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
namespace NumSharp.Core
77
{
8-
public partial class NumPy
8+
public static partial class NumPy
99
{
10-
public NDArray linspace(double start, double stop, int num, bool entdpoint = true, Type dtype = null)
10+
public static NDArray linspace(double start, double stop, int num, bool entdpoint = true, Type dtype = null)
1111
{
1212
dtype = (dtype == null) ? typeof(double) : dtype;
1313

1414
return new NDArray(dtype).linspace(start,stop,num,entdpoint);
1515
}
16-
public NDArray linspace<T>(double start, double stop, int num, bool entdpoint = true)
16+
public static NDArray linspace<T>(double start, double stop, int num, bool entdpoint = true)
1717
{
1818
double steps = (stop - start) / ((entdpoint) ? (double)num - 1.0 : (double)num);
1919

src/NumSharp.Core/Creation/NumPy.ones.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
namespace NumSharp.Core
99
{
10-
public partial class NumPy
10+
public static partial class NumPy
1111
{
12-
public NDArray ones(params int[] shapes)
12+
public static NDArray ones(params int[] shapes)
1313
{
1414
Type dtype = typeof(double);
1515

1616
return ones(dtype,shapes);
1717
}
1818

19-
public NDArray ones(Type dtype = null, params int[] shapes)
19+
public static NDArray ones(Type dtype = null, params int[] shapes)
2020
{
2121
dtype = (dtype == null ) ? typeof(double) : dtype;
2222

@@ -30,7 +30,7 @@ public NDArray ones(Type dtype = null, params int[] shapes)
3030
/// <param name="np"></param>
3131
/// <param name="shape"></param>
3232
/// <returns></returns>
33-
public NDArray ones(Shape shape, Type dtype = null)
33+
public static NDArray ones(Shape shape, Type dtype = null)
3434
{
3535
if(dtype == null)
3636
{
@@ -57,7 +57,7 @@ public NDArray ones(Shape shape, Type dtype = null)
5757
return nd;
5858
}
5959

60-
public NDArray ones<T>(params int[] shapes)
60+
public static NDArray ones<T>(params int[] shapes)
6161
{
6262
return ones(new Shape(shapes), typeof(T));
6363
}

src/NumSharp.Core/Creation/NumPy.zeros.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44

55
namespace NumSharp.Core
66
{
7-
public partial class NumPy
7+
public static partial class NumPy
88
{
99
/// <summary>
1010
/// Return a new float array of given shape, filled with zeros.
1111
/// </summary>
1212
/// <param name="np"></param>
1313
/// <param name="shape"></param>
1414
/// <returns></returns>
15-
public NDArray zeros(params int[] shape)
15+
public static NDArray zeros(params int[] shape)
1616
{
1717
var nd = new NDArray(float64, new Shape(shape));
1818
return nd;
1919
}
2020

21-
public NDArray zeros<T>(params int[] shape)
21+
public static NDArray zeros<T>(params int[] shape)
2222
{
2323
var nd = new NDArray(typeof(T));
2424
nd.Storage.Shape = new Shape(shape);
2525

2626
return nd;
2727
}
2828

29-
public NDArray zeros(Shape shape, Type dtype = null)
29+
public static NDArray zeros(Shape shape, Type dtype = null)
3030
{
3131
return new NDArray(dtype == null? float64 : dtype, shape);
3232
}

src/NumSharp.Core/Extensions/NdArray.Normalize.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using np = NumSharp.Core.NumPy;
56

67
namespace NumSharp.Core
78
{
89
public partial class NDArray
910
{
1011
public void normalize()
1112
{
12-
var np = new NumPy();
1313
var min = this.min(0);
1414
var max = this.max(0);
1515

src/NumSharp.Core/LinearAlgebra/NumPy.dot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace NumSharp.Core
66
{
7-
public partial class NumPy
7+
public static partial class NumPy
88
{
9-
public NDArray dot(NDArray a, NDArray b)
9+
public static NDArray dot(NDArray a, NDArray b)
1010
{
1111
return a.dot(b);
1212
}

src/NumSharp.Core/Manipulation/NDArray.ravel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
using System.Collections;
33
using System.Linq;
44
using System.Text;
5+
using np = NumSharp.Core.NumPy;
56

67
namespace NumSharp.Core
78
{
89
public partial class NDArray
910
{
1011
public NDArray delete(IEnumerable delete)
1112
{
12-
var np = new NumPy();
13-
1413
var sysArr = this.Storage.GetData();
1514

1615
NDArray res = null;

0 commit comments

Comments
 (0)