Table of Contents

Class CompiledExpression

Namespace
NumSharp.Backends.Iteration
Assembly
NumSharp.dll

An NDExpr tree compiled ahead of evaluation — the handle Compile() / Compile(params NPTypeCode[]) return. Holds the bound tree, the resolved dtypes and the fused kernel; Evaluate(NDArray) runs the per-call work only. Immutable and safe to share across threads (each evaluation builds its own iterator). The arrays an embedded-form handle references are the caller's: it neither owns nor disposes them, and it reads their CURRENT contents on every evaluation.

public sealed class CompiledExpression
Inheritance
CompiledExpression
Inherited Members

Properties

Expression

The tree this handle was compiled from.

public NDExpr Expression { get; }

Property Value

NDExpr

InputTypes

The input dtype signature this handle is compiled for, in input order.

public NPTypeCode[] InputTypes { get; }

Property Value

NPTypeCode[]

IsPositional

True for a positional tree (Input(int) leaves, operands supplied per call).

public bool IsPositional { get; }

Property Value

bool

IsReduction

True when the root is a reduction (Sum / Prod / Min / Max / Mean / … or a weighted Average), over text comparisons too (CountNonzero(NDExpr.Equal(city, "paris"))).

public bool IsReduction { get; }

Property Value

bool

OperandCount

Number of distinct inputs the kernel reads (embedded arrays are deduplicated by reference; hoisted 0-d parameters count).

public int OperandCount { get; }

Property Value

int

ResultType

The NumPy result dtype of an evaluation (the elementwise output, or the reduction's result).

public NPTypeCode ResultType { get; }

Property Value

NPTypeCode

Methods

Evaluate(NDArray)

Evaluate an embedded-array handle over the arrays the tree references (their current contents). Same contract as np.evaluate(expr, out): out joins the broadcast but is never stretched, takes a same_kind cast from ResultType, and may alias an input.

public NDArray Evaluate(NDArray @out = null)

Parameters

out NDArray

An optional pre-allocated, writeable result.

Returns

NDArray

The evaluated array (out itself when given).

Exceptions

InvalidOperationException

The handle is positional — pass its operands; or a hoisted 0-d array was resized in place.

Evaluate(NDArray[], NDArray)

Evaluate a positional handle against operands (Input(i) reads operands[i]), which must carry exactly the dtype signature the handle was compiled for (InputTypes); otherwise a TypeError. Shapes broadcast per call like a ufunc's.

public NDArray Evaluate(NDArray[] operands, NDArray @out = null)

Parameters

operands NDArray[]

The positional operands, one per Input(int) index.

out NDArray

An optional pre-allocated, writeable result.

Returns

NDArray

The evaluated array (out itself when given).

Exceptions

ArgumentNullException

operands or one of its entries is null.

InvalidOperationException

The handle is an embedded-array handle — evaluate it with Evaluate(NDArray).

TypeError

The operands' dtype signature differs from the compiled one.