Skip to content

Split operator.py into multiple files #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ extend-ignore =
per-file-ignores =
scripts/create_pickle.py:F403,F405,
graphblas/tests/*.py:T201,
graphblas/core/agg.py:F401,F403,
graphblas/core/ss/matrix.py:SIM113,
graphblas/**/__init__.py:F401,
2 changes: 1 addition & 1 deletion .github/workflows/test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
echo "versions: np${npver} sp${spver} pd${pdver} ak${akver} nx${nxver} numba${numbaver} yaml${yamlver} sparse${sparsever} psgver${psgver}"

# Once we have wheels for all OSes, we can delete the last two lines.
mamba install packaging pytest coverage coveralls=3.3.1 pytest-randomly cffi donfig pyyaml${yamlver} sparse${sparsever} \
mamba install packaging pytest coverage coveralls=3.3.1 pytest-randomly cffi donfig tomli pyyaml${yamlver} sparse${sparsever} \
pandas${pdver} scipy${spver} numpy${npver} awkward${akver} networkx${nxver} numba${numbaver} fast_matrix_market${fmmver} \
${{ matrix.slowtask == 'pytest_bizarro' && 'black' || '' }} \
${{ matrix.slowtask == 'notebooks' && 'matplotlib nbconvert jupyter "ipython>=7"' || '' }} \
Expand Down
16 changes: 11 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ repos:
hooks:
- id: validate-pyproject
name: Validate pyproject.toml
# I don't yet trust ruff to do what autoflake does
- repo: https://github.com/myint/autoflake
rev: v2.0.2
hooks:
- id: autoflake
args: [--in-place]
# We can probably remove `isort` if we come to trust `ruff --fix`,
# but we'll need to figure out the configuration to do this in `ruff`
- repo: https://github.com/pycqa/isort
Expand All @@ -42,15 +48,15 @@ repos:
- id: auto-walrus
args: [--line-length, "100"]
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.259
rev: v0.0.260
hooks:
- id: ruff
args: [--fix-only]
args: [--fix-only, --show-fixes]
# Let's keep `flake8` even though `ruff` does much of the same.
# `flake8-bugbear` and `flake8-simplify` have caught things missed by `ruff`.
- repo: https://github.com/PyCQA/flake8
Expand All @@ -60,7 +66,7 @@ repos:
additional_dependencies: &flake8_dependencies
# These versions need updated manually
- flake8==6.0.0
- flake8-bugbear==23.3.12
- flake8-bugbear==23.3.23
- flake8-simplify==0.19.3
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
Expand All @@ -75,7 +81,7 @@ repos:
additional_dependencies: [tomli]
files: ^(graphblas|docs)/
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.259
rev: v0.0.260
hooks:
- id: ruff
- repo: https://github.com/sphinx-contrib/sphinx-lint
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pre-commit
# For testing
packaging
pytest-cov
tomli
# For debugging
icecream
ipykernel
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies:
# For testing
- packaging
- pytest-cov
- tomli
# For debugging
- icecream
- ipykernel
Expand Down
4 changes: 2 additions & 2 deletions graphblas/agg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ def __getattr__(key):
raise AttributeError(f"module {__name__!r} has no attribute {key!r}")


from ..core import agg # noqa: E402 isort:skip
from ..core import operator # noqa: E402 isort:skip

del agg
del operator
4 changes: 2 additions & 2 deletions graphblas/agg/ss.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from ..core import agg
from ..core import operator

del agg
del operator
13 changes: 6 additions & 7 deletions graphblas/binary/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,18 @@ def __getattr__(name):
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
if _config.get("mapnumpy") and name in _numpy_to_graphblas:
if name == "float_power":
from ..core import operator
from ..core.operator import binary
from ..dtypes import FP64

new_op = operator.BinaryOp(f"numpy.{name}")
new_op = binary.BinaryOp(f"numpy.{name}")
builtin_op = _binary.pow
for dtype in builtin_op.types:
if dtype.name in {"FP32", "FC32", "FC64"}:
orig_dtype = dtype
else:
orig_dtype = operator.FP64
orig_dtype = FP64
orig_op = builtin_op[orig_dtype]
cur_op = operator.TypedBuiltinBinaryOp(
cur_op = binary.TypedBuiltinBinaryOp(
new_op,
new_op.name,
dtype,
Expand All @@ -166,14 +167,12 @@ def __getattr__(name):
else:
globals()[name] = getattr(_binary, _numpy_to_graphblas[name])
else:
from ..core import operator

numpy_func = getattr(_np, name)

def func(x, y): # pragma: no cover (numba)
return numpy_func(x, y)

operator.BinaryOp.register_new(f"numpy.{name}", func)
_binary.register_new(f"numpy.{name}", func)
rv = globals()[name]
if name in _commutative:
rv._commutes_to = rv
Expand Down
Loading