Skip to content

Commit 46d472d

Browse files
authored
Improved inference in coefficients (#163)
* improved inference in coefficients * version bump to v0.6.12
1 parent 120d573 commit 46d472d

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
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.6.11"
3+
version = "0.6.12"
44

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

src/Fun.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ end
7272
coefficient(f::Fun,K::Block) = coefficient(f,blockrange(space(f),K.n[1]))
7373
coefficient(f::Fun,::Colon) = coefficient(f,1:dimension(space(f)))
7474

75+
# convert to vector while computing coefficients
76+
_maybeconvert(inplace::Val{false}, f::Fun, v) = strictconvert(Vector{cfstype(f)}, v)
77+
7578
##Convert routines
7679

7780

src/LinearAlgebra/helper.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function isapprox_atol(x::AbstractArray{T}, y::AbstractArray{S},atol::Real=0; rt
5050
end
5151

5252
# The second case handles zero
53+
isapproxinteger(::Integer) = true
5354
isapproxinteger(x) = isapprox(x,round(Int,x)) || isapprox(x+1,round(Int,x+1))
5455

5556

src/Space.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,12 @@ _ldiv_coefficients!!(inplace::Val{false}) = ldiv_coefficients
309309

310310
_Fun(v::AbstractVector, sp) = Fun(sp, v)
311311
_Fun(v, sp) = Fun(v, sp)
312+
_maybeconvert(inplace::Val{true}, f, v) = v
313+
_maybeconvert(inplace::Val{false}, f::AbstractVector, v) = strictconvert(Vector{eltype(f)}, v)
312314
function defaultcoefficients(f,a,b,inplace = Val(false))
313315
ct=conversion_type(a,b) # gives a space that has a banded conversion to both a and b
314316

315-
if spacescompatible(a,b)
317+
x = if spacescompatible(a,b)
316318
f
317319
elseif hasconversion(a,b)
318320
_mul_coefficients!!(inplace)(Conversion(a,b),f)
@@ -331,6 +333,7 @@ function defaultcoefficients(f,a,b,inplace = Val(false))
331333
_coefficients!!(inplace)(f,a,csp,b)
332334
end
333335
end
336+
_maybeconvert(inplace, f, x)
334337
end
335338

336339
coefficients(f,a,b) = defaultcoefficients(f,a,b)

test/SpacesTest.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,14 @@ using ApproxFunOrthogonalPolynomials
225225
@test itransform(NormalizedChebyshev(), v2) v
226226

227227
f = @inferred Fun(x->x^2, Chebyshev())
228-
v = coefficients(f, Chebyshev(), Legendre())
228+
v = @inferred coefficients(f, Chebyshev(), Legendre())
229+
@test eltype(v) == eltype(coefficients(f))
229230
@test v coefficients(Fun(x->x^2, Legendre()))
230231

232+
# inference check for coefficients
233+
v = @inferred coefficients(Float64[0,0,1], Chebyshev(), Ultraspherical(1))
234+
@test v [-0.5, 0, 0.5]
235+
231236
@testset "inplace transform" begin
232237
@testset for sp_c in Any[Legendre(), Chebyshev(), Jacobi(1,2), Jacobi(0.3, 2.3),
233238
Ultraspherical(1), Ultraspherical(2)]

0 commit comments

Comments
 (0)