boundlab.zono.matmul_handler#

boundlab.zono.matmul_handler(A, B)[source]#

Dispatcher implementation for torch.matmul.

Routing rules:

  • Expr @ Expr: McCormick-style bilinear relaxation.

  • Expr @ Tensor or Tensor @ Expr: exact affine path.

  • Tensor @ Tensor: delegated to torch.matmul.

Examples

>>> import torch
>>> import boundlab.expr as expr
>>> from boundlab.zono.bilinear import matmul_handler
>>> A = expr.ConstVal(torch.ones(1, 2)) + expr.LpEpsilon([1, 2])
>>> B = torch.ones(2, 1)
>>> matmul_handler(A, B).shape
torch.Size([1, 1])