Skip to content

Commit d26f787

Browse files
authored
Fix multiplication of MultivariateFun (#218)
* product of LowRankFun and ProductFun * exponentiation for MultivariateFun * version bump to v0.7.13
1 parent b3f1a79 commit d26f787

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.7.12"
3+
version = "0.7.13"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Multivariate/LowRankFun.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,6 @@ sum(g::LowRankFun,n::Integer)=(n==1) ? dotu(g.B,map(sum,g.A)) : dotu(g.A,map(sum
424424
cumsum(g::LowRankFun,n::Integer)=(n==1) ? LowRankFun(map(cumsum,g.A),copy(g.B)) : LowRankFun(copy(g.A),map(cumsum,g.B))
425425
differentiate(g::LowRankFun,n::Integer)=(n==1) ? LowRankFun(map(differentiate,g.A),copy(g.B)) : LowRankFun(copy(g.A),map(differentiate,g.B))
426426
integrate(g::LowRankFun,n::Integer)=(n==1) ? LowRankFun(map(integrate,g.A),copy(g.B)) : LowRankFun(copy(g.A),map(integrate,g.B))
427+
428+
zero(L::LowRankFun) = LowRankFun((x...)->zero(cfstype(L)), space(L))
429+
one(L::LowRankFun) = LowRankFun((x...)->one(cfstype(L)), space(L))

src/Multivariate/Multivariate.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,23 @@ coefficients(f::BivariateFun,sp::TensorSpace)=coefficients(f,sp[1],sp[2])
5151
points(f::BivariateFun,k...)=points(space(f),size(f,1),size(f,2),k...)
5252

5353

54-
function *(vx::LowRankFun,u0::ProductFun)
55-
ret=zero(space(u0))
56-
for k=1:length(vx.A)
57-
a,b=vx.A[k],vx.B[k]
58-
ret+=transpose(b*(transpose(a*u0)))
54+
function *(vx::LowRankFun, u0::ProductFun)
55+
sum(zip(vx.A, vx.B)) do (a,b)
56+
transpose(b*(transpose(a*u0)))
5957
end
60-
ret
6158
end
6259

6360
*(a::ProductFun,b::LowRankFun)=b*a
6461
*(a::MultivariateFun,b::MultivariateFun)=LowRankFun(a)*ProductFun(b)
6562

63+
@inline function ^(a::MultivariateFun, n::Integer)
64+
n < 0 && return ^(inv(a), -n)
65+
n == 0 && return one(a)
66+
n == 1 && return a
67+
n == 2 && return a * a
68+
return foldr(*, fill(a, n-2), init=a*a)
69+
end
70+
6671
for OP in (:+,:-,:*,:/)
6772
@eval begin
6873
$OP(f::Fun,g::MultivariateFun)=$OP(ProductFun(f),g)

src/Multivariate/ProductFun.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,6 @@ end
344344
for op in (:tocanonical,:fromcanonical)
345345
@eval $op(f::ProductFun,x...) = $op(space(f),x...)
346346
end
347+
348+
zero(P::ProductFun) = ProductFun((x...)->zero(cfstype(P)), space(P))
349+
one(P::ProductFun) = ProductFun((x...)->one(cfstype(P)), space(P))

0 commit comments

Comments
 (0)