elli-gf2 0.1.0

Machine-first GF(2) elimination library with exact multi-backend reduction and auto-selection.
Documentation
use std::env;
use std::process;

use elli_gf2::io::load_sparse_columns_file;
use elli_gf2::{Strategy, avg_col_weight, recommended_strategy, reduce_with_strategy};

fn usage() -> ! {
    eprintln!(
        "Usage:
  cargo run --release --bin load_cli -- --file path/to/matrix.txt --strategy auto

Format:
  Line 1: rows=<N>
  Remaining non-comment lines: one column per line
  Each line is a whitespace-separated list of row indices
  Empty lines count as empty columns
  Comment lines start with '#'

Strategies:
  sparse | packed | dense | auto

Example:
  cargo run --release --bin load_cli -- --file examples/sample_matrix.txt --strategy auto"
    );
    process::exit(1);
}

fn parse_strategy(s: &str) -> Strategy {
    match s {
        "sparse" => Strategy::SparseList,
        "packed" => Strategy::PackedCached,
        "dense" => Strategy::DenseMacro,
        "auto" => Strategy::Auto,
        _ => {
            eprintln!("unknown strategy: {}", s);
            usage();
        }
    }
}

fn main() {
    let mut file: Option<String> = None;
    let mut strategy = Strategy::Auto;

    let mut args = env::args().skip(1);
    while let Some(arg) = args.next() {
        match arg.as_str() {
            "--file" => file = Some(args.next().unwrap_or_else(|| usage())),
            "--strategy" => strategy = parse_strategy(&args.next().unwrap_or_else(|| usage())),
            _ => {
                eprintln!("unknown arg: {}", arg);
                usage();
            }
        }
    }

    let file = file.unwrap_or_else(|| usage());

    let loaded = match load_sparse_columns_file(&file) {
        Ok(v) => v,
        Err(e) => {
            eprintln!("load error: {}", e);
            process::exit(2);
        }
    };

    let picked = if strategy == Strategy::Auto {
        recommended_strategy(&loaded.cols)
    } else {
        strategy
    };

    let summary = reduce_with_strategy(loaded.rows, &loaded.cols, strategy);

    println!(
        "file,rows,cols,avg_col_weight,requested_strategy,effective_strategy,rank,pivot_count"
    );
    println!(
        "{},{},{},{:.3},{:?},{:?},{},{}",
        file,
        loaded.rows,
        loaded.cols.len(),
        avg_col_weight(&loaded.cols),
        strategy,
        picked,
        summary.rank,
        summary.pivots.len()
    );
}