Skip to content

Commit

Permalink
Add view(::LazyTransposedMatElem, ...) (#1719)
Browse files Browse the repository at this point in the history
  • Loading branch information
joschmitt authored May 29, 2024
1 parent 978e26c commit 8ff2d59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ function Base.setindex!(M::LazyTransposeMatElem{T}, d::T, r::Int, c::Int) where
return M
end

function AbstractAlgebra.view(M::LazyTransposeMatElem, r::Union{Colon, AbstractVector{Int}}, c::Union{Colon, AbstractVector{Int}})
return lazy_transpose(view(data(M), c, r))
end

# If one of the arguments is an Int, then the result is 1-dimensional so wrapping
# it in a lazy_transpose does not make sense (and does not work, if we don't add
# something like lazy_transpose(::AbstractVector))
function AbstractAlgebra.view(M::LazyTransposeMatElem, r::Int, c::Union{Colon, AbstractVector{Int}})
return view(data(M), c, r)
end
function AbstractAlgebra.view(M::LazyTransposeMatElem, r::Union{Colon, AbstractVector{Int}}, c::Int)
return view(data(M), c, r)
end

AbstractAlgebra.base_ring(M::LazyTransposeMatElem) = base_ring(data(M))

Base.zero(M::LazyTransposeMatElem) = lazy_transpose(zero(data(M)))
Expand Down
7 changes: 7 additions & 0 deletions test/Solve-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ end
@test nrows(MT) == 5
@test ncols(MT) == 3

V = @inferred view(MT, 1, 1:3)
@test V == [QQ(1), QQ(0), QQ(0)]
V = @inferred view(MT, 1:5, 1)
@test V == [QQ(1), QQ(2), QQ(3), QQ(4), QQ(5)]
V = @inferred view(MT, 3:4, 1:2)
@test V == QQ[3 8; 4 9]

@test MT[2, 1] == QQ(2)
MT[2, 1] = QQ(100)
@test MT[2, 1] == QQ(100)
Expand Down

0 comments on commit 8ff2d59

Please sign in to comment.