MCPcopy Create free account
hub / github.com/pytorch/executorch / _make_triangular_test

Function _make_triangular_test

backends/mlx/test/test_ops.py:4747–4779  ·  view source on GitHub ↗

Generate a registered OpTestCase subclass for tril or triu.

(mode: str)

Source from the content-addressed store, hash-verified

4745
4746
4747def _make_triangular_test(mode: str) -> type:
4748 """Generate a registered OpTestCase subclass for tril or triu."""
4749
4750 class _Test(OpTestCase):
4751 name = mode
4752
4753 def __init__(
4754 self,
4755 shape: Tuple[int, ...] = (4, 4),
4756 diagonal: int = 0,
4757 dtype: torch.dtype = torch.float32,
4758 ):
4759 self.shape = shape
4760 self.diagonal = diagonal
4761 self.dtype = dtype
4762 shape_str = "x".join(str(s) for s in shape)
4763 dtype_str = str(dtype).replace("torch.", "")
4764 diag_str = f"d{diagonal}" if diagonal != 0 else ""
4765 self.name = f"{mode}_{shape_str}_{dtype_str}{diag_str}"
4766
4767 @classmethod
4768 def get_test_configs(cls) -> List["_Test"]:
4769 return [cls(**c) for c in _TRIANGULAR_CONFIGS]
4770
4771 def create_inputs(self) -> Tuple[torch.Tensor, ...]:
4772 return (torch.randn(self.shape, dtype=self.dtype),)
4773
4774 def create_model(self) -> nn.Module:
4775 return TriangularModel(mode=mode, diagonal=self.diagonal)
4776
4777 _Test.__name__ = f"{mode.title()}Test"
4778 _Test.__qualname__ = _Test.__name__
4779 return _Test
4780
4781
4782TrilTest = _make_triangular_test("tril")

Callers 1

test_ops.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected