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

Add tests for SubArrays in test/linalg/bunchkaufman.jl #15354

Merged
merged 3 commits into from
Mar 7, 2016

Conversation

pkofod
Copy link
Contributor

@pkofod pkofod commented Mar 4, 2016

  • Added tests for linalg/bunchkaufman.jl. Found tiny dispatch bug, as factorize didn't dispatch properly for SubArrays (changed Matrix -> StridedMatrix).
  • Moved two matrix calculations in svd.jl.
  • Added tests for givens.jl. Again, at loop over Array and SubArray, here for the matrix A, and vector x. SubArrays seem to pass just fine.

@andreasnoack
Copy link
Member

It might be better to make individual pull requests for each of the files or maybe a couple and use #14732 to track the progress. It's easier to review smaller PRs and since most of the changes probably won't depend on each other it shouldn't cause issues to split them up.

@pkofod pkofod changed the title [WIP] Add tests for SubArrays in test/linalg Add tests for SubArrays in test/linalg/bunchkaufman.jl Mar 4, 2016
@pkofod
Copy link
Contributor Author

pkofod commented Mar 4, 2016

I agree, edited to reflect your comment. It should be good to go, let's see if Travis agrees.

@pkofod
Copy link
Contributor Author

pkofod commented Mar 4, 2016

Doing the bunchkaufman.jl tests, I realized I had placed the asym and apd matrices in such a way in svd.jl, that they were not SubArrays, which made coverage worse than I thought. It didn't matter when I moved them in svd.jl (most recent commit), but it was what made me catch the factorize bug in bunchkaufman.jl.

@pkofod
Copy link
Contributor Author

pkofod commented Mar 4, 2016

Added tests for givens.jl. Again, at loop over Array and SubArray, here for the matrix A, and vector x. SubArrays seem to pass just fine.

if btype == "Array"
b = b
else
b = sub(a, 1:n, 1:2)
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be sub(b, ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course! Will fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing it, such that a-> b makes

@test_approx_eq_eps asym * (bc1\b) b 1000ε

fail with

ERROR: LoadError: MethodError: no method matching reinterpret(::Type{Float32}, ::SubArray{Complex{Float32},2,Array{Complex{Float32},2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}, ::Tuple{Int64,Int64})

Will try to fix it.

@pkofod
Copy link
Contributor Author

pkofod commented Mar 6, 2016

Adding the SubArray tests caused https://github.com/JuliaLang/julia/pull/15354/files#diff-be0f75db178315152e44756ee149ffd8R58 to fail for eltypeb==Complex64 and typeb=="SubArray" together. I fixed this at the \ level, by calling parent on B. Thoughts on this?

@andreasnoack
Copy link
Member

Using parent seems correct. LGTM. @tkelman do you have further comments?

@tkelman
Copy link
Contributor

tkelman commented Mar 7, 2016

Just one - given #15367, should StridedMatrix continue to be used rather than AbstractMatrix ?

@pkofod
Copy link
Contributor Author

pkofod commented Mar 7, 2016

I can change it if it's appropriate, and if there's no reason to restrict it to StridedMatrix, I assume that it is.

Is there an easy way to go back to the first commit and change it? I guess I would branch, reset to the commit, make the change, and then merge with my original branch. Is that the way to go?

@KristofferC
Copy link
Sponsor Member

You can do git rebase -i HEAD~3 where the 3 is the number of commits you want to go back and then pick edit for the first commit and do your changes.

See for example: http://stackoverflow.com/questions/1186535/how-to-modify-a-specified-commit-in-git

@pkofod
Copy link
Contributor Author

pkofod commented Mar 7, 2016

Perfect, thank you!

Edit: I am just wondering: since all of the other functions around it has StridedMatrix maybe this is a more general discussion, or?

@andreasnoack
Copy link
Member

I'm not sure if these work well beyond StridedMatrix. Some of the methods would probably fail for some DArrays or SparseMatrixCSCs. That might just suggest that some other methods should be fixed to work correctly for those matrix types, but I think we should merge this as it is and wait for a more specific need for AbstractMatrix.

andreasnoack added a commit that referenced this pull request Mar 7, 2016
Add tests for SubArrays in test/linalg/bunchkaufman.jl
@andreasnoack andreasnoack merged commit aeb31de into JuliaLang:master Mar 7, 2016
@timholy
Copy link
Sponsor Member

timholy commented Mar 21, 2016

The use of parent is problematic because the parent may not be the same size as the subarray:

julia> A = rand(6,5); A = A'*A
5x5 Array{Float64,2}:
 2.79981  1.44259  1.9957    2.33348  1.43793 
 1.44259  1.50449  1.16219   1.20452  1.22158 
 1.9957   1.16219  1.93965   1.61173  0.964557
 2.33348  1.20452  1.61173   1.9936   1.11126 
 1.43793  1.22158  0.964557  1.11126  1.66233 

julia> F = cholfact(A);

julia> v6 = rand(Complex128, 6)
6-element Array{Complex{Float64},1}:
 0.485376+0.020852im 
 0.855035+0.32091im  
 0.152016+0.935278im 
  0.78076+0.0182181im
 0.954256+0.378917im 
 0.982591+0.995221im 

julia> v5 = sub(v6, 1:5)
5-element SubArray{Complex{Float64},1,Array{Complex{Float64},1},Tuple{UnitRange{Int64}},true}:
 0.485376+0.020852im 
 0.855035+0.32091im  
 0.152016+0.935278im 
  0.78076+0.0182181im
 0.954256+0.378917im 

julia> F\v5
ERROR: DimensionMismatch("new dimensions (2,5) must be consistent with array size 12")
 in reinterpret(::Type{Float64}, ::Array{Complex{Float64},1}, ::Tuple{Int64,Int64}) at ./array.jl:94
 in \(::Base.LinAlg.Cholesky{Float64,Array{Float64,2}}, ::SubArray{Complex{Float64},1,Array{Complex{Float64},1},Tuple{UnitRange{Int64}},true}) at ./linalg/factorization.jl:27
 in eval(::Module, ::Any) at ./boot.jl:243

@timholy timholy mentioned this pull request Mar 21, 2016
@andreasnoack
Copy link
Member

Maybe the original version was correct if we can define reinterepret for SubArray.

@pkofod
Copy link
Contributor Author

pkofod commented Mar 27, 2016

Well that is obviously not intended. To to be sure, is this something you're working on @timholy or were you just pointing it out?

@timholy
Copy link
Sponsor Member

timholy commented Mar 27, 2016

Haven't started trying to fix it yet. It was going to get in my way (so I might have fixed it quickly), but then I had to take a step back and think some more.

@timholy
Copy link
Sponsor Member

timholy commented Mar 27, 2016

Oh, and @andreasnoack: since reinterpret can reshape an array (changing the dimensionality), and reshape doesn't currently compose with SubArray, I suspect this would be a hard path. (But maybe someday.)

@pkofod
Copy link
Contributor Author

pkofod commented Mar 27, 2016

Okay, if I can help let me know.

@timholy
Copy link
Sponsor Member

timholy commented Mar 28, 2016

Oh, I meant "think some more" about my BIG SCARY problem, not this specific issue. Sorry for the confusion 😄.

@pkofod
Copy link
Contributor Author

pkofod commented Mar 28, 2016

Oh, okay! So the bug is still there? I'm confused, sorry :)

@timholy
Copy link
Sponsor Member

timholy commented Mar 28, 2016

Yes, AFAIK the bug is still there, and I'm not working on it.

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.

5 participants