Added extension methods
This commit is contained in:
parent
c5b26afad0
commit
de75d12140
41
ExaArray/Extensions.ExaArray1D.cs
Normal file
41
ExaArray/Extensions.ExaArray1D.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace Exa
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <c>ExaArray1D</c>.
|
||||
/// </summary>
|
||||
public static class ExtensionsExaArray1D
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new ExaArray1D from this instance.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When <c>T</c> is a value type, data gets copied as values. When <c>T</c> 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)
|
||||
/// </remarks>
|
||||
/// <param name="other">The instance from which the new instance is to be created.</param>
|
||||
/// <returns>The new instance</returns>
|
||||
public static ExaArray1D<T> Clone<T>(this ExaArray1D<T> other) => ExaArray1D<T>.CreateFrom(other);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ExaArray1D from another, respecting the given range.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When <c>T</c> is a value type, data gets copied as values. When <c>T</c> 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.
|
||||
/// </remarks>
|
||||
/// <param name="other">The instance from which the new instance is to be created.</param>
|
||||
/// <param name="indexFrom">The first source element which should be part of the new array.</param>
|
||||
/// <param name="indexTo">The last source element which should be part of the new array.</param>
|
||||
/// <returns>The new instance</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">Throws, when one or both of the indices are out of range.</exception>
|
||||
public static ExaArray1D<T> Clone<T>(this ExaArray1D<T> other, ulong indexFrom, ulong indexTo) => ExaArray1D<T>.CreateFrom(other, indexFrom, indexTo);
|
||||
}
|
||||
}
|
@ -540,7 +540,12 @@ namespace ExaArrayTests
|
||||
exPerf.Extend(3 * MAX); // more than one chunk
|
||||
|
||||
var next = ExaArray1D<byte>.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]
|
||||
|
Loading…
Reference in New Issue
Block a user