Table of Contents

Class np.Broadcast

Namespace
NumSharp
Assembly
NumSharp.dll

NumPy's numpy.broadcast — the broadcast result of N operands, usable as an iterator. Like NumPy, the object is its OWN iterator (iter(b) is b): it keeps a single live cursor exposed as index, iterating it yields one tuple of per-operand values per step (advancing the cursor), and reset() rewinds it.

public class np.Broadcast : IEnumerable<object[]>, IEnumerable, IEnumerator<object[]>, IEnumerator, IDisposable
Inheritance
np.Broadcast
Implements
Inherited Members

Constructors

Broadcast(params NDArray[])

NumPy's np.broadcast(*arrays) class constructor: broadcast N operands together. The result shape is the broadcast of every operand's shape (resolved eagerly; iterators are built lazily on first iters access). Incompatible shapes raise IncorrectShapeException (NumPy parity). Unlike NumPy's fixed NPY_MAXARGS=64 cap, any number of operands is accepted — matching NumSharp's unlimited-operand NDIter. No operand at all (new np.Broadcast()) is NumPy's np.broadcast(): the 0-d broadcast, shape () and size 1.

public Broadcast(params NDArray[] arrays)

Parameters

arrays NDArray[]

The operands (null is treated as none); the object borrows them, it does not own or dispose them.

Remarks

Public since API-parity batch 13 (NumPy's class IS the function); the operand-less public constructor it replaced built an object whose shape threw and whose size was 0.

Exceptions

IncorrectShapeException

Two operands disagree on an axis: NumPy's shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between arg 0 with shape (3,) and arg 1 with shape (4,). (MultiIterShape(Shape[])).

ValueError

The broadcast shape's element count does not fit a 64-bit integer (broadcast dimensions too large.).

Broadcast(NDListArray[])

NumPy's np.broadcast(*arrays) over object arrays of lists (NDListArray, the np.char.split results): the list arrays' shapes broadcast together, and each step's tuple holds the operands' LISTS (a List<T> of its pieces each, NumPy's Python list).

public Broadcast(NDListArray[] arrays)

Parameters

arrays NDListArray[]

The list arrays (null is treated as none); borrowed, never disposed here.

Remarks

The broadcast runs over each list array's int64 ids (NumPy's object pointers), so the shape rule and its texts are the array constructor's; a step reads each id and hands back the list it names. iters is refused for list operands (its flat iterators read numbers). A sequence parameter, not params: a second params form would make new np.Broadcast() ambiguous. API-parity batch 13 (the owner: "Also NDListArray").

Exceptions

ArgumentNullException

An operand is null.

ObjectDisposedException

An operand was disposed.

IncorrectShapeException

The operands do not broadcast together (NumPy's text).

Properties

Current

The tuple of per-operand values produced by the most recent step (one per numiter).

public object[] Current { get; }

Property Value

object[]

index

The live flat position of the iterator (NumPy's broadcast.index): the number of elements already consumed — 0 before iterating, incrementing by one per step, and equal to size once exhausted. Use reset() to rewind.

public int index { get; }

Property Value

int

iters

Per-operand flat iterators (NumPy's broadcast.iters): one entry per input, each iterating that operand broadcast to the result shape in C-order (e.g. np.broadcast([1,2,3], [[10],[20]]).iters[0] yields 1,2,3,1,2,3). Built lazily on first access — np.broadcast() only resolves the shape eagerly — and backed by broadcast_to(NDArray, Shape) + NDFlatIterator, the NDIter-aligned replacement for the removed NDIterator. There are numiter entries (none for a broadcast of no operand). Unlike NumPy's flatiters these are independent and re-enumerable; they do not share the index cursor.

public NDFlatIterator[] iters { get; }

Property Value

NDFlatIterator[]

Exceptions

NotSupportedException

The operands are list arrays (NDListArray): their views hold ids, which a flat iterator would read as numbers; iterate the broadcast itself.

nd

public int nd { get; }

Property Value

int

ndim

public int ndim { get; }

Property Value

int

numiter

Number of operands being broadcast together (NumPy's broadcast.numiter, equal to len(iters)). Equals the operand count passed to broadcast(params NDArray[]) (0 for a broadcast of no operand, new np.Broadcast()).

public int numiter { get; }

Property Value

int

shape

public Shape shape { get; }

Property Value

Shape

size

public long size { get; }

Property Value

long

Methods

Dispose()

Releases the broadcast views built for iteration (each is a broadcast_to view over an operand's buffer — a counted alias whose ref would otherwise wait for the finalizer). Called by foreach at the end of a loop; the views and the iters over them are rebuilt lazily on the next access, so the object stays re-enumerable (NumPy's iter(b) is b; call reset() to rewind). The operands themselves are the caller's and are never touched.

public void Dispose()

GetEnumerator()

Returns the broadcast itself as its iterator — matching NumPy's iter(b) is b, so iteration shares the single index cursor (call reset() to iterate again).

public IEnumerator<object[]> GetEnumerator()

Returns

IEnumerator<object[]>

MoveNext()

Advances the cursor one element and reads each operand's value at that flat (C-order) position into Current. Returns false once index reaches size. A broadcast of no operand has one step, an empty tuple (NumPy's list(np.broadcast()) is [()]); a list operand's value is its list.

public bool MoveNext()

Returns

bool

reset()

NumPy's broadcast.reset(): rewind the live index cursor to 0 so the object can be iterated again.

public void reset()