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

Added cases for sparse arrays in __mul__ and __rmul__ #17014

Merged
merged 1 commit into from Jun 12, 2019

Conversation

Projects
None yet
4 participants
@kangzhiq
Copy link
Contributor

commented Jun 11, 2019

References to other Issues or PRs

#16941 __mul__ and __rmul__

Brief description of what is fixed or changed

The multiplcation is cast to a list while calculating each term, which is unnecessary for the zero value in sparse array(since 0*x = 0). Thanks to the lazy-evaluation of iterator in NDimArray, this issue will not cause a MemoryError, but the operation is slow.
Before:

>>> a = ImmutableSparseNDimArray({1:2, 3:4}, (10000, 20000))
>>> b = 3*a
#Operation takes a lot of time

Now

>>> a = ImmutableSparseNDimArray({1:2, 3:4}, (10000, 20000))
>>> 3*a == ImmutableSparseNDimArray({1:6, 3:12}, (10000, 20000))

Since only the no-zero values in the dictionary are changed, this execution time is much ameliorated.
Tests are also added.

Other comments

Release Notes

  • tensor
    • Added specific case for sparse array in mul, rmul and tests
Added cases in __mul__ and test
- Added cases for sparse array in __mul__ and __rmul__
- Added tests for large scale sparse array for __mul__ and __rmul__
@sympy-bot

This comment has been minimized.

Copy link

commented Jun 11, 2019

Hi, I am the SymPy bot (v147). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • tensor
    • Added specific case for sparse array in mul, rmul and tests (#17014 by @kangzhiq)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.5.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234". See
https://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->
#16941 `__mul__` and `__rmul__`

#### Brief description of what is fixed or changed
The multiplcation is cast to a list while calculating each term, which is unnecessary for the zero value in sparse array(since 0*x = 0). Thanks to the lazy-evaluation of iterator in NDimArray, this issue will not cause a MemoryError, but the operation is slow.
Before:
```
>>> a = ImmutableSparseNDimArray({1:2, 3:4}, (10000, 20000))
>>> b = 3*a
#Operation takes a lot of time
```
Now
```
>>> a = ImmutableSparseNDimArray({1:2, 3:4}, (10000, 20000))
>>> 3*a == ImmutableSparseNDimArray({1:6, 3:12}, (10000, 20000))

```
Since only the no-zero values in the dictionary are changed, this execution time is much ameliorated.
Tests are also added.
#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* tensor
  * Added specific case for sparse array in __mul__, __rmul__ and tests

<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@codecov

This comment has been minimized.

Copy link

commented Jun 11, 2019

Codecov Report

Merging #17014 into master will increase coverage by 0.017%.
The diff coverage is 100%.

@@              Coverage Diff              @@
##            master    #17014       +/-   ##
=============================================
+ Coverage   74.126%   74.144%   +0.017%     
=============================================
  Files          620       620               
  Lines       160572    160578        +6     
  Branches     37677     37681        +4     
=============================================
+ Hits        119026    119059       +33     
+ Misses       36140     36116       -24     
+ Partials      5406      5403        -3
@@ -139,6 +139,10 @@ def test_sparse():
b[1, 1] = 2
assert a != b

# __mul__ and __rmul__
assert a * 3 == MutableSparseNDimArray({200001: 3}, (100000, 200000))
assert 3 * a == MutableSparseNDimArray({200001: 3}, (100000, 200000))

This comment has been minimized.

Copy link
@Upabjojr

Upabjojr Jun 12, 2019

Contributor

what happens if you multiply by zero?

@Upabjojr Upabjojr merged commit 00faa7e into sympy:master Jun 12, 2019

3 checks passed

codecov/project 74.144% (target 0%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
sympy-bot/release-notes The release notes look OK
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.