forked from SciSharp/Numpy.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.cs
More file actions
57 lines (46 loc) · 1.84 KB
/
Shape.cs
File metadata and controls
57 lines (46 loc) · 1.84 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Numpy.Models
{
public class Shape
{
public int[] Dimensions { get; }
public Shape(params int[] shape)
{
this.Dimensions = shape;
}
public int this[int n] => Dimensions[n];
public static implicit operator Shape(ValueTuple<int> tuple) => new Shape(tuple.Item1);
public static implicit operator Shape(ValueTuple<int,int> tuple) => new Shape(tuple.Item1, tuple.Item2);
public static implicit operator Shape(ValueTuple<int, int,int> tuple) => new Shape(tuple.Item1, tuple.Item2,tuple.Item3);
public static implicit operator Shape(ValueTuple<int, int, int, int> tuple) => new Shape(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4);
public static implicit operator Shape(ValueTuple<int, int, int, int, int> tuple) => new Shape(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4, tuple.Item5);
#region Equality
public static bool operator ==(Shape a, Shape b)
{
if (b is null) return false;
return Enumerable.SequenceEqual(a.Dimensions, b?.Dimensions);
}
public static bool operator !=(Shape a, Shape b)
{
return !(a == b);
}
public override bool Equals(object obj)
{
if (obj.GetType() != typeof(Shape))
return false;
return Enumerable.SequenceEqual(Dimensions, ((Shape)obj).Dimensions);
}
public override int GetHashCode()
{
return (Dimensions??new int[0]).GetHashCode();
}
public override string ToString()
{
return $"({string.Join(", ", Dimensions ?? new int[0])})";
}
#endregion
}
}