def test_orthogonal() -> None:
    """
    **Overview**:
        Test the ``orthogonal_`` function. We use a weight tensor of convolutional layer and a weight tensor of linear layer as test cases, and check whether the results are correctly orthogonalized.
    """
    # For Conv. weights.
    w1 = torch.empty((4, 4, 3, 3))
    orthogonal_(w1)
    # Test whether the result is orthogonal.
    w1 = w1.reshape(w1.shape[0], -1).T
    res = w1.T @ w1
    gt = torch.eye(w1.shape[1])
    assert torch.sum((res - gt) ** 2).item() < 1e-9

    # For Linear weights.
    w2 = torch.empty((4, 4))
    orthogonal_(w2)
    # Test whether the result is orthogonal.
    res = w2.T @ w2
    gt = torch.eye(w2.shape[1])
    assert torch.sum((res - gt) ** 2).item() < 1e-9

    **Overview**:
        Test the ``orthogonal_`` function. We use a weight tensor of convolutional layer and a weight tensor of linear layer as test cases, and check whether the results are correctly orthogonalized.
    
chapter7_tricks/orthogonal_init.py