Skip to content
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 .github/workflows/debug.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This file is outdated
name: Debug CI Jobs

on:
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/imports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ on:
jobs:
test_imports:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
# strategy:
# matrix:
# python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: RNG for Python version
uses: ddradar/choose-random-action@v2.0.2
id: pyver
with:
contents: |
3.8
3.9
3.10
weights: |
1
1
1
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ steps.pyver.outputs.selected }}
# python-version: ${{ matrix.python-version }}
- run: python -m pip install --upgrade pip
- run: pip install -e .
- run: ./scripts/test_imports.sh
16 changes: 13 additions & 3 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:
build_and_deploy:
runs-on: ubuntu-latest
if: github.repository == 'python-graphblas/python-graphblas'
defaults:
run:
shell: bash -l {0}
Expand All @@ -21,9 +22,18 @@ jobs:
with:
python-version: "3.8"
- name: Install build dependencies
run: python -m pip install setuptools wheel
- name: Build wheel
run: python setup.py sdist bdist_wheel
run: |
python -m pip install --upgrade pip
python -m pip install build twine
- name: Build wheel and sdist
run: python -m build --sdist --wheel
- uses: actions/upload-artifact@v3
with:
name: releases
path: dist
if-no-files-found: error
- name: Check with twine
run: python -m twine check --strict dist/*
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
npver=$(python -c 'import random ; print(random.choice(["=1.23", ""]))')
spver=$(python -c 'import random ; print(random.choice(["=1.9", "=1.10", ""]))')
pdver=$(python -c 'import random ; print(random.choice(["=1.5", ""]))')
akver=$(python -c 'import random ; print(random.choice(["=1.10", "=2.0", ""]))')
akver=$(python -c 'import random ; print(random.choice(["=1.10", "=2.0.5", "=2.0.6", ""]))')
fi
if [[ ${{ steps.sourcetype.outputs.selected }} == "source" || ${{ steps.sourcetype.outputs.selected }} == "upstream" ]]; then
# TODO: there are currently issues with some numpy versions when
Expand All @@ -174,7 +174,7 @@ jobs:
# That is, we don't need to support versions of it that are two years old.
# But, it's still useful for us to test with different versions!
if [[ ${{ steps.sourcetype.outputs.selected}} == "conda-forge" ]] ; then
psgver=$(python -c 'import random ; print(random.choice(["=7.4.0", "=7.4.1", ""]))')
psgver=$(python -c 'import random ; print(random.choice(["=7.4.0", "=7.4.1", "=7.4.2", ""]))')
else
psgver=""
fi
Expand Down Expand Up @@ -233,7 +233,7 @@ jobs:
if [[ $H && $normal ]] ; then if [[ $macos ]] ; then echo " $vanilla" ; elif [[ $windows ]] ; then echo " $suitesparse" ; fi ; fi)$( \
if [[ $H && $bizarro ]] ; then if [[ $macos ]] ; then echo " $suitesparse" ; elif [[ $windows ]] ; then echo " $vanilla" ; fi ; fi)
echo $args
coverage run -m pytest --randomly -v $args \
coverage run -m pytest --color=yes -Werror --randomly -v $args \
${{ matrix.slowtask == 'pytest_normal' && '--runslow' || '' }}
- name: Unit tests (bizarro scalars)
run: |
Expand Down Expand Up @@ -268,7 +268,7 @@ jobs:
if [[ $H && $normal ]] ; then if [[ $macos ]] ; then echo " $suitesparse" ; elif [[ $windows ]] ; then echo " $vanilla" ; fi ; fi)$( \
if [[ $H && $bizarro ]] ; then if [[ $macos ]] ; then echo " $vanilla" ; elif [[ $windows ]] ; then echo " $suitesparse" ; fi ; fi)
echo $args
coverage run -a -m pytest --randomly -v $args \
coverage run -a -m pytest --color=yes -Werror --randomly -v $args \
${{ matrix.slowtask == 'pytest_bizarro' && '--runslow' || '' }}
git checkout . # Undo changes to scalar default
- name: Miscellaneous tests
Expand All @@ -289,8 +289,8 @@ jobs:
rm script.py
# Tests whose coverage depend on order of tests :/
# TODO: understand why these are order-dependent and try to fix
coverage run -a -m pytest -x --no-mapnumpy -k test_binaryop_attributes_numpy graphblas/tests/test_op.py
# coverage run -a -m pytest -x --no-mapnumpy -k test_npmonoid graphblas/tests/test_numpyops.py --runslow
coverage run -a -m pytest --color=yes -Werror -x --no-mapnumpy -k test_binaryop_attributes_numpy graphblas/tests/test_op.py
# coverage run -a -m pytest --color=yes -Werror -x --no-mapnumpy -k test_npmonoid graphblas/tests/test_numpyops.py --runslow
- name: Auto-generated code check
if: matrix.slowtask == 'pytest_bizarro'
run: |
Expand Down
37 changes: 30 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.10.1
rev: v0.11
hooks:
- id: validate-pyproject
name: Validate pyproject.toml
Expand All @@ -41,11 +41,13 @@ repos:
- repo: https://github.com/MarcoGorelli/auto-walrus
rev: v0.2.2
hooks:
- id: auto-walrus
- id: auto-walrus
args: [--line-length, "100"]
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
Expand All @@ -54,7 +56,7 @@ repos:
# These versions need updated manually
- flake8==6.0.0
- flake8-comprehensions==3.10.1
- flake8-bugbear==22.12.6
- flake8-bugbear==23.1.17
- flake8-simplify==0.19.3
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
Expand All @@ -69,18 +71,19 @@ repos:
additional_dependencies: [tomli]
files: ^(graphblas|docs)/
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.213
rev: v0.0.227
hooks:
- id: ruff
args: [--force-exclude]
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.6.7
hooks:
- id: sphinx-lint
args: [--enable, all, "--disable=line-too-long,leaked-markup"]
- id: sphinx-lint
args: [--enable, all, "--disable=line-too-long,leaked-markup"]
- repo: local
hooks:
# Add `--hook-stage manual` to pre-commit command to run (very slow)
# It's probably better (and faster!) to simply run `pylint graphblas/some/file.py`
- id: pylint
name: pylint
entry: pylint
Expand All @@ -93,4 +96,24 @@ repos:
rev: v4.4.0
hooks:
- id: no-commit-to-branch # no commit directly to main
# Maybe: black-jupyter, blacken-docs, blackdoc mypy, pydocstyle, rstcheck, pydocstringformatter, velin
#
# Maybe:
#
# - repo: https://github.com/rstcheck/rstcheck
# rev: v6.1.1
# hooks:
# - id: rstcheck
# additional_dependencies: [nbsphinx]
#
# - repo: https://github.com/PyCQA/pydocstyle
# rev: 6.3.0
# hooks:
# - id: pydocstyle
# additional_dependencies: [tomli]
#
# - repo: https://github.com/PyCQA/bandit
# rev: 1.7.4
# hooks:
# - id: bandit
#
# blacken-docs, blackdoc mypy, pydocstringformatter, velin, flynt, yamllint
2 changes: 1 addition & 1 deletion docs/user_guide/operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Matrix-Matrix Assignment Example:

A = gb.Matrix.from_coo([0, 0, 1, 1, 2, 2], [1, 2, 0, 1, 0, 2],
[2.0, 5.0, 1.5, 4.0, 0.5, -7.0])
B = gb.Matrix.from_coo([0, 0, 1, 1], [0, 1, 0, 1]
B = gb.Matrix.from_coo([0, 0, 1, 1], [0, 1, 0, 1],
[-99., -98., -97., -96.])

A[::2, ::2] << B
Expand Down
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies:
# - autoflake
# - black
# - black-jupyter
# - build
# - codespell
# - commonmark
# - cython
Expand Down Expand Up @@ -95,6 +96,7 @@ dependencies:
# - snakeviz
# - sphinx-lint
# - sympy
# - twine
# - vim
# - yesqa
# - zarr
56 changes: 48 additions & 8 deletions graphblas/agg.py → graphblas/agg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@
- harmonic_mean
- root_mean_square

Custom recipes:
- first
- last
Custom recipes (specific to SuiteSparse:GraphBLAS):
- ss.first
- ss.last
# These don't work with Matrix.reduce_scalar
- first_index
- last_index
- argmin
- argmax
- ss.first_index
- ss.last_index
- ss.argmin
- ss.argmax

.. deprecated:: 2023.1.0
Aggregators `first`, `last`, `first_index`, `last_index`, `argmin`, and `argmax` are
deprecated in the `agg` namespace such as `agg.first`. Use them from `agg.ss` namespace
instead such as `agg.ss.first`. Will be removed in version 2023.9.0 or later.

# Possible aggregators:
# - absolute_deviation, sum(abs(x - mean(x))), sum_absminus(x, mean(x))
Expand All @@ -70,6 +75,41 @@
"""
# All items are dynamically added by classes in core/agg.py
# This module acts as a container of Aggregator instances
from .core import agg
_deprecated = {}


def __dir__():
return globals().keys() | _deprecated.keys() | {"ss"}


def __getattr__(key):
if key in _deprecated:
import warnings

warnings.warn(
f"`gb.agg.{key}` is deprecated; please use `gb.agg.ss.{key}` instead. "
f"`{key}` is specific to SuiteSparse:GraphBLAS. "
f"`gb.agg.{key}` will be removed in version 2023.9.0 or later.",
DeprecationWarning,
)
rv = _deprecated[key]
globals()[key] = rv
return rv
if key == "ss":
from .. import backend

if backend != "suitesparse":
raise AttributeError(
f'module {__name__!r} only has attribute "ss" when backend is "suitesparse"'
)
from importlib import import_module

ss = import_module(".ss", __name__)
globals()["ss"] = ss
return ss
raise AttributeError(f"module {__name__!r} has no attribute {key!r}")


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

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

del agg
29 changes: 27 additions & 2 deletions graphblas/binary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@
"rfloordiv": "floordiv",
"rpow": "pow",
}
_deprecated = {}


def __dir__():
return globals().keys() | _delayed.keys()
return globals().keys() | _delayed.keys() | _deprecated.keys() | {"ss"}


def __getattr__(key):
if key in _deprecated:
import warnings

warnings.warn(
f"`gb.binary.{key}` is deprecated; please use `gb.binary.ss.{key}` instead. "
f"`{key}` is specific to SuiteSparse:GraphBLAS. "
f"`gb.binary.{key}` will be removed in version 2023.9.0 or later.",
DeprecationWarning,
)
rv = _deprecated[key]
globals()[key] = rv
return rv
if key in _delayed:
func, kwargs = _delayed.pop(key)
rv = func(**kwargs)
Expand All @@ -24,10 +37,22 @@ def __getattr__(key):
other = globals().get(other_key, other_key)
rv._commutes_to = other
return rv
if key == "ss":
from .. import backend

if backend != "suitesparse":
raise AttributeError(
f'module {__name__!r} only has attribute "ss" when backend is "suitesparse"'
)
from importlib import import_module

ss = import_module(".ss", __name__)
globals()["ss"] = ss
return ss
raise AttributeError(f"module {__name__!r} has no attribute {key!r}")


from ..core import operator # noqa: E402 isort:skip
from . import numpy # noqa: E402, F401 isort:skip
from . import numpy # noqa: E402 isort:skip

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

del operator
2 changes: 1 addition & 1 deletion graphblas/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def __getattr__(name):
if name in {"ffi", "lib", "NULL"}:
from .. import _autoinit # noqa: F401
from .. import _autoinit

return globals()[name]
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Loading