/// <summary> /// Check whether two narrays have the same rank and sizes. /// </summary> public bool SameDims <S>(Narray <S> b) { if (this.Rank() != b.Rank()) { return(false); } for (int i = 0; i < this.Rank(); i++) { if (this.Dim(i) != b.Dim(i)) { return(false); } } return(true); }
/// <summary> /// Check whether two narrays are equal (mostly for testing). /// </summary> public bool Equal(Narray <T> b) { if (this.Rank() != b.Rank()) { return(false); } for (int i = 0; i < this.Rank(); i++) { if (this.Dim(i) != b.Dim(i)) { return(false); } } index_t n = this.Length1d(); for (index_t i = 0; i < n; i++) { if (!this.UnsafeAt1d(i).Equals(b.UnsafeAt1d(i))) { return(false); } } return(true); }
/// <summary> /// Make the first array have the same dimensions as the second array. /// </summary> public Narray <T> MakeLike <S>(Narray <S> b) { if (SameDims(b)) { return(this); } Narray <T> a = this; int r = b.Rank(); switch (r) { case 0: a.Dealloc(); break; case 1: a.Resize(b.Dim(0)); break; case 2: a.Resize(b.Dim(0), b.Dim(1)); break; case 3: a.Resize(b.Dim(0), b.Dim(1), b.Dim(2)); break; case 4: a.Resize(b.Dim(0), b.Dim(1), b.Dim(2), b.Dim(3)); break; default: throw new Exception("bad rank"); } return(this); }