Skip to content

Commit f644571

Browse files
committed
feat(int64): add UnmanagedSpan extension methods for Span<T> parity
Implements Span<T>-equivalent extension methods for UnmanagedSpan<T> and ReadOnlyUnmanagedSpan<T> with full long indexing support. **Search Methods (return long)** - IndexOf(T value) - first occurrence - IndexOf(ReadOnlyUnmanagedSpan<T> value) - first sequence occurrence - LastIndexOf(T value) - last occurrence - LastIndexOf(ReadOnlyUnmanagedSpan<T> value) - last sequence occurrence - IndexOfAny(T, T) / IndexOfAny(T, T, T) / IndexOfAny(span) - LastIndexOfAny(T, T) / LastIndexOfAny(T, T, T) / LastIndexOfAny(span) - BinarySearch(T) / BinarySearch(T, IComparer<T>) **Predicates** - Contains(T value) - existence check - SequenceEqual(span) / SequenceEqual(span, comparer) - StartsWith(span) / EndsWith(span) **Sorting (IntroSort with long indices)** - Sort() / Sort(IComparer<T>) / Sort(Comparison<T>) - Sort(keys, items) - paired sort with values span **Modification** - Reverse() - in-place reversal - Replace(oldValue, newValue) - in-place replacement **Statistics** - Count(T value) - occurrence count (returns long) - CommonPrefixLength(span) - shared prefix length All methods support >2B element spans via long indexing.
1 parent 176336a commit f644571

2 files changed

Lines changed: 872 additions & 1 deletion

File tree

src/NumSharp.Core/Backends/Unmanaged/UnmanagedStorage.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,19 @@ public Shape Shape
176176
/// Returns an UnmanagedSpan representing this storage's memory.
177177
/// </summary>
178178
/// <remarks>This ignores completely slicing. Supports long indexing for arrays &gt; 2B elements.</remarks>
179-
public unsafe UnmanagedSpan<T> AsSpan<T>() where T : unmanaged
179+
public unsafe Span<T> AsSpan<T>() where T : unmanaged
180+
{
181+
if (!_shape.IsContiguous)
182+
throw new InvalidOperationException("Unable to span a non-contiguous storage.");
183+
184+
return new Span<T>(Address, (int)Count);
185+
}
186+
187+
/// <summary>
188+
/// Returns an UnmanagedSpan representing this storage's memory.
189+
/// </summary>
190+
/// <remarks>This ignores completely slicing. Supports long indexing for arrays &gt; 2B elements.</remarks>
191+
public unsafe UnmanagedSpan<T> AsUnmanagedSpan<T>() where T : unmanaged
180192
{
181193
if (!_shape.IsContiguous)
182194
throw new InvalidOperationException("Unable to span a non-contiguous storage.");

0 commit comments

Comments
 (0)