From 4c2919358830055fd80bda6d71c09588d03f9eb5 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Sun, 5 Nov 2023 11:17:12 -0600 Subject: [PATCH 1/4] Add `gb.INDEX_MAX`, which is `GrB_INDEX_MAX` This is the largest index, not the size of the domain of indices. For example, create the largest vector via `Vector(int, INDEX_MAX + 1)`. Also, note that the spec does not specify a value for `GrB_INDEX_MAX`, only that the implementation define it, so it may be backend-dependent. --- graphblas/__init__.py | 5 +++++ graphblas/tests/test_core.py | 4 ++++ scripts/test_imports.sh | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/graphblas/__init__.py b/graphblas/__init__.py index a9895cb6a..a689e02bf 100644 --- a/graphblas/__init__.py +++ b/graphblas/__init__.py @@ -39,6 +39,7 @@ def get_config(): backend = None _init_params = None _SPECIAL_ATTRS = { + "INDEX_MAX", "Matrix", "Recorder", "Scalar", @@ -205,6 +206,10 @@ def _load(name): if name in {"Matrix", "Vector", "Scalar", "Recorder"}: module = _import_module(f".core.{name.lower()}", __name__) globals()[name] = getattr(module, name) + elif name == "INDEX_MAX": + from .core import lib + + globals()[name] = lib.GrB_INDEX_MAX else: # Everything else is a module globals()[name] = _import_module(f".{name}", __name__) diff --git a/graphblas/tests/test_core.py b/graphblas/tests/test_core.py index 003affc6c..f3e8f5e8b 100644 --- a/graphblas/tests/test_core.py +++ b/graphblas/tests/test_core.py @@ -90,3 +90,7 @@ def test_packages(): assert ( pkgs == pkgs2 ), "If there are extra items on the left, add them to pyproject.toml:tool.setuptools.packages" + + +def test_index_max(): + assert gb.INDEX_MAX == 2**60 - 1 # True for all current backends diff --git a/scripts/test_imports.sh b/scripts/test_imports.sh index cc989ef06..41dbb1be5 100755 --- a/scripts/test_imports.sh +++ b/scripts/test_imports.sh @@ -13,7 +13,7 @@ if ! python -c "from graphblas.select import tril" ; then exit 1 ; fi if ! python -c "from graphblas.semiring import plus_times" ; then exit 1 ; fi if ! python -c "from graphblas.unary import exp" ; then exit 1 ; fi if ! (for attr in Matrix Scalar Vector Recorder agg binary dtypes exceptions \ - init io monoid op select semiring tests unary ss viz + init io monoid op select semiring tests unary ss viz INDEX_MAX do echo python -c \"from graphblas import $attr\" if ! python -c "from graphblas import $attr" then exit 1 From df46b919222947259645ad43d022be5e612d040e Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Sun, 5 Nov 2023 13:15:40 -0600 Subject: [PATCH 2/4] `MAX_SIZE` instead of `INDEX_MAX` --- graphblas/__init__.py | 6 +++--- graphblas/tests/test_core.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/graphblas/__init__.py b/graphblas/__init__.py index a689e02bf..f3816f297 100644 --- a/graphblas/__init__.py +++ b/graphblas/__init__.py @@ -39,7 +39,7 @@ def get_config(): backend = None _init_params = None _SPECIAL_ATTRS = { - "INDEX_MAX", + "MAX_SIZE", "Matrix", "Recorder", "Scalar", @@ -206,10 +206,10 @@ def _load(name): if name in {"Matrix", "Vector", "Scalar", "Recorder"}: module = _import_module(f".core.{name.lower()}", __name__) globals()[name] = getattr(module, name) - elif name == "INDEX_MAX": + elif name == "MAX_SIZE": from .core import lib - globals()[name] = lib.GrB_INDEX_MAX + globals()[name] = lib.GrB_INDEX_MAX + 1 else: # Everything else is a module globals()[name] = _import_module(f".{name}", __name__) diff --git a/graphblas/tests/test_core.py b/graphblas/tests/test_core.py index f3e8f5e8b..3586eb4a8 100644 --- a/graphblas/tests/test_core.py +++ b/graphblas/tests/test_core.py @@ -93,4 +93,4 @@ def test_packages(): def test_index_max(): - assert gb.INDEX_MAX == 2**60 - 1 # True for all current backends + assert gb.MAX_SIZE == 2**60 # True for all current backends From 543bc1dc99ef09b049e4b71e7ec5e55a51dc9709 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Sun, 5 Nov 2023 13:17:00 -0600 Subject: [PATCH 3/4] Add code comment --- graphblas/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphblas/__init__.py b/graphblas/__init__.py index f3816f297..63110eeeb 100644 --- a/graphblas/__init__.py +++ b/graphblas/__init__.py @@ -39,7 +39,7 @@ def get_config(): backend = None _init_params = None _SPECIAL_ATTRS = { - "MAX_SIZE", + "MAX_SIZE", # The maximum size of Vector and Matrix dimensions (GrB_INDEX_MAX + 1) "Matrix", "Recorder", "Scalar", From 31da669f0a9710a17de0196acd6727dfd817e2e4 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Sun, 5 Nov 2023 13:19:14 -0600 Subject: [PATCH 4/4] haha, oops --- scripts/test_imports.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test_imports.sh b/scripts/test_imports.sh index 41dbb1be5..6ce88c83e 100755 --- a/scripts/test_imports.sh +++ b/scripts/test_imports.sh @@ -13,7 +13,7 @@ if ! python -c "from graphblas.select import tril" ; then exit 1 ; fi if ! python -c "from graphblas.semiring import plus_times" ; then exit 1 ; fi if ! python -c "from graphblas.unary import exp" ; then exit 1 ; fi if ! (for attr in Matrix Scalar Vector Recorder agg binary dtypes exceptions \ - init io monoid op select semiring tests unary ss viz INDEX_MAX + init io monoid op select semiring tests unary ss viz MAX_SIZE do echo python -c \"from graphblas import $attr\" if ! python -c "from graphblas import $attr" then exit 1