-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create custom COO matrix representation for product operators #1635
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,54 @@ | ||
|
||
""" | ||
Sparse matrix representation for creating product space operators. | ||
""" | ||
|
||
__all__ = ('COOMatrix',) | ||
|
||
|
||
class COOMatrix(): | ||
""" | ||
Custom coo matrix representation for creating product space operators. | ||
|
||
The columns, rows and data are stored in separate lists such that | ||
A[i[k], j[k]] = data[k]. | ||
|
||
Note that, the class is only used as a container and does not provide | ||
any matrix operations. Further, no checks are performed on the data thus | ||
duplicate and out-of-order indices are allowed and the user is responsible | ||
for ensuring the correct shape of the matrix. | ||
|
||
""" | ||
|
||
def __init__(self, data, index, shape): | ||
|
||
# type check | ||
if len(data) != len(index[0]) or len(data) != len(index[1]): | ||
raise ValueError('data and index must have the same length') | ||
|
||
self.__data = data | ||
self.__index = index | ||
self.__shape = shape | ||
|
||
@property | ||
def row(self): | ||
"""Return the row indices of the matrix.""" | ||
return self.__index[0] | ||
|
||
@property | ||
def col(self): | ||
"""Return the column indices of the matrix.""" | ||
return self.__index[1] | ||
|
||
@property | ||
def shape(self): | ||
"""Return the shape of the matrix.""" | ||
return self.__shape | ||
|
||
@property | ||
def data(self): | ||
"""Return the data of the matrix.""" | ||
return self.__data | ||
|
||
def __repr__(self): | ||
return f"COO matrix({self.data}, {self.index})" |
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 |
---|---|---|
|
@@ -323,7 +323,7 @@ def noise_array(space): | |
""" | ||
from odl.space import ProductSpace | ||
if isinstance(space, ProductSpace): | ||
return np.array([noise_array(si) for si in space]) | ||
return np.array([noise_array(si) for si in space], dtype=object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handled by #1640 |
||
else: | ||
if space.dtype == bool: | ||
arr = np.random.randint(0, 2, size=space.shape, dtype=bool) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be in this PR, this is subject of #1638