Skip to content

Commit

Permalink
.wait return self so it can be used with method-chaining (python-…
Browse files Browse the repository at this point in the history
…graphblas#379)

* `.chain` return `self` so it can be used with method-chaining
  • Loading branch information
eriknw authored Feb 8, 2023
1 parent 81f9d9e commit 1bbce69
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
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 @@ -464,6 +464,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 @@ -4228,6 +4228,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

0 comments on commit 1bbce69

Please sign in to comment.