forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSliceHelper.cs
More file actions
70 lines (63 loc) · 1.86 KB
/
SliceHelper.cs
File metadata and controls
70 lines (63 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tensorflow.NumPy
{
public class SliceHelper
{
public static Slice[] AlignWithShape(Shape shape, Slice[] slices)
{
var ndim = shape.ndim;
if (ndim == slices.Length)
return slices;
// align slices
var new_slices = new List<Slice>();
var slice_index = 0;
for (int i = 0; i < ndim; i++)
{
if (slice_index > slices.Length - 1)
{
new_slices.Add(Slice.All);
continue;
}
if (slices[slice_index] == Slice.All)
{
new_slices.Add(Slice.All);
for (int j = 0; j < ndim - slices.Length; j++)
{
new_slices.Add(Slice.All);
i++;
}
}
else
{
new_slices.Add(slices[slice_index]);
}
slice_index++;
}
return new_slices.ToArray();
}
public static bool AreAllIndex(Slice[] slices, out int[] indices)
{
indices = new int[slices.Length];
for (int i = 0; i< slices.Length; i++)
{
indices[i] = slices[i].Start ?? 0;
if (!slices[i].IsIndex)
return false;
}
return true;
}
public static bool IsContinuousBlock(Slice[] slices, int ndim)
{
for (int i = ndim + 1; i < slices.Length; i++)
{
if (slices[i].Equals(Slice.All))
continue;
return false;
}
return true;
}
}
}