Skip to content

Commit

Permalink
Merge 78be04b into 0d7f8c2
Browse files Browse the repository at this point in the history
  • Loading branch information
wesselb committed Mar 5, 2023
2 parents 0d7f8c2 + 78be04b commit 917dda5
Show file tree
Hide file tree
Showing 66 changed files with 5,382 additions and 4,276 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plum/_version.py

# Virtual environments
venv
.tox

# Packaging
*.egg-info
Expand Down
3 changes: 3 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[settings]
profile = black
src_paths = plum,tests
16 changes: 15 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
default_language_version:
python: python3.8
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
args: ["--max-line-length=88", "--extend-ignore=E203,F811"]
additional_dependencies:
- flake8-bugbear>=22.12
- flake8-noqa>=1.3
51 changes: 3 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,11 @@

PACKAGE := plum

docmake:
rm -rf docs/source
sphinx-apidoc -eMT -o docs/source/ $(PACKAGE)
rm docs/source/$(PACKAGE).rst
pandoc --from=markdown --to=rst --output=docs/readme.rst README.md
cd docs && make html

docopen:
open docs/_build/html/index.html

docinit:
$(eval BRANCH := $(shell git rev-parse --abbrev-ref HEAD))
git checkout -b gh-pages
git ls-tree HEAD \
| awk '$$4 !~ /\.nojekyll|docs|index\.html/ { print $$4 }' \
| xargs -I {} git rm -r {}
touch .nojekyll
echo '<meta http-equiv="refresh" content="0; url=./docs/_build/html/index.html" />' > index.html
git add .nojekyll index.html
git commit -m "Branch cleaned for docs"
git push origin gh-pages
git checkout $(BRANCH)

docremove:
git branch -D gh-pages
git push origin --delete gh-pages

docupdate: docmake
$(eval BRANCH := $(shell git rev-parse --abbrev-ref HEAD))
rm -rf docs/_build/html_new
mv docs/_build/html docs/_build/html_new
git checkout gh-pages
rm -rf docs/_build/html
mv docs/_build/html_new docs/_build/html
git add -f docs/_build/html
git commit -m "Update docs at $$(date +'%d %b %Y, %H:%M')"
git push origin gh-pages
git checkout $(BRANCH)

install:
pip install -r requirements.txt

test:
python setup.py --version
PRAGMA_VERSION=`python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))"` \
pytest -v --cov=$(PACKAGE) --cov-report html:cover --cov-report term-missing

clean:
rm -rf docs/_build docs/source docs/readme.rst
git rm --cached -r docs
git add docs/Makefile docs/conf.py docs/index.rst docs/api.rst
rm -rf .coverage cover
find . | grep '\(\.DS_Store\|\.pyc\)$$' | xargs rm
pre-commit run --all-files && sleep 0.2 && \
PRAGMA_VERSION=`python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))"` \
pytest tests -v --cov=$(PACKAGE) --cov-report html:cover --cov-report term-missing
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

Everybody likes multiple dispatch, just like everybody likes plums.

*Note:*
Plum 2 is now powered by [Beartype](https://github.com/beartype/beartype)!
If you notice any issues with the new release, please open an issue.

# Installation

Plum requires Python 3.7 or higher.
Expand Down
72 changes: 23 additions & 49 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Tuple

import numpy as np

from plum import dispatch, Dispatcher, Tuple
from plum import Dispatcher, dispatch
from tests.util import benchmark


Expand All @@ -18,20 +20,13 @@ def g(x: str):
pass


dur_native = benchmark(f, (1,), n=1000000)
dur_first_plum = benchmark(g, (1,), n=1)
dur_plum = benchmark(g, (1,), n=1000000)
dur_native = benchmark(f, (1,), n=1000, burn=10)
dur_plum = benchmark(g, (1,), n=1000, burn=10)
factor = int(np.round(dur_plum / dur_native))

print("# Function Calls")
print("Native call: {:6.2f} us ({:.1f} x)".format(dur_native, 1))
print(
"First plum call: {:6.2f} us ({:.1f} x)"
"".format(dur_first_plum, int(np.round(dur_first_plum / dur_native)))
)
print(
"Plum call: {:6.2f} us ({:.1f} x)"
"".format(dur_plum, int(np.round(dur_plum / dur_native)))
)
print("Native call: {:6.2f} us ({:.1f} x)".format(dur_native, 1))
print("Plum call: {:6.2f} us ({:.1f} x)".format(dur_plum, factor))
print()


Expand All @@ -49,20 +44,13 @@ def g2(x: Tuple[str]):
pass


dur_native = benchmark(f2, ((1,),), n=1000000)
dur_first_plum = benchmark(g2, ((1,),), n=1)
dur_plum = benchmark(g2, ((1,),), n=1000000)
dur_native = benchmark(f2, ((1,),), n=1000, burn=10)
dur_plum = benchmark(g2, ((1,),), n=1000, burn=10)
factor = int(np.round(dur_plum / dur_native))

print("# Parametric Function Calls")
print("Native call: {:6.2f} us ({:.1f} x)".format(dur_native, 1))
print(
"First plum call: {:6.2f} us ({:.1f} x)"
"".format(dur_first_plum, int(np.round(dur_first_plum / dur_native)))
)
print(
"Plum call: {:6.2f} us ({:.1f} x)"
"".format(dur_plum, int(np.round(dur_plum / dur_native)))
)
print("Native call: {:6.2f} us ({:.1f} x)".format(dur_native, 1))
print("Plum call: {:6.2f} us ({:.1f} x)".format(dur_plum, factor))
print()


Expand Down Expand Up @@ -97,33 +85,19 @@ def go(self, x: str):
a = A()
b = B()

dur_native = benchmark(a, (1,), n=1000000)
dur_first_plum = benchmark(b, (1,), n=1)
dur_plum = benchmark(b, (1,), n=1000000)
dur_native = benchmark(a, (1,), n=1000, burn=10)
dur_plum = benchmark(b, (1,), n=1000, burn=10)
factor = int(np.round(dur_plum / dur_native))

print("# Class Calls")
print("Native call: {:6.2f} us ({:.1f} x)".format(dur_native, 1))
print(
"First plum call: {:6.2f} us ({:.1f} x)"
"".format(dur_first_plum, int(np.round(dur_first_plum / dur_native)))
)
print(
"Plum call: {:6.2f} us ({:.1f} x)"
"".format(dur_plum, int(np.round(dur_plum / dur_native)))
)
print("Native call: {:6.2f} us ({:.1f} x)".format(dur_native, 1))
print("Plum call: {:6.2f} us ({:.1f} x)".format(dur_plum, factor))
print()

dur_native = benchmark(lambda x: a.go(x), (1,), n=1000000)
dur_first_plum = benchmark(lambda x: b.go(x), (1,), n=1)
dur_plum = benchmark(lambda x: b.go(x), (1,), n=1000000)
dur_native = benchmark(lambda x: a.go(x), (1,), n=1000, burn=10)
dur_plum = benchmark(lambda x: b.go(x), (1,), n=1000, burn=10)
factor = int(np.round(dur_plum / dur_native))

print("# Class Attribute Calls")
print("Native call: {:6.2f} us ({:.1f} x)".format(dur_native, 1))
print(
"First plum call: {:6.2f} us ({:.1f} x)"
"".format(dur_first_plum, int(np.round(dur_first_plum / dur_native)))
)
print(
"Plum call: {:6.2f} us ({:.1f} x)"
"".format(dur_plum, int(np.round(dur_plum / dur_native)))
)
print("Native call: {:6.2f} us ({:.1f} x)".format(dur_native, 1))
print("Plum call: {:6.2f} us ({:.1f} x)".format(dur_plum, factor))
5 changes: 5 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ author: Wessel Bruinsma, Filippo Vicentini, and Ruan Comelli
copyright: "2022"
logo: logo.png

# Enable definition lists.
parse:
myst_enable_extensions:
- deflist

# Force re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
execute:
Expand Down
10 changes: 8 additions & 2 deletions docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ root: intro
chapters:
- file: basic_usage
sections:
- file: types
- file: dispatch
- file: scope
- file: classes
- file: keyword_arguments
- file: comparison
- file: type_system
- file: conversion_promotion
- file: advanced_usage
sections:
- file: conversion_promotion
- file: precedence
- file: parametric
- file: union_aliases
- file: autoreload
- file: api

0 comments on commit 917dda5

Please sign in to comment.