Skip to content
Open
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
23 changes: 13 additions & 10 deletions src/Multivariate/LowRankFun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct LowRankFun{S<:Space,M<:Space,SS<:AbstractProductSpace,T<:Number} <: Bivar
B::Vector{VFun{M,T}},
space::SS) where {S,M,SS,T}
@assert length(A) == length(B)
@assert length(A) > 0
new{S,M,SS,T}(A,B,space)
end
end
Expand All @@ -57,29 +56,33 @@ size(f::LowRankFun) = size(f,1),size(f,2)

function LowRankFun(X::Array{T},dx::S,dy::M) where {S<:Space,M<:Space,T<:Number}
U,Σ,V=svd(X)
m=max(1,count(s->s>10eps(T),Σ))
m=count(s->s>10eps(T),Σ)

A=VFun{S,T}[Fun(dx,U[:,k].*sqrt(Σ[k])) for k=1:m]
B=VFun{M,T}[Fun(dy,conj(V[:,k]).*sqrt(Σ[k])) for k=1:m]
A=VFun{S,T}[Fun(dx, (@view U[:,k]).*sqrt(Σ[k])) for k=1:m]
B=VFun{M,T}[Fun(dy, conj.(@view V[:,k]).*sqrt(Σ[k])) for k=1:m]

LowRankFun(A,B)
LowRankFun(A, B, dx ⊗ dy)
end

## Construction in a TensorSpace via a Vector of Funs

function LowRankFun(X::Vector{VFun{S,T}},d::TensorSpace{SV,DD}) where {S,T,DD<:EuclideanDomain{2},SV}
@assert d[1] == space(X[1])
LowRankFun(X,d[2])
if !isempty(X)
@assert factor(d, 1) == space(X[1])
else
@assert factor(d, 1) isa S
end
LowRankFun(X, factor(d, 2), factor(d, 1))
end

function LowRankFun(X::Vector{VFun{S,T}},dy::Space) where {S,T}
m=mapreduce(ncoefficients,max,X)
function LowRankFun(X::Vector{VFun{S,T}},dy::Space,dx::Space = nothing) where {S,T}
m=mapreduce(ncoefficients,max,X, init=0)
M=zeros(T,m,length(X))
for k=1:length(X)
M[1:ncoefficients(X[k]),k]=X[k].coefficients
end

LowRankFun(M,space(X[1]),dy)
LowRankFun(M, dx === nothing ? space(X[1]) : dx, dy)
end


Expand Down
3 changes: 2 additions & 1 deletion src/Multivariate/ProductFun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ end
*(f::ProductFun,B::Fun) = transpose(B*transpose(f))


LowRankFun(f::ProductFun{S,V,SS}) where {S,V,SS<:TensorSpace} = LowRankFun(f.coefficients,factor(space(f),2))
LowRankFun(f::ProductFun{S,V,SS}) where {S,V,SS<:TensorSpace} =
LowRankFun(f.coefficients, space(f))
LowRankFun(f::Fun) = LowRankFun(ProductFun(f))

function differentiate(f::ProductFun{S,V,SS},j::Integer) where {S,V,SS<:TensorSpace}
Expand Down
2 changes: 1 addition & 1 deletion src/Multivariate/VectorFun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ end

#TODO: fix for complex
evaluate(A::AbstractArray{T},x::Number) where {T<:Fun} =
typeof(first(A)(x))[Akj(x) for Akj in A]
[Akj(x) for Akj in A]