[FIX] Table: Fix ensure_copy for sparse matrices#1456
Merged
astaric merged 1 commit intobiolab:masterfrom Jul 15, 2016
Merged
Conversation
Current coverage is 87.94%@@ master #1456 diff @@
==========================================
Files 77 77
Lines 7582 7584 +2
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 6667 6670 +3
+ Misses 915 914 -1
Partials 0 0
|
| """ | ||
| if self.X.base is not None: | ||
| if not sp.issparse(self.X) and self.X.base is not None: | ||
| self.X = self.X.copy() |
Contributor
There was a problem hiding this comment.
But if they are sparse, no copy is made?
Contributor
Author
There was a problem hiding this comment.
Currently not, this is left to the constructor. As far as I understand ensure_copy only ensures that the data is not a view and makes a copy if it is. Since sparse matrices do not have views (at least I think so) I propose to skip the check. Currently the copy is made in the constructor anyway and hence we probably do not need to make an other here.
Member
|
Could you also add a test for copy with sparse data? |
Contributor
Author
|
A simple test was added 😄 |
`ensure_copy` is checking whether an array is a view through the `.base` argument which doesn't exist on `scipy.sparse` matrices. Since `scipy.sparse` don't work with views (e.g. indexing returns a copy of the matrix) the check should only be performed for dense matrices.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ensure_copyis checking whether an array is a view through the.baseargument which doesn't exist onscipy.sparsematrices. Sincescipy.sparsedon't work with views (e.g. indexing returns a copy of the matrix) the check should only be performed for dense matrices.