Skip to content

Commit

Permalink
Improved inference in coefficients (#163)
Browse files Browse the repository at this point in the history
* improved inference in coefficients

* version bump to v0.6.12
  • Loading branch information
jishnub authored Aug 16, 2022
1 parent 120d573 commit 46d472d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFunBase"
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
version = "0.6.11"
version = "0.6.12"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
3 changes: 3 additions & 0 deletions src/Fun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ end
coefficient(f::Fun,K::Block) = coefficient(f,blockrange(space(f),K.n[1]))
coefficient(f::Fun,::Colon) = coefficient(f,1:dimension(space(f)))

# convert to vector while computing coefficients
_maybeconvert(inplace::Val{false}, f::Fun, v) = strictconvert(Vector{cfstype(f)}, v)

##Convert routines


Expand Down
1 change: 1 addition & 0 deletions src/LinearAlgebra/helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function isapprox_atol(x::AbstractArray{T}, y::AbstractArray{S},atol::Real=0; rt
end

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


Expand Down
5 changes: 4 additions & 1 deletion src/Space.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,12 @@ _ldiv_coefficients!!(inplace::Val{false}) = ldiv_coefficients

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

if spacescompatible(a,b)
x = if spacescompatible(a,b)
f
elseif hasconversion(a,b)
_mul_coefficients!!(inplace)(Conversion(a,b),f)
Expand All @@ -331,6 +333,7 @@ function defaultcoefficients(f,a,b,inplace = Val(false))
_coefficients!!(inplace)(f,a,csp,b)
end
end
_maybeconvert(inplace, f, x)
end

coefficients(f,a,b) = defaultcoefficients(f,a,b)
Expand Down
7 changes: 6 additions & 1 deletion test/SpacesTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,14 @@ using ApproxFunOrthogonalPolynomials
@test itransform(NormalizedChebyshev(), v2) v

f = @inferred Fun(x->x^2, Chebyshev())
v = coefficients(f, Chebyshev(), Legendre())
v = @inferred coefficients(f, Chebyshev(), Legendre())
@test eltype(v) == eltype(coefficients(f))
@test v coefficients(Fun(x->x^2, Legendre()))

# inference check for coefficients
v = @inferred coefficients(Float64[0,0,1], Chebyshev(), Ultraspherical(1))
@test v [-0.5, 0, 0.5]

@testset "inplace transform" begin
@testset for sp_c in Any[Legendre(), Chebyshev(), Jacobi(1,2), Jacobi(0.3, 2.3),
Ultraspherical(1), Ultraspherical(2)]
Expand Down

2 comments on commit 46d472d

@jishnub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/66349

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.12 -m "<description of version>" 46d472db07df8bae42e0e84a70384938c45add9e
git push origin v0.6.12

Please sign in to comment.