diff --git a/stdlib/LinearAlgebra/src/adjtrans.jl b/stdlib/LinearAlgebra/src/adjtrans.jl index 8ded77a7eda74..3452f407ddcab 100644 --- a/stdlib/LinearAlgebra/src/adjtrans.jl +++ b/stdlib/LinearAlgebra/src/adjtrans.jl @@ -118,6 +118,9 @@ const AdjOrTransAbsMat{T} = AdjOrTrans{T,<:AbstractMatrix} wrapperop(A::Adjoint) = adjoint wrapperop(A::Transpose) = transpose +strides(a::AdjOrTrans) = size_to_strides(1, size(a)...) +stride(a::AdjOrTrans, i::Integer) = strides(a)[i] + # AbstractArray interface, basic definitions length(A::AdjOrTrans) = length(A.parent) size(v::AdjOrTransAbsVec) = (1, length(v.parent)) diff --git a/stdlib/LinearAlgebra/src/diagonal.jl b/stdlib/LinearAlgebra/src/diagonal.jl index b73279abb2878..8e3f7bd244560 100644 --- a/stdlib/LinearAlgebra/src/diagonal.jl +++ b/stdlib/LinearAlgebra/src/diagonal.jl @@ -103,7 +103,6 @@ function setindex!(D::Diagonal, v, i::Int, j::Int) return v end - ## structured matrix methods ## function Base.replace_in_print_matrix(A::Diagonal,i::Integer,j::Integer,s::AbstractString) i==j ? s : Base.replace_with_centered_mark(s) diff --git a/stdlib/LinearAlgebra/test/adjtrans.jl b/stdlib/LinearAlgebra/test/adjtrans.jl index d0e82aafa78bf..0803ed35d6d85 100644 --- a/stdlib/LinearAlgebra/test/adjtrans.jl +++ b/stdlib/LinearAlgebra/test/adjtrans.jl @@ -340,6 +340,15 @@ end @test broadcast(+, Transpose(sparsevec), 1.0, Transpose(sparsevec)) isa Transpose{Float64,SparseVector{Float64,Int}} end +@testset "Strides AdjOrTrans Issue#29705" begin + @test strides(rand(3,5)') == (1, 5) + @test strides([1 2 3; 4 5 6]') == (1, 3) + @test strides(transpose(rand(3,4))) == (1, 4) + @test strides(transpose([1 2 3; 4 5 6])) == (1, 3) + @test stride(rand(3,5)', 1) == 1 + @test stride(rand(3,5)', 2) == 5 +end + @testset "Adjoint/Transpose-wrapped vector multiplication" begin realvec, realmat = [1, 2, 3], [1 2 3; 4 5 6; 7 8 9] complexvec, complexmat = [1im, 2, -3im], [1im 2 3; 4 5 -6im; 7im 8 9]