Skip to content

Commit

Permalink
Use default values of 1.0 for from_* methods of Vector and Matrix (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw authored Jan 25, 2023
1 parent c54a274 commit 436e329
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
20 changes: 10 additions & 10 deletions graphblas/core/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def from_coo(
cls,
rows,
columns,
values,
values=1.0,
dtype=None,
*,
nrows=None,
Expand All @@ -810,7 +810,7 @@ def from_coo(
Row indices.
columns : list or np.ndarray
Column indices.
values : list or np.ndarray or scalar
values : list or np.ndarray or scalar, default 1.0
List of values. If a scalar is provided, all values will be set to this single value.
dtype :
Data type of the Matrix. If not provided, the values will be inspected
Expand Down Expand Up @@ -948,7 +948,7 @@ def _from_csx(cls, fmt, indptr, indices, values, dtype, num, check_num, name):

@classmethod
def from_csr(
cls, indptr, col_indices, values, dtype=None, *, nrows=None, ncols=None, name=None
cls, indptr, col_indices, values=1.0, dtype=None, *, nrows=None, ncols=None, name=None
):
"""Create a new Matrix from standard CSR representation of data.
Expand All @@ -964,7 +964,7 @@ def from_csr(
Pointers for each row into col_indices and values; `indptr.size == nrows + 1`.
col_indices : list or np.ndarray
Column indices.
values : list or np.ndarray or scalar
values : list or np.ndarray or scalar, default 1.0
List of values. If a scalar is provided, all values will be set to this single value.
dtype :
Data type of the Matrix. If not provided, the values will be inspected
Expand Down Expand Up @@ -994,7 +994,7 @@ def from_csr(

@classmethod
def from_csc(
cls, indptr, row_indices, values, dtype=None, *, nrows=None, ncols=None, name=None
cls, indptr, row_indices, values=1.0, dtype=None, *, nrows=None, ncols=None, name=None
):
"""Create a new Matrix from standard CSC representation of data.
Expand All @@ -1010,7 +1010,7 @@ def from_csc(
Pointers for each column into row_indices and values; `indptr.size == ncols + 1`.
col_indices : list or np.ndarray
Column indices.
values : list or np.ndarray or scalar
values : list or np.ndarray or scalar, default 1.0
List of values. If a scalar is provided, all values will be set to this single value.
dtype :
Data type of the Matrix. If not provided, the values will be inspected
Expand Down Expand Up @@ -1044,7 +1044,7 @@ def from_dcsr(
compressed_rows,
indptr,
col_indices,
values,
values=1.0,
dtype=None,
*,
nrows=None,
Expand All @@ -1069,7 +1069,7 @@ def from_dcsr(
Pointers for each non-empty row into col_indices and values.
col_indices : list or np.ndarray
Column indices.
values : list or np.ndarray or scalar
values : list or np.ndarray or scalar, default 1.0
List of values. If a scalar is provided, all values will be set to this single value.
dtype :
Data type of the Matrix. If not provided, the values will be inspected
Expand Down Expand Up @@ -1127,7 +1127,7 @@ def from_dcsc(
compressed_cols,
indptr,
row_indices,
values,
values=1.0,
dtype=None,
*,
nrows=None,
Expand All @@ -1152,7 +1152,7 @@ def from_dcsc(
Pointers for each non-empty columns into row_indices and values.
row_indices : list or np.ndarray
Row indices.
values : list or np.ndarray or scalar
values : list or np.ndarray or scalar, default 1.0
List of values. If a scalar is provided, all values will be set to this single value.
dtype :
Data type of the Matrix. If not provided, the values will be inspected
Expand Down
4 changes: 2 additions & 2 deletions graphblas/core/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,14 @@ def from_values(cls, indices, values, dtype=None, *, size=None, dup_op=None, nam
return cls.from_coo(indices, values, dtype, size=size, dup_op=dup_op, name=name)

@classmethod
def from_coo(cls, indices, values, dtype=None, *, size=None, dup_op=None, name=None):
def from_coo(cls, indices, values=1.0, dtype=None, *, size=None, dup_op=None, name=None):
"""Create a new Vector from indices and values.
Parameters
----------
indices : list or np.ndarray
Vector indices.
values : list or np.ndarray or scalar
values : list or np.ndarray or scalar, default 1.0
List of values. If a scalar is provided, all values will be set to this single value.
dtype :
Data type of the Vector. If not provided, the values will be inspected
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 @@ -176,6 +176,12 @@ def test_from_coo_scalar():
C.ss.iso_value


def test_from_coo_default_values():
B = Matrix.from_coo([1, 3], [2, 4])
C = Matrix.from_coo([1, 3], [2, 4], [1.0, 1.0])
assert B.isequal(C, check_dtype=True)


def test_clear(A):
A.clear()
assert A.nvals == 0
Expand Down
6 changes: 6 additions & 0 deletions graphblas/tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ def test_from_coo_scalar():
u.ss.iso_value


def test_from_coo_default_values():
u = Vector.from_coo([1, 3])
v = Vector.from_coo([1, 3], [1.0, 1.0])
assert v.isequal(u, check_dtype=True)


def test_clear(v):
v.clear()
assert v.nvals == 0
Expand Down

0 comments on commit 436e329

Please sign in to comment.