{"action":"created","comment":{"url":"https://api.github.com/repos/SciRuby/nmatrix/pulls/comments/51347945","id":51347945,"diff_hunk":"@@ -50,6 +50,32 @@\n     expect(m).to eq identity3\n   end\n \n+  it \"hilbert() creates an hilbert matrix\" do\n+    m = NMatrix.hilbert(3)\n+    hilbert3 = NMatrix.new([3, 3], [1.0, 0.5, 0.3333333333333333, 0.5, 0.3333333333333333, 0.25, 0.3333333333333333, 0.25, 0.2])\n+    expect(m).to eq hilbert3\n+\n+    m = NMatrix.hilbert(8)\n+    hilbert8 = [ 0.2, 0.16666666666666666, 0.14285714285714285, 0.125,  0.1111111111111111]\n+    expect(m[4, 0]).to eq(hilbert8[0])\n+    expect(m[4, 1]).to eq(hilbert8[1])\n+    expect(m[4, 2]).to eq(hilbert8[2])\n+    expect(m[4, 3]).to eq(hilbert8[3])\n+  end\n+\n+  it \"inv_hilbert() creates an inverse hilbert matrix\" do\n+    m = NMatrix.inv_hilbert(6)\n+    inv_hilbert6 = [3360.0,  -88200.0,   564480.0, -1411200.0]\n+    expect(m[2, 0]).to eq(inv_hilbert6[0])\n+    expect(m[2, 1]).to eq(inv_hilbert6[1])\n+    expect(m[2, 2]).to eq(inv_hilbert6[2])\n+    expect(m[2, 3]).to eq(inv_hilbert6[3])\n+\n+    m = NMatrix.inv_hilbert(3)\n+    inv_hilbert3 = NMatrix.new([3, 3], [  9.0,  -36.0,   30.0, -36.0,  192.0, -180.0, 30.0, -180.0,  180.0] )\n+    expect(m).to eq inv_hilbert3\n+  end","path":"spec/shortcuts_spec.rb","position":28,"original_position":28,"commit_id":"56eb709f4c3ce8aba2f16ce0a9a53209bdccfcce","original_commit_id":"56eb709f4c3ce8aba2f16ce0a9a53209bdccfcce","user":{"login":"v0dro","id":2629909,"avatar_url":"https://avatars.githubusercontent.com/u/2629909?v=3","gravatar_id":"","url":"https://api.github.com/users/v0dro","html_url":"https://github.com/v0dro","followers_url":"https://api.github.com/users/v0dro/followers","following_url":"https://api.github.com/users/v0dro/following{/other_user}","gists_url":"https://api.github.com/users/v0dro/gists{/gist_id}","starred_url":"https://api.github.com/users/v0dro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/v0dro/subscriptions","organizations_url":"https://api.github.com/users/v0dro/orgs","repos_url":"https://api.github.com/users/v0dro/repos","events_url":"https://api.github.com/users/v0dro/events{/privacy}","received_events_url":"https://api.github.com/users/v0dro/received_events","type":"User","site_admin":false},"body":"It would be easier and more dependable to use `be_within` when comparing floating point numbers.","created_at":"2016-01-30T17:31:42Z","updated_at":"2016-01-30T17:31:42Z","html_url":"https://github.com/SciRuby/nmatrix/pull/443#discussion_r51347945","pull_request_url":"https://api.github.com/repos/SciRuby/nmatrix/pulls/443","_links":{"self":{"href":"https://api.github.com/repos/SciRuby/nmatrix/pulls/comments/51347945"},"html":{"href":"https://github.com/SciRuby/nmatrix/pull/443#discussion_r51347945"},"pull_request":{"href":"https://api.github.com/repos/SciRuby/nmatrix/pulls/443"}}},"pull_request":{"url":"https://api.github.com/repos/SciRuby/nmatrix/pulls/443","id":57656862,"html_url":"https://github.com/SciRuby/nmatrix/pull/443","diff_url":"https://github.com/SciRuby/nmatrix/pull/443.diff","patch_url":"https://github.com/SciRuby/nmatrix/pull/443.patch","issue_url":"https://api.github.com/repos/SciRuby/nmatrix/issues/443","number":443,"state":"open","locked":false,"title":"[WIP] Adds hilbert matrix and inverse hilbert matrix as per #441","user":{"login":"Arafatk","id":11155207,"avatar_url":"https://avatars.githubusercontent.com/u/11155207?v=3","gravatar_id":"","url":"https://api.github.com/users/Arafatk","html_url":"https://github.com/Arafatk","followers_url":"https://api.github.com/users/Arafatk/followers","following_url":"https://api.github.com/users/Arafatk/following{/other_user}","gists_url":"https://api.github.com/users/Arafatk/gists{/gist_id}","starred_url":"https://api.github.com/users/Arafatk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arafatk/subscriptions","organizations_url":"https://api.github.com/users/Arafatk/orgs","repos_url":"https://api.github.com/users/Arafatk/repos","events_url":"https://api.github.com/users/Arafatk/events{/privacy}","received_events_url":"https://api.github.com/users/Arafatk/received_events","type":"User","site_admin":false},"body":"Adds hilbert matrix and inverse hilbert matrix\r\nBoth the functions work in O(n*n) for an n x n matrix(square matrix).\r\n\r\n## Hilbert Matrix\r\n`H[i,j]=1/(i+j-1)`\r\nThis takes O(n^2) time as this function is applied to every entry of the matrix.\r\n\r\n## Inverse Hilbert Matrix\r\nOne of the fastest ways to calculate inverse matrix uses the formula given on [Wikipedia.](https://en.wikipedia.org/wiki/Hilbert_matrix)\r\nThis also involves binomial coefficients which can be calculated via dynamic programming in \r\nO(n^2).\r\nNote: Inverse hilbert matrix has only _integer entries_ as proved [here.](http://math.stackexchange.com/questions/430060/why-does-the-inverse-of-the-hilbert-matrix-have-integer-entries) \r\n\r\n\r\nExample\r\n```\r\n[3] pry(main)> NMatrix.hilbert(4)\r\n=> \r\n[\r\n  [               1.0,                0.5,  0.3333333333333333,                0.25]\r\n  [               0.5, 0.3333333333333333,                0.25,                 0.2]\r\n  [0.3333333333333333,               0.25,                 0.2, 0.16666666666666666]\r\n  [              0.25,                0.2, 0.16666666666666666, 0.14285714285714285]\r\n]\r\n[4] pry(main)> NMatrix.inv_hilbert(4)\r\n=> \r\n[\r\n  [  16.0,  -120.0,   240.0,  -140.0]\r\n  [-120.0,  1200.0, -2700.0,  1680.0]\r\n  [ 240.0, -2700.0,  6480.0, -4200.0]\r\n  [-140.0,  1680.0, -4200.0,  2800.0]\r\n\r\n```\r\n\r\n\r\n\r\n\r\n ","created_at":"2016-01-29T14:54:50Z","updated_at":"2016-01-30T17:31:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8c74cb85b743ffdb1091428be77c004f77dc4fb8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SciRuby/nmatrix/pulls/443/commits","review_comments_url":"https://api.github.com/repos/SciRuby/nmatrix/pulls/443/comments","review_comment_url":"https://api.github.com/repos/SciRuby/nmatrix/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SciRuby/nmatrix/issues/443/comments","statuses_url":"https://api.github.com/repos/SciRuby/nmatrix/statuses/56eb709f4c3ce8aba2f16ce0a9a53209bdccfcce","head":{"label":"Arafatk:hilbert_matrix","ref":"hilbert_matrix","sha":"56eb709f4c3ce8aba2f16ce0a9a53209bdccfcce","user":{"login":"Arafatk","id":11155207,"avatar_url":"https://avatars.githubusercontent.com/u/11155207?v=3","gravatar_id":"","url":"https://api.github.com/users/Arafatk","html_url":"https://github.com/Arafatk","followers_url":"https://api.github.com/users/Arafatk/followers","following_url":"https://api.github.com/users/Arafatk/following{/other_user}","gists_url":"https://api.github.com/users/Arafatk/gists{/gist_id}","starred_url":"https://api.github.com/users/Arafatk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arafatk/subscriptions","organizations_url":"https://api.github.com/users/Arafatk/orgs","repos_url":"https://api.github.com/users/Arafatk/repos","events_url":"https://api.github.com/users/Arafatk/events{/privacy}","received_events_url":"https://api.github.com/users/Arafatk/received_events","type":"User","site_admin":false},"repo":{"id":50177437,"name":"nmatrix","full_name":"Arafatk/nmatrix","owner":{"login":"Arafatk","id":11155207,"avatar_url":"https://avatars.githubusercontent.com/u/11155207?v=3","gravatar_id":"","url":"https://api.github.com/users/Arafatk","html_url":"https://github.com/Arafatk","followers_url":"https://api.github.com/users/Arafatk/followers","following_url":"https://api.github.com/users/Arafatk/following{/other_user}","gists_url":"https://api.github.com/users/Arafatk/gists{/gist_id}","starred_url":"https://api.github.com/users/Arafatk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arafatk/subscriptions","organizations_url":"https://api.github.com/users/Arafatk/orgs","repos_url":"https://api.github.com/users/Arafatk/repos","events_url":"https://api.github.com/users/Arafatk/events{/privacy}","received_events_url":"https://api.github.com/users/Arafatk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Arafatk/nmatrix","description":"Dense and sparse linear algebra library for Ruby via SciRuby","fork":true,"url":"https://api.github.com/repos/Arafatk/nmatrix","forks_url":"https://api.github.com/repos/Arafatk/nmatrix/forks","keys_url":"https://api.github.com/repos/Arafatk/nmatrix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Arafatk/nmatrix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Arafatk/nmatrix/teams","hooks_url":"https://api.github.com/repos/Arafatk/nmatrix/hooks","issue_events_url":"https://api.github.com/repos/Arafatk/nmatrix/issues/events{/number}","events_url":"https://api.github.com/repos/Arafatk/nmatrix/events","assignees_url":"https://api.github.com/repos/Arafatk/nmatrix/assignees{/user}","branches_url":"https://api.github.com/repos/Arafatk/nmatrix/branches{/branch}","tags_url":"https://api.github.com/repos/Arafatk/nmatrix/tags","blobs_url":"https://api.github.com/repos/Arafatk/nmatrix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Arafatk/nmatrix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Arafatk/nmatrix/git/refs{/sha}","trees_url":"https://api.github.com/repos/Arafatk/nmatrix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Arafatk/nmatrix/statuses/{sha}","languages_url":"https://api.github.com/repos/Arafatk/nmatrix/languages","stargazers_url":"https://api.github.com/repos/Arafatk/nmatrix/stargazers","contributors_url":"https://api.github.com/repos/Arafatk/nmatrix/contributors","subscribers_url":"https://api.github.com/repos/Arafatk/nmatrix/subscribers","subscription_url":"https://api.github.com/repos/Arafatk/nmatrix/subscription","commits_url":"https://api.github.com/repos/Arafatk/nmatrix/commits{/sha}","git_commits_url":"https://api.github.com/repos/Arafatk/nmatrix/git/commits{/sha}","comments_url":"https://api.github.com/repos/Arafatk/nmatrix/comments{/number}","issue_comment_url":"https://api.github.com/repos/Arafatk/nmatrix/issues/comments{/number}","contents_url":"https://api.github.com/repos/Arafatk/nmatrix/contents/{+path}","compare_url":"https://api.github.com/repos/Arafatk/nmatrix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Arafatk/nmatrix/merges","archive_url":"https://api.github.com/repos/Arafatk/nmatrix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Arafatk/nmatrix/downloads","issues_url":"https://api.github.com/repos/Arafatk/nmatrix/issues{/number}","pulls_url":"https://api.github.com/repos/Arafatk/nmatrix/pulls{/number}","milestones_url":"https://api.github.com/repos/Arafatk/nmatrix/milestones{/number}","notifications_url":"https://api.github.com/repos/Arafatk/nmatrix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Arafatk/nmatrix/labels{/name}","releases_url":"https://api.github.com/repos/Arafatk/nmatrix/releases{/id}","deployments_url":"https://api.github.com/repos/Arafatk/nmatrix/deployments","created_at":"2016-01-22T11:28:40Z","updated_at":"2016-01-22T11:28:41Z","pushed_at":"2016-01-30T13:30:26Z","git_url":"git://github.com/Arafatk/nmatrix.git","ssh_url":"git@github.com:Arafatk/nmatrix.git","clone_url":"https://github.com/Arafatk/nmatrix.git","svn_url":"https://github.com/Arafatk/nmatrix","homepage":"","size":7529,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SciRuby:master","ref":"master","sha":"1281e21c00bf600fae0e44e0201a55f6df54be0d","user":{"login":"SciRuby","id":550805,"avatar_url":"https://avatars.githubusercontent.com/u/550805?v=3","gravatar_id":"","url":"https://api.github.com/users/SciRuby","html_url":"https://github.com/SciRuby","followers_url":"https://api.github.com/users/SciRuby/followers","following_url":"https://api.github.com/users/SciRuby/following{/other_user}","gists_url":"https://api.github.com/users/SciRuby/gists{/gist_id}","starred_url":"https://api.github.com/users/SciRuby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciRuby/subscriptions","organizations_url":"https://api.github.com/users/SciRuby/orgs","repos_url":"https://api.github.com/users/SciRuby/repos","events_url":"https://api.github.com/users/SciRuby/events{/privacy}","received_events_url":"https://api.github.com/users/SciRuby/received_events","type":"Organization","site_admin":false},"repo":{"id":3988087,"name":"nmatrix","full_name":"SciRuby/nmatrix","owner":{"login":"SciRuby","id":550805,"avatar_url":"https://avatars.githubusercontent.com/u/550805?v=3","gravatar_id":"","url":"https://api.github.com/users/SciRuby","html_url":"https://github.com/SciRuby","followers_url":"https://api.github.com/users/SciRuby/followers","following_url":"https://api.github.com/users/SciRuby/following{/other_user}","gists_url":"https://api.github.com/users/SciRuby/gists{/gist_id}","starred_url":"https://api.github.com/users/SciRuby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciRuby/subscriptions","organizations_url":"https://api.github.com/users/SciRuby/orgs","repos_url":"https://api.github.com/users/SciRuby/repos","events_url":"https://api.github.com/users/SciRuby/events{/privacy}","received_events_url":"https://api.github.com/users/SciRuby/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SciRuby/nmatrix","description":"Dense and sparse linear algebra library for Ruby via SciRuby","fork":true,"url":"https://api.github.com/repos/SciRuby/nmatrix","forks_url":"https://api.github.com/repos/SciRuby/nmatrix/forks","keys_url":"https://api.github.com/repos/SciRuby/nmatrix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SciRuby/nmatrix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SciRuby/nmatrix/teams","hooks_url":"https://api.github.com/repos/SciRuby/nmatrix/hooks","issue_events_url":"https://api.github.com/repos/SciRuby/nmatrix/issues/events{/number}","events_url":"https://api.github.com/repos/SciRuby/nmatrix/events","assignees_url":"https://api.github.com/repos/SciRuby/nmatrix/assignees{/user}","branches_url":"https://api.github.com/repos/SciRuby/nmatrix/branches{/branch}","tags_url":"https://api.github.com/repos/SciRuby/nmatrix/tags","blobs_url":"https://api.github.com/repos/SciRuby/nmatrix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SciRuby/nmatrix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SciRuby/nmatrix/git/refs{/sha}","trees_url":"https://api.github.com/repos/SciRuby/nmatrix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SciRuby/nmatrix/statuses/{sha}","languages_url":"https://api.github.com/repos/SciRuby/nmatrix/languages","stargazers_url":"https://api.github.com/repos/SciRuby/nmatrix/stargazers","contributors_url":"https://api.github.com/repos/SciRuby/nmatrix/contributors","subscribers_url":"https://api.github.com/repos/SciRuby/nmatrix/subscribers","subscription_url":"https://api.github.com/repos/SciRuby/nmatrix/subscription","commits_url":"https://api.github.com/repos/SciRuby/nmatrix/commits{/sha}","git_commits_url":"https://api.github.com/repos/SciRuby/nmatrix/git/commits{/sha}","comments_url":"https://api.github.com/repos/SciRuby/nmatrix/comments{/number}","issue_comment_url":"https://api.github.com/repos/SciRuby/nmatrix/issues/comments{/number}","contents_url":"https://api.github.com/repos/SciRuby/nmatrix/contents/{+path}","compare_url":"https://api.github.com/repos/SciRuby/nmatrix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SciRuby/nmatrix/merges","archive_url":"https://api.github.com/repos/SciRuby/nmatrix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SciRuby/nmatrix/downloads","issues_url":"https://api.github.com/repos/SciRuby/nmatrix/issues{/number}","pulls_url":"https://api.github.com/repos/SciRuby/nmatrix/pulls{/number}","milestones_url":"https://api.github.com/repos/SciRuby/nmatrix/milestones{/number}","notifications_url":"https://api.github.com/repos/SciRuby/nmatrix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SciRuby/nmatrix/labels{/name}","releases_url":"https://api.github.com/repos/SciRuby/nmatrix/releases{/id}","deployments_url":"https://api.github.com/repos/SciRuby/nmatrix/deployments","created_at":"2012-04-10T23:05:34Z","updated_at":"2016-01-21T18:09:41Z","pushed_at":"2016-01-30T13:30:26Z","git_url":"git://github.com/SciRuby/nmatrix.git","ssh_url":"git@github.com:SciRuby/nmatrix.git","clone_url":"https://github.com/SciRuby/nmatrix.git","svn_url":"https://github.com/SciRuby/nmatrix","homepage":"","size":7968,"stargazers_count":290,"watchers_count":290,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":89,"mirror_url":null,"open_issues_count":59,"forks":89,"open_issues":59,"watchers":290,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SciRuby/nmatrix/pulls/443"},"html":{"href":"https://github.com/SciRuby/nmatrix/pull/443"},"issue":{"href":"https://api.github.com/repos/SciRuby/nmatrix/issues/443"},"comments":{"href":"https://api.github.com/repos/SciRuby/nmatrix/issues/443/comments"},"review_comments":{"href":"https://api.github.com/repos/SciRuby/nmatrix/pulls/443/comments"},"review_comment":{"href":"https://api.github.com/repos/SciRuby/nmatrix/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SciRuby/nmatrix/pulls/443/commits"},"statuses":{"href":"https://api.github.com/repos/SciRuby/nmatrix/statuses/56eb709f4c3ce8aba2f16ce0a9a53209bdccfcce"}}}}