Class CastNode
Cast node — expr.astype(target) in the fused tree. Wraps a child and carries the TARGET
dtype (which a plain UnaryOp enum cannot, having no payload), so it is a distinct
node type rather than a UnaryNode. Its result dtype is the target; the child is
computed at its own dtype and converted per element with EmitConvertTo(ILGenerator, NPTypeCode, NPTypeCode)
— the exact conversion the engine's casts and every other node edge already use, which is why a
Cast is byte-for-byte np.evaluate(child).astype(target) for in-range values.
SCALAR-ONLY for now (CanEmitVectorV2(NPTypeCode, IReadOnlyDictionary<NDExpr, NPTypeCode>) is false), deferring the widening cast lanes to
Phase 5; a tree containing a Cast therefore runs scalar end-to-end.
public sealed class CastNode : NDExpr
- Inheritance
-
CastNode
- Inherited Members
Constructors
CastNode(NDExpr, NPTypeCode)
Construct a cast of child to target.
public CastNode(NDExpr child, NPTypeCode target)
Parameters
childNDExprThe sub-expression to convert.
targetNPTypeCodeThe target element dtype.
Exceptions
- ArgumentNullException
childis null.- NotSupportedException
targetis String: the storage lane names no text class or width, so a text cast is built from its descriptor (Cast(NDExpr, DType)) — the refusal From(NPTypeCode) gives the lane.
Properties
SupportsSimd
True if this node and its entire sub-tree have a SIMD emit path. Structural and type-independent — prefer SupportsSimdAt(NPTypeCode) for the compile decision, since some ops only vectorize at certain element types/runtimes.
public override bool SupportsSimd { get; }
Property Value
Methods
AppendSignature(StringBuilder)
Appends this cast to the legacy string key: the target's type code, and for a text target its whole descriptor
(NumPy's repr: the class, the width and a StringDType's NA object), since Cast(x, "U5") and
Cast(x, "U3") share the lane but not the result.
public override void AppendSignature(StringBuilder sb)
Parameters
sbStringBuilderThe key under construction.
EmitScalar(ILGenerator, NDExprCompileContext)
Emit scalar code. On exit, the evaluation stack must have exactly
one value of dtype ctx.OutputType.
public override void EmitScalar(ILGenerator il, NDExprCompileContext ctx)
Parameters
ilILGeneratorctxNDExprCompileContext
EmitVector(ILGenerator, NDExprCompileContext)
Emit vector code. On exit, the evaluation stack must have exactly
one Vector{W}<T> of element type ctx.OutputType.
Called only when SupportsSimd is true and all input
types equal the output type.
public override void EmitVector(ILGenerator il, NDExprCompileContext ctx)
Parameters
ilILGeneratorctxNDExprCompileContext