Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/spasm_certificate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
16 changes: 15 additions & 1 deletion tools/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
#include <assert.h>
#include <getopt.h>
#include <err.h>
#include <string.h>

#include "spasm.h"
#include "common.h"

/* 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;
Expand All @@ -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 }
};

Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}