diff --git a/src/LowerTriangularMatrices/lower_triangular_matrix.jl b/src/LowerTriangularMatrices/lower_triangular_matrix.jl index a3689b73f..1f107f720 100644 --- a/src/LowerTriangularMatrices/lower_triangular_matrix.jl +++ b/src/LowerTriangularMatrices/lower_triangular_matrix.jl @@ -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 @@ -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...) diff --git a/test/lower_triangular_matrix.jl b/test/lower_triangular_matrix.jl index f04775bcc..10f7f6f06 100644 --- a/test/lower_triangular_matrix.jl +++ b/test/lower_triangular_matrix.jl @@ -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