Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 8, 2024
1 parent 1572dba commit c2bf661
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
16 changes: 4 additions & 12 deletions src/mopsy/adders.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
__license__ = "MIT"


def append_row(
mat: sp.sparse.spmatrix, row: Union[sp.sparse.spmatrix, np.ndarray]
) -> sp.sparse.spmatrix:
def append_row(mat: sp.sparse.spmatrix, row: Union[sp.sparse.spmatrix, np.ndarray]) -> sp.sparse.spmatrix:
"""A generic append function for sparse matrices.
Args:
Expand All @@ -32,9 +30,7 @@ def append_row(
return sparse_append(mat=mat, row_or_column=row, axis=0)


def append_col(
mat: sp.sparse.spmatrix, col: Union[sp.sparse.spmatrix, np.ndarray]
) -> sp.sparse.spmatrix:
def append_col(mat: sp.sparse.spmatrix, col: Union[sp.sparse.spmatrix, np.ndarray]) -> sp.sparse.spmatrix:
"""A generic append function for sparse matrices.
Args:
Expand Down Expand Up @@ -89,16 +85,12 @@ def sparse_append(
new_mat = None
if axis == 0:
if mat.shape[0] != row_or_column.shape[0]:
raise TypeError(
"Matrix and new row do not have the same shape along the first dimension."
)
raise TypeError("Matrix and new row do not have the same shape along the first dimension.")

new_mat = sp.sparse.vstack([mat, row_or_column])
else:
if mat.shape[1] != row_or_column.shape[0]:
raise TypeError(
"Matrix and new row do not have the same shape along the second dimension."
)
raise TypeError("Matrix and new row do not have the same shape along the second dimension.")

new_mat = sp.sparse.hstack([mat, row_or_column])

Expand Down
7 changes: 1 addition & 6 deletions src/mopsy/mops.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ def groupby_indices(self, group: Sequence) -> dict:
A dictionary with each group name as the key and the values containing
the list of indices that map to it.
"""
return {
k: [x[0] for x in v]
for k, v in groupby(
sorted(enumerate(group), key=lambda x: x[1]), lambda x: x[1]
)
}
return {k: [x[0] for x in v] for k, v in groupby(sorted(enumerate(group), key=lambda x: x[1]), lambda x: x[1])}

def _apply(self, func: Callable[[list], Any], axis: Union[int, bool]):
if self.non_zero:
Expand Down
4 changes: 1 addition & 3 deletions src/mopsy/nops.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class Nops(Mops):
def __init__(self, mat: np.ndarray, non_zero: bool = False) -> None:
super().__init__(mat, non_zero=non_zero)

def iter(
self, group: Sequence[str] = None, axis: Union[int, bool] = 0
) -> Iterator[Tuple]:
def iter(self, group: Sequence[str] = None, axis: Union[int, bool] = 0) -> Iterator[Tuple]:
"""Iterator over groups and an axis.
Args:
Expand Down
4 changes: 1 addition & 3 deletions src/mopsy/sops.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def iter(self, group: list = None, axis: Union[int, bool] = 0) -> Iterator[Tuple
else:
yield (k, Sops(mat[:, v], self.non_zero))

def _apply(
self, func: Callable[[list], Any], axis: Union[int, bool] = 0
) -> np.ndarray:
def _apply(self, func: Callable[[list], Any], axis: Union[int, bool] = 0) -> np.ndarray:
mat = self.matrix.tocsc() if axis == 0 else self.matrix.tocsr()
if self.non_zero:
# reduction along an axis
Expand Down

0 comments on commit c2bf661

Please sign in to comment.