MAINT: rename functions and clarify docs

This commit is contained in:
alex 2016-02-23 17:07:59 -05:00
parent 260c530197
commit 25e3594704
6 changed files with 118 additions and 40 deletions

View file

@ -301,22 +301,21 @@ void arb_mat_trace(arb_t trace, const arb_mat_t mat, slong prec);
/* Sparsity structure */
void _arb_mat_entrywise_nonzero_round_up(fmpz_mat_t A, const arb_mat_t src);
void arb_mat_entrywise_is_zero(fmpz_mat_t dest, const arb_mat_t src);
ARB_MAT_INLINE void
arb_mat_adjacency(fmpz_mat_t A, const arb_mat_t src)
{
_arb_mat_entrywise_nonzero_round_up(A, src);
}
void arb_mat_entrywise_not_is_zero(fmpz_mat_t dest, const arb_mat_t src);
slong _arb_mat_count_nonzero_round_up(const arb_mat_t src);
slong arb_mat_count_is_zero(const arb_mat_t mat);
ARB_MAT_INLINE slong
arb_mat_count_nonzero(const arb_mat_t src)
arb_mat_count_not_is_zero(const arb_mat_t mat)
{
return _arb_mat_count_nonzero_round_up(src);
slong size;
size = arb_mat_nrows(mat) * arb_mat_ncols(mat);
return size - arb_mat_count_is_zero(mat);
}
#ifdef __cplusplus
}
#endif

45
arb_mat/count_is_zero.c Normal file
View file

@ -0,0 +1,45 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2016 Arb authors
******************************************************************************/
#include "arb_mat.h"
slong
arb_mat_count_is_zero(const arb_mat_t mat)
{
slong nz;
slong i, j;
nz = 0;
for (i = 0; i < arb_mat_nrows(mat); i++)
{
for (j = 0; j < arb_mat_ncols(mat); j++)
{
if (arb_is_zero(arb_mat_entry(mat, i, j)))
{
nz++;
}
}
}
return nz;
}

View file

@ -0,0 +1,43 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2016 Arb authors
******************************************************************************/
#include "arb_mat.h"
void
_arb_mat_entrywise_is_zero(fmpz_mat_t dest, const arb_mat_t src)
{
slong i, j;
fmpz_mat_zero(dest);
for (i = 0; i < arb_mat_nrows(src); i++)
{
for (j = 0; j < arb_mat_ncols(src); j++)
{
if (arb_is_zero(arb_mat_entry(src, i, j)))
{
fmpz_one(fmpz_mat_entry(dest, i, j));
}
}
}
}

View file

@ -26,37 +26,18 @@
#include "arb_mat.h"
void
_arb_mat_entrywise_nonzero_round_up(fmpz_mat_t A, const arb_mat_t src)
arb_mat_entrywise_not_is_zero(fmpz_mat_t dest, const arb_mat_t src)
{
slong i, j;
fmpz_mat_zero(A);
fmpz_mat_zero(dest);
for (i = 0; i < arb_mat_nrows(src); i++)
{
for (j = 0; j < arb_mat_ncols(src); j++)
{
if (!arb_is_zero(arb_mat_entry(src, i, j)))
{
fmpz_one(fmpz_mat_entry(A, i, j));
fmpz_one(fmpz_mat_entry(dest, i, j));
}
}
}
}
slong
_arb_mat_count_nonzero_round_up(const arb_mat_t src)
{
slong nnz;
slong i, j;
nnz = 0;
for (i = 0; i < arb_mat_nrows(src); i++)
{
for (j = 0; j < arb_mat_ncols(src); j++)
{
if (!arb_is_zero(arb_mat_entry(src, i, j)))
{
nnz++;
}
}
}
return nnz;
}

View file

@ -270,11 +270,11 @@ arb_mat_exp(arb_mat_t B, const arb_mat_t A, slong prec)
fmpz_mat_t S;
int using_structure;
using_structure = arb_mat_count_nonzero(A) < dim * dim;
using_structure = arb_mat_count_is_zero(A) > 0;
if (using_structure)
{
fmpz_mat_init(S, dim, dim);
arb_mat_adjacency(S, A);
arb_mat_entrywise_not_is_zero(S, A);
_fmpz_mat_transitive_closure(S, S);
}

View file

@ -328,15 +328,25 @@ Special functions
Sparsity structure
-------------------------------------------------------------------------------
.. function:: void _arb_mat_entrywise_nonzero_round_up(fmpz_mat_t A, const arb_mat_t src)
.. function:: void arb_mat_entrywise_is_zero(fmpz_mat_t dest, const arb_mat_t src)
.. function:: void arb_mat_adjacency(fmpz_mat_t A, const arb_mat_t src)
Sets each entry of *dest* to indicate whether the corresponding
entry of *src* is certainly zero.
If the entry of *src* at row `i` and column `j` is zero according to
:func:`arb_is_zero` then the entry of *dest* at that row and column
is set to one, otherwise that entry of *dest* is set to zero.
Each entry of *A* is set to 0 or 1 depending on whether or not
the corresponding entry of *src* is zero.
.. function:: void arb_mat_entrywise_not_is_zero(fmpz_mat_t dest, const arb_mat_t src)
.. function:: slong _arb_mat_count_nonzero_round_up(const arb_mat_t src)
Sets each entry of *dest* to indicate whether the corresponding
entry of *src* is not certainly zero.
This the complement of :func:`arb_mat_entrywise_is_zero`.
.. function:: slong arb_mat_count_nonzero(const arb_mat_t src)
.. function:: slong arb_mat_count_is_zero(const arb_mat_t mat)
Returns the number of nonzero entries of the matrix.
Returns the number of entries of *mat* that are certainly zero
according to :func:`arb_is_zero`.
.. function:: slong arb_mat_count_not_is_zero(const arb_mat_t mat)
Returns the number of entries of *mat* that are not certainly zero.