Skip to content

Commit

Permalink
Rank 1 matrix LinearMap added
Browse files Browse the repository at this point in the history
  • Loading branch information
krcools committed Jul 10, 2023
1 parent 478adb5 commit 18f7ebd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/BEAST.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ include("utils/specialfns.jl")
include("utils/combinatorics.jl")
include("utils/linearspace.jl")
include("utils/zeromap.jl")
include("utils/rank1map.jl")

include("bases/basis.jl")
include("bases/lincomb.jl")
Expand Down
23 changes: 23 additions & 0 deletions src/utils/rank1map.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import LinearMaps

struct Rank1Map{T,U,V} <: LinearMap{T}
u::U
v::V
end

Rank1Map{T}(u::U, v::V) where {T,U,V} = Rank1Map{T,U,V}(u,v)
LinearMaps.MulStyle(A::Rank1Map) = LinearMaps.FiveArg()

Base.size(A::Rank1Map) = (length(A.u), length(A.v),)
Base.axes(A::Rank1Map) = (axes(A.u)..., axes(A.v)...)

function LinearMaps._unsafe_mul!(y::AbstractVector, L::Rank1Map, x::AbstractVector, α::Number=true, β::Number=false)
y .*= β
y .+= α .* L.u .* dot(L.v, x)
end

function LinearMaps._unsafe_mul!(Y::AbstractMatrix, L::Rank1Map, c::Number, a::Number=true, b::Number=false)
rmul!(Y, b)
Y .+= (L.u * L.v') .* c .* α
return Y
end

0 comments on commit 18f7ebd

Please sign in to comment.