Skip to content

example_fgen_basic.error_v.passing#

Wrappers of m_error_v_passing.

At the moment, all written by hand. We will auto-generate this in future.

Functions:

Name Description
pass_error

Pass an error to Fortran

pass_errors

Pass a number of errors to Fortran

pass_error #

pass_error(inv: ErrorV) -> bool

Pass an error to Fortran

Parameters:

Name Type Description Default
inv ErrorV

Input value to pass to Fortran

required

Returns:

Type Description
bool

If inv is an error, True, otherwise False.

Source code in src/example_fgen_basic/error_v/passing.py
def pass_error(inv: ErrorV) -> bool:
    """
    Pass an error to Fortran

    Parameters
    ----------
    inv
        Input value to pass to Fortran

    Returns
    -------
    :
        If `inv` is an error, `True`, otherwise `False`.
    """
    # Tell Fortran to build the object on the Fortran side
    instance_index = inv.build_fortran_instance()

    # Call the Fortran function
    # Boolean wrapping strategy, have to cast to bool
    res_raw: int = m_error_v_passing_w.pass_error(instance_index)
    res = bool(res_raw)

    # Tell Fortran to finalise the object on the Fortran side
    # (all data has been used for the call now)
    m_error_v_w.finalise_instance(instance_index)

    return res

pass_errors #

pass_errors(invs: tuple[ErrorV, ...]) -> NP_ARRAY_OF_BOOL

Pass a number of errors to Fortran

Parameters:

Name Type Description Default
invs tuple[ErrorV, ...]

Errors to pass to Fortran

required

Returns:

Type Description
NP_ARRAY_OF_BOOL

Whether each value in invs is an error or not

Source code in src/example_fgen_basic/error_v/passing.py
def pass_errors(invs: tuple[ErrorV, ...]) -> NP_ARRAY_OF_BOOL:
    """
    Pass a number of errors to Fortran

    Parameters
    ----------
    invs
        Errors to pass to Fortran

    Returns
    -------
    :
        Whether each value in `invs` is an error or not
    """
    # Controlling memory from the Python side
    m_error_v_w.ensure_at_least_n_instances_can_be_passed_simultaneously(len(invs))

    instance_indexes: NP_ARRAY_OF_INT = np.array(
        [m_error_v_w.build_instance(code=inv.code, message=inv.message) for inv in invs]
    )

    # Convert the result to boolean
    res_raw: NP_ARRAY_OF_INT = m_error_v_passing_w.pass_errors(
        instance_indexes, n=instance_indexes.size
    )
    res = res_raw.astype(bool)

    # Tell Fortran to finalise the objects on the Fortran side
    # (all data has been copied to Python now)
    m_error_v_w.finalise_instances(instance_indexes)

    return res