{"action":"created","issue":{"url":"https://api.github.com/repos/SciRuby/nmatrix/issues/490","repository_url":"https://api.github.com/repos/SciRuby/nmatrix","labels_url":"https://api.github.com/repos/SciRuby/nmatrix/issues/490/labels{/name}","comments_url":"https://api.github.com/repos/SciRuby/nmatrix/issues/490/comments","events_url":"https://api.github.com/repos/SciRuby/nmatrix/issues/490/events","html_url":"https://github.com/SciRuby/nmatrix/pull/490","id":140115799,"number":490,"title":"Add QR factorization by exposing LAPACK functions XGEQRF, XORMQR, XUNMQR","user":{"login":"gau27","id":9413228,"avatar_url":"https://avatars.githubusercontent.com/u/9413228?v=3","gravatar_id":"","url":"https://api.github.com/users/gau27","html_url":"https://github.com/gau27","followers_url":"https://api.github.com/users/gau27/followers","following_url":"https://api.github.com/users/gau27/following{/other_user}","gists_url":"https://api.github.com/users/gau27/gists{/gist_id}","starred_url":"https://api.github.com/users/gau27/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gau27/subscriptions","organizations_url":"https://api.github.com/users/gau27/orgs","repos_url":"https://api.github.com/users/gau27/repos","events_url":"https://api.github.com/users/gau27/events{/privacy}","received_events_url":"https://api.github.com/users/gau27/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-11T08:00:49Z","updated_at":"2016-03-12T17:43:08Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/SciRuby/nmatrix/pulls/490","html_url":"https://github.com/SciRuby/nmatrix/pull/490","diff_url":"https://github.com/SciRuby/nmatrix/pull/490.diff","patch_url":"https://github.com/SciRuby/nmatrix/pull/490.patch"},"body":"Fixes #440 : \r\n\r\nThis PR is not ready to be merged yet, I am in the process of making a test suite for all data types.\r\n\r\n#TODO : Add tests and possibly improve interface/memory consumption on outside calls.\r\n\r\nRuby Methods Added : (Requires nmatrix-lapacke plugin)\r\n\r\n**geqrf!**  :  Ruby method to interface with LAPACKE_XGEQRF\r\n**ormqr** :  Ruby method to interface with LAPACKE_XORMQR (Necessary for generating Q)\r\n**unmqr** : Ruby method to interface with LAPACKE_XUNMQR (Complex type equivalent of ormqr)\r\n**factorize_qr** : Friendly user interface to obtain QR decomposition.\r\n \r\n\r\n\r\n\r\n19 LAPACKE Source Files Added : \r\n```ruby\r\n/ext/nmatrix_lapacke/lapacke/src/\r\n\r\n  - 4 x  XGEQRF \r\n  - 4 x  XGEQRF_WORK\r\n  - 2 x XORMQR\r\n  - 2 x XORMQR_WORK\r\n  - 2 x UNMQR\r\n  - 2 x UNRMQR_WORK\r\n\r\n/ext/nmatrix_lapacke/lapacke/utils/\r\n \r\n - lapacke_c_nancheck.c\r\n - lapacke_d_nancheck.c\r\n - lapacke_s_nancheck.c\r\n```\r\nExample Usage : \r\n\r\n```ruby\r\n[1] pry(main)> a = N.new([3,3], [12.0, -51, 4, 6, 167, -68, -4, 24, -41])\r\n=> \r\n[\r\n  [12.0, -51.0,   4.0]   [ 6.0, 167.0, -68.0]   [-4.0,  24.0, -41.0] ]\r\n\r\n[3] pry(main)> q,r = a.factorize_qr\r\n=> [\r\n[\r\n   [-0.8571428571428572,  0.3942857142857143,  0.33142857142857146]\r\n   [-0.4285714285714286, -0.9028571428571428, -0.03428571428571425]\r\n   [0.28571428571428575, -0.1714285714285714,   0.9428571428571428]\r\n ],\r\n \r\n[\r\n   [-14.0,               -21.0, 14.000000000000002]\r\n   [  0.0, -175.00000000000003,  70.00000000000001]\r\n   [  0.0,                 0.0,              -35.0]\r\n ]]\r\n\r\n[4] pry(main)> q.dot(r)\r\n=> \r\n[\r\n  [              12.0, -51.000000000000014,  4.000000000000002]\r\n  [               6.0,  167.00000000000003, -68.00000000000001]\r\n  [-4.000000000000001,                24.0,              -41.0]\r\n]\r\n```\r\n\r\ncc @wlevine : Please have a look"},"comment":{"url":"https://api.github.com/repos/SciRuby/nmatrix/issues/comments/195779386","html_url":"https://github.com/SciRuby/nmatrix/pull/490#issuecomment-195779386","issue_url":"https://api.github.com/repos/SciRuby/nmatrix/issues/490","id":195779386,"user":{"login":"wlevine","id":7783548,"avatar_url":"https://avatars.githubusercontent.com/u/7783548?v=3","gravatar_id":"","url":"https://api.github.com/users/wlevine","html_url":"https://github.com/wlevine","followers_url":"https://api.github.com/users/wlevine/followers","following_url":"https://api.github.com/users/wlevine/following{/other_user}","gists_url":"https://api.github.com/users/wlevine/gists{/gist_id}","starred_url":"https://api.github.com/users/wlevine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wlevine/subscriptions","organizations_url":"https://api.github.com/users/wlevine/orgs","repos_url":"https://api.github.com/users/wlevine/repos","events_url":"https://api.github.com/users/wlevine/events{/privacy}","received_events_url":"https://api.github.com/users/wlevine/received_events","type":"User","site_admin":false},"created_at":"2016-03-12T17:43:08Z","updated_at":"2016-03-12T17:43:08Z","body":"Nice work, @gau27. I'll try to finish looking at the code tonight.\r\n\r\nDo you think it's more useful to return the full Q and R matrices or the reduced ones? What do other libraries do?\r\n\r\n[this wikipedia page](https://en.wikipedia.org/wiki/QR_decomposition#Using_for_solution_to_linear_inverse_problems) describes how to use the QR factorization for least squares: we want the product R_1^(-1)(Q_1^T b). If we wanted to do this would we need to all three steps separately: use geqrf to get Q and R, then ormqr to get (Q_1^T b), and then trsm to solve R_1 x = Q_1^T b? Or is there another LAPACK function which will combine some of these steps? @agisga, does this sound right to you? @gau27, I'm not saying you should include this in this pull request, I'm just trying to figure out what the next step is."}}