diff --git a/src/spasm_certificate.c b/src/spasm_certificate.c index c5aa5ae..ae7f3a7 100644 --- a/src/spasm_certificate.c +++ b/src/spasm_certificate.c @@ -260,12 +260,12 @@ bool spasm_rank_certificate_load(FILE *f, struct spasm_rank_certificate *proof) proof->hash[i] = strtoul(byte, NULL, 16); } for (int k = 0; k < r; k++) - fscanf(f, "%d", &proof->i[k]); + if (1 != fscanf(f, "%d", &proof->i[k])) return 0; for (int k = 0; k < r; k++) - fscanf(f, "%d", &proof->i[k]); + if (1 != fscanf(f, "%d", &proof->i[k])) return 0; for (int k = 0; k < r; k++) - fscanf(f, "%d", &proof->x[k]); + if (1 != fscanf(f, "%d", &proof->x[k])) return 0; for (int k = 0; k < r; k++) - fscanf(f, "%d", &proof->y[k]); + if (1 != fscanf(f, "%d", &proof->y[k])) return 0; return 1; -} \ No newline at end of file +} diff --git a/tools/kernel.c b/tools/kernel.c index 6488f22..fab5454 100644 --- a/tools/kernel.c +++ b/tools/kernel.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "spasm.h" #include "common.h" @@ -10,6 +11,8 @@ /* Program documentation. */ char doc[] = "Compute a kernel basis of a sparse matrix"; +char qinv_filename[1000]; /* we should put this in cmdline_args. Here we use that it's 0-initialized so we both know if it was set and where to write */ + struct cmdline_args { /* input problem */ struct input_matrix input; @@ -27,6 +30,7 @@ struct argp_option options[] = { {0, 0, 0, 0, "Kernel options", 2 }, {"left", 'l', 0, 0, "Compute the left-kernel", 2}, {"output", 'o', "FILE", 0, "Write the kernel basis in FILE", 2 }, + {"qinv-file", 'q', "FILE", 0, "Save qinv", 2 }, { 0 } }; @@ -41,6 +45,9 @@ error_t parse_ker_opt(int key, char *arg, struct argp_state *state) case 'o': arguments->output_filename = arg; break; + case 'q': + strcpy(qinv_filename, arg); + break; case ARGP_KEY_INIT: arguments->left = 0; arguments->output_filename = NULL; @@ -82,10 +89,17 @@ int main(int argc, char **argv) struct spasm_lu *fact = spasm_echelonize(A, &args.opts); spasm_csr_free(A); + if (qinv_filename[0]) { /* save qinv */ + FILE *qinv_stream = fopen(qinv_filename,"w"); + for (int i = 0; i < fact->U->m; i++) + fprintf(qinv_stream,"%d\n",fact->qinv[i]); + fclose(qinv_stream); + } + /* kernel basis */ struct spasm_csr *K = spasm_kernel(fact); fprintf(stderr, "Kernel basis matrix is %d x %d with %" PRId64 " nz\n", K->n, K->m, spasm_nnz(K)); FILE *f = open_output(args.output_filename); spasm_csr_save(K, f); -} \ No newline at end of file +}