@@ -68,20 +68,25 @@ linesum(f::Fun{CosSpace{DD,RR}}) where {DD<:PeriodicSegment,RR} =
68
68
69
69
70
70
function integrate (f:: Fun{CS} ) where CS<: CosSpace
71
- if isa (domain (f),Circle)
72
- error (" Integrate not implemented for CosSpace on Circle" )
73
- else # Probably periodic itnerval, drop constant term if zero
71
+ d = domain (f)
72
+ tinf = if d isa Circle
73
+ throw (ArgumentError (" Integrate not implemented for CosSpace on Circle" ))
74
+ else # Probably periodic interval, drop constant term if zero
74
75
tol= 1E-14 # TODO : smart tolerance. Here relative is a bit tricky
75
76
# since this is called by Fourier integrate
76
- if abs (f. coefficients[1 ])< tol
77
+ if isempty (f . coefficients) || abs (f. coefficients[1 ])< tol
77
78
integrate (Fun (f,space (f)| (2 : ∞)))
78
- else
79
- d= domain (f)
80
- @assert isa (d,PeriodicSegment)
79
+ elseif d isa PeriodicSegment
81
80
x= Fun (identity, Interval (d))
82
- (f. coefficients[1 ]* x)⊕ integrate (Fun (f,space (f)| (2 : ∞)))
81
+ fconstant = (f. coefficients[1 ]* x)
82
+ fperiodic = integrate (Fun (f,space (f)| (2 : ∞)))
83
+ SS = SumSpace (space (fconstant), space (fperiodic))
84
+ Fun (SS, ApproxFunBase. interlace (coefficients (fconstant), coefficients (fperiodic)))
85
+ else
86
+ throw (ArgumentError (" not implemented" ))
83
87
end
84
88
end
89
+ chop (tinf)
85
90
end
86
91
87
92
function integrate (f:: Fun{SS} ) where SS<: SinSpace
@@ -98,9 +103,13 @@ for OP in (:differentiate,:integrate)
98
103
@eval $ OP (f:: Fun{Fourier{D,R},T} ) where {T,D<: Circle ,R} = $ OP (Fun (f,Laurent))
99
104
end
100
105
101
- integrate (f:: Fun{Fourier{D,R},T} ) where {T,D<: PeriodicSegment ,R} =
102
- integrate (component (f,2 ))⊕ integrate (component (f,1 ))
103
-
106
+ function integrate (f:: Fun{Fourier{D,R},T} ) where {T,D<: PeriodicSegment ,R}
107
+ g1 = integrate (component (f,2 ))
108
+ g2 = integrate (component (f,1 ))
109
+ # g1 ⊕ g2, but we construct the space directly to improve type-stability
110
+ SS = SumSpace (space (g1), space (g2))
111
+ Fun (SS, ApproxFunBase. interlace (coefficients (g1), coefficients (g2)))
112
+ end
104
113
105
114
106
115
0 commit comments