Skip to content

Commit 7854942

Browse files
committed
Drop Python 3.9 and Numpy 1.23 support.
Following release of Numpy 2.1.0.
1 parent ec82df2 commit 7854942

13 files changed

+46
-93
lines changed

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ python:
88
build:
99
os: ubuntu-22.04
1010
tools:
11-
python: "3.9"
11+
python: "3.10"
1212
sphinx:
1313
configuration: docs/conf.py

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
dist: jammy
22
language: python
33
jobs:
4-
- python: 3.9
5-
env:
6-
- MPYC_NOPRSS=1
7-
install: pip install numpy==1.23.* gmpy2 uvloop
8-
- python: pypy3.9-7.3.9
94
- python: 3.10
105
env:
116
- MPYC_NONUMPY=1
127
- MPYC_NOGMPY=1
138
- MPYC_NOUVLOOP=1
9+
- python: pypy3.10-7.3.16
1410
- python: 3.11
11+
env:
12+
- MPYC_NOPRSS=1
1513
install: pip install numpy==1.24.* gmpy2
1614
- python: 3.12
1715
install: pip install numpy uvloop

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The [MPyC homepage](https://www.win.tue.nl/~berry/mpyc/) has some more info and
2525

2626
## Installation
2727

28-
Pure Python, no dependencies. Python 3.9+ (following [SPEC 0 -- Minimum Supported Dependencies](https://scientific-python.org/specs/spec-0000/)).
28+
Pure Python, no dependencies. Python 3.10+ (following [SPEC 0 -- Minimum Supported Dependencies](https://scientific-python.org/specs/spec-0000/)).
2929

3030
Run `pip install .` in the root directory (containing file `pyproject.toml`).\
3131
Or, run `pip install -e .`, if you want to edit the MPyC source files.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#
1515
import os
1616
import sys
17+
from mpyc.__init__ import __version__
1718
# sys.path.insert(0, os.path.abspath('.'))
1819
sys.path.insert(0, os.path.abspath('..'))
1920

@@ -23,7 +24,6 @@
2324
copyright = '2018 - 2024, Berry Schoenmakers'
2425
author = 'Berry Schoenmakers'
2526

26-
from mpyc.__init__ import __version__
2727
# The short X.Y version
2828
version = __version__
2929
# The full version, including alpha/beta/rc tags

docs/install.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MPyC installation
22
=================
33

4-
MPyC runs on Windows/Mac/Linux platforms supporting Python 3.9+.
4+
MPyC runs on Windows/Mac/Linux platforms supporting Python 3.10+.
55
There are no hard dependencies on other Python packages.
66

77
If you first want to try MPyC online, click
@@ -59,7 +59,7 @@ See the ``README.md`` files in these directories for more information.
5959
Deployment
6060
----------
6161

62-
Currently Python 3.9+ is the only requirement.
62+
Currently Python 3.10+ is the only requirement.
6363

6464
Written in pure Python, without any dependencies, MPyC should run on common
6565
Windows/Mac/Linux platforms, including the 32-bit Raspberry Pi, if you like.

mpyc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
and statistics (securely mimicking Python’s statistics module).
3030
"""
3131

32-
__version__ = '0.10.2'
32+
__version__ = '0.10.3'
3333

3434
import os
3535
import sys

mpyc/fingroups.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,14 +1056,15 @@ def _EllipticCurve(curvename, coordinates):
10561056
raise ValueError('invalid curvename')
10571057

10581058
name = f'E({gf.__name__}){curvename}{coordinates}'
1059-
if coordinates == 'extended':
1060-
base = EdwardsExtended
1061-
elif coordinates == 'affine':
1062-
base = EdwardsAffine
1063-
elif coordinates == 'projective':
1064-
base = EdwardsProjective
1065-
else:
1066-
raise ValueError('invalid coordinates')
1059+
match coordinates:
1060+
case 'extended':
1061+
base = EdwardsExtended
1062+
case 'affine':
1063+
base = EdwardsAffine
1064+
case 'projective':
1065+
base = EdwardsProjective
1066+
case _:
1067+
raise ValueError('invalid coordinates')
10671068

10681069
EC = type(name, (base,), {'__slots__': ()})
10691070
EC.field = gf
@@ -1097,14 +1098,15 @@ def _EllipticCurve(curvename, coordinates):
10971098
raise ValueError('invalid curvename')
10981099

10991100
name = f'E({gf.__name__}){curvename}{coordinates}'
1100-
if coordinates == 'jacobian':
1101-
base = WeierstrassJacobian
1102-
elif coordinates == 'affine':
1103-
base = WeierstrassAffine
1104-
elif coordinates == 'projective':
1105-
base = WeierstrassProjective
1106-
else:
1107-
raise ValueError('invalid coordinates')
1101+
match coordinates:
1102+
case 'jacobian':
1103+
base = WeierstrassJacobian
1104+
case 'affine':
1105+
base = WeierstrassAffine
1106+
case 'projective':
1107+
base = WeierstrassProjective
1108+
case _:
1109+
raise ValueError('invalid coordinates')
11081110

11091111
EC = type(name, (base,), {'__slots__': ()})
11101112
EC.field = gf
@@ -1128,14 +1130,15 @@ def _EllipticCurve(curvename, coordinates):
11281130
gf = GF(p)
11291131

11301132
name = f'E({gf.__name__}){curvename}{coordinates}'
1131-
if coordinates == 'jacobian':
1132-
base = WeierstrassJacobian
1133-
elif coordinates == 'affine':
1134-
base = WeierstrassAffine
1135-
elif coordinates == 'projective':
1136-
base = WeierstrassProjective
1137-
else:
1138-
raise ValueError('invalid coordinates')
1133+
match coordinates:
1134+
case 'jacobian':
1135+
base = WeierstrassJacobian
1136+
case 'affine':
1137+
base = WeierstrassAffine
1138+
case 'projective':
1139+
base = WeierstrassProjective
1140+
case _:
1141+
raise ValueError('invalid coordinates')
11391142

11401143
EC = type(name, (base,), {'__slots__': ()})
11411144
EC.field = gf

mpyc/mpctools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
The alternative implementations can be used as drop-in replacements, however,
55
potentially enhancing the performance when used in secure computations. More
66
specifically, these implementations are aimed at reducing the overall round
7-
complexity, possible at the expense of increasing overall space complexity,
7+
complexity, possibly at the expense of increasing overall space complexity,
88
time complexity, and communication complexity.
99
"""
1010

mpyc/numpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def _item_shape(shape, key):
161161
np._matmul_shape = _matmul_shape
162162
np._item_shape = _item_shape
163163

164-
if np.lib.NumpyVersion(np.__version__) < '1.23.0':
165-
logging.warning(f'NumPy {np.__version__} not (fully) supported. Upgrade to NumPy 1.23+.')
164+
if np.lib.NumpyVersion(np.__version__) < '1.24.0':
165+
logging.warning(f'NumPy {np.__version__} not (fully) supported. Upgrade to NumPy 1.24+.')
166166
except ImportError:
167167
del _matmul_shape
168168
del _item_shape

mpyc/statistics.py

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
function in Python's statistics module.
2323
"""
2424

25-
import sys
2625
from math import fsum, sqrt
2726
import statistics
2827
from mpyc import asyncoro
@@ -506,14 +505,7 @@ def covariance(x, y):
506505

507506
sectype = type(x[0]) # all elts of x assumed of same type
508507
if not issubclass(sectype, SecureObject):
509-
if sys.version_info.minor >= 10:
510-
return statistics.covariance(x, y)
511-
512-
# inline code of statistics.covariance() copied from Python 3.10.0:
513-
xbar = fsum(x) / n
514-
ybar = fsum(y) / n
515-
sxy = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
516-
return sxy / (n - 1)
508+
return statistics.covariance(x, y)
517509

518510
if issubclass(sectype, SecureFixedPoint):
519511
xbar = runtime.sum(x) / n
@@ -549,20 +541,7 @@ def correlation(x, y):
549541

550542
sectype = type(x[0]) # all elts of x assumed of same type
551543
if not issubclass(sectype, SecureObject):
552-
if sys.version_info.minor >= 10:
553-
return statistics.correlation(x, y)
554-
555-
# inline code of statistics.correlation() copied from Python 3.10.0:
556-
xbar = fsum(x) / n
557-
ybar = fsum(y) / n
558-
sxy = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
559-
sxx = fsum((xi - xbar) ** 2.0 for xi in x)
560-
syy = fsum((yi - ybar) ** 2.0 for yi in y)
561-
try:
562-
return sxy / sqrt(sxx * syy)
563-
564-
except ZeroDivisionError:
565-
raise statistics.StatisticsError('at least one of the inputs is constant') from None
544+
return statistics.correlation(x, y)
566545

567546
if issubclass(sectype, SecureFixedPoint):
568547
xbar = runtime.sum(x) / n
@@ -577,13 +556,6 @@ def correlation(x, y):
577556
raise TypeError('secure fixed-point type required')
578557

579558

580-
if sys.version_info.minor >= 10:
581-
LinearRegression = statistics.LinearRegression
582-
else:
583-
from collections import namedtuple
584-
LinearRegression = namedtuple('LinearRegression', ('slope', 'intercept'))
585-
586-
587559
def linear_regression(x, y):
588560
"""Return a (simple) linear regression model for x and y.
589561
@@ -610,21 +582,7 @@ def linear_regression(x, y):
610582

611583
sectype = type(x[0]) # all elts of x assumed of same type
612584
if not issubclass(sectype, SecureObject):
613-
if sys.version_info.minor >= 10:
614-
return statistics.linear_regression(x, y)
615-
616-
# inline code of statistics.linear_regression() adapted from Python 3.10.0:
617-
xbar = fsum(x) / n
618-
ybar = fsum(y) / n
619-
sxy = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
620-
sxx = fsum((xi - xbar) ** 2.0 for xi in x)
621-
try:
622-
slope = sxy / sxx # equivalent to: covariance(x, y) / variance(x)
623-
except ZeroDivisionError:
624-
raise statistics.StatisticsError('x is constant') from None
625-
626-
intercept = ybar - slope * xbar
627-
return LinearRegression(slope=slope, intercept=intercept)
585+
return statistics.linear_regression(x, y)
628586

629587
if issubclass(sectype, SecureFixedPoint):
630588
xbar = runtime.sum(x) / n
@@ -635,7 +593,7 @@ def linear_regression(x, y):
635593
sxx = runtime.in_prod(xxbar, xxbar)
636594
slope = sxy / sxx
637595
intercept = ybar - slope * xbar
638-
return LinearRegression(slope=slope, intercept=intercept)
596+
return statistics.LinearRegression(slope=slope, intercept=intercept)
639597

640598
# TODO: implement for secure integers as well
641599
raise TypeError('secure fixed-point type required')

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ classifiers = [
3535
'Topic :: System :: Distributed Computing'
3636
]
3737
license = {text = 'MIT License'}
38-
requires-python = '>=3.9'
38+
requires-python = '>=3.10'
3939

4040
[project.urls]
4141
documentation = 'https://mpyc.readthedocs.io'

tests/test_mpctools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import unittest
21
import operator
32
import itertools
43
import functools
4+
import unittest
55
from mpyc.runtime import mpc
66
import mpyc.mpctools
77

tests/test_statistics.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import sys
2-
import unittest
31
import random
42
import statistics
3+
import unittest
54
from mpyc.runtime import mpc
65
from mpyc.statistics import (mean, variance, stdev, pvariance, pstdev,
76
mode, median, median_low, median_high, quantiles,
87
covariance, correlation, linear_regression)
98

10-
if sys.version_info.minor < 10:
11-
statistics.covariance = covariance
12-
statistics.correlation = correlation
13-
statistics.linear_regression = linear_regression
14-
159

1610
class Arithmetic(unittest.TestCase):
1711

0 commit comments

Comments
 (0)