Skip to content
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
4 changes: 4 additions & 0 deletions stdlib/LinearAlgebra/src/abstractq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ transpose(Q::AbstractQ{<:Real}) = AdjointQ(Q)
transpose(Q::AbstractQ) = error("transpose not implemented for $(typeof(Q)). Consider using adjoint instead of transpose.")
adjoint(adjQ::AdjointQ) = adjQ.Q

(^)(Q::AbstractQ, p::Integer) = p < 0 ? power_by_squaring(inv(Q), -p) : power_by_squaring(Q, p)
@inline Base.literal_pow(::typeof(^), Q::AbstractQ, ::Val{1}) = Q
@inline Base.literal_pow(::typeof(^), Q::AbstractQ, ::Val{-1}) = inv(Q)
Comment on lines +22 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@inline Base.literal_pow(::typeof(^), Q::AbstractQ, ::Val{1}) = Q
@inline Base.literal_pow(::typeof(^), Q::AbstractQ, ::Val{-1}) = inv(Q)

Is there a reason for these? The fallback should work just fine here, no?


# promotion with AbstractMatrix, at least for equal eltypes
promote_rule(::Type{<:AbstractMatrix{T}}, ::Type{<:AbstractQ{T}}) where {T} =
(@inline; Union{AbstractMatrix{T},AbstractQ{T}})
Expand Down
6 changes: 6 additions & 0 deletions stdlib/LinearAlgebra/test/abstractq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ n = 5
@test Q'*I ≈ Q.Q'*I rtol=2eps(real(T))
@test I*Q ≈ Q.Q*I rtol=2eps(real(T))
@test I*Q' ≈ I*Q.Q' rtol=2eps(real(T))
@test Q^3 ≈ Q*Q*Q
@test Q^2 ≈ Q*Q
@test Q^1 == Q
@test Q^(-1) == Q'
@test (Q')^(-1) == Q
@test (Q')^2 ≈ Q'*Q'
@test abs(det(Q)) ≈ 1
@test logabsdet(Q)[1] ≈ 0 atol=2n*eps(real(T))
y = rand(T, n)
Expand Down