@@ -68,20 +68,25 @@ linesum(f::Fun{CosSpace{DD,RR}}) where {DD<:PeriodicSegment,RR} =
6868
6969
7070function 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
7475 tol= 1E-14 # TODO : smart tolerance. Here relative is a bit tricky
7576 # since this is called by Fourier integrate
76- if abs (f. coefficients[1 ])< tol
77+ if isempty (f . coefficients) || abs (f. coefficients[1 ])< tol
7778 integrate (Fun (f,space (f)| (2 : ∞)))
78- else
79- d= domain (f)
80- @assert isa (d,PeriodicSegment)
79+ elseif d isa PeriodicSegment
8180 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" ))
8387 end
8488 end
89+ chop (tinf)
8590end
8691
8792function integrate (f:: Fun{SS} ) where SS<: SinSpace
@@ -98,9 +103,13 @@ for OP in (:differentiate,:integrate)
98103 @eval $ OP (f:: Fun{Fourier{D,R},T} ) where {T,D<: Circle ,R} = $ OP (Fun (f,Laurent))
99104end
100105
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
104113
105114
106115
0 commit comments