Skip to content

.wait return self so it can be used with method-chaining #379

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 4 commits into from
Feb 8, 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 graphblas/core/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ def wait(self, how="materialize"):
else:
raise ValueError(f'`how` argument must be "materialize" or "complete"; got {how!r}')
call("GrB_Matrix_wait", [self, mode])
return self

def get(self, row, col, default=None):
"""Get an element at (``row``, ``col``) indices as a Python scalar.
Expand Down
1 change: 1 addition & 0 deletions graphblas/core/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ def wait(self, how="materialize"):
raise ValueError(f'`how` argument must be "materialize" or "complete"; got {how!r}')
if not self._is_cscalar:
call("GrB_Scalar_wait", [self, mode])
return self

def get(self, default=None):
"""Get the internal value of the Scalar as a Python scalar.
Expand Down
1 change: 1 addition & 0 deletions graphblas/core/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ def wait(self, how="materialize"):
else:
raise ValueError(f'`how` argument must be "materialize" or "complete"; got {how!r}')
call("GrB_Vector_wait", [self, mode])
return self

def get(self, index, default=None):
"""Get an element at ``index`` as a Python scalar.
Expand Down
6 changes: 6 additions & 0 deletions graphblas/tests/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4234,6 +4234,12 @@ def test_ss_descriptors(A):
(A @ A).new(nthreads=4, axb_method="dot", sort=True)


@autocompute
def test_wait_chains(A):
result = A.wait().T.wait().reduce_rowwise().wait().reduce().wait()
assert result == 47


def test_subarray_dtypes():
a = np.arange(3 * 4, dtype=np.int64).reshape(3, 4)
A = Matrix.from_coo([1, 3, 5], [0, 1, 3], a)
Expand Down