1 /* 2 Copyright (C) 2010 Fredrik Johansson 3 4 This file is part of FLINT. 5 6 FLINT is free software: you can redistribute it and/or modify it under 7 the terms of the GNU Lesser General Public License (LGPL) as published 8 by the Free Software Foundation; either version 2.1 of the License, or 9 (at your option) any later version. See <http://www.gnu.org/licenses/>. 10 */ 11 12 #include "fmpz_mat.h" 13 14 slong fmpz_mat_rank(const fmpz_mat_t A)15fmpz_mat_rank(const fmpz_mat_t A) 16 { 17 fmpz_mat_t tmp; 18 fmpz_t den; 19 slong rank; 20 21 if (fmpz_mat_is_empty(A)) 22 return 0; 23 24 fmpz_mat_init_set(tmp, A); 25 fmpz_init(den); 26 27 if (FLINT_ABS(fmpz_mat_max_bits(tmp)) <= (FLINT_BITS - 4)/2) 28 rank = fmpz_mat_rank_small_inplace(tmp); 29 else if (FLINT_MIN(tmp->r, tmp->c) < 25) 30 rank = fmpz_mat_fflu(tmp, den, NULL, tmp, 0); 31 else 32 rank = fmpz_mat_rref(tmp, den, tmp); 33 34 fmpz_mat_clear(tmp); 35 fmpz_clear(den); 36 37 return rank; 38 } 39