Created attachment 380 [details]
I implemented the NNLS algorithm  for Eigen. It is not perfect yet but I think it could be included into the "unsupported" modules of Eigen.
One think that is definitely missing is a check that the Scalar type of the system is real as the NNLS problem is only defined on R^N and I do not know how to do this.
I have tested the code against some simple units test  so far and I used it for some larger problems where it produces reasonable results although I have not verified them against some other implementation.
Let me know if I can improve the implementation.
 "SOLVING LEAST SQUARES PROBLEMS", by
Charles L. Lawson and Richard J. Hanson, Prentice-Hall, 1974
To check if a type is complex, use NumTraits<Scalar>::IsComplex.
You can use it in a static assertion like this:
Thanks for this hint, I have included the assertion. To avoid tracking such changes as attachments her, I created a GIT repository for the code, including some unit tests: https://github.com/hmatuschek/eigen3-nnls .
Thanks for your contribution. I haven't looked at it in detail, but NNLS is for me important enough and close enough to linear algebra that I'd like to have it included in Eigen. At a first look, the code looks well written and the algorithm is a standard one, so that is promising.
At the moment, the code is not structured as an unsupported module in Eigen. You can look at <root of Eigen tree>/unsupported/Eigen/AlignedVector3 for fairly simple example, or use any of the other unsupported modules as a template.
I assume you know that development of Eigen is done using mercurial on bitbucket, but if you prefer to use github that should not be too much of a problem (though we will probably not be able to preserve the history of the GIT repository). I suggest that you structure your repository as a fork of https://github.com/RLovelett/eigen which mirrors our mercurial repository.
The test should go in .../unsupported/tests and follow the framework described at http://eigen.tuxfamily.org/index.php?title=Tests section "Writing unit tests" (or use an existing test file as inspiration). I would also like to see one example of how to solve NNLS included in the documentation.
Any questions, please ask.
-- GitLab Migration Automatic Message --
This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.
You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/655.