fn is_consistent<F: LinearAlgebraElement<F> + SparseComparator>(general_form: &GeneralForm<F>) -> bool {
    // Reference values
    let nr_active_constraints = general_form.nr_active_constraints();
    let nr_active_variables = general_form.nr_active_variables();
    let nr_free_variables = general_form.original_variables.iter().filter(|(_, variable)| {
        matches!(variable, OriginalVariable::ActiveFree(_, _))
    }).count();

    let b = general_form.b.len() == nr_active_constraints;
    let constraints = general_form.constraint_types.len() == nr_active_constraints;
    let rows = general_form.constraints.nr_rows() == nr_active_constraints;

    let variables = general_form.variables.len() == nr_active_variables;
    let columns = general_form.constraints.nr_columns() == nr_active_variables;
    let original_variables = {
        let nr_original_variables = general_form.original_variables.len();
        let size = nr_original_variables >= nr_active_variables - nr_free_variables;
        let kept_increasing = general_form.original_variables.iter()
            .filter_map(|(_, variable)| match variable {
                OriginalVariable::Active(index) => Some(*index),
                OriginalVariable::ActiveFree(positive, _) => Some(*positive),
                _ => None,
            }).is_sorted();
        let no_cycles = {
            let nodes = repeat_n(Element::Node { weight: (), }, nr_original_variables);
            let edges = general_form.original_variables
                .iter().enumerate()
                .filter_map(|(target, (_, variable))| match variable {
                    OriginalVariable::Removed(FunctionOfOthers{ constant: _, coefficients: els, }) => Some((els, target)),
                    _ => None,
                })
                .flat_map(|(els, target)| {
                    els.iter().map(move |&(j, _)| Element::<(), ()>::Edge { source: j, target, weight: (), })
                });

            !matches!(Dag::<(), (), usize>::from_elements(nodes.chain(edges)), Err(WouldCycle(_)))
        };

        [size, kept_increasing, no_cycles].iter().all(|v| *v)
    };
    let from_active_to_original = {
        let size = general_form.from_active_to_original.len() == nr_active_variables;
        let sorted_non_free = general_form.from_active_to_original[..(nr_active_variables - nr_free_variables)].is_sorted();
        let sorted_free = general_form.from_active_to_original[(nr_active_variables - nr_free_variables)..].is_sorted();
        let max = if nr_active_variables > 0 {
            general_form.from_active_to_original[nr_active_variables - 1] < general_form.nr_original_variables()
        } else { true };

        [
            size,
            sorted_non_free,
            sorted_free,
            max,
        ].iter().all(|v| *v)
    };

    [
        b,
        constraints,
        rows,
        variables,
        columns,
        original_variables,
        from_active_to_original,
    ].iter().all(|v| *v)
}
/// Check whether the dimensions of the `GeneralForm` are consistent.
///
/// This method might be expensive, use it in debugging only. It can be viewed as a piece of
/// documentation on the requirements of a `GeneralForm` struct.
Check whether the dimensions of the `GeneralForm` are consistent.
This method might be expensive, use it in debugging only. It can be viewed as a piece of
documentation on the requirements of a `GeneralForm` struct.
Check whether the dimensions of the ` GeneralForm ` are consistent . This method might be expensive use it in debugging only . It can be viewed as a piece of documentation on the requirements of a ` GeneralForm ` struct .
fn is_consistent<F: LinearAlgebraElement<F> + SparseComparator>(general_form: &GeneralForm<F>) -> bool {
    // Reference values
    let nr_active_constraints = general_form.nr_active_constraints();
    let nr_active_variables = general_form.nr_active_variables();
    let nr_free_variables = general_form.original_variables.iter().filter(|(_, variable)| {
        matches!(variable, OriginalVariable::ActiveFree(_, _))
    }).count();
    let b = general_form.b.len() == nr_active_constraints;
    let constraints = general_form.constraint_types.len() == nr_active_constraints;
    let rows = general_form.constraints.nr_rows() == nr_active_constraints;
    let variables = general_form.variables.len() == nr_active_variables;
    let columns = general_form.constraints.nr_columns() == nr_active_variables;
    let original_variables = {
        let nr_original_variables = general_form.original_variables.len();
        let size = nr_original_variables >= nr_active_variables - nr_free_variables;
        let kept_increasing = general_form.original_variables.iter()
            .filter_map(|(_, variable)| match variable {
                OriginalVariable::Active(index) => Some(*index),
                OriginalVariable::ActiveFree(positive, _) => Some(*positive),
                _ => None,
            }).is_sorted();
        let no_cycles = {
            let nodes = repeat_n(Element::Node { weight: (), }, nr_original_variables);
            let edges = general_form.original_variables
                .iter().enumerate()
                .filter_map(|(target, (_, variable))| match variable {
                    OriginalVariable::Removed(FunctionOfOthers{ constant: _, coefficients: els, }) => Some((els, target)),
                    _ => None,
                })
                .flat_map(|(els, target)| {
                    els.iter().map(move |&(j, _)| Element::<(), ()>::Edge { source: j, target, weight: (), })
                });
            !matches!(Dag::<(), (), usize>::from_elements(nodes.chain(edges)), Err(WouldCycle(_)))
        };
        [size, kept_increasing, no_cycles].iter().all(|v| *v)
    };
    let from_active_to_original = {
        let size = general_form.from_active_to_original.len() == nr_active_variables;
        let sorted_non_free = general_form.from_active_to_original[..(nr_active_variables - nr_free_variables)].is_sorted();
        let sorted_free = general_form.from_active_to_original[(nr_active_variables - nr_free_variables)..].is_sorted();
        let max = if nr_active_variables > 0 {
            general_form.from_active_to_original[nr_active_variables - 1] < general_form.nr_original_variables()
        } else { true };
        [
            size,
            sorted_non_free,
            sorted_free,
            max,
        ].iter().all(|v| *v)
    };
    [
        b,
        constraints,
        rows,
        variables,
        columns,
        original_variables,
        from_active_to_original,
    ].iter().all(|v| *v)
}
fn is_consistent < F : LinearAlgebraElement < F > + SparseComparator > ( general_form : & GeneralForm < F > ) -> bool { // Reference values let nr_active_constraints = general_form . nr_active_constraints ( ) ; let nr_active_variables = general_form . nr_active_variables ( ) ; let nr_free_variables = general_form . original_variables . iter ( ) . filter ( | ( _ , variable ) | { matches ! ( variable OriginalVariable ActiveFree ( ) ) } ) . count ( ) ; let b = general_form . b . len ( ) == nr_active_constraints ; let constraints = general_form . constraint_types . len ( ) == nr_active_constraints ; let rows = general_form . constraints . nr_rows ( ) == nr_active_constraints ; let variables = general_form . variables . len ( ) == nr_active_variables ; let columns = general_form . constraints . nr_columns ( ) == nr_active_variables ; let original_variables = { let nr_original_variables = general_form . original_variables . len ( ) ; let size = nr_original_variables >= nr_active_variables - nr_free_variables ; let kept_increasing = general_form . original_variables . iter ( ) . filter_map ( | ( _ , variable ) | match variable { OriginalVariable :: Active ( index ) => Some ( * index ) , OriginalVariable :: ActiveFree ( positive , _ ) => Some ( * positive ) , _ => None , } ) . is_sorted ( ) ; let no_cycles = { let nodes = repeat_n ( Element :: Node { weight : ( ) , } , nr_original_variables ) ; let edges = general_form . original_variables . iter ( ) . enumerate ( ) . filter_map ( | ( target , ( _ , variable ) ) | match variable { OriginalVariable :: Removed ( FunctionOfOthers { constant : _ , coefficients : els , } ) => Some ( ( els , target ) ) , _ => None , } ) . flat_map ( | ( els , target ) | { els . iter ( ) . map ( move | & ( j , _ ) | Element :: < ( ) , ( ) > :: Edge { source : j , target , weight : ( ) , } ) } ) ; ! matches ! ( Dag ( ) ( ) usize from_elements ( nodes chain ( edges ) ) Err ( WouldCycle ( ) ) ) } ; [ size , kept_increasing , no_cycles ] . iter ( ) . all ( | v | * v ) } ; let from_active_to_original = { let size = general_form . from_active_to_original . len ( ) == nr_active_variables ; let sorted_non_free = general_form . from_active_to_original [ .. ( nr_active_variables - nr_free_variables ) ] . is_sorted ( ) ; let sorted_free = general_form . from_active_to_original [ ( nr_active_variables - nr_free_variables ) .. ] . is_sorted ( ) ; let max = if nr_active_variables > 0 { general_form . from_active_to_original [ nr_active_variables - 1 ] < general_form . nr_original_variables ( ) } else { true } ; [ size , sorted_non_free , sorted_free , max , ] . iter ( ) . all ( | v | * v ) } ; [ b , constraints , rows , variables , columns , original_variables , from_active_to_original , ] . iter ( ) . all ( | v | * v ) }
Check whether the dimensions of the `GeneralForm` are consistent.
Check whether the dimensions of the ` GeneralForm ` are consistent .
general_form
&GeneralForm<F>
general_form
&GeneralForm<F>