Skip to content
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

Fix bug in sparse matrix indexing #1651

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions odl/util/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Sparse matrix representation for creating product space operators.
"""

import numpy as np

__all__ = ('COOMatrix',)


Expand All @@ -27,18 +29,19 @@ def __init__(self, data, index, shape):
raise ValueError('data and index must have the same length')

self.__data = data
self.__index = index
self.__row_index = np.asarray(index[0])
self.__col_index = np.asarray(index[1])
self.__shape = shape

@property
def row(self):
"""Return the row indices of the matrix."""
return self.__index[0]
return self.__row_index

@property
def col(self):
"""Return the column indices of the matrix."""
return self.__index[1]
return self.__col_index

@property
def shape(self):
Expand All @@ -51,4 +54,5 @@ def data(self):
return self.__data

def __repr__(self):
return f"COO matrix({self.data}, {self.index})"
return ( f"COO matrix({self.data},"
+ f"({self.__row_index}, {self.__col_index}), {self.shape})" )