def get_orthogonal_matrix(size: int, mode: str, device: torch.device) -> torch.Tensor:
        """Get an orthogonal matrix of the specified size.

        Supported modes:
        - random: generate a random orthogonal matrix
        - hadamard: generate a random Hadamard matrix
        """
        if mode == "random":
            # First, we generate a random matrix with entries from a standard distribution.
            # Then, we use QR decomposition to obtain an orthogonal matrix.
            # Finally, we multiply by a diagonal matrix with diag r to adjust the signs.
            cleanup_memory()
            random_matrix = torch.randn(size, size, dtype=torch.float64).to(device)
            q, r = torch.linalg.qr(random_matrix)  # pylint: disable=not-callable
            q *= torch.sign(torch.diag(r)).unsqueeze(0)
            return q
        elif mode == "hadamard":
            from olive.passes.pytorch.hadamard_utils import random_hadamard_matrix

            return random_hadamard_matrix(size, device)
        else:
            raise ValueError(f"Unknown mode {mode}")
Get an orthogonal matrix of the specified size.

        Supported modes:
        - random: generate a random orthogonal matrix
        - hadamard: generate a random Hadamard matrix
        
olive/passes/pytorch/rotate.py