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

WIP: Refactors QR and Cholesky factorization codes #4621

Closed
wants to merge 10 commits into from

Conversation

jiahao
Copy link
Member

@jiahao jiahao commented Oct 23, 2013

The primary goal of this refactor is to subsume the pivoted QR and Cholesky factorizations into the functions that previously only computed the ordinary (non-pivoted) factorizations

  • Deprecates qrp, qrpfact, qrpfact, cholpfact, cholpfact!
  • Adds positional pivoted::Bool argument to qr, qrfact, qrpfact!, cholfact, and cholfact!
  • Reorganizes QR factorizations section so that methods common to QR, QRPackedQ, QRPivoted, QRPivotedQ are grouped together.

@@ -384,6 +409,7 @@ end
(\)(A::QRPivoted, B::StridedMatrix) = (\)(A, B, sqrt(eps(typeof(real(B[1])))))[1]
(\)(A::QRPivoted, B::StridedVector) = (\)(A, reshape(B, length(B), 1))[:]

<<<<<<< HEAD
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look like it should be here.

@ViralBShah
Copy link
Member

You are probably planning on it anyways, but we need to update the docs too.

@IainNZ
Copy link
Member

IainNZ commented Oct 24, 2013

Is this going into 0.2? Seems like a big change post-rc!

@ViralBShah
Copy link
Member

A bit big - but better to go in now rather than later. Also, the pivoted routines are not widely used, so hopefully the impact will be small.

@StefanKarpinski
Copy link
Member

cc: @ViralBShah, @dmbates, @IainNZ – please review.

@ViralBShah
Copy link
Member

It is a typo in the issue description. The pivoted versions of cholesky are deprecated.

if nr == 0 return zeros(0, nrhs), 0 end
ar = abs(A.hh[1])
if ar == 0 return zeros(nr, nrhs), 0 end
if ar < eps(typeof(ar)) return zeros(nr, nrhs), 0 end
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you are right here. If the matrix is scaled such that all the elements are small this criterion could make it look as a rank zero matrix. The old criterion is taken from the LAPACK source.

Copy link
Member Author

Choose a reason for hiding this comment

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

I admit I didn't think through this one carefully. I see the issue with the new line, but returning zeros only if the householder reflector is exactly zero doesn't seem right either. I'll revert this for now, but this should be reviewed.

@ViralBShah
Copy link
Member

I think it would be better if this was a named parameter so that we would have to do qr(A, pivoted=true), to make the code more readable.

@stevengj
Copy link
Member

(I don't think it makes sense for this to go into 0.2 at this stage. It's not a bug fix, and probably few people are using pivoted QR so it's not an essential feature, and we are still arguing over the interface.)

@IainNZ
Copy link
Member

IainNZ commented Oct 25, 2013

Agreed

@ViralBShah
Copy link
Member

Agree - this should be 0.3.

@jiahao
Copy link
Member Author

jiahao commented Oct 26, 2013

@ViralBShah I agree that a named argument is more sensible. Are named arguments compatible with varargs? There are a bunch of methods like

cholfact!(A::StridedMatrix, uplo::Symbol=:U, pivoted::Bool=false, args...)

(and similarly for QR) that take a variable number of arguments but don't seem to do anything with them. Can we just get rid of these particular methods? Why were they there in the first place?

- Deprecates qrp, qrpfact and qrpfact!
- Adds trailing pivoted::Bool option to qr, qrfact and qrpfact!
- Reorganizes QR factorizations section so that methods common to QR,
  QRPackedQ, QRPivoted, QRPivotedQ are grouped together.
- Remove improperly cleaned up blob from merge
- Replace methods defining default parameters with methods with default
  parameter values
- Rename QRPivoted.jpvt to QRPivoted.pivots
Revert A.hh[1] < eps to A.hh[1] == 0 testing for (\)(QRPivoted)
@ViralBShah
Copy link
Member

bump. We should merge this once the linalg refactor is completed.

@ViralBShah
Copy link
Member

@andreasnoackjensen Could you comment on @jiahao 's question above? It seems like we could get rid of the variable number of arguments.

@andreasnoack
Copy link
Member

The varargs serve a purpose for most of the factorizations, e.g.

cholfact!(A::StridedMatrix, args...) = cholfact!(float(A), args...)

converts non-float matrices to float matrices wether or not uplo has been supplied. The presence of varargs in the QR might seem a bid weird, but the fancy algorithm we are using takes some tuning parameters.

@ViralBShah
Copy link
Member

@jiahao Do you think we can merge this now? I think this requires updates to the docs too, but otherwise seems largely ready.

@jiahao
Copy link
Member Author

jiahao commented Dec 4, 2013

Let me review it given the recent linalg cleanup.

@ViralBShah
Copy link
Member

I think we should get this merged before it becomes too stale!

@ViralBShah
Copy link
Member

@jiahao I have some time today, and can take this up. Do you have any commits you haven't pushed?

jiahao and others added 4 commits December 29, 2013 10:40
- Deprecates qrp, qrpfact and qrpfact!
- Adds trailing pivoted::Bool option to qr, qrfact and qrpfact!
- Reorganizes QR factorizations section so that methods common to QR,
  QRPackedQ, QRPivoted, QRPivotedQ are grouped together.
- Remove improperly cleaned up blob from merge
- Replace methods defining default parameters with methods with default
  parameter values
- Rename QRPivoted.jpvt to QRPivoted.pivots
Revert A.hh[1] < eps to A.hh[1] == 0 testing for (\)(QRPivoted)
@ViralBShah
Copy link
Member

I took at a deep look at this today. I rebased this branch to master which took quite some effort, and the tests are not passing still. Considering the effort to make pivoted as an argument to qr and chol, and the resulting complexity in the codebase, I wonder if we should just leave things as they are. We just end up with two extra functions, and that may be ok.

@jiahao @andreasnoackjensen What do you guys think?

@jiahao
Copy link
Member Author

jiahao commented Dec 30, 2013

@ViralBShah can you push the rebased branch?

Part of the overall issue, which I haven't been too clear on, is whether it is desirable for methods that return Factorizations that are type stable with respect to the output. Does it make sense for qrfact to sometimes return QR and other times QRPivoted?

When working on this branch I also found it difficult to make changes to the factorization code, since it relies quite heavily on methods with varargs that break whenever I try to change them. I know for sure that I wasn't willing to merge this branch because of this fragility.

Perhaps the entire factorization codebase could use cleaning up. However, I don't think I can do that alone.

@ViralBShah
Copy link
Member

That was what I took away as well, that we need a general codebase cleanup here. I am willing to join that effort.

… cjh/nopivot-default

Conflicts:
	base/linalg/factorization.jl
@jiahao
Copy link
Member Author

jiahao commented Dec 30, 2013

For example, I added a wrapper to LAPACK.gesvx!, the general linear solver that calculates an error estimate, and I have absolutely no idea where to put it.

@ViralBShah
Copy link
Member

This merge is getting too screwy, and the tests are failing too. I am not sure if I should push what I have. I say, we brainstorm what we want this to look like, answering various API questions, and then just start from the latest master.

@ViralBShah
Copy link
Member

Ok, I have pushed what I had, in any case, since this branch would otherwise be unusable anyways. Some stuff is failiing, which I have to track down.

@andreasnoack
Copy link
Member

I have fixed the last issues that made this pr fail the tests. There were only few problems. Some of them were related to promotion which is generally quite annoying and make you wish that conversions should be explicit.

What is your end 2013 opinion on pivoted as a named argument? I can do the rewrite if we want it to be named.

Regarding cleanup, I think that we should consider to split lapack.jl into more files. It is huge and the splitting would force us decide on a structure for the wrappers. Should it be by matrix or problem type?

@ViralBShah
Copy link
Member

I feel that pivoted is an uncommon option, and makes sense to have as a named argument. That would also allow for other things as named arguments, like which part of a matrix to use for the cholesky factorization and such, making the code generally more readable.

I feel that lapack.jl in general contains only wrappers, and having a large monolithic file is ok, but the rest of the stuff could use a better structure. I don't have well-formed opinion on how to refactor though.

@ViralBShah
Copy link
Member

@andreasnoackjensen Thanks for fixing this PR. Nice to see it all green.

@ViralBShah
Copy link
Member

@andreasnoackjensen Should we merge this for now, and then do a separate PR for the cleanup and making pivoted a named argument?

What is your view on making it a named argument?

@andreasnoack
Copy link
Member

I think named arguments are better and will try to update this pull request soon.

@jiahao
Copy link
Member Author

jiahao commented Jan 11, 2014

Subsumed by #5330.

@jiahao jiahao closed this Jan 11, 2014
@jiahao jiahao deleted the cjh/nopivot-default branch January 11, 2014 07:38
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.

8 participants