pub enum TypeRelation {
SameType(&'static [PortRef]),
SameElementType(&'static [PortRef]),
BroadcastShape {
in0: PortRef,
in1: PortRef,
out: PortRef,
},
Elementwise {
input: PortRef,
output: PortRef,
},
ReduceOver {
input: PortRef,
output: PortRef,
},
Custom {
name: &'static str,
run: fn(&CustomRelationCtx<'_>) -> RelationResult,
},
}Expand description
One type relation declared on an op. The TypeSolver instantiates each as a constraint node linked to its participating type variables via back-edges.
Variants§
SameType(&'static [PortRef])
All listed ports share the SAME concrete TypeNode. Implements
Julia’s “diagonal variable” rule - a port declared Tensor
that participates in SameType([in0, in1, out0]) collapses
to ONE element type across all three positions, regardless
of the bound’s permissiveness.
SameElementType(&'static [PortRef])
All listed Tensor-typed ports share the same ELEMENT type.
Shapes may differ (broadcasting is a separate concern).
Add(x: Tensor, y: Tensor) -> Tensor uses this.
BroadcastShape
The output is the broadcast of two tensor inputs. Composes
with SameElementType to express Add / Mul / Sub /
Div fully.
Fields
Elementwise
Output preserves the input’s TypeNode entirely. Used by
element-wise unary ops (Sqrt, Neg, Abs, Relu, etc.):
shape preserved, element type preserved.
ReduceOver
Output is a reduction over the input: same element type,
reduced shape (driven by op attributes like axes).
ReduceSum / ReduceMean / ReduceMax use this.
Fields
Custom
Escape hatch for ops that don’t fit a predicate. The custom
function receives the current TypeNodes for participating
ports and returns a RelationResult.
Use sparingly - Reshape, Gather, Concat, Cast, and
any op with attribute-driven type changes need this.
Fields
run: fn(&CustomRelationCtx<'_>) -> RelationResultSolver entry point. Receives the participating ports’
current resolutions (Option<&TypeNode>); narrows them
or returns Failed.