{"action":"created","comment":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/comments/98246131","pull_request_review_id":18884743,"id":98246131,"diff_hunk":"@@ -1867,48 +1867,53 @@ function logm{T<:Union{Float64,Complex{Float64}}}(A0::UpperTriangular{T})\n end\n logm(A::LowerTriangular) = logm(A.').'\n \n-function sqrtm{T}(A::UpperTriangular{T})\n-    n = checksquare(A)\n+function sqrtm(A::UpperTriangular)\n     realmatrix = false\n     if isreal(A)\n         realmatrix = true\n-        for i = 1:n\n+        for i = 1:checksquare(A)\n             if real(A[i,i]) < 0\n                 realmatrix = false\n                 break\n             end\n         end\n     end\n-    if realmatrix\n-        TT = typeof(sqrt(zero(T)))\n-    else\n-        TT = typeof(sqrt(complex(-one(T))))\n-    end\n-    R = zeros(TT, n, n)\n-    for j = 1:n\n-        R[j,j] = realmatrix?sqrt(A[j,j]):sqrt(complex(A[j,j]))\n-        for i = j-1:-1:1\n-            r = A[i,j]\n-            for k = i+1:j-1\n-                r -= R[i,k]*R[k,j]\n+    sqrtm(A,Val{realmatrix})\n+end\n+function sqrtm{T,realmatrix}(A::UpperTriangular{T},::Type{Val{realmatrix}})\n+    n = checksquare(A)\n+    t = realmatrix ? typeof(sqrt(zero(T))) : typeof(sqrt(complex(zero(T))))\n+    R = zeros(t, n, n)\n+    tt = typeof(zero(t)*zero(t))\n+    @inbounds begin\n+        for j = 1:n\n+            R[j,j] = realmatrix ? sqrt(A[j,j]) : sqrt(complex(A[j,j]))\n+            for i = j-1:-1:1\n+                r::tt = A[i,j]\n+                @simd for k = i+1:j-1\n+                    r -= R[i,k]*R[k,j]\n+                end\n+                r==0 || (R[i,j] = r / (R[i,i] + R[j,j]))","path":"base/linalg/triangular.jl","position":45,"original_position":45,"commit_id":"075fd38a0579dc017291fde070c3c7e46d9faa78","original_commit_id":"075fd38a0579dc017291fde070c3c7e46d9faa78","user":{"login":"stevengj","id":2913679,"avatar_url":"https://avatars.githubusercontent.com/u/2913679?v=3","gravatar_id":"","url":"https://api.github.com/users/stevengj","html_url":"https://github.com/stevengj","followers_url":"https://api.github.com/users/stevengj/followers","following_url":"https://api.github.com/users/stevengj/following{/other_user}","gists_url":"https://api.github.com/users/stevengj/gists{/gist_id}","starred_url":"https://api.github.com/users/stevengj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevengj/subscriptions","organizations_url":"https://api.github.com/users/stevengj/orgs","repos_url":"https://api.github.com/users/stevengj/repos","events_url":"https://api.github.com/users/stevengj/events{/privacy}","received_events_url":"https://api.github.com/users/stevengj/received_events","type":"User","site_admin":false},"body":"Per @tkelman's comment below, for non-commutative number types (e.g. quaternions), this is not right.\r\n\r\nI haven't gone through the algebra very carefully, but I think the final `R[i,j]` needs to solve `R[i,i]*R[i,j] + R[i,j]*R[j,j] == r`, i.e. a [Sylvester equation](https://en.wikipedia.org/wiki/Sylvester_equation).  So, the right thing to do seems like:\r\n```julia\r\nR[i,j] = sylvester(R[i,i], R[j,j], -r)\r\n```\r\nand then add a method `sylvester(a::Union{Real,Complex},b::Union{Real,Complex},c::Union{Real,Complex}) = -c / (a + b)` for the commutative `Number` cases.  New `Number` types will have then to provide their own `sylvester` method if they want `sqrtm` to work.\r\n```","created_at":"2017-01-27T17:07:41Z","updated_at":"2017-01-27T17:07:41Z","html_url":"https://github.com/JuliaLang/julia/pull/20214#discussion_r98246131","pull_request_url":"https://api.github.com/repos/JuliaLang/julia/pulls/20214","_links":{"self":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/comments/98246131"},"html":{"href":"https://github.com/JuliaLang/julia/pull/20214#discussion_r98246131"},"pull_request":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/20214"}}},"pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/20214","id":102930336,"html_url":"https://github.com/JuliaLang/julia/pull/20214","diff_url":"https://github.com/JuliaLang/julia/pull/20214.diff","patch_url":"https://github.com/JuliaLang/julia/pull/20214.patch","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/20214","number":20214,"state":"open","locked":false,"title":"type-stable inner loop for sqrtm","user":{"login":"felixrehren","id":3264428,"avatar_url":"https://avatars.githubusercontent.com/u/3264428?v=3","gravatar_id":"","url":"https://api.github.com/users/felixrehren","html_url":"https://github.com/felixrehren","followers_url":"https://api.github.com/users/felixrehren/followers","following_url":"https://api.github.com/users/felixrehren/following{/other_user}","gists_url":"https://api.github.com/users/felixrehren/gists{/gist_id}","starred_url":"https://api.github.com/users/felixrehren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixrehren/subscriptions","organizations_url":"https://api.github.com/users/felixrehren/orgs","repos_url":"https://api.github.com/users/felixrehren/repos","events_url":"https://api.github.com/users/felixrehren/events{/privacy}","received_events_url":"https://api.github.com/users/felixrehren/received_events","type":"User","site_admin":false},"body":"As suggested by Ralph_Smith on [discourse](https://discourse.julialang.org/t/review-schur-pade-matrix-powers-speedup/1650/6)\r\n\r\nOn my machine: speedup x15","created_at":"2017-01-24T14:38:37Z","updated_at":"2017-01-27T17:07:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1cd737ee4dba905f7631583f11330b584b80f12f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/JuliaLang/julia/pulls/20214/commits","review_comments_url":"https://api.github.com/repos/JuliaLang/julia/pulls/20214/comments","review_comment_url":"https://api.github.com/repos/JuliaLang/julia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/20214/comments","statuses_url":"https://api.github.com/repos/JuliaLang/julia/statuses/075fd38a0579dc017291fde070c3c7e46d9faa78","head":{"label":"felixrehren:fr-sqrt","ref":"fr-sqrt","sha":"075fd38a0579dc017291fde070c3c7e46d9faa78","user":{"login":"felixrehren","id":3264428,"avatar_url":"https://avatars.githubusercontent.com/u/3264428?v=3","gravatar_id":"","url":"https://api.github.com/users/felixrehren","html_url":"https://github.com/felixrehren","followers_url":"https://api.github.com/users/felixrehren/followers","following_url":"https://api.github.com/users/felixrehren/following{/other_user}","gists_url":"https://api.github.com/users/felixrehren/gists{/gist_id}","starred_url":"https://api.github.com/users/felixrehren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixrehren/subscriptions","organizations_url":"https://api.github.com/users/felixrehren/orgs","repos_url":"https://api.github.com/users/felixrehren/repos","events_url":"https://api.github.com/users/felixrehren/events{/privacy}","received_events_url":"https://api.github.com/users/felixrehren/received_events","type":"User","site_admin":false},"repo":{"id":76472698,"name":"julia","full_name":"felixrehren/julia","owner":{"login":"felixrehren","id":3264428,"avatar_url":"https://avatars.githubusercontent.com/u/3264428?v=3","gravatar_id":"","url":"https://api.github.com/users/felixrehren","html_url":"https://github.com/felixrehren","followers_url":"https://api.github.com/users/felixrehren/followers","following_url":"https://api.github.com/users/felixrehren/following{/other_user}","gists_url":"https://api.github.com/users/felixrehren/gists{/gist_id}","starred_url":"https://api.github.com/users/felixrehren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixrehren/subscriptions","organizations_url":"https://api.github.com/users/felixrehren/orgs","repos_url":"https://api.github.com/users/felixrehren/repos","events_url":"https://api.github.com/users/felixrehren/events{/privacy}","received_events_url":"https://api.github.com/users/felixrehren/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/felixrehren/julia","description":"The Julia Language: A fresh approach to technical computing.","fork":true,"url":"https://api.github.com/repos/felixrehren/julia","forks_url":"https://api.github.com/repos/felixrehren/julia/forks","keys_url":"https://api.github.com/repos/felixrehren/julia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/felixrehren/julia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/felixrehren/julia/teams","hooks_url":"https://api.github.com/repos/felixrehren/julia/hooks","issue_events_url":"https://api.github.com/repos/felixrehren/julia/issues/events{/number}","events_url":"https://api.github.com/repos/felixrehren/julia/events","assignees_url":"https://api.github.com/repos/felixrehren/julia/assignees{/user}","branches_url":"https://api.github.com/repos/felixrehren/julia/branches{/branch}","tags_url":"https://api.github.com/repos/felixrehren/julia/tags","blobs_url":"https://api.github.com/repos/felixrehren/julia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/felixrehren/julia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/felixrehren/julia/git/refs{/sha}","trees_url":"https://api.github.com/repos/felixrehren/julia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/felixrehren/julia/statuses/{sha}","languages_url":"https://api.github.com/repos/felixrehren/julia/languages","stargazers_url":"https://api.github.com/repos/felixrehren/julia/stargazers","contributors_url":"https://api.github.com/repos/felixrehren/julia/contributors","subscribers_url":"https://api.github.com/repos/felixrehren/julia/subscribers","subscription_url":"https://api.github.com/repos/felixrehren/julia/subscription","commits_url":"https://api.github.com/repos/felixrehren/julia/commits{/sha}","git_commits_url":"https://api.github.com/repos/felixrehren/julia/git/commits{/sha}","comments_url":"https://api.github.com/repos/felixrehren/julia/comments{/number}","issue_comment_url":"https://api.github.com/repos/felixrehren/julia/issues/comments{/number}","contents_url":"https://api.github.com/repos/felixrehren/julia/contents/{+path}","compare_url":"https://api.github.com/repos/felixrehren/julia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/felixrehren/julia/merges","archive_url":"https://api.github.com/repos/felixrehren/julia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/felixrehren/julia/downloads","issues_url":"https://api.github.com/repos/felixrehren/julia/issues{/number}","pulls_url":"https://api.github.com/repos/felixrehren/julia/pulls{/number}","milestones_url":"https://api.github.com/repos/felixrehren/julia/milestones{/number}","notifications_url":"https://api.github.com/repos/felixrehren/julia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/felixrehren/julia/labels{/name}","releases_url":"https://api.github.com/repos/felixrehren/julia/releases{/id}","deployments_url":"https://api.github.com/repos/felixrehren/julia/deployments","created_at":"2016-12-14T15:36:20Z","updated_at":"2016-12-14T15:36:30Z","pushed_at":"2017-01-27T14:11:42Z","git_url":"git://github.com/felixrehren/julia.git","ssh_url":"git@github.com:felixrehren/julia.git","clone_url":"https://github.com/felixrehren/julia.git","svn_url":"https://github.com/felixrehren/julia","homepage":"http://julialang.org/","size":116225,"stargazers_count":0,"watchers_count":0,"language":"Julia","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"JuliaLang:master","ref":"master","sha":"b3cbcc24cbc35907b2a9159864b7466b568ac6db","user":{"login":"JuliaLang","id":743164,"avatar_url":"https://avatars.githubusercontent.com/u/743164?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaLang","html_url":"https://github.com/JuliaLang","followers_url":"https://api.github.com/users/JuliaLang/followers","following_url":"https://api.github.com/users/JuliaLang/following{/other_user}","gists_url":"https://api.github.com/users/JuliaLang/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaLang/subscriptions","organizations_url":"https://api.github.com/users/JuliaLang/orgs","repos_url":"https://api.github.com/users/JuliaLang/repos","events_url":"https://api.github.com/users/JuliaLang/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaLang/received_events","type":"Organization","site_admin":false},"repo":{"id":1644196,"name":"julia","full_name":"JuliaLang/julia","owner":{"login":"JuliaLang","id":743164,"avatar_url":"https://avatars.githubusercontent.com/u/743164?v=3","gravatar_id":"","url":"https://api.github.com/users/JuliaLang","html_url":"https://github.com/JuliaLang","followers_url":"https://api.github.com/users/JuliaLang/followers","following_url":"https://api.github.com/users/JuliaLang/following{/other_user}","gists_url":"https://api.github.com/users/JuliaLang/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaLang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaLang/subscriptions","organizations_url":"https://api.github.com/users/JuliaLang/orgs","repos_url":"https://api.github.com/users/JuliaLang/repos","events_url":"https://api.github.com/users/JuliaLang/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaLang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JuliaLang/julia","description":"The Julia Language: A fresh approach to technical computing.","fork":false,"url":"https://api.github.com/repos/JuliaLang/julia","forks_url":"https://api.github.com/repos/JuliaLang/julia/forks","keys_url":"https://api.github.com/repos/JuliaLang/julia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JuliaLang/julia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JuliaLang/julia/teams","hooks_url":"https://api.github.com/repos/JuliaLang/julia/hooks","issue_events_url":"https://api.github.com/repos/JuliaLang/julia/issues/events{/number}","events_url":"https://api.github.com/repos/JuliaLang/julia/events","assignees_url":"https://api.github.com/repos/JuliaLang/julia/assignees{/user}","branches_url":"https://api.github.com/repos/JuliaLang/julia/branches{/branch}","tags_url":"https://api.github.com/repos/JuliaLang/julia/tags","blobs_url":"https://api.github.com/repos/JuliaLang/julia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JuliaLang/julia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JuliaLang/julia/git/refs{/sha}","trees_url":"https://api.github.com/repos/JuliaLang/julia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JuliaLang/julia/statuses/{sha}","languages_url":"https://api.github.com/repos/JuliaLang/julia/languages","stargazers_url":"https://api.github.com/repos/JuliaLang/julia/stargazers","contributors_url":"https://api.github.com/repos/JuliaLang/julia/contributors","subscribers_url":"https://api.github.com/repos/JuliaLang/julia/subscribers","subscription_url":"https://api.github.com/repos/JuliaLang/julia/subscription","commits_url":"https://api.github.com/repos/JuliaLang/julia/commits{/sha}","git_commits_url":"https://api.github.com/repos/JuliaLang/julia/git/commits{/sha}","comments_url":"https://api.github.com/repos/JuliaLang/julia/comments{/number}","issue_comment_url":"https://api.github.com/repos/JuliaLang/julia/issues/comments{/number}","contents_url":"https://api.github.com/repos/JuliaLang/julia/contents/{+path}","compare_url":"https://api.github.com/repos/JuliaLang/julia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JuliaLang/julia/merges","archive_url":"https://api.github.com/repos/JuliaLang/julia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JuliaLang/julia/downloads","issues_url":"https://api.github.com/repos/JuliaLang/julia/issues{/number}","pulls_url":"https://api.github.com/repos/JuliaLang/julia/pulls{/number}","milestones_url":"https://api.github.com/repos/JuliaLang/julia/milestones{/number}","notifications_url":"https://api.github.com/repos/JuliaLang/julia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JuliaLang/julia/labels{/name}","releases_url":"https://api.github.com/repos/JuliaLang/julia/releases{/id}","deployments_url":"https://api.github.com/repos/JuliaLang/julia/deployments","created_at":"2011-04-21T07:01:50Z","updated_at":"2017-01-27T15:50:40Z","pushed_at":"2017-01-27T16:58:58Z","git_url":"git://github.com/JuliaLang/julia.git","ssh_url":"git@github.com:JuliaLang/julia.git","clone_url":"https://github.com/JuliaLang/julia.git","svn_url":"https://github.com/JuliaLang/julia","homepage":"http://julialang.org/","size":129875,"stargazers_count":8139,"watchers_count":8139,"language":"Julia","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1897,"mirror_url":null,"open_issues_count":2137,"forks":1897,"open_issues":2137,"watchers":8139,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/20214"},"html":{"href":"https://github.com/JuliaLang/julia/pull/20214"},"issue":{"href":"https://api.github.com/repos/JuliaLang/julia/issues/20214"},"comments":{"href":"https://api.github.com/repos/JuliaLang/julia/issues/20214/comments"},"review_comments":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/20214/comments"},"review_comment":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JuliaLang/julia/pulls/20214/commits"},"statuses":{"href":"https://api.github.com/repos/JuliaLang/julia/statuses/075fd38a0579dc017291fde070c3c7e46d9faa78"}}}}
{"actor":{"display_login":"stevengj"}}