def test_inv_skew_symmetrize_throws_if_dim_not_square(ndim):
    dim = 3
    blocksize = 16

    # Matrix not necessary to be sk-symm in this case
    if ndim == 1:
        incorrect_input_matrix = np.random.randn(dim + dim)
    elif ndim == 2:
        incorrect_input_matrix = np.random.randn(dim + dim, blocksize)
    elif ndim == 3:
        incorrect_input_matrix = np.random.randn(dim, dim + 1, blocksize)

    with pytest.raises(AssertionError) as excinfo:
        inv_skew_symmetrize(incorrect_input_matrix)
    assert excinfo.type == AssertionError
def test_inv_skew_symmetrize_raises_dimension_error(ndim):
    dim = 4  # one greater than allowed dimension
    blocksize = 8
    # Matrix not necessary to be sk-symm in this case
    if ndim == 1:
        incorrect_input_matrix = np.random.randn(dim ** 2)
    elif ndim == 2:
        incorrect_input_matrix = np.random.randn(dim ** 2, blocksize)
    elif ndim == 3:
        incorrect_input_matrix = np.random.randn(dim, dim, blocksize)

    # Matrix not necessary to be sk-symm in this case
    with pytest.raises(AssertionError) as excinfo:
        inv_skew_symmetrize(incorrect_input_matrix)
    assert excinfo.type == AssertionError
def test_inv_skew_symmetrize_handles_blocksizes(blocksize):
    dim = 3  # decides when to transpose
    input_vector = np.random.randn(dim, blocksize)
    input_matrix = skew_symmetrize(input_vector)  # tested

    # reshape and squeeze because we are testing a single vector
    test_vector = inv_skew_symmetrize(input_matrix)

    assert_allclose(test_vector, input_vector)
def test_inv_skew_symmetrize_against_input_shapes(ndim):
    dim = 3

    # First generate a skew-symmetric matrix from vector
    if ndim == 1:
        blocksize = 1
    else:
        blocksize = 16

    input_vector = np.random.randn(dim, blocksize)

    input_matrix = _skew_symmetrize(input_vector)

    if ndim == 1:
        input_matrix = input_matrix.reshape(dim ** 2)
    elif ndim == 2:
        input_matrix = input_matrix.reshape(dim ** 2, blocksize)
    elif ndim == 3:
        input_matrix = input_matrix.reshape(dim, dim, blocksize)

    test_vector = inv_skew_symmetrize(input_matrix)

    assert_allclose(test_vector, input_vector)
def test_inv_skew_symmetrize_checks_skew_symmetry(blocksize):
    incorrect_input_matrix = np.random.randn(3, 3, blocksize)

    with pytest.raises(ValueError) as excinfo:
        inv_skew_symmetrize(incorrect_input_matrix)
    assert excinfo.type == ValueError