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

Some linalg cleanup. Fix module path to exceptions. #3089

Merged
merged 1 commit into from
May 16, 2013
Merged

Conversation

andreasnoack
Copy link
Member

Remove parametric dependence in copying factorization constructors. Add parametric dependence in \ and * methods.

@andreasnoack
Copy link
Member Author

This should fix #3082

@bsxfan
Copy link

bsxfan commented May 13, 2013

Thanks @andreasnoackjensen .

Is there any chance before this gets merged, that you can add a transposed field to type LU? This would alllow lightweight transposition of the LU factorization and then this flag could be sent through to LAPACK.getrs. This would then allow one to do:

transpose(F::LU) = LU(F.factors,F.ipiv,F.info,~F.transposed)
lufact(A.')\B == lufact(A).'\B

This would be useful for example when you want to also implement rdivide for LU, like

/(A:Vector,B::LU) = (B.'\A.').'

The only other place where the flag will have an effect as far as I can see is for inv(::LU), where one will have to explicitly transpose the inverse if the flag is set.

P.S. Cholesky does not need such a flag---LAPACK.potrs does not accept a flag, and you can do:

transpose{T<:Union(Complex64,Complex128)}(C::Cholesky{T}) = Cholesky{T}(conj(C.UL),C.uplo)
transpose{T<:Union(Float64,Float32)}(C::Cholesky{T}) = C
ctranspose(C::Cholesky) = C

@bsxfan
Copy link

bsxfan commented May 13, 2013

Hmm, on second thoughts, maybe transpose and ctranspose for both Cholesky and LU should produce copies, because regular matrix transposition effectively copies.

@@ -432,7 +425,7 @@ function eigfact!{T<:BlasFloat}(A::StridedMatrix{T})
end

eigfact(A::StridedMatrix) = eigfact!(copy(A))
eigfact{T<:Integer}(x::StridedMatrix{T}) = eigfact(float64(x))
eigfact!{T<:Integer}(x::StridedMatrix{T}) = eigfact!(float64(x))
Copy link
Member

Choose a reason for hiding this comment

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

It would be best to just use float(x) as everywhere else.

Copy link
Contributor

Choose a reason for hiding this comment

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

This also introduces a performance penalty. For integral matrices eigfact will now do two copies instead of one.

@ViralBShah
Copy link
Member

@bsxfan It is a good idea to have a transpose flag in the factorizations, and provide a method to transpose the factorization that just updates the flag. Best not to hold up this pull request though.

@andreasnoackjensen Apart from the couple of comments above, the rest looks good to me.

@daviddelaat
Copy link
Contributor

This seems to undo some of the changes in:
#3052 (it has a confusing title now)

The idea in that commit was to annotate on the BlasFloat type (or StridedArray{BlasFloat}) for operations that require this. And then to have functions such as

svdvals(A::StridedMatrix) = svdvals!(float(A)) 

which uses duck typing on the float function.

With this commit function calls such as rank([1//2 1//5; 2//1 3//5]) and rank(Any[1//2 1.0; 1+3im 6]) will not work anymore.

This commit will also introduce performance penalties, for instance, svdvals on an integral matrix will require two copies instead of one.

@ViralBShah
Copy link
Member

I was just thinking that this commit might interfere with your earlier commit.

@ViralBShah
Copy link
Member

@daviddelaat Won't just getting rid of {T<:Integer} everywhere resolve this?

@daviddelaat
Copy link
Contributor

That will mostly resolve it, but then there is still the problem of two copies instead of one for non BlasFloat matrices.

@simonbyrne
Copy link
Contributor

@bsxfan Lightweight transpose is currently handled by the A[t/c]_(mul/ldiv/rdiv)_B[t/c] functions, which are automatically substituted into the parser when required. For example:

U.' \V

will actually call At_ldiv_B(U,V). However a lot of these methods are still missing (feel free to add them in).

@andreasnoack
Copy link
Member Author

@daviddelaat I forgot the discussion about the rational matrices. I'll go through the code and make a new version. Hopefully also without unnecessary copying.

@andreasnoack
Copy link
Member Author

@daviddelaat Please have a look at the new version.

@daviddelaat
Copy link
Contributor

That looks great @andreasnoackjensen. The only thing I'm missing is the ! versions for the non BlasFloat functions. Of course they are a bit strange because they don't actually modify their arguments (because float makes a copy), but I think it is good to have them for generic programming.

… dependence in copying factorization constructors.
@andreasnoack
Copy link
Member Author

@daviddelaat I have now added the ! versions.

@daviddelaat
Copy link
Contributor

This looks good to me. Very nice that you took care of all the factorizations!

@bsxfan
Copy link

bsxfan commented May 15, 2013

Here are some more things in factorization.jl that will need attention at some stage:

  • See Refactorization of factorization.jl --- problems with StridedMatrix  LinearAlgebra.jl#14. I don't think StridedMatrix is really working all that well here.
  • The factorizations can now be constructed from Integer and Rational Matrices, but they can still be applied only to BlasFloat operands. For example in lufact(A)\B, A can be more general but B is still restricted to BlasFloat.
  • The /operator is not defined for factorizations. To dispatch / to \ however, one needs to be able to handle (preferably shallow) transposes of the factorizations: B/A = (A.'\B.').'.

I have been experimenting with coding strategies to handle the last two requirements. It may be nice to handle them together, because then one can do things like converting and transposing together, like e.g.: [float(B[j,i]) for i=1:size(B,1), j=1:size(B,2)]. I could perhaps try to contribute this, but not while others are still working on factorization in parallel.

@andreasnoack
Copy link
Member Author

@bsxfan I think we should merge this as soon as @ViralBShah says go and then look into your suggestions in a new issue.

@ViralBShah
Copy link
Member

Sorry for the delay - this looks good. Please merge.

@bsxfan Thanks for digging deep into the array and linear algebra code. Let's hold off doing anything with StridedMatrix for now, as we probably want to do an overhaul in any case. For the rest, please do submit pull requests, as all your suggestions are quite sound.

andreasnoack added a commit that referenced this pull request May 16, 2013
Some linalg cleanup. Fix module path to exceptions.
@andreasnoack andreasnoack merged commit ce456b4 into master May 16, 2013
@andreasnoack andreasnoack deleted the anj/linalg branch May 16, 2013 11:35
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