Skip to content

Commit

Permalink
Update v.diag() to use GrB_Matrix_diag
Browse files Browse the repository at this point in the history
Also, run slow tests less often in CI
  • Loading branch information
eriknw committed Apr 11, 2022
1 parent 0156352 commit 612662c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion grblas/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def pytest_configure(config):
mapnumpy = np.random.rand() < 0.5 if randomly else False
runslow = config.getoption("--runslow", False)
if runslow is None:
runslow = np.random.rand() < 0.5 if randomly else False
runslow = np.random.rand() < 0.25 if randomly else False
config.runslow = runslow

gb.config.set(autocompute=False, mapnumpy=mapnumpy)
Expand Down
17 changes: 10 additions & 7 deletions grblas/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from . import _automethods, backend, binary, ffi, lib, monoid, semiring, utils
from ._ss.vector import ss
from .base import BaseExpression, BaseType, call
from .dtypes import _INDEX, FP64, lookup_dtype, unify
from .dtypes import _INDEX, FP64, INT64, lookup_dtype, unify
from .exceptions import DimensionMismatch, NoValue, check_status
from .expr import AmbiguousAssignOrExtract, IndexerResolver, Updater
from .mask import StructuralMask, ValueMask
Expand Down Expand Up @@ -318,19 +318,22 @@ def dup(self, dtype=None, *, mask=None, name=None):
rv = Vector(dtype, size=self._size, name=name)
rv(mask=mask)[...] = self
else:
new_vec = ffi_new("GrB_Vector*")
rv = Vector._from_obj(new_vec, self.dtype, self._size, name=name)
rv = Vector._from_obj(ffi_new("GrB_Vector*"), self.dtype, self._size, name=name)
call("GrB_Vector_dup", [_Pointer(rv), self])
return rv

def diag(self, k=0, dtype=None, *, name=None):
def diag(self, k=0, *, name=None):
"""
GrB_diag
GrB_Matrix_diag
Create a Matrix whose kth diagonal is this Vector
"""
from .ss._core import diag
from .matrix import Matrix

return diag(self, k=k, dtype=dtype, name=name)
k = _as_scalar(k, INT64, is_cscalar=True)
n = self._size + abs(k.value)
rv = Matrix._from_obj(ffi_new("GrB_Matrix*"), self.dtype, n, n, name=name)
call("GrB_Matrix_diag", [_Pointer(rv), self, k])
return rv

def wait(self):
"""
Expand Down

0 comments on commit 612662c

Please sign in to comment.