Skip to content

Commit

Permalink
Remove traces, fix memory leaks, fix bug in d_mat_init, fix segfault.
Browse files Browse the repository at this point in the history
  • Loading branch information
wbhart committed Oct 20, 2016
1 parent c594fb7 commit 864489d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 60 deletions.
4 changes: 2 additions & 2 deletions d_mat/init.c
Expand Up @@ -18,8 +18,8 @@ d_mat_init(d_mat_t mat, slong rows, slong cols)
if (rows != 0 && cols != 0) /* Allocate space for r*c small entries */
{
slong i;
mat->entries = (double *) flint_malloc(rows * cols * sizeof(double));
mat->rows = (double **) flint_malloc(rows * sizeof(double *)); /* Initialise rows */
mat->entries = (double *) flint_calloc(rows*cols, sizeof(double));
mat->rows = (double **) flint_malloc(rows*sizeof(double *)); /* Initialise rows */

for (i = 0; i < rows; i++)
mat->rows[i] = mat->entries + i * cols;
Expand Down
1 change: 1 addition & 0 deletions fmpz_mat/next_col_van_hoeij.c
Expand Up @@ -114,6 +114,7 @@ int fmpz_mat_next_col_van_hoeij(fmpz_mat_t M, fmpz_t P,
fmpz_set(M->rows[j] + M->c - 1, y->rows[j - 1]);

/* cleanup */
fmpz_mat_clear(x);
fmpz_mat_clear(y);
fmpz_clear(P_trunc);

Expand Down
33 changes: 4 additions & 29 deletions fmpz_poly_factor/factor_van_hoeij.c
Expand Up @@ -48,13 +48,11 @@ void fmpz_poly_factor_van_hoeij(fmpz_poly_factor_t final_fac,
slong U_exp, a, next_col, num_coeffs, prev_num_coeffs, prev_exp, N, worst_exp;
ulong sqN;
fmpz_poly_t * v, * w;
fmpz_mat_t col, data, U;
fmpz_mat_t col, data;
slong * link;
int hensel_loops;
fmpz_lll_t fl;

printf("made it 1\n");

/* set to identity */
fmpz_mat_init(M, r, r);

Expand Down Expand Up @@ -114,12 +112,8 @@ void fmpz_poly_factor_van_hoeij(fmpz_poly_factor_t final_fac,
fmpz_mat_init(col, r, 1);
fmpz_lll_context_init_default(fl);

printf("made it 2\n");

while (!fmpz_poly_factor_van_hoeij_check_if_solved(M, final_fac, lifted_fac, f, P, exp, lc))
{
printf("made it 3\n");

if (hensel_loops < 3 && 3*r > N + 1)
num_coeffs = r > 200 ? 50 : 30;
else
Expand All @@ -128,8 +122,6 @@ void fmpz_poly_factor_van_hoeij(fmpz_poly_factor_t final_fac,
num_coeffs = FLINT_MIN(num_coeffs, (N + 1)/2);
prev_num_coeffs = 0;

printf("made it 4\n");

do {
fmpz_mat_init(data, r + 1, 2*num_coeffs);
_fmpz_poly_factor_CLD_mat(data, f, lifted_fac, P, num_coeffs);
Expand All @@ -152,52 +144,37 @@ void fmpz_poly_factor_van_hoeij(fmpz_poly_factor_t final_fac,

fmpz_mat_next_col_van_hoeij(M, P, col, worst_exp, U_exp);

fmpz_mat_init(U, M->r, M->r);
fmpz_lll_wrapper_with_removal_knapsack(M, U, B, fl);
fmpz_mat_clear(U);

printf("made it 5\n");

fmpz_lll_wrapper_with_removal_knapsack(M, NULL, B, fl);

if (fmpz_poly_factor_van_hoeij_check_if_solved(M, final_fac, lifted_fac, f, P, exp, lc))
{
fmpz_mat_clear(data);
goto cleanup;
}
printf("made it 6\n");
}

prev_num_coeffs = num_coeffs;
num_coeffs = FLINT_MIN(2*num_coeffs, (N + 1)/2);
fmpz_mat_clear(data);

printf("made it 7\n");
} while (num_coeffs != prev_num_coeffs);

printf("made it 8\n");

hensel_loops++;

fmpz_mat_clear(data);

printf("made it 9\n");

prev_exp = _fmpz_poly_hensel_continue_lift(lifted_fac, link, v, w, f, prev_exp, a, 2*a, fp);

a = 2*a;
fmpz_pow_ui(P, fp, a);

printf("made it 10\n");
}


cleanup:
printf("made it 11\n");

fmpz_clear(lc);
fmpz_clear(fp);
fmpz_clear(P);
fmpz_clear(B);
fmpz_mat_clear(col);
fmpz_mat_clear(M);
fmpz_clear(bound_sum);
fmpz_poly_factor_clear(lifted_fac);

Expand All @@ -209,6 +186,4 @@ void fmpz_poly_factor_van_hoeij(fmpz_poly_factor_t final_fac,
flint_free(v);
flint_free(w);
flint_free(link);

printf("made it 12\n");
}
3 changes: 0 additions & 3 deletions fmpz_poly_factor/test/t-factor_zassenhaus.c
Expand Up @@ -43,7 +43,6 @@ main(void)
for (j = 0; j < n; j++)
{
fmpz_poly_randtest(g, state, n_randint(state, 5) + 2, n_randint(state, 40));
printf("poly %ld: ", j); fmpz_poly_print(g); printf("\n");
fmpz_poly_mul(f, f, g);
}

Expand Down Expand Up @@ -71,8 +70,6 @@ main(void)
abort();
}

printf("factored poly %ld!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", i);

fmpz_clear(c);
fmpz_poly_clear(f);
fmpz_poly_clear(g);
Expand Down
27 changes: 1 addition & 26 deletions fmpz_poly_factor/van_hoeij_check_if_solved.c
Expand Up @@ -35,25 +35,18 @@ int fmpz_poly_factor_van_hoeij_check_if_solved(fmpz_mat_t M,
int num_facs, res = 0;
slong i, j, r;
slong * part;

printf("here -c\n");

r = lifted_fac->num;
printf("here -b\n");

part = (slong *) flint_calloc(r, sizeof(slong));

printf("here -a\n");

fmpz_poly_factor_init(trial_factors);
fmpz_poly_init(prod);
fmpz_poly_init(q);
fmpz_poly_init(f_copy);
fmpz_mat_window_init(U, M, 0, 0, M->r, r);
fmpz_init(temp_lc);

printf("here a\n");

if ((num_facs = fmpz_mat_col_partition(part, U, 1)) == 0 || num_facs > r)
goto cleanup;

Expand All @@ -72,8 +65,6 @@ int fmpz_poly_factor_van_hoeij_check_if_solved(fmpz_mat_t M,

fmpz_set(temp_lc, lc);

printf("here b\n");

for (i = 1; i <= num_facs; i++)
{
fmpz_poly_set_fmpz(prod, temp_lc);
Expand All @@ -82,30 +73,23 @@ int fmpz_poly_factor_van_hoeij_check_if_solved(fmpz_mat_t M,
{
if (part[j] == i)
{
fmpz_poly_print(lifted_fac->p + j); printf("\n");
fmpz_poly_mul(prod, prod, lifted_fac->p + j);
fmpz_poly_scalar_smod_fmpz(prod, prod, P);
}
}

printf("prod = "); fmpz_poly_print(prod); printf("\n");

fmpz_poly_content(temp_lc, prod);
fmpz_abs(temp_lc, temp_lc);
fmpz_poly_scalar_divexact_fmpz(prod, prod, temp_lc);

fmpz_poly_factor_insert(trial_factors, prod, 1);
}

printf("here c\n");

/* sort factors by length */

qsort(trial_factors->p, trial_factors->num,
sizeof(fmpz_poly_struct), _compare_poly_lengths);

printf("here d\n");

/* trial divide potential factors */

fmpz_poly_set(f_copy, f);
Expand All @@ -120,27 +104,20 @@ int fmpz_poly_factor_van_hoeij_check_if_solved(fmpz_mat_t M,
goto cleanup;
}

printf("here e i = %ld\n", i);

/* if we found all the factors, insert them */

if (num_facs == 1)
{
for (j = 0; j < i; j++)
{
printf("fac %ld: ", j); fmpz_poly_print(trial_factors->p + j); printf("\n");
fmpz_poly_factor_insert(final_fac, trial_factors->p + j, exp);
}

printf("fac %ld: ", j); fmpz_poly_print(f_copy); printf("\n");
fmpz_poly_factor_insert(final_fac, f_copy, exp);

res = 1; /* we factorised f */
}

printf("here f\n");

cleanup:

fmpz_clear(temp_lc);
fmpz_poly_clear(q);
fmpz_poly_clear(f_copy);
Expand All @@ -149,7 +126,5 @@ int fmpz_poly_factor_van_hoeij_check_if_solved(fmpz_mat_t M,
fmpz_mat_window_clear(U);
flint_free(part);

printf("here g\n");

return res;
}

0 comments on commit 864489d

Please sign in to comment.