Skip to content

Commit c3cfaaf

Browse files
authored
promote in (::Fun) + (::Number) (#208)
* promote in (::Fun) + (::Number) * version bump to v0.7.8
1 parent 39a50e8 commit c3cfaaf

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
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.7"
3+
version = "0.7.8"
44

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

src/Fun.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ struct Fun{S,T,VT} <: Function
1212
space::S
1313
coefficients::VT
1414
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))"))
1619
new{S,T,VT}(sp,coeff)
1720
end
1821
end
@@ -293,9 +296,10 @@ for op in (:+,:-)
293296
function $op(f::Fun,g::Fun)
294297
if spacescompatible(f,g)
295298
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);
297301

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))
299303
else
300304
m=union(f.space,g.space)
301305
if isa(m,NoSpace)
@@ -305,7 +309,12 @@ for op in (:+,:-)
305309
end
306310
end
307311
$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
309318
$op(f::Fun,c::UniformScaling) = $op(f,c.λ)
310319
$op(c::UniformScaling,f::Fun) = $op(c.λ,f)
311320
end

0 commit comments

Comments
 (0)