ENH: allow addition/substraction of 0 to a sparse matrix #171

Merged
merged 3 commits into from Mar 12, 2012

Conversation

Projects
None yet
2 participants
Member

dlax commented Feb 29, 2012

No description provided.

Member

jakevdp commented Feb 29, 2012

I'd change the error text to specify "adding a nonzero scalar..."

Member

jakevdp commented Feb 29, 2012

Also, this behavior may lead to some confusion: with dense matrices, adding zero returns a copy. Sparse matrices should probably behave the same way to be consistent.

Member

dlax commented Feb 29, 2012

Jacob Vanderplas wrote:

I'd change the error text to specify "adding a nonzero scalar..."

Also, this behavior may lead to some confusion: with dense matrices, adding zero returns a copy. Sparse matrices should probably behave the same way to be consistent.

Done.

Member

jakevdp commented Feb 29, 2012

Out of curiosity, what use case do you have in mind for this? I can't think of any case where I'd want to add a scalar to a matrix, raising an error unless the scalar is zero. That would essentially require me to explicitly check to see if the scalar is zero before the operation. But if I know it's zero, why would I do this operation, except as a roundabout path to a matrix copy?

Member

dlax commented Feb 29, 2012

Jacob Vanderplas wrote:

Out of curiosity, what use case do you have in mind for this?

sum(a_list_of_sparse_matrices)

Member

jakevdp commented Mar 1, 2012

Makes sense!

Member

dlax commented Mar 12, 2012

I'd like to merge this soon unless somebody objects.

Member

jakevdp commented Mar 12, 2012

Sorry - I lost track of this in all the buzz around pycon!
Before merge, we'll need a unit test for this feature.

Member

dlax commented Mar 12, 2012

Jacob Vanderplas wrote:

Before merge, we'll need a unit test for this feature.

Test added.

By the way, there's a test in test_construct/test_diags_bad that
appears to fail in this branch but not in master. I'm not sure why this
happens but this may be related the merge of #167.

Member

jakevdp commented Mar 12, 2012

Nice work on the test, I'll merge this now.
If you could write the scipy-dev list with the traceback for the test_diags_bad error, that would be very helpful.

@jakevdp jakevdp added a commit that referenced this pull request Mar 12, 2012

@jakevdp jakevdp Merge pull request #171 from dlaxalde/enh/sparse/add-0
ENH: allow addition/substraction of 0 to a sparse matrix
c606186

@jakevdp jakevdp merged commit c606186 into scipy:master Mar 12, 2012

Member

dlax commented Mar 12, 2012

Jacob Vanderplas wrote:

If you could write the scipy-dev list with the traceback for the test_diags_bad error, that would be very helpful.

The test failure was only in the topic branch. Now that you've merged
into master, there's no more failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment