upper_triangular and lower_triangular now use triu and tril, so Adjoint Cholesky factors on Julia 1.13 no longer raise a MethodError.
Fix triangular helpers for adjoint Cholesky factors on Julia 1.13Revisions
- Base
2d1580a926b902146a8a5e6b508cabba28eb5c76- Head
f4f30f5b0b35ca4069f349804fe7624caa2868f3- PR checked
- 2026-11-11T19:57:27.808Z
- Agent
- Claude Code cloud
- Requested model
- sonnet
- Requested effort
- medium
- Cloud session
- Open in Claude
- Reported models
- Unreported
Reviewed snapshot. Validation checks structure, not call paths.
Overview
Recommendation: Approve
No blocking issue found in the reviewed source.
Bijectors.jl provides bijections between constrained and unconstrained spaces. CorrBijector and VecCorrBijector map correlation matrices using a Cholesky factor.
On Julia 1.13 the upper factor of a Cholesky object stored as the lower triangle is UpperTriangular(C.factors'), so its parent is an Adjoint. The old upper_triangular tried to convert that matrix back to an Adjoint and threw a MethodError. Mooncake forward mode always stores the lower triangle, so correlation bijectors fail under it. This PR changes the two helpers to triu and tril.1, 8
Affected users: Julia 1.13 users of CorrBijector, VecCorrBijector or cholesky_upper, mostly with Mooncake. The helpers are internal functions, not documented API.
Example
Input from the PR description
A = [2.0 1; 1 2]
CL = cholesky(Hermitian(A, :L))
Bijectors.upper_triangular(parent(CL.U))Result on Julia 1.13 (from the PR description)
Before
MethodError: the Adjoint parent cannot be produced by convert(typeof(A), UpperTriangular(A)).
After
A Matrix with the upper triangle of the factor. The new test expects it to equal Matrix(CL.U).
Changes
Files in the PR
| File | Change |
|---|---|
| src/utils.jl | lower_triangular is tril(A) and upper_triangular is triu(A). |
| test/bijectors/pd.jl | New testset compares each helper on an Adjoint factor with the Matrix of the factor. |
| HISTORY.md | Entry for the MethodError fix under 0.16.4. |
Helper definitions
The PR's change to src/utils.jl.
| @@ -1,2 +1,2 @@ | |||
| 1 | - | lower_triangular(A::AbstractMatrix) = convert(typeof(A), LowerTriangular(A)) | |
| 2 | - | upper_triangular(A::AbstractMatrix) = convert(typeof(A), UpperTriangular(A)) | |
| \ No newline at end of file | |||
| 1 | + | lower_triangular(A::AbstractMatrix) = tril(A) | |
| 2 | + | upper_triangular(A::AbstractMatrix) = triu(A) | |
| \ No newline at end of file | |||
Copyable text
Design
Read left to right: functions in src/utils.jl and the ReverseDiff extension call the two helpers, which now call tril and triu. The scope is src/utils.jl and the ReverseDiff extension. Other callers were not searched in other extensions.
Select a node for its meaning and source.
Labels identify types, functions, methods, macros, values and groups. Dashed arrows are uncertain.
Drag to pan. Ctrl + scroll to zoom. Keyboard: arrows, +, -, 0.
Nodes and relationships
function: cholesky_lower
Returns the lower Cholesky factor as a Matrix.
cholesky_lower(X::AbstractMatrix)Sources (1)
function: cholesky_upper
Returns the upper Cholesky factor as a Matrix. Fails on Julia 1.13 at base when the factor is stored lower.
cholesky_upper(X::AbstractMatrix)Sources (1)
group: vec_to_triu and vec_to_triu1
Group of two functions that fill an upper triangle from a vector and then call upper_triangular. The group implies no call between its members.
group: pd_from_lower and pd_from_upper
Group of two helpers that call lower_triangular and upper_triangular before forming a product.
Sources (1)
method: lower_triangular
Changed: now tril(A).
lower_triangular(A::AbstractMatrix)method: upper_triangular
Changed: now triu(A).
upper_triangular(A::AbstractMatrix)function: tril and triu
Standard library functions. They return a new Matrix for an Adjoint input.
Sources (1)
group: ReverseDiff overrides
Overrides for TrackedMatrix that call the helpers on the underlying values.
Sources (1)
cholesky-lower calls lower-triangular (source). Passes parent(cholesky(...).L).
Sources (1)
cholesky-upper calls upper-triangular (source). Passes parent(cholesky(...).U).
Sources (1)
vec-to-triu calls upper-triangular (source). Passes a Matrix built by update_triu_from_vec.
pd-from calls lower-triangular (source). pd_from_lower calls lower_triangular. pd_from_upper calls upper_triangular.
Sources (1)
lower-triangular calls tril-triu (source). Calls tril at head. At base it called convert(typeof(A), LowerTriangular(A)).
upper-triangular calls tril-triu (source). Calls triu at head. At base it called convert(typeof(A), UpperTriangular(A)).
rd-ext calls lower-triangular (source). The @grad bodies call the helpers on plain values, so they reach tril and triu. Not executed here.
Sources (1)
Generated Mermaid
Benefits and costs
| Aspect | Assessment |
|---|---|
| Benefit | tril and triu return a plain Matrix for any AbstractMatrix input, including an Adjoint. This removes the failing conversion. |
| Cost | The result type is no longer typeof(A). For a Matrix input nothing changes. For other input types the output may differ. The callers read here pass Matrix values. |
| AD | ReverseDiff overrides still intercept TrackedMatrix. Other backends now differentiate through tril and triu instead of convert and LowerTriangular. This was not checked. |
Findings
The regression test passes trivially before Julia 1.13
On earlier Julia versions parent(CL.U) is already a Matrix, so the test exercises the old code path without failing. It guards the bug only on 1.13 and later. The test also calls the helpers directly and does not call cholesky_upper or cholesky_lower on a lower-stored factor. A direct call of cholesky_upper with a Hermitian lower input would cover the reported path. This is a nonblocking suggestion.
7, 4AD through tril and triu with Mooncake and others
The failure was reported under Mooncake forward mode. After the change those backends differentiate tril and triu. The PR says the Mooncake integration cases fail on 1.13 in CI. Does CI on this head show those cases passing? The check was not made here.
1, 6Review scope
Cloud source review. Package-test results were not verified.
Linked work: public repositories only, depth 2, at most 15 items. Read status describes collection, not semantic review.
Checks
Definitions and linked work
Definitions
Two helper methods changed. Test code lives in unexpanded macros.
Collection notes (15)
Parser: Julia 1.10.13 Meta.parseall.
Written declarations are compared without loading the project. Macros, generated code and quoted code need separate checks. Signature edits and moves may appear as removal and addition.
lower_triangular
Base
lower_triangular(A::AbstractMatrix)Head
lower_triangular(A::AbstractMatrix)upper_triangular
Base
upper_triangular(A::AbstractMatrix)Head
upper_triangular(A::AbstractMatrix)Linked issues and pull requests
Discovery paths. Explanations need review.
Scope and limits
Bodies, paginated comments, submitted/inline reviews and incoming timeline references. Mentions may be quoted or incidental.
Depth: 2. Read budget: 15.
Only three items have explanations. The rest show collection status only and were not reviewed.
All items and links
Fix triangular helpers for adjoint Cholesky factors on Julia 1.13
The PR under review.
remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`)
Upstream change that makes Cholesky factors non-copying. The PR cites it as the cause. Read through the PR description only.
Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later
Merged base PR that this PR is stacked on. Not reviewed here.
Avoid allocation when accessing `cholesky` factors (.L, .U)
Needs an explanation after review.
Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves
Needs an explanation after review.
Eventually retire `chol_lower` and `chol_upper`
Needs an explanation after review.
Fix doctest
Needs an explanation after review.
Backports release 1.12
Needs an explanation after review.
Improve Cholesky type inference without copying
Needs an explanation after review.
Fix argument handling in `@grad_from_chainrules`
Needs an explanation after review.
Request a PR review
Needs an explanation after review.
JuliaLang/julia#38389
Not read.
Depth limit.
JuliaStats/PDMats.jl#143
Not read.
Depth limit.
JuliaGaussianProcesses/ParameterHandling.jl#39
Not read.
Depth limit.
FluxML/Zygote.jl#1117
Not read.
Depth limit.
JuliaLang/julia#57509
Not read.
Depth limit.
JuliaLang/LinearAlgebra.jl#1239
Not read.
Depth limit.
JuliaLang/LinearAlgebra.jl#1405
Not read.
Depth limit.
EnzymeAD/Enzyme.jl#2813
Not read.
Depth limit.
JuliaLang/julia#57347
Not read.
Depth limit.
JuliaLang/LinearAlgebra.jl#1207
Not read.
Depth limit.
JuliaLang/LinearAlgebra.jl#1196
Not read.
Depth limit.
JuliaLang/LinearAlgebra.jl#1202
Not read.
Depth limit.
JuliaLang/LinearAlgebra.jl#1203
Not read.
Depth limit.
JuliaLang/LinearAlgebra.jl#1210
Not read.
Depth limit.
JuliaLang/LinearAlgebra.jl#1214
Not read.
Depth limit.
JuliaLang/LinearAlgebra.jl#1237
Not read.
Depth limit.
JuliaDiff/ReverseDiff.jl#314
Not read.
Depth limit.
JuliaDiff/ReverseDiff.jl#315
Not read.
Depth limit.
JuliaDiff/ReverseDiff.jl#319
Not read.
Depth limit.
JuliaDiff/ReverseDiff.jl#320
Not read.
Depth limit.
JuliaDiff/ReverseDiff.jl#316
Not read.
Depth limit.
JuliaDiff/ReverseDiff.jl#318
Not read.
Depth limit.
JuliaDiff/ReverseDiff.jl#331
Not read.
Depth limit.
JuliaDiff/ReverseDiff.jl#330
Not read.
Depth limit.
Fix triangular helpers for adjoint Cholesky factors on Julia 1.13 mentions remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`). Collected reference.
Fix triangular helpers for adjoint Cholesky factors on Julia 1.13 mentions Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later. Collected reference.
Fix triangular helpers for adjoint Cholesky factors on Julia 1.13 mentions Fix triangular helpers for adjoint Cholesky factors on Julia 1.13. Collected reference.
remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`) mentions Avoid allocation when accessing `cholesky` factors (.L, .U). Collected reference.
remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`) mentions remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`). Collected reference.
remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`) mentions Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves. Collected reference.
remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`) referenced by Eventually retire `chol_lower` and `chol_upper`. Collected reference.
remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`) referenced by Fix doctest. Collected reference.
remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`) referenced by Backports release 1.12. Collected reference.
remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`) referenced by Improve Cholesky type inference without copying. Collected reference.
remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`) referenced by Fix triangular helpers for adjoint Cholesky factors on Julia 1.13. Collected reference.
Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later mentions Fix argument handling in `@grad_from_chainrules`. Collected reference.
Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later mentions Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later. Collected reference.
Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later referenced by Fix triangular helpers for adjoint Cholesky factors on Julia 1.13. Collected reference.
Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later referenced by Request a PR review. Collected reference.
Avoid allocation when accessing `cholesky` factors (.L, .U) mentions JuliaLang/julia#38389. Collected reference.
Avoid allocation when accessing `cholesky` factors (.L, .U) mentions JuliaStats/PDMats.jl#143. Collected reference.
Avoid allocation when accessing `cholesky` factors (.L, .U) referenced by JuliaStats/PDMats.jl#143. Collected reference.
Avoid allocation when accessing `cholesky` factors (.L, .U) referenced by JuliaGaussianProcesses/ParameterHandling.jl#39. Collected reference.
Avoid allocation when accessing `cholesky` factors (.L, .U) referenced by FluxML/Zygote.jl#1117. Collected reference.
Avoid allocation when accessing `cholesky` factors (.L, .U) referenced by remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`). Collected reference.
Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves mentions Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves. Collected reference.
Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves referenced by remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`). Collected reference.
Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves referenced by Backports release 1.12. Collected reference.
Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves referenced by JuliaLang/julia#57509. Collected reference.
Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves referenced by JuliaLang/LinearAlgebra.jl#1239. Collected reference.
Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves referenced by JuliaLang/LinearAlgebra.jl#1405. Collected reference.
Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves referenced by EnzymeAD/Enzyme.jl#2813. Collected reference.
Eventually retire `chol_lower` and `chol_upper` mentions remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`). Collected reference.
Fix doctest mentions Fix doctest. Collected reference.
Fix doctest mentions remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`). Collected reference.
Fix doctest referenced by JuliaLang/julia#57347. Collected reference.
Backports release 1.12 mentions Use `BLAS.trsm!` instead of `LAPACK.trtrs!` in left-triangular solves. Collected reference.
Backports release 1.12 mentions JuliaLang/LinearAlgebra.jl#1207. Collected reference.
Backports release 1.12 mentions JuliaLang/LinearAlgebra.jl#1196. Collected reference.
Backports release 1.12 mentions JuliaLang/LinearAlgebra.jl#1202. Collected reference.
Backports release 1.12 mentions JuliaLang/LinearAlgebra.jl#1203. Collected reference.
Backports release 1.12 mentions JuliaLang/LinearAlgebra.jl#1210. Collected reference.
Backports release 1.12 mentions JuliaLang/LinearAlgebra.jl#1214. Collected reference.
Backports release 1.12 mentions remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`). Collected reference.
Backports release 1.12 mentions Backports release 1.12. Collected reference.
Backports release 1.12 mentions JuliaLang/LinearAlgebra.jl#1237. Collected reference.
Improve Cholesky type inference without copying mentions remove copy-allocation on accessing `cholesky` factors (`.L`, `.U`). Collected reference.
Fix argument handling in `@grad_from_chainrules` mentions JuliaDiff/ReverseDiff.jl#314. Collected reference.
Fix argument handling in `@grad_from_chainrules` mentions JuliaDiff/ReverseDiff.jl#315. Collected reference.
Fix argument handling in `@grad_from_chainrules` mentions JuliaDiff/ReverseDiff.jl#319. Collected reference.
Fix argument handling in `@grad_from_chainrules` mentions JuliaDiff/ReverseDiff.jl#320. Collected reference.
Fix argument handling in `@grad_from_chainrules` mentions JuliaDiff/ReverseDiff.jl#316. Collected reference.
Fix argument handling in `@grad_from_chainrules` mentions JuliaDiff/ReverseDiff.jl#318. Collected reference.
Fix argument handling in `@grad_from_chainrules` mentions Fix argument handling in `@grad_from_chainrules`. Collected reference.
Fix argument handling in `@grad_from_chainrules` referenced by JuliaDiff/ReverseDiff.jl#331. Collected reference.
Fix argument handling in `@grad_from_chainrules` referenced by Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later. Collected reference.
Fix argument handling in `@grad_from_chainrules` referenced by JuliaDiff/ReverseDiff.jl#330. Collected reference.
Request a PR review mentions Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later. Collected reference.