boundlab.expr.GetTupleItem#
- class boundlab.expr.GetTupleItem[source]#
Bases:
ExprExpression representing indexing into a TupleExpr.
This is used to extract individual outputs from a TupleExpr. Like TupleExpr, this is an implementation detail for handling multi-output operations and is not intended for direct use by users.
- index#
The integer index of the tuple element to extract.
- child#
The TupleExpr being indexed.
Methods
Return a list of all sub-expressions in the DAG rooted at this expression, in topological order.
Perform backward-mode bound propagation through this expression.
Compute the width of the bounds for this expression.
Compute the breakdown of the bound width by reason.
Compute the center of the bounds for this expression.
Return the concrete tensor if self is a pure constant expression, else None.
Return True if this expression is symmetric about zero, else False.
Compute a lower bound for this expression.
Compute the maximum width across all output dimensions.
Return a new expression with the same structure but sub-expressions replaced by replace_fn.
Recursively compute simplified ops for affine expressions.
Decompose this expression into a constant part and a zero-constant part.
Return string representation with child strings substituted.
Compute an upper bound for this expression.
Compute both an upper bound and a lower bound for this expression.
Compute the breakdown of the bound width by reason, aggregated to total contributions.
Return a new expression with the same type and flags but new children.
- property shape: torch.Size#
The shape of the output(s) produced by this expression.
- property tuple_expr: TupleExpr#
The TupleExpr being indexed. This is used for topological sorting and weight propagation.
- backward(weights, direction='==')[source]#
Perform backward-mode bound propagation through this expression.
Given an accumulated weight
weights(usually aEinsumOp) from the output back to this node, backward propagation derives child weights and a bias:\[\mathbf{w}^\top f(x_1, \ldots, x_n) \;\square\; b + \sum_i \mathbf{w}_i^\top x_i\]- Parameters:
weights – A
EinsumOpaccumulated weight from the root expression to this node.direction – Bound direction —
">="(lower),"<="(upper), or"=="(exact).
- Returns:
A tuple
(bias, child_weights)wherebiasis atorch.Tensoror0, andchild_weightsis a list ofEinsumOp(one per child). ReturnsNoneif this expression cannot contribute to the bound in the given direction.- Return type:
tuple[torch.Tensor, list[LinearOp]] | None
- with_children(*new_children)[source]#
Return a new expression with the same type and flags but new children.
- to_string(*children_str, indent=0)[source]#
Return string representation with child strings substituted.
- __add__(other)#
- __mul__(other)#
Element-wise multiplication (no broadcast).
- all_subnodes()#
Return a list of all sub-expressions in the DAG rooted at this expression, in topological order.
- bound_width()#
Compute the width of the bounds for this expression.
- bound_width_reasons_breakdown()#
Compute the breakdown of the bound width by reason.
- center()#
Compute the center of the bounds for this expression.
- diag(diagonal=0)#
- expand(*sizes)#
- expand_on(dim, size)#
- flatten(start_dim=0, end_dim=-1)#
- flip(dims)#
- gather(indices, dim=0)#
- get_const()#
Return the concrete tensor if self is a pure constant expression, else None.
Works for
ConstValand anyAffineSumthat has no symbolic children.
- is_symmetric_to_0()#
Return True if this expression is symmetric about zero, else False.
- lb()#
Compute a lower bound for this expression.
- max_bound_width()#
Compute the maximum width across all output dimensions.
- mean(dim=None, keepdim=False)#
- narrow(dim, start, length)#
- permute(*dims)#
- repeat(*sizes)#
- replace_subnode_once(replace_fn)#
Return a new expression with the same structure but sub-expressions replaced by replace_fn.
- reshape(*shape)#
- roll(shifts, dims)#
- scatter(indices, output_shape)#
- split_const()#
Decompose this expression into a constant part and a zero-constant part.
If the expression is symmetric about zero, the constant part is zero. If the expression is a pure constant, the zero-constant part is zero.
- squeeze(dim=None)#
- sum(dim=None, keepdim=False)#
- tile(*sizes)#
- transpose(dim0, dim1)#
- ub()#
Compute an upper bound for this expression.
- ublb()#
Compute both an upper bound and a lower bound for this expression.
- uncertainty_reasons()#
Compute the breakdown of the bound width by reason, aggregated to total contributions.
- unflatten(dim, sizes)#
- unsqueeze(dim)#
- zeros_set(output_shape)#