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

LTA: colon indexing for LTM #562

Merged
merged 2 commits into from
Jul 9, 2024
Merged
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
11 changes: 10 additions & 1 deletion src/LowerTriangularMatrices/lower_triangular_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,15 @@ end
end

@inline function Base.getindex(L::LowerTriangularMatrix{T}, col::Colon, i::Integer) where T
return Matrix(L)[:,i]
if i==1
return L.data[1:size(L, 1, as=Matrix)]
else
return Matrix(L)[:,i]
end
end

@inline function Base.getindex(L::LowerTriangularMatrix{T}, i::Integer, col::Colon) where T
return Matrix(L)[i,:]
end

# important to do Tuple(I) here for the j > i case as one of the getindex methods above is called
Expand All @@ -224,6 +232,7 @@ Base.@propagate_inbounds Base.getindex(L::LowerTriangularArray{T,1,V}, i::Intege
Base.@propagate_inbounds Base.getindex(L::LowerTriangularArray{T,1,V}, I::CartesianIndex{M}) where {T,V<:AbstractVector{T},M} = getindex(L, Tuple(I)...)
Base.@propagate_inbounds Base.getindex(L::LowerTriangularArray{T,1,V}, i::Integer, I::CartesianIndex{0}) where {T,V<:AbstractVector{T}} = getindex(L, i)


# setindex with lm, ..
@inline Base.setindex!(L::LowerTriangularArray{T,N}, x, I::Vararg{Any, N}) where {T, N} = setindex!(L.data, x, I...)

Expand Down
2 changes: 2 additions & 0 deletions test/lower_triangular_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import Random

@test all(L[:,1] .== A[:,1])
@test all(L[:,2] .== A[:,2])
@test all(L[1,:] .== A[1,:])
@test all(L[2,:] .== A[2,:])
end
end
end
Expand Down