Skip to content

Commit bff3df0

Browse files
committed
Tensor Range test.
1 parent 6d66092 commit bff3df0

File tree

5 files changed

+83
-316
lines changed

5 files changed

+83
-316
lines changed

src/TensorFlowNET.Core/Tensors/Tensor.Index.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public Tensor this[params Slice[] slices]
6060
}
6161
}
6262

63+
public Tensor this[Range slices]
64+
=> throw new NotImplementedException("");
65+
6366
public Tensor this[params string[] slices]
6467
=> this[slices.Select(x => new Slice(x)).ToArray()];
6568

src/TensorFlowNET.Core/Range.cs renamed to src/TensorFlowNET.Core/Util/Range.cs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace System
1313
/// int lastElement = someArray[^1]; // lastElement = 5
1414
/// </code>
1515
/// </remarks>
16-
internal readonly struct Index : IEquatable<Index>
16+
public readonly struct Index : IEquatable<Index>
1717
{
1818
private readonly int _value;
1919

@@ -150,7 +150,7 @@ public override string ToString()
150150
/// int[] subArray2 = someArray[1..^0]; // { 2, 3, 4, 5 }
151151
/// </code>
152152
/// </remarks>
153-
internal readonly struct Range : IEquatable<Range>
153+
public readonly struct Range : IEquatable<Range>
154154
{
155155
/// <summary>Represent the inclusive start index of the Range.</summary>
156156
public Index Start { get; }
@@ -232,43 +232,3 @@ public override string ToString()
232232
}
233233
}
234234
}
235-
236-
namespace System.Runtime.CompilerServices
237-
{
238-
internal static class RuntimeHelpers
239-
{
240-
/// <summary>
241-
/// Slices the specified array using the specified range.
242-
/// </summary>
243-
public static T[] GetSubArray<T>(T[] array, Range range)
244-
{
245-
if (array == null)
246-
{
247-
throw new ArgumentNullException(nameof(array));
248-
}
249-
250-
(int offset, int length) = range.GetOffsetAndLength(array.Length);
251-
252-
if (default(T) != null || typeof(T[]) == array.GetType())
253-
{
254-
// We know the type of the array to be exactly T[].
255-
256-
if (length == 0)
257-
{
258-
return Array.Empty<T>();
259-
}
260-
261-
var dest = new T[length];
262-
Array.Copy(array, offset, dest, 0, length);
263-
return dest;
264-
}
265-
else
266-
{
267-
// The array is actually a U[] where U:T.
268-
var dest = (T[])Array.CreateInstance(array.GetType().GetElementType(), length);
269-
Array.Copy(array, offset, dest, 0, length);
270-
return dest;
271-
}
272-
}
273-
}
274-
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace System.Runtime.CompilerServices
2+
{
3+
public static class RuntimeHelpers
4+
{
5+
/// <summary>
6+
/// Slices the specified array using the specified range.
7+
/// </summary>
8+
public static T[] GetSubArray<T>(T[] array, Range range)
9+
{
10+
if (array == null)
11+
{
12+
throw new ArgumentNullException(nameof(array));
13+
}
14+
15+
(int offset, int length) = range.GetOffsetAndLength(array.Length);
16+
17+
if (default(T) != null || typeof(T[]) == array.GetType())
18+
{
19+
// We know the type of the array to be exactly T[].
20+
21+
if (length == 0)
22+
{
23+
return Array.Empty<T>();
24+
}
25+
26+
var dest = new T[length];
27+
Array.Copy(array, offset, dest, 0, length);
28+
return dest;
29+
}
30+
else
31+
{
32+
// The array is actually a U[] where U:T.
33+
var dest = (T[])Array.CreateInstance(array.GetType().GetElementType(), length);
34+
Array.Copy(array, offset, dest, 0, length);
35+
return dest;
36+
}
37+
}
38+
}
39+
}

src/TensorFlowNET.Keras/Range.cs

Lines changed: 0 additions & 274 deletions
This file was deleted.

0 commit comments

Comments
 (0)