guards ====== .. py:module:: guards .. autoapi-nested-parse:: Strict Mode Guards Injection. Attributes ---------- .. autoapisummary:: guards.STRICT_RANK_HELPER Functions --------- .. autoapisummary:: guards.apply_strict_guards Module Contents --------------- .. py:data:: STRICT_RANK_HELPER :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """ def _check_rank(x, rank): if hasattr(x, 'ndim'): n = x.ndim elif hasattr(x, 'shape'): n = len(x.shape) else: return x assert n == rank, f"Strict Guard: Expected rank {rank}, got {n}" return x """ .. raw:: html
.. py:function:: apply_strict_guards(rewriter: Any, norm_args: List[libcst.Arg], details: Dict[str, Any], target_impl: Dict[str, Any]) -> List[libcst.Arg] Wraps args with rank assertions.