Skip to content

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Nov 26, 2024

The LAPACK functions require contiguous matrices. Currently, the multiplication (BLAS) methods throw errors for non-contiguous arguments, while the LAPACK.trtrs! appears to silently accept a non-contiguous argument and returns an incorrect result (JuliaLang/julia#40613). This PR makes such cases fall back to the julia implementation, and only the stride-1 cases are forwarded to the corresponding LAPACK/BLAS functions.

Fixes JuliaLang/julia#40613
Fixes #878

After this, in-place multiplication by a triangular matrix works for non-contiguous matrices.

julia> U = UpperTriangular(float.(reshape(1:9,3,3)))
3×3 UpperTriangular{Float64, Matrix{Float64}}:
 1.0  4.0  7.0
     5.0  8.0
         9.0

julia> B = float.(collect(reshape(1:25, 5, 5)));

julia> Bv_nc = view(B, 1:2:5, 1:2:5)
3×3 view(::Matrix{Float64}, 1:2:5, 1:2:5) with eltype Float64:
 1.0  11.0  21.0
 3.0  13.0  23.0
 5.0  15.0  25.0

julia> ldiv!(U, lmul!(U, Bv_nc))
3×3 view(::Matrix{Float64}, 1:2:5, 1:2:5) with eltype Float64:
 1.0  11.0  21.0
 3.0  13.0  23.0
 5.0  15.0  25.0

julia> rdiv!(rmul!(Bv_nc, U), U)
3×3 view(::Matrix{Float64}, 1:2:5, 1:2:5) with eltype Float64:
 1.0  11.0  21.0
 3.0  13.0  23.0
 5.0  15.0  25.0

@jishnub
Copy link
Member Author

jishnub commented Nov 27, 2024

We may want to backport this change (at least the fix).

@jishnub jishnub added backport 1.11 Change should be backported to the 1.11 release backport 1.10 Change should be backported to the 1.10 release labels Nov 27, 2024
@jishnub jishnub force-pushed the jishnub/tri_muldiv_stride branch from 90540dd to cd0da66 Compare December 2, 2024 07:26
@jishnub jishnub merged commit 85919e6 into master Dec 2, 2024
2 checks passed
@jishnub jishnub deleted the jishnub/tri_muldiv_stride branch December 2, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to the 1.11 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when inverting array view under certain conditions ldiv! assumes StridedArray has unit stride?
2 participants