forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTensorShape.cs
More file actions
53 lines (45 loc) · 1.62 KB
/
Copy pathTensorShape.cs
File metadata and controls
53 lines (45 loc) · 1.62 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
using NumSharp;
using System;
using System.Linq;
namespace Tensorflow
{
/// <summary>
/// Represents the shape of a `Tensor`.
/// </summary>
public class TensorShape : Shape
{
public TensorShape(TensorShapeProto proto)
{
if (proto.UnknownRank) return;
Reshape(proto.Dim.Select(x => (int)x.Size).ToArray());
}
public TensorShape(params int[] dims) : base(dims)
{
}
public TensorShape this[Slice slice]
{
get
{
return new TensorShape(Dimensions.Skip(slice.Start.Value)
.Take(slice.Length.Value)
.ToArray());
}
}
/// <summary>
/// Returns True iff `self` is fully defined in every dimension.
/// </summary>
/// <returns></returns>
public bool is_fully_defined()
{
return Dimensions != null && Dimensions.Count(x => x < 1) == 0;
}
public bool is_compatible_with(TensorShape shape2)
{
throw new NotImplementedException("TensorShape is_compatible_with");
}
public static implicit operator TensorShape(int[] dims) => new TensorShape(dims);
public static implicit operator TensorShape((int, int) dims) => new TensorShape(dims.Item1, dims.Item2);
public static implicit operator TensorShape((int, int, int) dims) => new TensorShape(dims.Item1, dims.Item2, dims.Item3);
public static implicit operator TensorShape((int, int, int, int) dims) => new TensorShape(dims.Item1, dims.Item2, dims.Item3, dims.Item4);
}
}