25 Commits

Author SHA1 Message Date
Sergey B Kirpichev fb69943530 Use explicit kwargs in public API, where possible
Following functions kept:
```pycon
>>> import inspect
... with_args = []
... with_kwargs = []
... for n in dir(mpmath):
...     m = getattr(mpmath, n)
...     try:
...         s = inspect.signature(m)
...     except:
...         continue
...     if any(_.kind == inspect._ParameterKind.VAR_POSITIONAL for _ in s.parameters.values()):
...         for name in s.parameters:
...             if s.parameters[name].kind == inspect._ParameterKind.VAR_POSITIONAL and name == 'args':
...                 with_args.append(n)
...                 break
...     if any(_.kind == inspect._ParameterKind.VAR_KEYWORD for _ in s.parameters.values()):
...         with_kwargs.append(n)
... print(with_args)
... print(with_kwargs)
...
['arange', 'ellipe', 'ellippi', 'linspace', 'matrix', 'ones', 'timing', 'zeros']
['multiplicity', 'timing']
```

We need support for multiple signatures in the first case.  In the
second - it's impossible to implement these functions without kwargs.

Closes #1056
2026-08-04 06:40:53 +03:00
Sergey B Kirpichev 0e1bd9496d Restrict libmp exports to public API
This is following namespace:
```
{'BACKEND', 'ComplexResult', 'MPZ', 'MPZ_ONE', 'NoConvergence',
 'catalan_fixed', 'dps_to_prec', 'euler_fixed', 'fhalf', 'finf',
 'fnan', 'fninf', 'fnone', 'fone', 'from_float', 'from_int', 'from_man_exp',
 'from_rational', 'from_str', 'fzero', 'giant_steps', 'ifac', 'ifib',
 'int_types', 'isqrt', 'mpc_abs', 'mpc_exp', 'mpc_pow', 'mpc_pow_int',
 'mpc_pow_mpf', 'mpc_sqrt', 'mpf_abs', 'mpf_add', 'mpf_atan', 'mpf_atan2',
 'mpf_bernoulli', 'mpf_ceil', 'mpf_cmp', 'mpf_cos', 'mpf_cosh_sinh', 'mpf_div',
 'mpf_e', 'mpf_eq', 'mpf_exp', 'mpf_floor', 'mpf_ge', 'mpf_gt', 'mpf_le',
 'mpf_log', 'mpf_lt', 'mpf_mod', 'mpf_mul', 'mpf_neg', 'mpf_pi', 'mpf_pow',
 'mpf_pow_int', 'mpf_shift', 'mpf_sign', 'mpf_sin', 'mpf_sqrt', 'mpf_sub',
 'mpf_tan', 'normalize', 'phi_fixed', 'prec_to_dps', 'repr_dps',
 'round_nearest', 'sqrtrem', 'to_float', 'to_int', 'to_man_exp', 'to_rational',
 'to_str'}
```

Closes #704
2026-05-25 08:31:19 +03:00
Sergey B Kirpichev b9ac31f5cd Better introspection support for decorated functions
Closes #899
2025-01-19 07:33:28 +03:00
Sergey B Kirpichev a93b19dffe Amend d3c6428 2024-09-23 07:32:40 +03:00
Sergey B Kirpichev 816668dcb2 Support pickling for mpi
Closes #264
2024-02-29 07:46:43 +03:00
Sergey B Kirpichev 57a9e0d49d Fix few more py2 remnants (__truediv__ vs __div__) 2024-02-26 08:57:27 +03:00
Sergey B Kirpichev 0efdfeb7cd Drop ctx._mpq 2023-05-19 07:03:11 +03:00
Sergey B Kirpichev 721e2571eb Drop private mpq class, use Rational's provided by backend 2023-05-19 07:03:11 +03:00
Sergey B Kirpichev 3414c6ec51 Fix flake8 F401 in ctx_*.py (not for imports for mpf_binary_op) 2023-05-18 08:29:53 +03:00
Fangchen Li dfc289289d Drop py2 support (#629)
* remove xrange compat shim
* remove str compat shim
* remove exec compat shim
* remove object from class defination
* remove misc workarounds for python versions <3.5
* remove __future__ imports
* update readme
* Update setup.cfg

Closes #594

Co-authored-by: Fredrik Johansson <fredrik.johansson@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Colin B. Macdonald <cbm@m.fsf.org>
2023-03-30 04:50:18 +03:00
Maximilian Gaukler c2d2bf33ab Fix scalar-matrix-multiplication for mpi * iv.matrix 2020-03-24 12:23:07 +01:00
Fredrik Johansson 88d01b7bd5 Revert "Fixed scalar-matrix multiplication in iv module" 2019-02-03 11:46:56 +01:00
Fredrik Johansson 41426f8b9f Merge pull request #426 from warnerjon12/floatComplexCastExc266
Implemented float and complex conversions for ivmpf
2019-02-03 02:45:56 +01:00
Jonathan Warner bce0e9afef Implemented float and complex conversions for ivmpf
Response to issue fredrik-johansson#266
2019-01-09 10:40:20 -07:00
Jonathan Warner 5c4cccd436 Fixed issue with scalar-matrix multiplication
Response to issue fredrik-johansson#280
2019-01-09 09:43:24 -07:00
Stefan Krastanov e688746a68 Catch ImportError of numbers ABC on 2.5 2012-11-23 16:07:05 +01:00
Stefan Krastanov 7585100bc0 Add initial ABC support.
We do not use subclassing in order to keep it as simple as possible. This
precludes the use of `@abstractmethod`, however it keeps the
`__init__`/`__new__` unchanged.

Not using subclassing/`@abstractmethod` means that checks whether the inferface
conforms to the requirements of the ABC are not done. Given the simplicity of
the interface in our case, this is the prefered approach. Conformity of the
interface is checked durring developpement.

Examples
========

`issubclass` works as well.

```
In [12]: import numbers

In [13]: import mpmath

In [14]: isinstance(mpmath.mpf(0.23), numbers.Complex)
Out[14]: True

In [15]: isinstance(mpmath.mpf(0.23), numbers.Real)
Out[15]: True

In [16]: isinstance(mpmath.mpf(0.23), numbers.Rational)
Out[16]: False
```

```
In [18]: isinstance(mpmath.mpc(0.23), numbers.Complex)
Out[18]: True

In [19]: isinstance(mpmath.mpc(0.23), numbers.Real)
Out[19]: False
```

```
In [20]: isinstance(mpmath.mpi(0.23), numbers.Complex)
Out[20]: True

In [21]: isinstance(mpmath.mpi(0.23), numbers.Real)
Out[21]: True

In [22]: isinstance(mpmath.mpi(0.23), numbers.Rational)
Out[22]: False
```

```
In [23]: isinstance(mpmath.mpi(0.23+1j), numbers.Complex)
Out[23]: True

In [24]: isinstance(mpmath.mpi(0.23+1j), numbers.Real)
Out[24]: False
```
2012-11-23 15:27:36 +01:00
Fredrik Johansson 61b9a7a68d give intervals a hash function 2012-03-29 17:50:33 +02:00
Fredrik Johansson 296892154f fix remaining py3 compatibility issues 2011-01-08 23:52:03 +00:00
Fredrik Johansson 3bb0f4c5cd some more py3 compatibility fixes 2011-01-08 23:11:04 +00:00
Fredrik Johansson b8651c00f1 switch to using explicit relative imports (Python 2.4 compatibility henceforth abandoned) 2011-01-08 22:15:29 +00:00
Fredrik Johansson 27eab13de6 convert line endings in trunk to unix format; rebuild docs 2010-07-28 20:09:06 +00:00
Fredrik Johansson 16ae718cc7 preliminary gamma/loggamma/rgamma/factorial for real and complex intervals (needs more work and tests) 2010-06-09 15:30:29 +00:00
Fredrik Johansson 9b4ad11e7b add complex interval cos/sin; compute z^n for complex interval z using binary exponentiation 2010-06-02 14:51:12 +00:00
Fredrik Johansson df06e3b642 forgot to include the main file 2010-04-14 15:19:05 +00:00