--p-raw option

This commit is contained in:
Miguel M 2023-05-03 15:53:36 +01:00
parent ef438d8e5c
commit ed739fed17
3 changed files with 87 additions and 19 deletions

View File

@ -67,4 +67,8 @@ void PrintCg(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
void PrintP(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
const data_t* p);
// Print a P row as if it was in the input format.
void PrintPRaw(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
const data_t* p);
#endif

View File

@ -355,11 +355,31 @@ void PrintP(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
for (size_t b_out_i = 0; b_out_i < b_out; b_out_i++) {
for (size_t a_in_i = 0; a_in_i < a_in; a_in_i++) {
for (size_t b_in_i = 0; b_in_i < b_in; b_in_i++) {
size_t idx =
b_out_i + b_out * (b_in_i + b_in * (a_out_i + a_out * a_in_i));
size_t idx = PIndex(a_out, b_out, a_in, b_in, a_out_i, b_out_i,
a_in_i, b_in_i);
if (p[idx] != 0) {
printf("(%zu,%zu|%zu,%zu): %" PRImDATA ", ", a_out_i, b_out_i,
a_in_i, b_in_i, p[idx]);
printf("%s%" PRImDATA "p(%zu,%zu|%zu,%zu)", p[idx] < 0 ? "" : "+",
p[idx], a_out_i, b_out_i, a_in_i, b_in_i);
}
}
}
}
}
printf("\n");
}
void PrintPRaw(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
const data_t* p) {
const size_t len = a_out * b_out * a_in * b_in;
for (size_t a_out_i = 0; a_out_i < a_out; a_out_i++) {
for (size_t b_out_i = 0; b_out_i < b_out; b_out_i++) {
for (size_t a_in_i = 0; a_in_i < a_in; a_in_i++) {
for (size_t b_in_i = 0; b_in_i < b_in; b_in_i++) {
size_t idx = PIndex(a_out, b_out, a_in, b_in, a_out_i, b_out_i,
a_in_i, b_in_i);
printf("%" PRImDATA, p[idx]);
if (idx != len - 1) {
printf(", ");
}
}
}

View File

@ -33,11 +33,18 @@ static inline void ResetConditionalPermutations(
}
}
typedef enum {
kRowFmt,
kCgFmt,
kPFmt,
kPRawFmt,
} arg_format_t;
int main(int argc, char *argv[]) {
if (argc < 5) {
fprintf(stderr,
"Usage:\n ./main.exe <A outputs> <B outputs> <A inputs> <B "
"inputs> [--cg]");
"inputs> [--cg|--p|--p-raw]");
exit(EXIT_FAILURE);
}
@ -47,9 +54,15 @@ int main(int argc, char *argv[]) {
ReadArguments(argv[3], &a_in, "A inputs");
ReadArguments(argv[4], &b_in, "B inputs");
_Bool cg_format = 0;
if (argc > 5 && strcmp(argv[5], "--cg") == 0) {
cg_format = 1;
int cg_format = kRowFmt;
if (argc > 5) {
if (strcmp(argv[5], "--cg") == 0) {
cg_format = kCgFmt;
} else if (strcmp(argv[5], "--p") == 0) {
cg_format = kPFmt;
} else if (strcmp(argv[5], "--p-raw") == 0) {
cg_format = kPRawFmt;
}
}
size_t row_len = (a_out - 1) * (b_out - 1) * a_in * b_in +
@ -107,6 +120,9 @@ int main(int argc, char *argv[]) {
continue;
}
fprintf(stderr, "%zu/%zu \033[G", lhs_i, row_count - 1);
fflush(stderr);
data_t *lhs = matrix.head + lhs_i * matrix.row_len;
for (size_t rhs_i = lhs_i + 1; rhs_i < row_count; rhs_i++) {
@ -132,8 +148,8 @@ int main(int argc, char *argv[]) {
{
FromPToCg(a_out, b_out, a_in, b_in, cg_buf, p_buf);
_Bool equivalent = 1;
for (size_t i = 0; i < row_len; i++) {
if (lhs[i] != cg_buf[i]) {
for (size_t i = row_len; i > 0; i--) {
if (lhs[i - 1] != cg_buf[i - 1]) {
equivalent = 0;
break;
}
@ -149,14 +165,14 @@ int main(int argc, char *argv[]) {
// input labels is also the same, we can also check for equality
// under party swapping.
// I don't expect this conditional to be very penalizing because
// it's very perdictable.
// it's very predictable.
if (a_in == b_in && a_out == b_out) {
// Use the results in p_buf
PSwapParties(a_out, a_in, p_buf);
FromPToCg(a_out, b_out, a_in, b_in, cg_buf, p_buf);
_Bool equivalent = 1;
for (size_t i = 0; i < row_len; i++) {
if (lhs[i] != cg_buf[i]) {
for (size_t i = row_len; i > 0; i--) {
if (lhs[i - 1] != cg_buf[i - 1]) {
equivalent = 0;
break;
}
@ -184,19 +200,47 @@ int main(int argc, char *argv[]) {
} // For loop over rhs_i
} // For loop over lhs_i
if (cg_format == kPFmt) {
PermutationReset(&a_in_perm);
PermutationReset(&b_in_perm);
for (size_t i = 0; i < a_in; i++) {
PermutationReset(a_out_perms + i);
}
for (size_t i = 0; i < b_in; i++) {
PermutationReset(b_out_perms + i);
}
}
// Print every unique row
for (size_t i = 0; i < row_count; i++) {
if (!seen[i]) {
if (cg_format) {
printf("%zu: ", i);
PrintCg(a_out, b_out, a_in, b_in, matrix.head + i * matrix.row_len);
} else {
PrintMatrixRow(&matrix, i);
switch (cg_format) {
default:
case kRowFmt: {
PrintMatrixRow(&matrix, i);
} break;
case kCgFmt: {
printf("%zu: ", i);
PrintCg(a_out, b_out, a_in, b_in, matrix.head + i * matrix.row_len);
} break;
case kPFmt: {
printf("%zu: ", i);
FromCgToP(a_out, b_out, a_in, b_in, matrix.head + i * matrix.row_len,
p_buf, a_in_perm.permutation, b_in_perm.permutation,
a_out_perms, b_out_perms);
PrintP(a_out, b_out, a_in, b_in, p_buf);
} break;
case kPRawFmt: {
FromCgToP(a_out, b_out, a_in, b_in, matrix.head + i * matrix.row_len,
p_buf, a_in_perm.permutation, b_in_perm.permutation,
a_out_perms, b_out_perms);
PrintPRaw(a_out, b_out, a_in, b_in, p_buf);
} break;
}
}
}
// Free all the mmeory so the sanitizer is happy.
// Free all the memory so the sanitizer is happy.
free(seen);
free(cg_buf);
free(p_buf);