ldpc_toolbox/cli/
systematic.rs

1//! Systematic CLI subcommand.
2//!
3//! This command can be used to convert an n x m parity check matrix into one
4//! that supports systematic encoding using the first m - n columns by permuting
5//! columns in such a way that the n x n submatrix formed by the last n columns
6//! is invertible.
7
8use crate::{cli::Run, sparse::SparseMatrix, systematic::parity_to_systematic};
9use clap::Parser;
10use std::error::Error;
11
12/// Systematic CLI arguments.
13#[derive(Debug, Parser)]
14#[command(about = "Converts a parity check matrix into systematic form")]
15pub struct Args {
16    /// alist file for the code
17    alist: String,
18}
19
20impl Run for Args {
21    fn run(&self) -> Result<(), Box<dyn Error>> {
22        let h = SparseMatrix::from_alist(&std::fs::read_to_string(&self.alist)?)?;
23        let h_sys = parity_to_systematic(&h)?;
24        println!("{}", h_sys.alist());
25        Ok(())
26    }
27}