From a7ed3269c22cbadc60d1eeef68528f52066e77bb Mon Sep 17 00:00:00 2001 From: ayushpatnaikgit Date: Fri, 23 Jun 2023 17:16:23 +0530 Subject: [PATCH 1/3] Use cholesky decomposition whenever possible. --- src/Loess.jl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Loess.jl b/src/Loess.jl index e882e3b..7cf7462 100644 --- a/src/Loess.jl +++ b/src/Loess.jl @@ -123,12 +123,16 @@ function loess( end end - if VERSION < v"1.7.0-DEV.1188" - F = qr(us, Val(true)) + if isposdef(us' * us) + coefs = cholesky(us' * us) \ (us' * vs) else - F = qr(us, ColumnNorm()) + if VERSION < v"1.7.0-DEV.1188" + F = qr(us, Val(true)) + else + F = qr(us, ColumnNorm()) + end + coefs = F\vs end - coefs = F\vs predictions_and_gradients[vert] = [ us[1, :]' * coefs; # the prediction From ddd915a2705d5f78d897feccb6fcb44f51dc49d8 Mon Sep 17 00:00:00 2001 From: ayushpatnaikgit Date: Fri, 23 Jun 2023 22:31:53 +0530 Subject: [PATCH 2/3] Use exception handling --- src/Loess.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Loess.jl b/src/Loess.jl index 7cf7462..10f97c5 100644 --- a/src/Loess.jl +++ b/src/Loess.jl @@ -123,15 +123,16 @@ function loess( end end - if isposdef(us' * us) - coefs = cholesky(us' * us) \ (us' * vs) - else + coefs = Matrix{Real}(undef, size(us, 2), 1) + try + coefs = cholesky(us * us') \ (us' * vs) + catch PosDefException if VERSION < v"1.7.0-DEV.1188" F = qr(us, Val(true)) else F = qr(us, ColumnNorm()) end - coefs = F\vs + coefs = F \ vs end predictions_and_gradients[vert] = [ From 2722659c81a2ba4bf90bbd08e7d8d4da539b127b Mon Sep 17 00:00:00 2001 From: ayushpatnaikgit Date: Sat, 24 Jun 2023 09:41:08 +0530 Subject: [PATCH 3/3] Minor correction --- src/Loess.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Loess.jl b/src/Loess.jl index 10f97c5..2d79fa4 100644 --- a/src/Loess.jl +++ b/src/Loess.jl @@ -122,10 +122,10 @@ function loess( xl *= x end end - + coefs = Matrix{Real}(undef, size(us, 2), 1) try - coefs = cholesky(us * us') \ (us' * vs) + coefs = cholesky(us' * us) \ (us' * vs) catch PosDefException if VERSION < v"1.7.0-DEV.1188" F = qr(us, Val(true))