Skip to content

Commit a50dfb9

Browse files
committed
add slice test
1 parent 91b3e3f commit a50dfb9

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/NumSharp.Core/Slice.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ namespace NumSharp
4545
/// </summary>
4646
public class Slice
4747
{
48-
public long? Start { get; set; }
49-
public long? Stop { get; set; }
50-
public long Step { get; set; } = 1;
48+
public int? Start { get; set; }
49+
public int? Stop { get; set; }
50+
public int Step { get; set; } = 1;
5151

5252
/// <summary>
5353
/// Length of the slice.
5454
/// <remarks>
5555
/// The length is not guaranteed to be known for i.e. a slice like ":". Make sure to check Start and Stop
5656
/// for null before using it</remarks>
5757
/// </summary>
58-
public long? Length => Stop - Start;
58+
public int? Length => Stop - Start;
5959

6060
/// <summary>
6161
/// ndarray can be indexed using slicing
@@ -64,7 +64,7 @@ public class Slice
6464
/// <param name="start">Start index of the slice, null means from the start of the array</param>
6565
/// <param name="stop">Stop index (first index after end of slice), null means to the end of the array</param>
6666
/// <param name="step">Optional step to select every n-th element, defaults to 1</param>
67-
public Slice(long? start=null, long? stop=null, long step = 1)
67+
public Slice(int? start=null, int? stop=null, int step = 1)
6868
{
6969
Start = start;
7070
Stop = stop;
@@ -105,7 +105,7 @@ private void Parse(string slice_notation)
105105
var single_pick_string = match.Groups[5].Value;
106106
if (!string.IsNullOrWhiteSpace(single_pick_string))
107107
{
108-
if (!long.TryParse(Regex.Replace(single_pick_string ?? "", @"\s+", ""), out var start))
108+
if (!int.TryParse(Regex.Replace(single_pick_string ?? "", @"\s+", ""), out var start))
109109
throw new ArgumentException($"Invalid value for start: {start_string}");
110110
Start = start;
111111
Stop = start+1;
@@ -116,23 +116,23 @@ private void Parse(string slice_notation)
116116
Start = null;
117117
else
118118
{
119-
if (!long.TryParse(start_string, out var start))
119+
if (!int.TryParse(start_string, out var start))
120120
throw new ArgumentException($"Invalid value for start: {start_string}");
121121
Start = start;
122122
}
123123
if (string.IsNullOrWhiteSpace(stop_string))
124124
Stop = null;
125125
else
126126
{
127-
if (!long.TryParse(stop_string, out var stop))
127+
if (!int.TryParse(stop_string, out var stop))
128128
throw new ArgumentException($"Invalid value for start: {stop_string}");
129129
Stop = stop;
130130
}
131131
if (string.IsNullOrWhiteSpace(step_string))
132132
Step = 1;
133133
else
134134
{
135-
if (!long.TryParse(step_string, out var step))
135+
if (!int.TryParse(step_string, out var step))
136136
throw new ArgumentException($"Invalid value for start: {step_string}");
137137
Step = step;
138138
}
@@ -177,7 +177,7 @@ public static Slice All()
177177
return new Slice(null, null);
178178
}
179179

180-
public static Slice SingleValue(long index)
180+
public static Slice SingleValue(int index)
181181
{
182182
return new Slice(index, index + 1);
183183
}

test/NumSharp.UnitTest/Selection/NDArray.Indexing.Test.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ public void Filter2D()
136136
Assert.IsTrue(Enumerable.SequenceEqual(new int[] { 2, 1, 1, 3 }, (result[1] as NDArray).Data<int>()));
137137
}
138138

139+
[TestMethod]
140+
public void Slice1()
141+
{
142+
var x = np.arange(10);
143+
var y = x["1:3"];
144+
}
139145

140146
[TestMethod]
141147
public void SliceNotation()

0 commit comments

Comments
 (0)