boundlab.expr.ConstVal#

class boundlab.expr.ConstVal[source]#

Bases: AffineSum

Expression representing a constant tensor value.

Implemented as an AffineSum with no children and only a constant term. When used as a child of another AffineSum, the constant is automatically absorbed via eager contraction.

Methods

__init__

Construct an AffineSum.

backward

Propagate weights backward: each child gets weights ∘ op_i.

bound_width

Compute the width of the bounds for this expression.

center

Compute the center of the bounds for this expression.

diag

expand

flatten

flip

gather

get_const

Return the concrete tensor if self is a pure constant expression, else None.

jacobian_ops_

Recursively compute Jacobian ops for affine expressions.

lb

Compute a lower bound for this expression.

narrow

permute

repeat

reshape

roll

scatter

squeeze

tile

to_string

Return string representation with child strings substituted.

transpose

ub

Compute an upper bound for this expression.

ublb

Compute both an upper bound and a lower bound for this expression.

unflatten

unsqueeze

with_children

Return a new AffineSum with the same ops but new children.

zeros_set

__init__(value=None, name=None, *_pairs, const=None)[source]#

Construct an AffineSum.

Parameters:

*pairs – Sequence of (op, child) pairs where op is a EinsumOp and child is an Expr or torch.Tensor.

to_string()[source]#

Return string representation with child strings substituted.

get_const()[source]#

Return the concrete tensor if self is a pure constant expression, else None.

Works for ConstVal and any AffineSum that has no symbolic children.

__add__(other)[source]#
__mul__(other)[source]#

Element-wise multiplication (no broadcast).

property T: Expr#

Convenience for transpose of the last two dimensions.

static __new__(cls, *pairs, const=None, **_kw)#
backward(weights, direction)#

Propagate weights backward: each child gets weights ∘ op_i.

Parameters:
  • weights – A EinsumOp accumulated weight.

  • direction (Literal['>=', '<=', '==']) – Bound direction (unused — Linear is always linear).

Returns:

(bias, [weights @ op_i for op_i in self.children_dict.values()]).

Return type:

tuple

bound_width()#

Compute the width of the bounds for this expression.

center()#

Compute the center of the bounds for this expression.

property children: tuple[Expr, ...]#

The child expressions that serve as inputs to this expression.

diag(diagonal=0)#
expand(*sizes)#
flatten(start_dim=0, end_dim=-1)#
flip(dims)#
gather(indices)#
jacobian_ops_()#

Recursively compute Jacobian ops for affine expressions.

lb()#

Compute a lower bound for this expression.

narrow(dim, start, length)#
permute(*dims)#
repeat(*sizes)#
reshape(*shape)#
roll(shifts, dims)#
scatter(indices, output_shape)#
property shape: torch.Size#

The shape of the output(s) produced by this expression.

squeeze(dim=None)#
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.

unflatten(dim, sizes)#
unsqueeze(dim)#
with_children(*new_children)#

Return a new AffineSum with the same ops but new children.

zeros_set(output_shape)#
children_dict: dict[Expr, LinearOp]#
id: int#

Unique identifier for the expression, used for topological sorting.

flags: ExprFlags#

Flags indicating expression properties for optimization.