From 342f37bcf53a0c85c214c8fdd7ec4fb13b1a4da9 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 27 Oct 2022 11:30:47 +0530 Subject: [PATCH] Avoid double copying in `nullspace` return value This reduces allocations, but doesn't really change performance to any significant degree. ```julia julia> A = ones(1000, 1000); julia> @btime nullspace($A); 375.469 ms (15 allocations: 61.14 MiB) # master 374.243 ms (13 allocations: 53.52 MiB) # PR ``` This might help when working with large arrays. --- stdlib/LinearAlgebra/src/dense.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/dense.jl b/stdlib/LinearAlgebra/src/dense.jl index bcf9443f7632c..0689eee635330 100644 --- a/stdlib/LinearAlgebra/src/dense.jl +++ b/stdlib/LinearAlgebra/src/dense.jl @@ -1543,7 +1543,7 @@ function nullspace(A::AbstractVecOrMat; atol::Real = 0.0, rtol::Real = (min(size SVD = svd(A; full=true) tol = max(atol, SVD.S[1]*rtol) indstart = sum(s -> s .> tol, SVD.S) + 1 - return copy(SVD.Vt[indstart:end,:]') + return copy((@view SVD.Vt[indstart:end,:])') end """