Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cholesky accessors of adjoints should return views #29823

Open
simonbyrne opened this issue Oct 26, 2018 · 0 comments
Open

Cholesky accessors of adjoints should return views #29823

simonbyrne opened this issue Oct 26, 2018 · 0 comments
Labels
linear algebra Linear algebra

Comments

@simonbyrne
Copy link
Contributor

simonbyrne commented Oct 26, 2018

Currently accessing the lower triangular portion of a Cholesky object which has been stored using its upper triangle (or vice-versa) will return a copy

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

To avoid unnecessary allocations, you end up with code that looks like this:
https://github.com/JuliaStats/PDMats.jl/blob/eeec1c1bfdddb8f522952f81b3f6a3d5ec8aa7bd/src/pdmat.jl#L57-L59

The logical solution is that it should return an Adjoint object. However this would no longer be type-stable, since the flag is stored as a value part of the Cholesky struct.

Possible solutions:
a) include the flag as part of the type parameter, either directly as a symbol, or store the factor field as a LowerTriangular/UpperTriangular.
b) get rid of the option and only ever store it as an UpperTriangular matrix.

@simonbyrne simonbyrne added the linear algebra Linear algebra label Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

No branches or pull requests

1 participant