Class np.NDEnumerate<T>
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
Typed np.NDEnumerate — identical traversal, but reads elements as
T without boxing. See ndenumerate<T>(NDArray).
public class np.NDEnumerate<T> : IEnumerable<(long[] index, T value)>, IEnumerable, IEnumerator<(long[] index, T value)>, IEnumerator, IDisposable where T : unmanaged
Type Parameters
T
- Inheritance
-
np.NDEnumerate<T>
- Implements
- Inherited Members
Properties
Current
Gets the element in the collection at the current position of the enumerator.
public (long[] index, T value) Current { get; }
Property Value
Methods
AsRef(bool)
The allocation-free, by-ref T form of this walk — the high-performance
counterpart. Where iterating this object hands out a (long[] index, T value)
tuple per step (T is unboxed, but the value is a COPY and each step allocates a
fresh long[] for the index), np.NDEnumerateRef<T> hands out
ref T straight into the array's memory plus a ReadOnlySpan<T>
over a REUSED coordinate buffer — no per-element allocation, and write-through:
foreach (var e in np.ndenumerate<double>(a).AsRef(writeable: true))
{
e.Value += e.Index[0]; // ref double — writes through to the array
}
Same logical C-order as the boxed/tuple walks (the value comes from the same
NDIterRef C-order cursor flat<T>(NDArray, bool)
uses, so the k-th step is the element at C-order position k, whatever the layout).
Index is a span over a buffer reused each step — copy it (e.Index.ToArray())
if you need to keep it past the current iteration, exactly as with a
Span<T> chunk.
public np.NDEnumerateRef<T> AsRef(bool writeable = false)
Parameters
writeableboolOpen the array
readwriteso assignments throughe.Valuereach it; a read-only broadcast view is refused with NumPy's message. Defaults to read.
Returns
- np.NDEnumerateRef<T>
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<(long[] index, T value)> GetEnumerator()
Returns
- IEnumerator<(long[] index, T value)>
An enumerator that can be used to iterate through the collection.
MoveNext()
Advances the enumerator to the next element of the collection.
public bool MoveNext()
Returns
- bool
true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
Exceptions
- InvalidOperationException
The collection was modified after the enumerator was created.