Compare commits
2 Commits
9cd4c8c1b1
...
05ed0ad350
Author | SHA1 | Date |
---|---|---|
Miguel M | 05ed0ad350 | |
Miguel M | 1ad3a4c813 |
|
@ -31,4 +31,9 @@ void PrintMatrixRow(matrix_t *matrix, size_t row);
|
|||
// row_len The number of entries in one row.
|
||||
matrix_t ParseMatrix(size_t row_len);
|
||||
|
||||
// Releases the memory associated to the given matrix.
|
||||
//
|
||||
// Usage after free results in undefined behaviour.
|
||||
void MatrixFree(matrix_t *matrix);
|
||||
|
||||
#endif // ACED_INCLUDES_MATRIX_H_
|
52
src/main.c
52
src/main.c
|
@ -52,8 +52,10 @@ int main(int argc, char *argv[]) {
|
|||
size_t row_count = matrix.len / matrix.row_len;
|
||||
|
||||
data_t *p_buf = malloc(a_out * b_out * a_in * b_in * sizeof(data_t));
|
||||
data_t *cg_buf =
|
||||
malloc((a_out - 1) * (b_out - 1) * a_in * b_in * sizeof(data_t));
|
||||
data_t *cg_buf = malloc((((a_out - 1) * (b_out - 1) * a_in * b_in +
|
||||
(a_out - 1) * a_in + (b_out - 1) * b_in) +
|
||||
1) *
|
||||
sizeof(data_t));
|
||||
_Bool *seen = calloc(row_count, sizeof(_Bool));
|
||||
|
||||
if (p_buf == NULL) {
|
||||
|
@ -69,8 +71,6 @@ int main(int argc, char *argv[]) {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// This is a lot of separate allocations, but this section isn't expected to
|
||||
// be hot.
|
||||
permutation_generator_t a_in_perm = PermutationNewGenerator(a_in);
|
||||
permutation_generator_t b_in_perm = PermutationNewGenerator(b_in);
|
||||
permutation_generator_t *a_out_perms =
|
||||
|
@ -129,19 +129,6 @@ int main(int argc, char *argv[]) {
|
|||
a_out_perms, b_out_perms);
|
||||
FromPToCg(a_out, b_out, a_in, b_in, cg_buf, p_buf);
|
||||
|
||||
// printf("--------------\n");
|
||||
// PrintPermutation(&a_in_perm);
|
||||
// PrintPermutation(&b_in_perm);
|
||||
// for (size_t i = 0; i < a_in; i++) {
|
||||
// printf("A=%zu: ", i);
|
||||
// PrintPermutation(a_out_perms + i);
|
||||
//}
|
||||
// for (size_t i = 0; i < b_in; i++) {
|
||||
// printf("B=%zu: ", i);
|
||||
// PrintPermutation(b_out_perms + i);
|
||||
//}
|
||||
// PrintCg(a_out, b_out, a_in, b_in, cg_buf);
|
||||
|
||||
_Bool equivalent = 1;
|
||||
for (size_t i = 0; i < row_len; i++) {
|
||||
if (lhs[i] != cg_buf[i]) {
|
||||
|
@ -151,11 +138,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
if (equivalent) {
|
||||
printf("%zu equivalent to %zu\n", rhs_i, lhs_i);
|
||||
seen[rhs_i] = 1;
|
||||
for (size_t i = 0; i < row_count; i++) {
|
||||
printf("%s,", seen[i] ? "true" : "false");
|
||||
}
|
||||
goto skip_permutations;
|
||||
}
|
||||
|
||||
|
@ -175,13 +158,32 @@ int main(int argc, char *argv[]) {
|
|||
} // For loop over rhs_i
|
||||
} // For loop over lhs_i
|
||||
|
||||
|
||||
|
||||
// Print every unique row
|
||||
for (size_t i = 0; i < row_count; i++) {
|
||||
printf("%s,", seen[i] ? "true" : "false");
|
||||
// if (!seen[i]) {
|
||||
// PrintMatrixRow(&matrix, i);
|
||||
//}
|
||||
if (!seen[i]) {
|
||||
PrintMatrixRow(&matrix, i);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef RELEASE
|
||||
// Free all the mmeory so the sanitizer is happy.
|
||||
free(seen);
|
||||
free(cg_buf);
|
||||
free(p_buf);
|
||||
PermutationFree(&a_in_perm);
|
||||
PermutationFree(&b_in_perm);
|
||||
for (size_t i = 0; i < a_in; i++) {
|
||||
PermutationFree(a_out_perms + i);
|
||||
}
|
||||
free(a_out_perms);
|
||||
for (size_t i = 0; i < b_in; i++) {
|
||||
PermutationFree(b_out_perms + i);
|
||||
}
|
||||
free(b_out_perms);
|
||||
MatrixFree(&matrix);
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -166,4 +166,8 @@ matrix_t ParseMatrix(size_t row_len) {
|
|||
compact_buffers(&matrix);
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
void MatrixFree(matrix_t *matrix) {
|
||||
free(matrix->head);
|
||||
}
|
Loading…
Reference in New Issue