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

Generalise kron to an arbitrary number of dimensions. #195

Merged
merged 4 commits into from Sep 20, 2018

Conversation

hameerabbasi
Copy link
Collaborator

Generalizes kron to an arbitrary number of dimensions.

@hameerabbasi
Copy link
Collaborator Author

cc @jcrist for review.

@codecov
Copy link

codecov bot commented Sep 20, 2018

Codecov Report

Merging #195 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #195      +/-   ##
==========================================
+ Coverage   97.57%   97.63%   +0.06%     
==========================================
  Files          11       11              
  Lines        1444     1440       -4     
==========================================
- Hits         1409     1406       -3     
+ Misses         35       34       -1
Impacted Files Coverage Δ
sparse/coo/common.py 98.03% <100%> (+0.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f865a9...e80e957. Read the comment docs.

@@ -334,10 +334,10 @@ def test_kron(a_ndim, b_ndim):
assert_eq(sparse.kron(a, b), sol)


@pytest.mark.parametrize('ndim', [0, 1, 2])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was, again, a case better handled in the dense regime, so I removed it.

Copy link
Collaborator

@jcrist jcrist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks pretty good to me.

a_shape = (10, 11)[:a_ndim]
b_shape = (12, 13)[:b_ndim]
a_shape = (3, 4, 5)[:a_ndim]
b_shape = (4, 5, 3)[:b_ndim]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be maybe good to test:

  • Using dimensions that don't ever match up (len(set(a_shape).intersection(b_shape)) == 0) to ensure no accidental reliance on broadcasting aligning. Perhaps (3, 4, 5), and (6, 7, 8).
  • Cases with a nonzero fill value

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one might be being overly paranoid though, feel free to ignore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. My algorithm only works with a zero fill-value.

a_sparse = isinstance(a, SparseArray)
b_sparse = isinstance(b, SparseArray)
a_sparse = isinstance(a, (SparseArray, scipy.sparse.spmatrix))
b_sparse = isinstance(b, (SparseArray, scipy.sparse.spmatrix))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't ever test with a scipy.sparse.spmatrix, is this something that should also be added to the tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future references, asCOO and the COO constructor are pretty heavily tested, so we probably don't need to test things like these everywhere.

@hameerabbasi hameerabbasi merged commit 81eccee into pydata:master Sep 20, 2018
@hameerabbasi hameerabbasi deleted the kron branch October 22, 2018 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants