-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add convenience methods to monkey patch
__repr__
methods
- Loading branch information
Showing
6 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Copyright (C) 2023 Adam Lugowski. | ||
# Use of this source code is governed by the BSD 2-clause license found in the LICENSE.txt file. | ||
# SPDX-License-Identifier: BSD-2-Clause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (C) 2023 Adam Lugowski. | ||
# Use of this source code is governed by the BSD 2-clause license found in the LICENSE.txt file. | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
""" | ||
Import this module to automatically print python-graphblas `Matrix` and `Vector` using MatRepr. | ||
A `__repr__` method that calls MatRepr is inserted to those classes. | ||
Also includes all public methods from the matrepr module for convenient one-line imports. | ||
""" | ||
|
||
from .. import * | ||
|
||
import graphblas | ||
|
||
|
||
def _str_(mat): | ||
return to_str(mat) | ||
|
||
|
||
graphblas.Matrix.__repr__ = _str_ | ||
graphblas.Vector.__repr__ = _str_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (C) 2023 Adam Lugowski. | ||
# Use of this source code is governed by the BSD 2-clause license found in the LICENSE.txt file. | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
""" | ||
Import this module to automatically print SciPy sparse matrices using MatRepr. | ||
A `__repr__` method that calls MatRepr is inserted to all SciPy sparse matrix classes. | ||
Also includes all public methods from the matrepr module for convenient one-line imports. | ||
""" | ||
|
||
from .. import * | ||
|
||
import scipy.sparse | ||
|
||
|
||
def _str_(mat): | ||
return to_str(mat) | ||
|
||
|
||
try: | ||
scipy.sparse.bsr_matrix.__repr__ = _str_ | ||
scipy.sparse.coo_matrix.__repr__ = _str_ | ||
scipy.sparse.csc_matrix.__repr__ = _str_ | ||
scipy.sparse.csr_matrix.__repr__ = _str_ | ||
scipy.sparse.dia_matrix.__repr__ = _str_ | ||
scipy.sparse.dok_matrix.__repr__ = _str_ | ||
scipy.sparse.lil_matrix.__repr__ = _str_ | ||
except AttributeError: | ||
pass | ||
|
||
try: | ||
scipy.sparse.bsr_array.__repr__ = _str_ | ||
scipy.sparse.coo_array.__repr__ = _str_ | ||
scipy.sparse.csc_array.__repr__ = _str_ | ||
scipy.sparse.csr_array.__repr__ = _str_ | ||
scipy.sparse.dia_array.__repr__ = _str_ | ||
scipy.sparse.dok_array.__repr__ = _str_ | ||
scipy.sparse.lil_array.__repr__ = _str_ | ||
except AttributeError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters