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

Implemented strides for AbstractArray subtypes #30429

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions stdlib/LinearAlgebra/test/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down