Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a07cf8b

Browse filesBrowse files
committed
np.split: add overload to accept scalar integer index instead of int[] (#114)
1 parent 7f6eadb commit a07cf8b
Copy full SHA for a07cf8b

File tree

Expand file treeCollapse file tree

5 files changed

+142
-0
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+142
-0
lines changed

‎src/CodeMinion.ApiGenerator/NumPy/ApiGenerator.cs

Copy file name to clipboardExpand all lines: src/CodeMinion.ApiGenerator/NumPy/ApiGenerator.cs
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,10 @@ private IEnumerable<Function> InferOverloads(Function decl)
11401140
yield break;
11411141
case "gradient": // don't generate.
11421142
yield break;
1143+
case "split":
1144+
yield return decl;
1145+
yield return decl.Clone(f => { f.Arguments[1].Type = "int"; });
1146+
yield break;
11431147
}
11441148

11451149
// without args we don't need to consider possible overloads

‎src/Numpy/Models/NDarray.gen.cs

Copy file name to clipboardExpand all lines: src/Numpy/Models/NDarray.gen.cs
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,43 @@ public NDarray[] split(int[] indices_or_sections, int? axis = 0)
954954
return ToCsharp<NDarray[]>(py);
955955
}
956956

957+
/// <summary>
958+
/// Split an array into multiple sub-arrays.
959+
/// </summary>
960+
/// <param name="indices_or_sections">
961+
/// If indices_or_sections is an integer, N, the array will be divided
962+
/// into N equal arrays along axis.<br></br>
963+
/// If such a split is not possible,
964+
/// an error is raised.<br></br>
965+
///
966+
/// If indices_or_sections is a 1-D array of sorted integers, the entries
967+
/// indicate where along axis the array is split.<br></br>
968+
/// For example,
969+
/// [2, 3] would, for axis=0, result in
970+
///
971+
/// If an index exceeds the dimension of the array along axis,
972+
/// an empty sub-array is returned correspondingly.
973+
/// </param>
974+
/// <param name="axis">
975+
/// The axis along which to split, default is 0.
976+
/// </param>
977+
/// <returns>
978+
/// A list of sub-arrays.
979+
/// </returns>
980+
public NDarray[] split(int indices_or_sections, int? axis = 0)
981+
{
982+
//auto-generated code, do not change
983+
var __self__=self;
984+
var pyargs=ToTuple(new object[]
985+
{
986+
indices_or_sections,
987+
});
988+
var kwargs=new PyDict();
989+
if (axis!=0) kwargs["axis"]=ToPython(axis);
990+
dynamic py = __self__.InvokeMethod("split", pyargs, kwargs);
991+
return ToCsharp<NDarray[]>(py);
992+
}
993+
957994
/// <summary>
958995
/// Construct an array by repeating A the number of times given by reps.<br></br>
959996
///

‎src/Numpy/np.array_manipulation.gen.cs

Copy file name to clipboardExpand all lines: src/Numpy/np.array_manipulation.gen.cs
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,47 @@ public static NDarray[] split(NDarray ary, int[] indices_or_sections, int? axis
11331133
return ToCsharp<NDarray[]>(py);
11341134
}
11351135

1136+
/// <summary>
1137+
/// Split an array into multiple sub-arrays.
1138+
/// </summary>
1139+
/// <param name="ary">
1140+
/// Array to be divided into sub-arrays.
1141+
/// </param>
1142+
/// <param name="indices_or_sections">
1143+
/// If indices_or_sections is an integer, N, the array will be divided
1144+
/// into N equal arrays along axis.<br></br>
1145+
/// If such a split is not possible,
1146+
/// an error is raised.<br></br>
1147+
///
1148+
/// If indices_or_sections is a 1-D array of sorted integers, the entries
1149+
/// indicate where along axis the array is split.<br></br>
1150+
/// For example,
1151+
/// [2, 3] would, for axis=0, result in
1152+
///
1153+
/// If an index exceeds the dimension of the array along axis,
1154+
/// an empty sub-array is returned correspondingly.
1155+
/// </param>
1156+
/// <param name="axis">
1157+
/// The axis along which to split, default is 0.
1158+
/// </param>
1159+
/// <returns>
1160+
/// A list of sub-arrays.
1161+
/// </returns>
1162+
public static NDarray[] split(NDarray ary, int indices_or_sections, int? axis = 0)
1163+
{
1164+
//auto-generated code, do not change
1165+
var __self__=self;
1166+
var pyargs=ToTuple(new object[]
1167+
{
1168+
ary,
1169+
indices_or_sections,
1170+
});
1171+
var kwargs=new PyDict();
1172+
if (axis!=0) kwargs["axis"]=ToPython(axis);
1173+
dynamic py = __self__.InvokeMethod("split", pyargs, kwargs);
1174+
return ToCsharp<NDarray[]>(py);
1175+
}
1176+
11361177
/// <summary>
11371178
/// Construct an array by repeating A the number of times given by reps.<br></br>
11381179
///

‎src/Numpy/np.string.gen.cs

Copy file name to clipboardExpand all lines: src/Numpy/np.string.gen.cs
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,43 @@ public static NDarray split(string[] a, string sep = null, int? maxsplit = null)
677677
}
678678
}
679679

680+
public static partial class core {
681+
public static partial class defchararray {
682+
/// <summary>
683+
/// For each element in a, return a list of the words in the
684+
/// string, using sep as the delimiter string.<br></br>
685+
///
686+
/// Calls str.split element-wise.
687+
/// </summary>
688+
/// <param name="sep">
689+
/// If sep is not specified or None, any whitespace string is a
690+
/// separator.
691+
/// </param>
692+
/// <param name="maxsplit">
693+
/// If maxsplit is given, at most maxsplit splits are done.
694+
/// </param>
695+
/// <returns>
696+
/// Array of list objects
697+
/// </returns>
698+
public static NDarray split(string[] a, int? sep = null, int? maxsplit = null)
699+
{
700+
//auto-generated code, do not change
701+
var core = self.GetAttr("core");
702+
var defchararray = core.GetAttr("defchararray");
703+
var __self__=defchararray;
704+
var pyargs=ToTuple(new object[]
705+
{
706+
a,
707+
});
708+
var kwargs=new PyDict();
709+
if (sep!=null) kwargs["sep"]=ToPython(sep);
710+
if (maxsplit!=null) kwargs["maxsplit"]=ToPython(maxsplit);
711+
dynamic py = __self__.InvokeMethod("split", pyargs, kwargs);
712+
return ToCsharp<NDarray>(py);
713+
}
714+
}
715+
}
716+
680717
public static partial class core {
681718
public static partial class defchararray {
682719
/// <summary>

‎test/Numpy.UnitTest/NumpyTest.cs

Copy file name to clipboardExpand all lines: test/Numpy.UnitTest/NumpyTest.cs
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,29 @@ public async Task IssueByMaLichtenegger()
991991
Assert.IsTrue(doubles[1].asscalar<double>() == 0);
992992
}
993993

994+
[TestMethod]
995+
public async Task IssueByMartinDevans()
996+
{
997+
//>>> x = np.arange(9)
998+
//>>> np.split(x, 3)
999+
//[array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8])]
1000+
var x = np.arange(9);
1001+
var b = np.split(x, 3).repr();
1002+
var a = "(array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8]))";
1003+
Assert.AreEqual(a, b);
1004+
//>>> x = np.arange(8.0)
1005+
//>>> np.split(x, [3, 5, 6, 10])
1006+
//[array([0., 1., 2.]),
1007+
//array([3., 4.]),
1008+
//array([5.]),
1009+
//array([6., 7.]),
1010+
//array([], dtype = float64)]
1011+
x = np.arange(8);
1012+
b = np.split(x, new[] { 3, 5, 6, 10 }).repr();
1013+
a = "(array([0, 1, 2]), array([3, 4]), array([5]), array([6, 7]), array([], dtype=int32))";
1014+
Assert.AreEqual(a, b);
1015+
}
1016+
9941017
// TODO: https://docs.scipy.org/doc/numpy/user/basics.indexing.html?highlight=slice#structural-indexing-tools
9951018
// TODO: https://docs.scipy.org/doc/numpy/user/basics.indexing.html?highlight=slice#assigning-values-to-indexed-arrays
9961019
// TODO: https://docs.scipy.org/doc/numpy/user/basics.indexing.html?highlight=slice#dealing-with-variable-numbers-of-indices-within-programs

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.