Skip to content

Commit

Permalink
More linting (python-graphblas#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw authored Jan 22, 2023
1 parent 3380e04 commit f66d8c8
Show file tree
Hide file tree
Showing 38 changed files with 274 additions and 283 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ repos:
additional_dependencies: [tomli]
files: ^(graphblas|docs)/
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.227
rev: v0.0.229
hooks:
- id: ruff
args: [--force-exclude]
Expand Down
2 changes: 1 addition & 1 deletion graphblas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_config():


def __getattr__(name):
"""Auto-initialize if special attrs used without explicit init call by user"""
"""Auto-initialize if special attrs used without explicit init call by user."""
if name in _SPECIAL_ATTRS:
if _init_params is None:
_init("suitesparse", None, automatic=True)
Expand Down
2 changes: 1 addition & 1 deletion graphblas/binary/numpy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Create UDFs of numpy functions supported by numba.
"""Create UDFs of numpy functions supported by numba.
See list of numpy ufuncs supported by numpy here:
Expand Down
2 changes: 1 addition & 1 deletion graphblas/core/agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def _get_types(ops, initdtype):
"""Determine the input and output types of an aggregator based on a list of ops"""
"""Determine the input and output types of an aggregator based on a list of ops."""
if initdtype is None:
prev = dict(ops[0].types)
else:
Expand Down
2 changes: 1 addition & 1 deletion graphblas/core/automethods.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Define functions to use as property methods on expressions.
"""Define functions to use as property methods on expressions.
These will automatically compute the value and avoid the need for `.new()`.
Expand Down
6 changes: 2 additions & 4 deletions graphblas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ def __lshift__(self, expr, **opts):
return self._update(expr, opts=opts)

def update(self, expr, **opts):
"""
Convenience function when no output arguments (mask, accum, replace) are used
"""
"""Convenience function when no output arguments (mask, accum, replace) are used."""
return self._update(expr, opts=opts)

def _update(self, expr, mask=None, accum=None, replace=False, input_mask=None, *, opts):
Expand Down Expand Up @@ -497,7 +495,7 @@ def _update(self, expr, mask=None, accum=None, replace=False, input_mask=None, *

@property
def _name_html(self):
"""Treat characters after _ as subscript"""
"""Treat characters after _ as subscript."""
split = self.name.split("_", 1)
if len(split) == 1:
return self.name
Expand Down
7 changes: 4 additions & 3 deletions graphblas/core/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _expr_name(self):
return f"[{', '.join(map(str, idx[:3]))}, ...]"

def _py_index(self):
"""Convert resolved index back into a valid Python index"""
"""Convert resolved index back into a valid Python index."""
if self.size is None:
return self.index.value
if self.index is _ALL_INDICES:
Expand Down Expand Up @@ -149,6 +149,7 @@ def py_indices(self):
def parse_indices(self, indices, shape):
"""
Returns
-------
[(rows, rowsize), (cols, colsize)] for Matrix
[(idx, idx_size)] for Vector
Expand Down Expand Up @@ -251,7 +252,7 @@ def parse_index(self, index, typ, size):
return self.parse_index(np.array(index), np.ndarray, size)

def get_index(self, dim):
"""Return a new IndexerResolver with index for the selected dimension"""
"""Return a new IndexerResolver with index for the selected dimension."""
rv = object.__new__(IndexerResolver)
rv.obj = self.obj
rv.indices = (self.indices[dim],)
Expand Down Expand Up @@ -327,7 +328,7 @@ def new(self, dtype=None, *, mask=None, input_mask=None, name=None, **opts):
return delayed_extractor.new(dtype, mask=mask, name=name, **opts)

def _extract_delayed(self):
"""Return an Expression object, treating this as an extract call"""
"""Return an Expression object, treating this as an extract call."""
return self.parent._prep_for_extract(self.resolved_indexes)

def _input_mask_to_mask(self, input_mask, **opts):
Expand Down
62 changes: 31 additions & 31 deletions graphblas/core/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,22 @@ def _name_html(self):
# CS: complemented structural
# CV: complemented value
def _combine_S_S(m1, m2, dtype, name, opts):
"""S-S"""
"""S-S."""
return pair(m1.parent & m2.parent).new(dtype, name=name, **opts)


def _combine_S_A(m1, m2, dtype, name, opts):
"""S-S, S-V, S-CS, S-CV"""
"""S-S, S-V, S-CS, S-CV."""
return one(m1.parent).new(dtype, mask=m2, name=name, **opts)


def _combine_A_S(m1, m2, dtype, name, opts):
"""S-S, V-S, CS-S, CV-S"""
"""S-S, V-S, CS-S, CV-S."""
return one(m2.parent).new(dtype, mask=m1, name=name, **opts)


def _combine_V_A(m1, m2, dtype, name, opts):
"""V-S, V-V, V-CS, V-CV"""
"""V-S, V-V, V-CS, V-CV."""
if isinstance(m2, ValueMask) and m1.parent._nvals > m2.parent._nvals:
m1, m2 = m2, m1
val = valuene(m1.parent).new(dtype, mask=m2, name=name, **opts)
Expand All @@ -233,36 +233,36 @@ def _combine_V_A(m1, m2, dtype, name, opts):


def _combine_A_V(m1, m2, dtype, name, opts):
"""S-V, V-V, CS-V, CV-V"""
"""S-V, V-V, CS-V, CV-V."""
val = valuene(m2.parent).new(dtype, mask=m1, name=name, **opts)
if dtype != BOOL or backend != "suitesparse" or not val.ss.is_iso:
val(val.S, **opts) << True
return val


def _combine_CS_CS(m1, m2, dtype, name, opts):
"""CS-CS"""
"""CS-CS."""
val = pair(m1.parent | m2.parent).new(dtype, name=name, **opts)
val(~val.S, replace=True, **opts) << True
return val


def _combine_CS_CV(m1, m2, dtype, name, opts):
"""CS-CV"""
"""CS-CV."""
val = pair(one(m1.parent).new(**opts) | m2.parent).new(dtype, name=name, **opts)
val(~val.V, replace=True, **opts) << True
return val


def _combine_CV_CS(m1, m2, dtype, name, opts):
"""CV-CS"""
"""CV-CS."""
val = pair(m1.parent | one(m2.parent).new(**opts)).new(dtype, name=name, **opts)
val(~val.V, replace=True, **opts) << True
return val


def _combine_CV_CV(m1, m2, dtype, name, opts):
"""CV-CV"""
"""CV-CV."""
val = lor(m1.parent | m2.parent).new(dtype, name=name, **opts)
val(~val.V, replace=True, **opts) << True
return val
Expand Down Expand Up @@ -300,84 +300,84 @@ def _combine_CV_CV(m1, m2, dtype, name, opts):

# Recipes to return the *complement* of combining two masks
def _complement_S_S(m1, m2, dtype, name, opts):
"""S-S"""
"""S-S."""
val = pair(m1.parent & m2.parent).new(dtype, name=name, **opts)
val(~val.S, replace=True, **opts) << True
return val


def _complement_S_A(m1, m2, dtype, name, opts):
"""S-S, S-V, S-CS, S-CV"""
"""S-S, S-V, S-CS, S-CV."""
val = one(m1.parent).new(dtype, mask=m2, name=name, **opts)
val(~val.S, replace=True, **opts) << True
return val


def _complement_A_S(m1, m2, dtype, name, opts):
"""S-S, V-S, CS-S, CV-S"""
"""S-S, V-S, CS-S, CV-S."""
val = one(m2.parent).new(dtype, mask=m1, name=name, **opts)
val(~val.S, replace=True, **opts) << True
return val


def _complement_V_V(m1, m2, dtype, name, opts):
"""V-V"""
"""V-V."""
val = land(m1.parent & m2.parent).new(dtype, name=name, **opts)
val(~val.V, replace=True, **opts) << True
return val


def _complement_CS_CS(m1, m2, dtype, name, opts):
"""CS-CS"""
"""CS-CS."""
return pair(one(m1.parent).new(**opts) | one(m2.parent).new(**opts)).new(
dtype, name=name, **opts
)


def _complement_CS_A(m1, m2, dtype, name, opts):
"""CS-S, CS-V, CS-CS, CS-CV"""
"""CS-S, CS-V, CS-CS, CS-CV."""
val = one(m1.parent).new(dtype, name=name, **opts)
val(~m2, **opts) << True
return val


def _complement_A_CS(m1, m2, dtype, name, opts):
"""S-CS, V-CS, CS-CS, CV-CS"""
"""S-CS, V-CS, CS-CS, CV-CS."""
val = one(m2.parent).new(dtype, name=name, **opts)
val(~m1, **opts) << True
return val


def _complement_CS_CV(m1, m2, dtype, name, opts):
"""CS-CV"""
"""CS-CV."""
val = pair(one(m1.parent).new(**opts) | m2.parent).new(dtype, name=name, **opts)
val(val.V, replace=True, **opts) << True
return val


def _complement_CV_CS(m1, m2, dtype, name, opts):
"""CV-CS"""
"""CV-CS."""
val = pair(m1.parent | one(m2.parent).new(**opts)).new(dtype, name=name, **opts)
val(val.V, replace=True, **opts) << True
return val


def _complement_CV_CV(m1, m2, dtype, name, opts):
"""CV-CV"""
"""CV-CV."""
val = lor(m1.parent | m2.parent).new(dtype, name=name, **opts)
val(val.V, replace=True, **opts) << True
return val


def _complement_CV_A(m1, m2, dtype, name, opts):
"""CV-S, CV-V, CV-CS, CV-CV"""
"""CV-S, CV-V, CV-CS, CV-CV."""
val = one(m1.parent).new(dtype, mask=~m1, name=name, **opts)
val(~m2, **opts) << True
return val


def _complement_A_CV(m1, m2, dtype, name, opts):
"""S-CV, V-CV, CS-CV, CV-CV"""
"""S-CV, V-CV, CS-CV, CV-CV."""
val = one(m2.parent).new(dtype, mask=~m2, name=name, **opts)
val(~m1, **opts) << True
return val
Expand Down Expand Up @@ -414,69 +414,69 @@ def _complement_A_CV(m1, m2, dtype, name, opts):


def _combine_S_S_mask_or(m1, m2, opts):
"""S-S"""
"""S-S."""
val = monoid.any(one(m1.parent).new(bool, **opts) | one(m2.parent).new(bool, **opts)).new(
**opts
)
return StructuralMask(val)


def _combine_S_SV_mask_or(m1, m2, opts):
"""S-V"""
"""S-V."""
val = monoid.any(
one(m1.parent).new(bool, **opts) | one(m2.parent).new(bool, mask=m2, **opts)
).new(**opts)
return StructuralMask(val)


def _combine_SV_S_mask_or(m1, m2, opts):
"""V-S"""
"""V-S."""
val = monoid.any(
one(m1.parent).new(bool, mask=m1, **opts) | one(m2.parent).new(bool, **opts)
).new(**opts)
return StructuralMask(val)


def _complement_A_CS_mask_or(m1, m2, opts):
"""~S-CS, ~V-CS, ~CV-CS"""
"""~S-CS, ~V-CS, ~CV-CS."""
val = one(m2.parent).new(bool, mask=~m1, **opts)
return ComplementedStructuralMask(val)


def _complement_CS_A_mask_or(m1, m2, opts):
"""~CS-S, ~CS-V, ~CS-CV"""
"""~CS-S, ~CS-V, ~CS-CV."""
val = one(m1.parent).new(bool, mask=~m2, **opts)
return ComplementedStructuralMask(val)


def _complement_A_CV_mask_or(m1, m2, opts):
"""~S-CV, ~V-CV"""
"""~S-CV, ~V-CV."""
val = valuene(m2.parent).new(bool, mask=~m1, **opts)
return ComplementedStructuralMask(val)


def _complement_CV_A_mask_or(m1, m2, opts):
"""~CV-S, ~CV-V"""
"""~CV-S, ~CV-V."""
val = valuene(m1.parent).new(bool, mask=~m2, **opts)
return ComplementedStructuralMask(val)


def _combine_V_V_mask_or(m1, m2, opts):
"""V-V"""
"""V-V."""
val = monoid.any(valuene(m1.parent).new(**opts) | valuene(m2.parent).new(**opts)).new(
bool, **opts
)
return StructuralMask(val)


def _complement_CS_CS_mask_or(m1, m2, opts):
"""~CS-CS"""
"""~CS-CS."""
val = pair(m1.parent & m2.parent).new(bool, **opts)
return ComplementedStructuralMask(val)


def _complement_CV_CV_mask_or(m1, m2, opts):
"""~CV-CV"""
"""~CV-CV."""
val = valuene(land(m1.parent & m2.parent).new(bool, **opts)).new(**opts)
return ComplementedStructuralMask(val)

Expand Down
Loading

0 comments on commit f66d8c8

Please sign in to comment.