Skip to content

Commit

Permalink
Improved ModP and PAdic constructors accept a wider range on inputs. …
Browse files Browse the repository at this point in the history
…Splitting CI into lint and test. Automating PyPI release on github release.
  • Loading branch information
GDeLaurentis committed May 4, 2024
1 parent 23b261b commit 9b355c2
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 18 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-

name: CI Lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
branches: [ main ]

jobs:

CI:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: 3.9
- name: Checkout this Repo
uses: actions/checkout@v3
with:
path: pyadic
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
run: |
cd pyadic
flake8 pyadic/ --count --max-line-length=190 --statistics --verbose
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

name: Continuous Integration
name: CI Test

on:
push:
Expand Down Expand Up @@ -28,16 +28,19 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
pip install pytest pytest-cov
pip install -e pyadic
- name: Lint with flake8
run: |
cd pyadic
flake8 pyadic/ --count --max-line-length=190 --statistics --verbose
- name: Test with pytest
run: |
cd pyadic
pytest |& tee coverage.txt
PYTEST_EXIT_CODE=${PIPESTATUS[0]}
if [ "$PYTEST_EXIT_CODE" -ne 0 ]; then
echo "pytest failed with exit code $PYTEST_EXIT_CODE"
exit 1
else
echo "pytest passed with exit code 0"
fi
- name: Run update-badges script
run: |
cd pyadic
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/pypi_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PyPI Release

on:
release:
types: [created]

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build
run: |
python setup.py sdist bdist_wheel
- name: Publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/*
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

### Changed

### Fixed

## [0.2.1] - 2024-05-04

### Added

- Multivariate Newton interpolation algorithm, `multivariate_Newton_polynomial_interpolation`.

### Changed

- Improved compatibility of `extended_euclidean_algorithm`: output is of same type as input.
- Improved `ModP` and `PAdic` constructors to handle a wider variety of inputs, e.g. `ModP('+1', 2 ** 31 - 1)` is now valid.
- Splitting CI Test and Lint, adding automatic PyPI release workflow.

### Fixed

Expand Down Expand Up @@ -54,7 +64,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Finite fields, `ModP`.


[unreleased]: https://github.com/GDeLaurentis/pyadic/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/GDeLaurentis/pyadic/releases/tag/v0.2.0
[0.1.2]: https://github.com/GDeLaurentis/pyadic/releases/tag/v0.1.2
[unreleased]: https://github.com/GDeLaurentis/pyadic/compare/v0.2.1...HEAD
[0.2.1]: https://github.com/GDeLaurentis/pyadic/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/GDeLaurentis/pyadic/compare/v0.1.2...v0.2.0
[0.1.2]: https://github.com/GDeLaurentis/pyadic/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/GDeLaurentis/pyadic/releases/tag/v0.1.1
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# pyAdic

[![Continuous Integration Status](https://github.com/GDeLaurentis/pyadic/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/GDeLaurentis/pyadic/actions)
[![CI Lint](https://github.com/GDeLaurentis/pyadic/actions/workflows/ci_lint.yml/badge.svg)](https://github.com/GDeLaurentis/pyadic/actions/workflows/ci_lint.yml)
[![CI Test](https://github.com/GDeLaurentis/pyadic/actions/workflows/ci_test.yml/badge.svg)](https://github.com/GDeLaurentis/pyadic/actions/workflows/ci_test.yml)
[![Coverage](https://img.shields.io/badge/Coverage-91%25-green?labelColor=2a2f35)](https://github.com/GDeLaurentis/pyadic/actions)
[![pypi](https://img.shields.io/pypi/v/pyadic)](https://pypi.org/project/pyadic/)
[![PyPI](https://img.shields.io/pypi/v/pyadic?label=PyPI)](https://pypi.org/project/pyadic/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/pyadic.svg?label=PyPI%20downloads)](https://pypistats.org/packages/pyadic)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/GDeLaurentis/pyadic/HEAD)

Expand Down
12 changes: 7 additions & 5 deletions pyadic/finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ def __init__(self, n, p=None):
raise ValueError("Complex to ModP conversion requires √-1 in field or zero imaginary part.")
self.n = res.n
self.p = res.p
elif p is None and isinstance(n, ModP):
elif isinstance(n, ModP):
if p is not None:
assert p == n.p
self.n = n.n
self.p = n.p
elif p is None and isinstance(n, padic.PAdic):
self.n = int(n)
self.p = n.p ** n.k
elif p is None and isinstance(n, str):
self.n, self.p = self.__rstr__(n)
elif isinstance(n, str) and (n.isnumeric() or n.lstrip("+-").isnumeric()):
self.p = n.p ** n._k
elif isinstance(n, str) and (n.isnumeric() or n.lstrip("+-").isnumeric()) and p is not None:
self.n, self.p = int(n) % int(p), p
elif isinstance(n, str):
self.n, self.p = self.__rstr__(n)
else:
raise TypeError('Bad finite field constructor, (n, p) of value:({}, {}) and type:({}, {}).'.format(n, p, type(n), type(p)))

Expand Down
8 changes: 7 additions & 1 deletion pyadic/padic.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def __init__(self, num, p=None, k=None, n=0, from_addition=False):
elif isinstance(num, fractions.Fraction):
res = PAdic(num.numerator, p, k, n, from_addition) / PAdic(num.denominator, p, k, n, from_addition)
self.num, self.p, self.k, self.n = res.num, res.p, res.k, res.n
elif isinstance(num, PAdic):
self.num, self.p, self.k, self.n = num.num, num.p, num.k, num.n
elif hasattr(num, "imag"):
res = PAdic(num.real, p, k, n, from_addition)
if num.imag != 0:
Expand All @@ -131,8 +133,12 @@ def __init__(self, num, p=None, k=None, n=0, from_addition=False):
self.k = res.k
self.n = res.n
self.num = res.num
elif isinstance(num, str):
elif p is None and k is None and isinstance(num, str):
self.num, self.p, self.k, self.n = self.__rstr__(num)
elif isinstance(num, str):
num = fractions.Fraction(num)
res = PAdic(num.numerator, p, k, n, from_addition) / PAdic(num.denominator, p, k, n, from_addition)
self.num, self.p, self.k, self.n = res.num, res.p, res.k, res.n
else:
raise Exception(f"Invalid p-adic initialisation: {num}, {p}, {k}, {n}, {from_addition}.")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='pyadic',
version='0.2.0',
version='0.2.1',
license='GNU General Public License v3.0',
description='p-Adic numbers and finite fields in Python',
long_description=long_description,
Expand Down

0 comments on commit 9b355c2

Please sign in to comment.