Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/NumSharp.Core/Creation/NdArray.Ones.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ public NDArray ones(Type dtype = null, params int[] shapes)

return this;
}
public NDArray ones(params int[] shapes)
{
return this.ones(typeof(double),shapes);
}
}
}
24 changes: 16 additions & 8 deletions src/NumSharp.Core/Creation/NumPy.array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@

namespace NumSharp.Core
{
public static partial class NumPyExtensions
public partial class NumPy
{
public static NDArray array(this NumPy np, Array array, Type dtype = null, int ndim = 1)
public NDArray array(Array array, Type dtype = null, int ndim = 1)
{
dtype = (dtype == null) ? array.GetType().GetElementType() : dtype;

var nd = new NDArray(dtype);

nd.Storage = NDStorage.CreateByShapeAndType (dtype, new Shape(new int[] { array.Length }));
nd.Storage.SetData(array);

if ((array.Rank == 1) && ( !array.GetType().GetElementType().IsArray ))
{
nd.Storage = NDStorage.CreateByShapeAndType (dtype, new Shape(new int[] { array.Length }));
nd.Storage.SetData(array);
}
else
{
throw new Exception("Method is not implemeneted for multidimensional arrays or jagged arrays.");
}

return nd;
}

public static NDArray array<T>(this NumPy np, System.Drawing.Bitmap image)
public NDArray array(System.Drawing.Bitmap image)
{
var imageArray = new NDArray(typeof(T));
var imageArray = new NDArray(typeof(Byte));

var bmpd = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, image.PixelFormat);
var dataSize = bmpd.Stride * bmpd.Height;
Expand All @@ -37,7 +45,7 @@ public static NDArray array<T>(this NumPy np, System.Drawing.Bitmap image)
return imageArray;
}

public static NDArray array<T>(this NumPy np, T[][] data)
public NDArray array<T>(T[][] data)
{
int size = data.Length * data[0].Length;
var all = new T[size];
Expand Down
59 changes: 0 additions & 59 deletions src/NumSharp.Core/Extensions/NDArray.Std.cs

This file was deleted.

70 changes: 0 additions & 70 deletions src/NumSharp.Core/Extensions/NdArray.AMin.cs

This file was deleted.

24 changes: 0 additions & 24 deletions src/NumSharp.Core/Extensions/NdArray.Absolute.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/NumSharp.Core/Extensions/NumPy.min.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/NumSharp.Core/Math/NdArray.Convolve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public NDArray Convolve(NDArray numSharpArray2, string mode = "full" )
if (shape.NDim > 1)
throw new IncorrectShapeException();

var numSharpReturn = new NDArray(this.dtype);
var numSharpReturn = new NDArray(typeof(double));

double[] np1 = this.Storage.GetData<double>();
double[] np2 = numSharpArray2.Storage.GetData<double>();
Expand Down
58 changes: 1 addition & 57 deletions src/NumSharp.Core/Math/NumPy.amax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,7 @@ public partial class NumPy
{
public NDArray amax(NDArray nd, int? axis = null)
{
var res = new NDArray(nd.dtype, nd.shape);

if (axis == null)
{
res.Set(new double[1] { nd.Data<double>().Max() });
res.Storage.Shape = new Shape(new int[] { 1 });
}
else
{
if (axis < 0 || axis >= nd.ndim)
throw new Exception("Invalid input: axis");
int[] resShapes = new int[nd.ndim - 1];
int index = 0; //index for result shape set
//axis departs the shape into three parts: prev, cur and post. They are all product of shapes
int prev = 1;
int cur = 1;
int post = 1;
int size = 1; //total number of the elements for result
//Calculate new Shape
for (int i = 0; i < nd.ndim; i++)
{
if (i == axis)
cur = nd.shape.Shapes[i];
else
{
resShapes[index++] = nd.shape.Shapes[i];
size *= nd.shape.Shapes[i];
if (i < axis)
prev *= nd.shape.Shapes[i];
else
post *= nd.shape.Shapes[i];
}
}
res.Storage.Shape = new Shape(resShapes);
//Fill in data
index = 0; //index for result data set
int sameSetOffset = nd.shape.DimOffset[axis.Value];
int increments = cur * post;
int start = 0;
double min = 0;
for (int i = 0; i < nd.size; i += increments)
{
for (int j = i; j < i + post; j++)
{
start = j;
min = nd.Data<double>()[start];
for (int k = 0; k < cur; k++)
{
min = Math.Max(min, nd.Data<double>()[start]);
start += sameSetOffset;
}
res[index++] = min;
}
}
}

return res;
return nd.amax(axis);
}
}
}
66 changes: 1 addition & 65 deletions src/NumSharp.Core/Math/NumPy.amin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,7 @@ public partial class NumPy
{
public NDArray amin(NDArray nd, int? axis = null)
{
NDArray res = null;

if (axis == null)
{
res = new NDArray(nd.dtype,new Shape(new int[] { 1 }));

Array resArray = Array.CreateInstance(nd.dtype,1);
resArray.SetValue(nd.Storage.GetData<double>().Min(),0);

res.Storage.SetData(resArray);

}
else
{
if (axis < 0 || axis >= nd.ndim)
throw new Exception("Invalid input: axis");
int[] resShapes = new int[nd.ndim - 1];
int index = 0; //index for result shape set
//axis departs the shape into three parts: prev, cur and post. They are all product of shapes
int prev = 1;
int cur = 1;
int post = 1;
int size = 1; //total number of the elements for result
//Calculate new Shape
for (int i = 0; i < nd.ndim; i++)
{
if (i == axis)
cur = nd.shape.Shapes[i];
else
{
resShapes[index++] = nd.shape.Shapes[i];
size *= nd.shape.Shapes[i];
if (i < axis)
prev *= nd.shape.Shapes[i];
else
post *= nd.shape.Shapes[i];
}
}

//Fill in data
index = 0; //index for result data set
int sameSetOffset = nd.shape.DimOffset[axis.Value];
int increments = cur * post;
int start = 0;
double min = 0;

res = new NDArray(nd.dtype,new Shape(resShapes));

for (int i = 0; i < nd.size; i += increments)
{
for (int j = i; j < i + post; j++)
{
start = j;
min = nd.Data<double>()[start];
for (int k = 0; k < cur; k++)
{
min = Math.Min(min, nd.Data<double>()[start]);
start += sameSetOffset;
}
res.Data<double>()[index++] = min;
}
}
}

return res;
return nd.amin(axis);
}
}
}
Loading