Skip to content

Commit 74ae84f

Browse files
committed
Add IsEllipsis and IsNewAxis to Slice.
1 parent 919b476 commit 74ae84f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/NumSharp.Core/NumSharp.Core.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
- Use of unmanaged memory and unsafe code in favor of performance.
2323

2424
- NumSharp no longer perform copies except for cases when numpy does. Compared to previous version, indexing an n-d array (e.g. nd[0,1] when shape is (3,3,3,3)) would return a copy when now it returns a reference (alias).</PackageReleaseNotes>
25-
<AssemblyVersion>0.20.0.0</AssemblyVersion>
26-
<FileVersion>0.20.0.0</FileVersion>
25+
<AssemblyVersion>0.20.1.0</AssemblyVersion>
26+
<FileVersion>0.20.1.0</FileVersion>
2727
<RepositoryType>git</RepositoryType>
2828
<PackageTags>Numpy, NumSharp, MachineLearning, Math, Scientific, Numeric, Mathlab, SciSharp</PackageTags>
2929
<PackageLicenseUrl></PackageLicenseUrl>
@@ -33,7 +33,7 @@
3333
<Product>NumSharp</Product>
3434
<Company>SciSharp STACK</Company>
3535
<RootNamespace>NumSharp</RootNamespace>
36-
<Version>0.20.0</Version>
36+
<Version>0.20.1</Version>
3737
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
3838
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3939
<SignAssembly>false</SignAssembly>

src/NumSharp.Core/View/Slice.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class Slice
6262
public int? Stop;
6363
public int Step;
6464
public bool IsIndex;
65+
public bool IsEllipsis;
66+
public bool IsNewAxis;
6567

6668
/// <summary>
6769
/// Length of the slice.
@@ -108,6 +110,23 @@ public static string FormatSlices(params Slice[] slices)
108110

109111
private void Parse(string slice_notation)
110112
{
113+
if (slice_notation == "...")
114+
{
115+
Start = 0;
116+
Stop = 0;
117+
Step = 1;
118+
IsEllipsis = true;
119+
return;
120+
}
121+
else if (slice_notation == "")
122+
{
123+
Start = 0;
124+
Stop = 0;
125+
Step = 1;
126+
IsNewAxis = true;
127+
return;
128+
}
129+
111130
if (string.IsNullOrEmpty(slice_notation))
112131
throw new ArgumentException("Slice notation expected, got empty string or null");
113132
var match = Regex.Match(slice_notation, @"^\s*([+-]?\s*\d+)?\s*:\s*([+-]?\s*\d+)?\s*(:\s*([+-]?\s*\d+)?)?\s*$|^\s*([+-]?\s*\d+)\s*$");
@@ -200,6 +219,10 @@ public override string ToString()
200219
{
201220
if (IsIndex)
202221
return $"{Start ?? 0}";
222+
else if (IsNewAxis)
223+
return "newaxis";
224+
else if (IsEllipsis)
225+
return "ellipsis";
203226
var optional_step = Step == 1 ? "" : $":{Step}";
204227
return $"{(Start == 0 ? "" : Start.ToString())}:{(Stop == null ? "" : Stop.ToString())}{optional_step}";
205228
}

0 commit comments

Comments
 (0)