File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
src/NumSharp.Core/Utilities Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 4
4
using System . Numerics ;
5
5
using System . Reflection ;
6
6
using System . Runtime . CompilerServices ;
7
+ using System . Threading . Tasks ;
7
8
using NumSharp . Backends ;
8
9
9
10
namespace NumSharp . Utilities
10
11
{
11
12
public static class Arrays
12
13
{
14
+ /// <summary>
15
+ /// Slice an array.
16
+ /// </summary>
17
+ /// <remarks>Supports negative <paramref name="end"/> index</remarks>
18
+ public static T [ ] Slice < T > ( this T [ ] source , int start , int end )
19
+ {
20
+ // Handles negative ends.
21
+ if ( end < 0 ) end = source . Length + end ;
22
+ var len = end - start ;
23
+
24
+ // Return new array.
25
+ var res = new T [ len ] ;
26
+ Parallel . For ( 0 , len , i => res [ i ] = source [ i + start ] ) ;
27
+ return res ;
28
+ }
29
+
30
+ /// <summary>
31
+ /// Slice an array.
32
+ /// </summary>
33
+ /// <remarks>Supports negative <paramref name="end"/> index</remarks>
34
+ public static T [ ] Slice < T > ( this T [ ] source , long start , long end )
35
+ {
36
+ // Handles negative ends.
37
+ if ( end < 0 ) end = source . Length + end ;
38
+ var len = end - start ;
39
+
40
+ // Return new array.
41
+ var res = new T [ len ] ;
42
+ Parallel . For ( 0 , len , i => res [ i ] = source [ i + start ] ) ;
43
+ return res ;
44
+ }
45
+
13
46
/// <summary>
14
47
/// Inserts item into a specific index.
15
48
/// </summary>
You can’t perform that action at this time.
0 commit comments