JuliaLang / JuliaLang/LinearAlgebra.jl

`getproperty` overhead for `::Cholesky`

Open
#862 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
77
Forks
65
Avg merge
3d 23h
Merged PRs (30d)
10

Description

For `C::Cholesky`, `C.UL` calls this:
```julia
function getproperty(C::Cholesky, d::Symbol)
Cfactors = getfield(C, :factors)
Cuplo = getfield(C, :uplo)
if d === :U
return UpperTriangular(Cuplo === char_uplo(d) ? Cfactors : copy(Cfactors'))
elseif d === :L
return LowerTriangular(Cuplo === char_uplo(d) ? Cfactors : copy(Cfactors'))
elseif d === :UL
return (Cuplo === 'U' ? UpperTriangular(Cfactors) : LowerTriangular(Cfactors))
else
return getfield(C, d)
end
end
```

But there's some overhead here, so it's always better to instead call `getfield(C, :factors)` directly:
```julia
julia> @btime $C.UL;
4.208 ns (1 allocation: 16 bytes)

julia> @btime getfield($C, :factors);
1.172 ns (0 allocations: 0 bytes)

julia> C.UL === getfield(C, :factors)
true
```

Could it make sense for the first two lines to instead be
```julia
Cfactors = getfield(C, :factors)
d === :UL && return Cfactors
```
?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.