@@ -12,7 +12,10 @@ struct Fun{S,T,VT} <: Function
12
12
space:: S
13
13
coefficients:: VT
14
14
function Fun {S,T,VT} (sp:: S ,coeff:: VT ) where {S,T,VT}
15
- @assert length (coeff) ≤ dimension (sp)
15
+ nc = length (coeff)
16
+ dimsp = dimension (sp)
17
+ nc ≤ dimsp ||
18
+ throw (ArgumentError (" length(coeff) = $(length (coeff)) exceeds dimension(space) = $(dimension (sp)) " ))
16
19
new {S,T,VT} (sp,coeff)
17
20
end
18
21
end
@@ -293,9 +296,10 @@ for op in (:+,:-)
293
296
function $op (f:: Fun ,g:: Fun )
294
297
if spacescompatible (f,g)
295
298
n = max (ncoefficients (f),ncoefficients (g))
296
- f2 = pad (f,n); g2 = pad (g,n)
299
+ f2 = pad (f,n);
300
+ g2 = pad (g,n);
297
301
298
- Fun (isambiguous (domain (f)) ? g. space : f. space,($ op)(f2. coefficients,g2. coefficients))
302
+ Fun (isambiguous (domain (f)) ? g. space : f. space, ($ op)(f2. coefficients,g2. coefficients))
299
303
else
300
304
m= union (f. space,g. space)
301
305
if isa (m,NoSpace)
@@ -305,7 +309,12 @@ for op in (:+,:-)
305
309
end
306
310
end
307
311
$ op (f:: Fun{S,T} ,c:: T ) where {S,T<: Number } = c== 0 ? f : $ op (f,Fun (c))
308
- $ op (f:: Fun ,c:: Number ) = $ op (f,Fun (c))
312
+ function $op (f:: Fun , c:: Number )
313
+ T = promote_type (typeof (c), cfstype (f))
314
+ g = cfstype (f) == T ? f : Fun (space (f), T .(coefficients (f)))
315
+ d = convert (T, c)
316
+ $ op (g,Fun (d))
317
+ end
309
318
$ op (f:: Fun ,c:: UniformScaling ) = $ op (f,c. λ)
310
319
$ op (c:: UniformScaling ,f:: Fun ) = $ op (c. λ,f)
311
320
end
0 commit comments