From de75d121408a6d755e057e745d5df45f6183e30e Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 1 Aug 2020 15:42:18 +0200 Subject: [PATCH] Added extension methods --- ExaArray/Extensions.ExaArray1D.cs | 41 +++++++++++++++++++++++++++++++ ExaArrayTests/ExaArray1DTests.cs | 5 ++++ 2 files changed, 46 insertions(+) create mode 100644 ExaArray/Extensions.ExaArray1D.cs diff --git a/ExaArray/Extensions.ExaArray1D.cs b/ExaArray/Extensions.ExaArray1D.cs new file mode 100644 index 0000000..ffc64f3 --- /dev/null +++ b/ExaArray/Extensions.ExaArray1D.cs @@ -0,0 +1,41 @@ +using System; + +namespace Exa +{ + /// + /// Extension methods for ExaArray1D. + /// + public static class ExtensionsExaArray1D + { + /// + /// Creates a new ExaArray1D from this instance. + /// + /// + /// When T is a value type, data gets copied as values. When T is a reference type, the pointers + /// to the original objects are copied. Thus, this factory method does not create a deep copy. + /// + /// Performance: O(n) + /// + /// The instance from which the new instance is to be created. + /// The new instance + public static ExaArray1D Clone(this ExaArray1D other) => ExaArray1D.CreateFrom(other); + + /// + /// Creates a new ExaArray1D from another, respecting the given range. + /// + /// + /// When T is a value type, data gets copied as values. When T is a reference type, the pointers + /// to the original objects are copied. Thus, this factory method does not create a deep copy. + /// + /// Performance: O(n) + /// + /// The indices are inclusive. + /// + /// The instance from which the new instance is to be created. + /// The first source element which should be part of the new array. + /// The last source element which should be part of the new array. + /// The new instance + /// Throws, when one or both of the indices are out of range. + public static ExaArray1D Clone(this ExaArray1D other, ulong indexFrom, ulong indexTo) => ExaArray1D.CreateFrom(other, indexFrom, indexTo); + } +} \ No newline at end of file diff --git a/ExaArrayTests/ExaArray1DTests.cs b/ExaArrayTests/ExaArray1DTests.cs index 88f476c..7400637 100644 --- a/ExaArrayTests/ExaArray1DTests.cs +++ b/ExaArrayTests/ExaArray1DTests.cs @@ -540,7 +540,12 @@ namespace ExaArrayTests exPerf.Extend(3 * MAX); // more than one chunk var next = ExaArray1D.CreateFrom(exPerf, 0, exPerf.Length - 1); + var next2 = exPerf.Clone(); + var next3 = exPerf.Clone(0, exPerf.Length - 1); + Assert.That(next.Length, Is.EqualTo(exPerf.Length)); + Assert.That(next2.Length, Is.EqualTo(exPerf.Length)); + Assert.That(next3.Length, Is.EqualTo(exPerf.Length)); } [Test]