Skip to content

Commit

Permalink
Merge pull request #1976 from albinahlback/reduce_fmpz_h
Browse files Browse the repository at this point in the history
Remove some `gmp.h` inclusions and cleanup some headers
  • Loading branch information
albinahlback committed May 17, 2024
2 parents 7528e42 + 3cdc0eb commit bc6ba64
Show file tree
Hide file tree
Showing 503 changed files with 747 additions and 1,134 deletions.
15 changes: 15 additions & 0 deletions doc/source/fmpq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ Conversion
Sets ``a``, ``b`` to the numerator and denominator of ``c``
respectively.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void fmpq_set_si(fmpq_t res, slong p, ulong q)

Sets ``res`` to the canonical form of the fraction ``p / q``.
Expand All @@ -206,6 +209,9 @@ Conversion
Sets the value of ``dest`` to that of the ``mpq_t`` variable
``src``.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: int fmpq_set_str(fmpq_t dest, const char * s, int base)

Sets the value of ``dest`` to the value represented in the string
Expand All @@ -222,6 +228,9 @@ Conversion

Sets the value of ``dest``

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: int fmpq_get_mpfr(mpfr_t dest, const fmpq_t src, mpfr_rnd_t rnd)

Sets the MPFR variable ``dest`` to the value of ``src``,
Expand Down Expand Up @@ -268,10 +277,16 @@ Conversion
This provides a convenient function for user code, only
requiring to work with the types ``fmpq_t`` and ``mpq_t``.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void flint_mpq_clear_readonly(mpq_t z)

Clears the readonly ``mpq_t`` `z`.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void fmpq_init_set_readonly(fmpq_t f, const mpq_t z)

Sets the uninitialised ``fmpq_t`` `f` to a readonly
Expand Down
59 changes: 56 additions & 3 deletions doc/source/fmpz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,35 @@ Types, macros and constants
A macro which returns `1` if `f` represents an ``mpz_t``, otherwise `0` is
returned.

.. macro:: MPZ_MIN_ALLOC

A constant determining the minimum number of limbs the *fmpz* memory manager
will allocate for each *mpz*. This constant is currently 2.

.. function:: mpz_ptr _fmpz_new_mpz(void)

Initialises a new ``mpz_t`` and returns a pointer to it. This is only used
internally.
Returns a pointer to an initialised *mpz* with at least
:macro:`MPZ_MIN_ALLOC` limbs allocated. This is only used internally.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void _fmpz_clear_mpz(fmpz f)

Clears the ``mpz_t`` "pointed to" by the ``fmpz`` `f`. This is only used
Clears the *mpz* "pointed to" by the *fmpz* *f*. This is only used
internally.

.. note::

As of FLINT 3.2.0, it is required that the *mpz* pointed to by *f* has at
least :macro:`MPZ_MIN_ALLOC` limbs allocated when :func:`_fmpz_clear_mpz` is
called. Note that GMP functions never reduce the number of allocated limbs,
apart from a bug in ``mpz_remove`` which as of GMP 6.3.0 may reduce the
number of allocated limbs in the output *mpz*. Hence, as long as
``mpz_realloc`` never is called with a second argument less than
:macro:`MPZ_MIN_ALLOC` on an *mpz* received from :func:`_fmpz_new_mpz`, any
other usage should be fine.

.. function:: void _fmpz_cleanup_mpz_content()

This function does nothing in the reentrant version of ``fmpz``.
Expand All @@ -153,6 +172,9 @@ Types, macros and constants
If `f` doesn't represent an ``mpz_t``, initialise one and associate it to
`f`.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: mpz_ptr _fmpz_promote_val(fmpz_t f)

If `f` doesn't represent an ``mpz_t``, initialise one and associate it to
Expand All @@ -163,6 +185,9 @@ Types, macros and constants
inconsistent state with respect to the other Flint ``fmpz`` functions such as
``fmpz_is_zero``, etc.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void _fmpz_demote(fmpz_t f)

If `f` represents an ``mpz_t`` clear it and make `f` just represent an
Expand Down Expand Up @@ -303,10 +328,16 @@ Conversion
Sets `f` to the ``mpf_t`` `x`, rounding down towards zero if
the value of `x` is fractional.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void fmpz_get_mpf(mpf_t x, const fmpz_t f)

Sets the value of the ``mpf_t`` `x` to the value of `f`.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void fmpz_get_mpfr(mpfr_t x, const fmpz_t f, mpfr_rnd_t rnd)

Sets the value of `x` from `f`, rounded toward the given
Expand All @@ -325,6 +356,9 @@ Conversion

Sets the ``mpz_t`` `x` to the same value as `f`.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: int fmpz_get_mpn(nn_ptr * n, fmpz_t n_in)

Sets the ``nn_ptr`` `n` to the same value as `n_{in}`. Returned
Expand Down Expand Up @@ -412,6 +446,13 @@ Conversion
words of the result in ``out[0], ..., out[n-1]``. This will give a signed
two's complement representation of `in` (assuming `in` doesn't overflow the array).

.. function:: void fmpz_set_mpn_large(fmpz_t z, nn_srcptr src, slong n, int negative)

Sets *z* to the integer represented by the *n* limbs in the array *src*,
or minus this value if *negative* is 1.
Requires `n \ge 2` and that the top limb of *src* is nonzero.
Note that *fmpz_set_ui*, *fmpz_neg_ui* can be used for single-limb integers.

.. function:: void fmpz_get_signed_uiui(ulong * hi, ulong * lo, const fmpz_t in)

Retrieves the value of `in` modulo `2^{2 * FLINT\_BITS}` and puts the high
Expand All @@ -421,6 +462,9 @@ Conversion

Sets `f` to the given ``mpz_t`` value.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: int fmpz_set_str(fmpz_t f, const char * str, int b)

Sets `f` to the value given in the null-terminated string ``str``,
Expand Down Expand Up @@ -471,10 +515,16 @@ Conversion
_fmpz_demote_val(f);
}

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void flint_mpz_clear_readonly(mpz_t z)

Clears the readonly ``mpz_t`` `z`.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void fmpz_init_set_readonly(fmpz_t f, const mpz_t z)

Sets the uninitialised ``fmpz_t`` `f` to a readonly
Expand All @@ -498,6 +548,9 @@ Conversion
fmpz_clear_readonly(f);
}

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void fmpz_clear_readonly(fmpz_t f)

Clears the readonly ``fmpz_t`` `f`.
Expand Down
7 changes: 0 additions & 7 deletions doc/source/fmpz_extras.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ so these methods should not be used gratuitously.
Low-level conversions
-------------------------------------------------------------------------------

.. function:: void fmpz_set_mpn_large(fmpz_t z, nn_srcptr src, slong n, int negative)

Sets *z* to the integer represented by the *n* limbs in the array *src*,
or minus this value if *negative* is 1.
Requires `n \ge 2` and that the top limb of *src* is nonzero.
Note that *fmpz_set_ui*, *fmpz_neg_ui* can be used for single-limb integers.

.. macro:: FMPZ_GET_MPN_READONLY(zsign, zn, zptr, ztmp, zv)

Given an *fmpz_t* *zv*, this macro sets *zptr* to a pointer to the limbs of *zv*,
Expand Down
12 changes: 12 additions & 0 deletions doc/source/padic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,16 @@ reduced to the precision of ``rop``.

Sets the `p`-adic number ``rop`` to the GMP integer ``op``.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void padic_set_mpq(padic_t rop, const mpq_t op, const padic_ctx_t ctx)

Sets ``rop`` to the GMP rational ``op``.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void padic_get_fmpz(fmpz_t rop, const padic_t op, const padic_ctx_t ctx)

Sets the integer ``rop`` to the exact `p`-adic integer ``op``.
Expand All @@ -224,10 +230,16 @@ reduced to the precision of ``rop``.

If ``op`` is not a `p`-adic integer, raises an ``abort`` signal.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void padic_get_mpq(mpq_t rop, const padic_t op, const padic_ctx_t ctx)

Sets the GMP rational ``rop`` to the value of ``op``.

**Note:** Requires that ``gmp.h`` has been included before any FLINT
header is included.

.. function:: void padic_swap(padic_t op1, padic_t op2)

Swaps the two `p`-adic numbers ``op1`` and ``op2``.
Expand Down
1 change: 1 addition & 0 deletions src/NTL-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef FLINT_NTL_INT_H
#define FLINT_NTL_INT_H

#include <gmp.h>
#include <NTL/ZZX.h>
#include <NTL/ZZ_pXFactoring.h>
#include <NTL/ZZ_pEX.h>
Expand Down
1 change: 1 addition & 0 deletions src/arf.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define ARF_INLINE static inline
#endif

#include <gmp.h>
#include "mag.h"
#include "arf_types.h"

Expand Down
13 changes: 4 additions & 9 deletions src/arf/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,12 @@ arf_get_fmpz_2exp(fmpz_t man, fmpz_t exp, const arf_t x)
else
{
mpz_ptr z = _fmpz_promote(man);

if (z->_mp_alloc < xn)
mpz_realloc(z, xn);
mp_ptr zptr = FLINT_MPZ_REALLOC(z, xn);

if (shift == 0)
flint_mpn_copyi(z->_mp_d, xptr, xn);
flint_mpn_copyi(zptr, xptr, xn);
else
mpn_rshift(z->_mp_d, xptr, xn, shift);
mpn_rshift(zptr, xptr, xn, shift);

/* top limb cannot be zero */
z->_mp_size = ARF_SGNBIT(x) ? -xn : xn;
Expand Down Expand Up @@ -321,10 +319,7 @@ arf_get_fmpz(fmpz_t z, const arf_t x, arf_rnd_t rnd)
zn = (exp + (rnd != ARF_RND_DOWN) + FLINT_BITS - 1) / FLINT_BITS;

zz = _fmpz_promote(z);
if (zz->_mp_alloc < zn)
mpz_realloc2(zz, zn * FLINT_BITS);

zp = zz->_mp_d;
zp = FLINT_MPZ_REALLOC(zz, zn);

if (rnd == ARF_RND_DOWN)
{
Expand Down
1 change: 1 addition & 0 deletions src/arith/bell_number_multi_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include <gmp.h>
#include "nmod.h"
#include "fmpz.h"
#include "arith.h"
Expand Down
2 changes: 1 addition & 1 deletion src/arith/bell_number_size.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include <math.h>
#include "flint.h"
#include "arith.h"

double
arith_bell_number_size(ulong n)
Expand Down
2 changes: 2 additions & 0 deletions src/arith/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include <gmp.h>

/* Include functions *********************************************************/

#include "t-bell_number.c"
Expand Down
12 changes: 1 addition & 11 deletions src/calcium.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,7 @@ const char * calcium_func_name(calcium_func_code func);

/* Flint extras */

/* slower alternative: fmpz_fdiv_ui(x 1000000007) */
CALCIUM_INLINE ulong calcium_fmpz_hash(const fmpz_t x)
{
if (!COEFF_IS_MPZ(*x))
return *x;
else
{
mpz_ptr z = COEFF_TO_PTR(*x);
return (z->_mp_size > 0) ? z->_mp_d[0] : -z->_mp_d[0];
}
}
ulong calcium_fmpz_hash(const fmpz_t x);

#ifdef __cplusplus
}
Expand Down
22 changes: 13 additions & 9 deletions src/fmpq/get_d.c → src/calcium/fmpz_hash.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2019 Daniel Schultz
Copyright (C) 2020 Fredrik Johansson
This file is part of FLINT.
Expand All @@ -9,14 +9,18 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "fmpq.h"
#include <gmp.h>
#include "calcium.h"

double fmpq_get_d(const fmpq_t a)
/* slower alternative: fmpz_fdiv_ui(x 1000000007) */

ulong calcium_fmpz_hash(const fmpz_t x)
{
double d;
mpq_t z;
flint_mpq_init_set_readonly(z, a);
d = mpq_get_d(z);
flint_mpq_clear_readonly(z);
return d;
if (!COEFF_IS_MPZ(*x))
return *x;
else
{
mpz_ptr z = COEFF_TO_PTR(*x);
return (z->_mp_size > 0) ? z->_mp_d[0] : -z->_mp_d[0];
}
}
1 change: 0 additions & 1 deletion src/d_mat/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@

#define D_MAT_INLINES_C

#include "flint.h"
#include "d_mat.h"
1 change: 0 additions & 1 deletion src/d_vec/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@

#define D_VEC_INLINES_C

#include "flint.h"
#include "d_vec.h"
1 change: 0 additions & 1 deletion src/double_extras/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@

#define DOUBLE_EXTRAS_INLINES_C

#include "flint.h"
#include "double_extras.h"
Loading

0 comments on commit bc6ba64

Please sign in to comment.