Skip to content

Commit

Permalink
nmod_mat continued
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-johansson committed Jan 14, 2025
1 parent a8a16ae commit 1afaa38
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 72 deletions.
5 changes: 0 additions & 5 deletions src/nmod_mat/charpoly.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,10 @@ void nmod_mat_charpoly_danilevsky(nmod_poly_t p, const nmod_mat_t M)
}
} else
{
ulong * ptr;
ulong t;

nmod_mat_swap_rows(M2, NULL, n - i - k - 1, n - i - 1);

for (j = 1; j <= n - i + 1; j++)
{
FLINT_SWAP(ulong, A(j - 1, n - i - k - 1), A(j - 1, n - i - 1));
}
}

h = A(n - i, n - i - 1);
Expand Down
1 change: 0 additions & 1 deletion src/nmod_mat/det_howell.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ static inline int
_nmod_mat_pivot(nmod_mat_t A, slong start_row, slong col)
{
slong j;
nn_ptr u;

if (nmod_mat_entry(A, start_row, col) != 0)
return 1;
Expand Down
3 changes: 1 addition & 2 deletions src/nmod_mat/lu_classical.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
static inline int
nmod_mat_pivot(nmod_mat_t A, slong * P, slong start_row, slong col)
{
slong j, t;
nn_ptr u;
slong j;

if (nmod_mat_entry(A, start_row, col) != 0)
return 1;
Expand Down
9 changes: 3 additions & 6 deletions src/nmod_mat/lu_classical_delayed.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ nmod_mat_lu_classical_delayed_1(slong * P, nmod_mat_t A, int rank_check)
{
ulong d, e, f, *aa;
nmod_t mod;
slong i, j, nrows, ncols, rank, row, col, pivot_row, tmp_index;
slong i, j, nrows, ncols, rank, row, col, pivot_row;
slong stride = A->stride;
nn_ptr tnn_ptr;

nrows = A->r;
ncols = A->c;
Expand Down Expand Up @@ -121,9 +120,8 @@ nmod_mat_lu_classical_delayed_2(slong * P, nmod_mat_t A, int rank_check)
{
ulong d, e, f, *aa;
nmod_t mod;
slong i, j, nrows, ncols, rank, row, col, pivot_row, tmp_index;
slong i, j, nrows, ncols, rank, row, col, pivot_row;
slong stride = A->stride;
nn_ptr tnn_ptr;
nn_ptr b;
TMP_INIT;

Expand Down Expand Up @@ -290,9 +288,8 @@ nmod_mat_lu_classical_delayed_3(slong * P, nmod_mat_t A, int rank_check)
{
ulong d, e, f, *aa;
nmod_t mod;
slong i, j, nrows, ncols, rank, row, col, pivot_row, tmp_index;
slong i, j, nrows, ncols, rank, row, col, pivot_row;
slong stride = A->stride;
nn_ptr tnn_ptr;
nn_ptr b;
TMP_INIT;

Expand Down
29 changes: 16 additions & 13 deletions src/nmod_mat/lu_recursive.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (C) 2011 Fredrik Johansson
g
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
Expand All @@ -13,8 +13,7 @@
#include "nmod_mat.h"

static void
_apply_permutation_P(slong * AP, nmod_mat_t A, slong * P,
slong n, slong offset)
_apply_permutation_P(slong * AP, slong * P, slong n, slong offset)
{
if (n != 0)
{
Expand All @@ -31,19 +30,22 @@ _apply_permutation_P(slong * AP, nmod_mat_t A, slong * P,
}

static void
_apply_permutation_A(slong * AP, nmod_mat_t A, slong * P,
slong n, slong col_offset)
_apply_permutation_A(nmod_mat_t A, slong * P,
slong num_rows, slong row_offset, slong num_cols, slong col_offset)
{
if (n != 0)
if (num_rows != 0)
{
ulong * Atmp;
slong i;
slong c = A->c - col_offset;

Atmp = flint_malloc(sizeof(ulong) * n * c);
/* todo: reduce memory allocation */
Atmp = flint_malloc(sizeof(ulong) * num_rows * num_cols);

for (i = 0; i < num_rows; i++)
_nmod_vec_set(Atmp + i * num_cols, nmod_mat_entry_ptr(A, P[i] + row_offset, col_offset), num_cols);

for (i = 0; i < n; i++) _nmod_vec_set(Atmp + i * c, nmod_mat_entry_ptr(A, P[i], col_offset), c);
for (i = 0; i < n; i++) _nmod_vec_set(nmod_mat_entry_ptr(A, i, col_offset), Atmp + i * c, c);
for (i = 0; i < num_rows; i++)
_nmod_vec_set(nmod_mat_entry_ptr(A, i + row_offset, col_offset), Atmp + i * num_cols, num_cols);

flint_free(Atmp);
}
Expand Down Expand Up @@ -85,8 +87,8 @@ nmod_mat_lu_recursive(slong * P, nmod_mat_t A, int rank_check)

if (r1 != 0)
{
_apply_permutation_A(P, A, P1, m, 0);
_apply_permutation_P(P, A, P1, m, 0);
_apply_permutation_A(A, P1, m, 0, n - n1, n1);
_apply_permutation_P(P, P1, m, 0);
}

nmod_mat_window_init(A00, A, 0, 0, r1, r1);
Expand All @@ -108,7 +110,8 @@ nmod_mat_lu_recursive(slong * P, nmod_mat_t A, int rank_check)
}
else
{
_apply_permutation_P(P, A, P1, m - r1, r1);
_apply_permutation_A(A, P1, m - r1, r1, n1, 0);
_apply_permutation_P(P, P1, m - r1, r1);

/* Compress L */
if (r1 != n1)
Expand Down
2 changes: 1 addition & 1 deletion src/nmod_mat/mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ nmod_mat_mul(nmod_mat_t C, const nmod_mat_t A, const nmod_mat_t B)

if (flint_num_threads > 1)
nmod_mat_mul_classical_threaded(C, A, B);
else if (min_dim < cutoff || 1)
else if (min_dim < cutoff)
nmod_mat_mul_classical(C, A, B);
else
nmod_mat_mul_strassen(C, A, B);
Expand Down
Loading

0 comments on commit 1afaa38

Please sign in to comment.