Skip to content

Commit

Permalink
Av basis (#194)
Browse files Browse the repository at this point in the history
* stop avoids(basis) doing irritating things

* raise error if you pass a list

* changelog

* typing

* pylint

* Update test.yml

* Update build-and-deploy.yml

* Update pyproject.toml

* Update tox.ini

* Update tox.ini

* update tox again

* testing

* this will fix it for sure

* make sure pip installs setuptools

* more changes

* more changes

* more changes

* more changes

---------

Co-authored-by: jaypantone <[email protected]>
  • Loading branch information
christianbean and jaypantone authored Feb 22, 2024
1 parent 031cf63 commit 61edbbd
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: "3.10"
- name: install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
32 changes: 16 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ jobs:
fail-fast: false
matrix:
include:
- python: 3.8
- python: "3.11"
toxenv: flake8
os: ubuntu-latest
- python: 3.8
- python: "3.11"
toxenv: mypy
os: ubuntu-latest
- python: 3.8
- python: "3.11"
toxenv: pylint
os: ubuntu-latest
- python: 3.8
- python: "3.11"
toxenv: black
os: ubuntu-latest

- python: 3.7
toxenv: py37
os: ubuntu-latest
- python: 3.8
toxenv: py38
os: ubuntu-latest
Expand All @@ -37,25 +34,28 @@ jobs:
- python: "3.11"
toxenv: py311
os: ubuntu-latest
- python: pypy-3.7
toxenv: pypy37
- python: "3.12"
toxenv: py312
os: ubuntu-latest
- python: 'pypy3.9'
toxenv: pypy39
os: ubuntu-latest

- python: 3.8
toxenv: py38
- python: "3.11"
toxenv: py311
os: macos-latest
- python: 3.8
toxenv: py38
- python: "3.11"
toxenv: py311
os: windows-latest

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: install dependencies
run: python -m pip install --upgrade pip tox
run: python -m pip install --upgrade pip tox setuptools wheel
- name: run
env:
TOXENV: ${{ matrix.toxenv }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Functions for ascents and descents now take an optional argument to specify what step size to calculate.
- Moved sorting functions from `permuta/bisc/perm_properties.py` to `permuta/patterns/perm.py`.
- If you pass an iterable (that is not a perm) to a contains method, then it will now raise an error.
These should be passed with the splat '*'.

## 2.0.3 - 2021-04-28
### Added
Expand Down
3 changes: 0 additions & 3 deletions permuta/bisc/bisc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


def bisc(A, m, n=None, report=False):

if isinstance(A, list):
D = defaultdict(list)
for perm in A:
Expand Down Expand Up @@ -56,7 +55,6 @@ def bisc(A, m, n=None, report=False):


def auto_bisc(prop):

L = 8 # Want to sanity check on at least S8, and one above n
n = 4
m = 2
Expand Down Expand Up @@ -274,7 +272,6 @@ def create_bisc_input(N, prop):
A, B = {}, {}

for n in range(N + 1):

An, Bn = [], []

for perm in Perm.of_length(n):
Expand Down
17 changes: 11 additions & 6 deletions permuta/patterns/meshpatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
and 0 <= coordinate[0] <= len(self.pattern)
and 0 <= coordinate[1] <= len(self.pattern)
for coordinate in self.shading
)
), "shadings should be 2-tuples with integers between 0 and len(pattern)"

@classmethod
def unrank(cls, pattern: Perm, number: int) -> "MeshPatt":
Expand Down Expand Up @@ -327,6 +327,11 @@ def add_decrease(self, pos: Tuple[int, int]) -> "MeshPatt":
x, y = pos
return self.add_point((x, y)).add_point((x + 1, y))

def _contains(self, patt: Patt) -> bool:
if isinstance(patt, Patt):
return any(True for _ in patt.occurrences_in(self))
raise TypeError("patt must be a Patt")

def contains(self, *patts: Patt) -> bool:
"""Check if self contains all provided patterns.
Expand All @@ -336,7 +341,7 @@ def contains(self, *patts: Patt) -> bool:
>>> MeshPatt(Perm((0,)), [(0, 1)]).contains(MeshPatt(Perm((0,)), []))
True
"""
return all(patt in self for patt in patts)
return all(self._contains(patt) for patt in patts)

def avoids(self, *patts: Patt) -> bool:
"""Check if self avoids all provided patterns.
Expand All @@ -351,7 +356,7 @@ def avoids(self, *patts: Patt) -> bool:
>>> MeshPatt(Perm((0,)), [(0, 1)]).avoids(MeshPatt(Perm((0,)), []))
False
"""
return all(patt not in self for patt in patts)
return all(not self._contains(patt) for patt in patts)

def occurrences_in(self, patt: Patt, *args, **kwargs) -> Iterator[Tuple[int, ...]]:
"""
Expand Down Expand Up @@ -689,7 +694,7 @@ def rank(self) -> int:
'0b1011101001100101'
"""
n, res = len(self), 0
for (x, y) in self.shading:
for x, y in self.shading:
res |= 1 << (x * (n + 1) + y)
return res

Expand Down Expand Up @@ -845,5 +850,5 @@ def __ge__(self, other: object) -> bool:

def __contains__(self, patt: object) -> bool:
if isinstance(patt, Patt):
return any(True for _ in patt.occurrences_in(self))
return False
return self._contains(patt)
raise TypeError("patt must be a Patt")
11 changes: 8 additions & 3 deletions permuta/patterns/patt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class Patt(abc.ABC):

def avoided_by(self, *patts: "Patt") -> bool:
"""Check if self is avoided by all the provided patterns."""
return all(self not in patt for patt in patts)
return all(not patt.contains(self) for patt in patts)

def contained_in(self, *patts: "Patt") -> bool:
"""Check if self is a pattern of all the provided patterns."""
return all(self in patt for patt in patts)
return all(patt.contains(self) for patt in patts)

def count_occurrences_in(self, patt: "Patt") -> int:
"""Count the number of occurrences of self in the pattern."""
Expand All @@ -36,5 +36,10 @@ def get_perm(self) -> "Perm":
"""Get the permutation part of the pattern"""

@abc.abstractmethod
def __contains__(self, patt: object) -> bool:
def _contains(self, patt: "Patt") -> bool:
"""Does pattern contains another?"""

contains = _contains

def __contains__(self, patt: "Patt") -> bool:
return self._contains(patt)
13 changes: 9 additions & 4 deletions permuta/patterns/perm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2496,7 +2496,12 @@ def contains(self, *patts: "Patt") -> bool:
>>> Perm((5, 3, 0, 4, 2, 1)).contains(pattern2, pattern3)
False
"""
return all(patt in self for patt in patts)
return all(self._contains(patt) for patt in patts)

def _contains(self, patt: "Patt") -> bool:
if isinstance(patt, Patt):
return any(True for _ in patt.occurrences_in(self))
raise TypeError("patt must be a Patt")

def avoids(self, *patts: "Patt") -> bool:
"""Check if self avoids patts.
Expand All @@ -2519,7 +2524,7 @@ def avoids(self, *patts: "Patt") -> bool:
>>> Perm((5, 3, 0, 4, 2, 1)).avoids(pattern3, pattern4)
True
"""
return all(patt not in self for patt in patts)
return all(not self._contains(patt) for patt in patts)

def avoids_set(self, patts: Iterable["Patt"]) -> bool:
"""Check if self avoids patts for an iterable of patterns.
Expand Down Expand Up @@ -3027,5 +3032,5 @@ def __len__(self) -> int:

def __contains__(self, patt: object) -> bool:
if isinstance(patt, Patt):
return any(True for _ in patt.occurrences_in(self))
return False
return self._contains(patt)
raise TypeError("patt must be a Patt")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.black]
target-version = ['py37']
target-version = ['py310']
include = '\.pyi?$'
exclude = '''
Expand Down
11 changes: 5 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
[tox]
envlist =
flake8, mypy, pylint, black
py{37,38,39, 310, 311},
pypy37
py{39, 310, 311, 312},
pypy39

[default]
basepython=python3.8
basepython=python3.11

[testenv]
description = run test
basepython =
py37: python3.7
py38: python3.8
py39: python3.9
py310: python3.10
py311: python3.11
pypy37: pypy3
py312: python3.12
pypy39: pypy3.9
deps =
pytest==7.2.0
pytest-timeout==2.1.0
Expand Down

0 comments on commit 61edbbd

Please sign in to comment.