Skip to content

Replace Vec by SVector #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ uuid = "b70543e2-c0d9-56b8-a290-0d4d6d4de211"
version = "0.5.15"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
FastTransforms = "057dd010-8810-581a-b7be-e3fc3b93f78c"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand All @@ -21,15 +19,13 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
AbstractFFTs = "0.5, 1"
ApproxFunBase = "0.7"
ApproxFunBaseTest = "0.1"
Aqua = "0.5"
BandedMatrices = "0.16, 0.17"
BlockArrays = "0.14, 0.15, 0.16"
BlockBandedMatrices = "0.10, 0.11"
DomainSets = "0.5"
FFTW = "1.1"
FastGaussQuadrature = "0.4, 0.5"
FastTransforms = "0.12, 0.13, 0.14"
FillArrays = "0.11, 0.12, 0.13"
Expand Down
137 changes: 61 additions & 76 deletions src/ApproxFunOrthogonalPolynomials.jl
Original file line number Diff line number Diff line change
@@ -1,97 +1,82 @@
module ApproxFunOrthogonalPolynomials
using Base, LinearAlgebra, Reexport, BandedMatrices, BlockBandedMatrices, AbstractFFTs, FFTW, BlockArrays, FillArrays, FastTransforms, IntervalSets,
using Base, LinearAlgebra, Reexport, BandedMatrices, BlockBandedMatrices,
BlockArrays, FillArrays, FastTransforms, IntervalSets,
DomainSets, Statistics, SpecialFunctions, FastGaussQuadrature

@reexport using ApproxFunBase

import AbstractFFTs: Plan, fft, ifft
import FFTW: plan_r2r!, fftwNumber, REDFT10, REDFT01, REDFT00, RODFT00, R2HC, HC2R,
r2r!, r2r, plan_fft, plan_ifft, plan_ifft!, plan_fft!

import ApproxFunBase: normalize!, flipsign, FiniteRange, Fun, MatrixFun, UnsetSpace, VFun, RowVector,
UnivariateSpace, AmbiguousSpace, SumSpace, SubSpace, WeightSpace, NoSpace, Space,
HeavisideSpace, PointSpace,
IntervalOrSegment, RaggedMatrix, AlmostBandedMatrix,
AnyDomain, ZeroSpace, ArraySpace, TrivialInterlacer, BlockInterlacer,
import ApproxFunBase: Fun, SubSpace, WeightSpace, NoSpace, HeavisideSpace,
IntervalOrSegment, AnyDomain, ArraySpace,
AbstractTransformPlan, TransformPlan, ITransformPlan,
ConcreteConversion, ConcreteMultiplication, ConcreteDerivative, ConcreteIntegral,
ConcreteVolterra, Volterra, VolterraWrapper,
MultiplicationWrapper, ConversionWrapper, DerivativeWrapper, Evaluation, EvaluationWrapper,
Conversion, defaultConversion, defaultcoefficients, default_Fun, Multiplication, Derivative, Integral, bandwidths,
ConcreteEvaluation, ConcreteDefiniteLineIntegral, ConcreteDefiniteIntegral, ConcreteIntegral,
DefiniteLineIntegral, DefiniteIntegral, ConcreteDefiniteIntegral, ConcreteDefiniteLineIntegral, IntegralWrapper,
ReverseOrientation, ReverseOrientationWrapper, ReverseWrapper, Reverse, NegateEven, Dirichlet, ConcreteDirichlet,
ConcreteConversion, ConcreteMultiplication, ConcreteDerivative,
ConcreteDefiniteIntegral, ConcreteDefiniteLineIntegral,
ConcreteVolterra, Volterra, Evaluation, EvaluationWrapper,
MultiplicationWrapper, ConversionWrapper, DerivativeWrapper,
Conversion, defaultcoefficients, default_Fun, Multiplication,
Derivative, bandwidths, ConcreteEvaluation, ConcreteIntegral,
DefiniteLineIntegral, DefiniteIntegral, IntegralWrapper,
ReverseOrientation, ReverseOrientationWrapper, ReverseWrapper,
Reverse, NegateEven, Dirichlet, ConcreteDirichlet,
TridiagonalOperator, SubOperator, Space, @containsconstants, spacescompatible,
hasfasttransform, canonicalspace, domain, setdomain, prectype, domainscompatible,
plan_transform, plan_itransform, plan_transform!, plan_itransform!, transform, itransform, hasfasttransform,
canonicalspace, domain, setdomain, prectype, domainscompatible,
plan_transform, plan_itransform, plan_transform!, plan_itransform!,
transform, itransform, hasfasttransform,
CanonicalTransformPlan, ICanonicalTransformPlan,
Integral,
domainspace, rangespace, boundary,
union_rule, conversion_rule, maxspace_rule, conversion_type, maxspace, hasconversion, points,
rdirichlet, ldirichlet, lneumann, rneumann, ivp, bvp,
Integral, domainspace, rangespace, boundary,
maxspace, hasconversion, points,
union_rule, conversion_rule, maxspace_rule, conversion_type,
linesum, differentiate, integrate, linebilinearform, bilinearform,
UnsetNumber, coefficienttimes, subspace_coefficients, sumspacecoefficients, specialfunctionnormalizationpoint,
Segment, IntervalOrSegmentDomain, PiecewiseSegment, isambiguous, Vec, eps, isperiodic,
arclength, complexlength,
invfromcanonicalD, fromcanonical, tocanonical, fromcanonicalD, tocanonicalD, canonicaldomain, setcanonicaldomain, mappoint,
reverseorientation, checkpoints, evaluate, extrapolate, mul_coefficients, coefficients, isconvertible,
clenshaw, ClenshawPlan, sineshaw,
toeplitz_getindex, toeplitz_axpy!, sym_toeplitz_axpy!, hankel_axpy!, ToeplitzOperator, SymToeplitzOperator, hankel_getindex,
SpaceOperator, ZeroOperator, InterlaceOperator,
interlace!, reverseeven!, negateeven!, cfstype, pad!, alternatesign!, mobius,
extremal_args, hesseneigvals, chebyshev_clenshaw, recA, recB, recC, roots,splitatroots,
chebmult_getindex, intpow, alternatingsum,
domaintype, diagindshift, rangetype, weight, isapproxinteger, default_Dirichlet, scal!, dotu,
components, promoterangespace, promotedomainspace,
block, blockstart, blockstop, blocklengths, isblockbanded, pointscompatible, affine_setdiff, complexroots,
Segment, IntervalOrSegmentDomain, PiecewiseSegment, isambiguous,
eps, isperiodic, arclength, complexlength,
invfromcanonicalD, fromcanonical, tocanonical, fromcanonicalD,
tocanonicalD, canonicaldomain, setcanonicaldomain, mappoint,
reverseorientation, checkpoints, evaluate, extrapolate, mul_coefficients,
coefficients, isconvertible, clenshaw, ClenshawPlan,
toeplitz_axpy!, sym_toeplitz_axpy!, hankel_axpy!,
ToeplitzOperator, SymToeplitzOperator, SpaceOperator, cfstype,
alternatesign!, mobius, chebmult_getindex, intpow, alternatingsum,
extremal_args, chebyshev_clenshaw, recA, recB, recC, roots,
diagindshift, rangetype, weight, isapproxinteger, default_Dirichlet, scal!,
components, promoterangespace,
block, blockstart, blockstop, blocklengths, isblockbanded,
pointscompatible, affine_setdiff, complexroots,
ℓ⁰, recα, recβ, recγ, ℵ₀, ∞, RectDomain

import DomainSets: Domain, indomain, UnionDomain, ProductDomain, FullSpace, Point, elements, DifferenceDomain,
Interval, ChebyshevInterval, boundary, ∂, rightendpoint, leftendpoint,
import DomainSets: Domain, indomain, UnionDomain, FullSpace, Point,
Interval, ChebyshevInterval, boundary, rightendpoint, leftendpoint,
dimension, WrappedDomain

import BandedMatrices: bandrange, bandshift,
inbands_getindex, inbands_setindex!, bandwidth, AbstractBandedMatrix,
colstart, colstop, colrange, rowstart, rowstop, rowrange,
bandwidths, _BandedMatrix, BandedMatrix

import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !, !=, eltype, iterate,
>=, /, ^, \, ∪, transpose, size, tail, broadcast, broadcast!, copyto!, copy, to_index, (:),
similar, map, vcat, hcat, hvcat, show, summary, stride, sum, cumsum, sign, imag, conj, inv,
complex, reverse, exp, sqrt, abs, abs2, sign, issubset, values, in, first, last, rand, intersect, setdiff,
isless, union, angle, join, isnan, isapprox, isempty, sort, merge, promote_rule,
minimum, maximum, extrema, argmax, argmin, findmax, findmin, isfinite,
zeros, zero, one, promote_rule, repeat, length, resize!, isinf,
getproperty, findfirst, unsafe_getindex, fld, cld, div, real, imag,
@_inline_meta, eachindex, firstindex, lastindex, keys, isreal, OneTo,
Array, Vector, Matrix, view, ones, @propagate_inbounds, print_array,
split

import LinearAlgebra: BlasInt, BlasFloat, norm, ldiv!, mul!, det, eigvals, dot, cross,
qr, qr!, rank, isdiag, istril, istriu, issymmetric, ishermitian,
Tridiagonal, diagm, diagm_container, factorize, nullspace,
Hermitian, Symmetric, adjoint, transpose, char_uplo

import FastTransforms: ChebyshevTransformPlan, IChebyshevTransformPlan, plan_chebyshevtransform,
plan_chebyshevtransform!, plan_ichebyshevtransform, plan_ichebyshevtransform!,
import BandedMatrices: bandshift, bandwidth, colstop, bandwidths, BandedMatrix

import Base: convert, getindex, *, +, -, ==, <, <=, >, |, !, !=, eltype,
>=, /, ^, \, ∪, transpose, size, copyto!, copy,
map, vcat, hcat, show, stride, sum, cumsum, conj, inv,
complex, reverse, exp, sqrt, abs, sign, issubset, values,
first, last, rand, intersect, setdiff,
isless, union, angle, isnan, isapprox, isempty, sort, merge,
minimum, maximum, extrema, argmax, argmin,
zeros, zero, one, promote_rule, length, resize!, isinf,
getproperty, cld, div, real, imag,
max, min, log, acosh, tanh, atanh,
atan, sinh, asinh,
tan, tanh, asin, sec, acos,
sin, cos, sinh, cosh,
asinh, acosh, atanh,
Array, Vector, Matrix, view, ones, split

import LinearAlgebra: norm, mul!, det, eigvals, qr, Tridiagonal, transpose

import FastTransforms: plan_chebyshevtransform, plan_chebyshevtransform!,
plan_ichebyshevtransform, plan_ichebyshevtransform!,
pochhammer, lgamma, chebyshevtransform!, ichebyshevtransform!

import BlockBandedMatrices: blockbandwidths, subblockbandwidths

# we need to import all special functions to use Calculus.symbolic_derivatives_1arg
# we can't do importall Base as we replace some Base definitions
import SpecialFunctions: sinpi, cospi, airy, besselh,
asinh, acosh,atanh, erfcx, dawson, erf, erfi,
sin, cos, sinh, cosh, airyai, airybi, airyaiprime, airybiprime,
hankelh1, hankelh2, besselj, besselj0, bessely, besseli, besselk,
besselkx, hankelh1x, hankelh2x, exp2, exp10, log2, log10,
tan, tanh, csc, asin, acsc, sec, acos, asec,
cot, atan, acot, sinh, csch, asinh, acsch,
sech, acosh, asech, tanh, coth, atanh, acoth,
expm1, log1p, lfact, sinc, cosc, erfinv, erfcinv, beta, lbeta,
eta, zeta, gamma, polygamma, invdigamma, digamma, trigamma,
abs, sign, log, expm1, tan, abs2, sqrt, angle, max, min, cbrt, log,
atan, acos, asin, erfc, inv
import SpecialFunctions: erfcx, dawson, erf,
hankelh1, hankelh2, besselj, bessely, besseli, besselk,
besselkx, hankelh1x, hankelh2x,
expm1, eta, gamma, erfc

using StaticArrays: SVector

Expand Down
26 changes: 13 additions & 13 deletions src/Domains/Arc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ Arc(c::T,r::V,t::Tuple{V1,V2}) where {T<:Number,V<:Real,V1<:Real,V2<:Real} =
Arc{promote_type(T,V,V1,V2),
promote_type(real(T),V,V1,V2),
Complex{promote_type(real(T),V,V1,V2)}}(c,r,t)
Arc(c::Vec{2,T},r::V,t::Tuple{V,V}) where {T<:Number,V<:Real} =
Arc{Vec{2,promote_type(T,V)},
Arc(c::SVector{2,T},r::V,t::Tuple{V,V}) where {T<:Number,V<:Real} =
Arc{SVector{2,promote_type(T,V)},
promote_type(real(T),V),
Vec{2,promote_type(real(T),V)}}(c,r,t)
Arc(c::Vec{2,T},r::V,t::Tuple{V1,V2}) where {T<:Number,V<:Real,V1<:Real,V2<:Real} =
Arc{Vec{2,promote_type(T,V,V1,V2)},
SVector{2,promote_type(real(T),V)}}(c,r,t)
Arc(c::SVector{2,T},r::V,t::Tuple{V1,V2}) where {T<:Number,V<:Real,V1<:Real,V2<:Real} =
Arc{SVector{2,promote_type(T,V,V1,V2)},
promote_type(real(T),V,V1,V2),
Vec{2,promote_type(T,V,V1,V2)}}(c,r,t)
SVector{2,promote_type(T,V,V1,V2)}}(c,r,t)

Arc(c::Tuple,r,t) = Arc(Vec(c...),r,t)
Arc(c::Tuple,r,t) = Arc(SVector(c...),r,t)
Arc(c,r,t0,t1) = Arc(c,r,(t0,t1))


complex(a::Arc{V}) where {V<:Vec} = Arc(complex(a.center...),a.radius,a.angles)
complex(a::Arc{V}) where {V<:SVector} = Arc(complex(a.center...),a.radius,a.angles)

isambiguous(d::Arc) =
isnan(d.center) && isnan(d.radius) && isnan(d.angles[1]) && isnan(d.angles[2])
Expand Down Expand Up @@ -75,12 +75,12 @@ fromcanonical(a::Arc{T,V,TT},x) where {T<:Number,V<:Real,TT<:Complex} =
mobiusinv(a,x)
fromcanonicalD(a::Arc{T},x) where {T<:Number} = mobiusinvD(a,x)

tocanonical(a::Arc{V},x::Vec) where {V<:Vec} =
tocanonical(a::Arc{V},x::SVector) where {V<:SVector} =
tocanonical(complex(a),complex(x...))
fromcanonical(a::Arc{V},x::Number) where {V<:Vec} =
Vec(reim(fromcanonical(complex(a),x))...)
fromcanonicalD(a::Arc{V},x::Number) where {V<:Vec} =
Vec(reim(fromcanonicalD(complex(a),x))...)
fromcanonical(a::Arc{V},x::Number) where {V<:SVector} =
SVector(reim(fromcanonical(complex(a),x))...)
fromcanonicalD(a::Arc{V},x::Number) where {V<:SVector} =
SVector(reim(fromcanonicalD(complex(a),x))...)

## information

Expand Down
4 changes: 2 additions & 2 deletions src/Spaces/Chebyshev/Chebyshev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ _padua_length(N) = Int(cld(-3+sqrt(1+8N),2))
function squarepoints(::Type{T}, N) where T
pts = paduapoints(T, _padua_length(N))
n = size(pts,1)
ret = Array{Vec{2,T}}(undef, n)
ret = Array{SVector{2,T}}(undef, n)
@inbounds for k=1:n
ret[k] = Vec{2,T}(pts[k,1],pts[k,2])
ret[k] = SVector{2,T}(pts[k,1],pts[k,2])
end
ret
end
Expand Down
2 changes: 1 addition & 1 deletion src/Spaces/PolynomialSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end

# we need the ... for multi-dimensional
evaluate(f::AbstractVector,S::PolynomialSpace,x,y,z...) =
evaluate(f,S,Vec(x,y,z...))
evaluate(f,S,SVector(x,y,z...))

function evaluate(f::AbstractVector, S::PolynomialSpace, x::Fun)
if issubset(Interval(minimum(x),maximum(x)),domain(S))
Expand Down
2 changes: 1 addition & 1 deletion src/Spaces/Ultraspherical/DirichletSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct ChebyshevDirichlet{left,right,D,R} <: PolynomialSpace{D,R}
ChebyshevDirichlet{left,right,D,R}() where {left,right,D,R} = new(strictconvert(D, ChebyshevInterval()))
end

for TYP in (:Number,:AbstractArray,:Vec,:Fun)
for TYP in (:Number,:AbstractArray,:SVector,:Fun)
@eval evaluate(f::AbstractVector,S::ChebyshevDirichlet,x::$TYP) =
evaluate(Fun(Fun(S,f),canonicalspace(S)),x)
end
Expand Down
5 changes: 3 additions & 2 deletions test/JacobiTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ using ApproxFunBase
using Test
using SpecialFunctions
using LinearAlgebra
using ApproxFunBase: Vec, maxspace, NoSpace, hasconversion,
using ApproxFunBase: maxspace, NoSpace, hasconversion,
reverseorientation, ReverseOrientation, transform!, itransform!
using ApproxFunBaseTest: testbandedbelowoperator, testbandedoperator, testspace, testtransforms,
testfunctional
using ApproxFunOrthogonalPolynomials: jacobip
using StaticArrays: SVector

@verbose @testset "Jacobi" begin
@testset "Basic" begin
Expand Down Expand Up @@ -211,7 +212,7 @@ using ApproxFunOrthogonalPolynomials: jacobip
end

@testset "vector valued case" begin
f=Fun((x,y)->real(exp(x+im*y)), Legendre(Segment(Vec(0.,0.),Vec(1.,1.))))
f=Fun((x,y)->real(exp(x+im*y)), Legendre(Segment(SVector(0.,0.),SVector(1.,1.))))
@test f(0.1,0.1) ≈ real(exp(0.1+0.1im))
end

Expand Down
13 changes: 7 additions & 6 deletions test/MultivariateTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ using LinearAlgebra
using SpecialFunctions
using BlockBandedMatrices
using Test
using ApproxFunBase: factor, Block, cfstype, blocklengths, block, tensorizer, Vec, ArraySpace, ∞
using ApproxFunBase: factor, Block, cfstype, blocklengths, block, tensorizer, ArraySpace, ∞
using ApproxFunBaseTest: testbandedblockbandedoperator, testraggedbelowoperator,
testblockbandedoperator
using ApproxFunOrthogonalPolynomials: chebyshevtransform
using StaticArrays: SVector

using Base: oneto

Expand Down Expand Up @@ -102,20 +103,20 @@ using Base: oneto
end


@testset "Vec segment" begin
d = Segment(Vec(0.,0.) , Vec(1.,1.))
@testset "SVector segment" begin
d = Segment(SVector(0.,0.) , SVector(1.,1.))
x = Fun()
@test (ApproxFunBase.complexlength(d)*x/2)(0.1) ≈ (d.b - d.a)*0.1/2
@test ApproxFunBase.fromcanonical(d,x)(0.1) ≈ (d.b+d.a)/2 + (d.b - d.a)*0.1/2

x,y = Fun(Segment(Vec(0.,0.) , Vec(2.,1.)))
x,y = Fun(Segment(SVector(0.,0.) , SVector(2.,1.)))
@test x(0.2,0.1) ≈ 0.2
@test y(0.2,0.1) ≈ 0.1

d=Segment((0.,0.),(1.,1.))
f=Fun(xy->exp(-xy[1]-2cos(xy[2])),d)
@test f(0.5,0.5) ≈ exp(-0.5-2cos(0.5))
@test f(Vec(0.5,0.5)) ≈ exp(-0.5-2cos(0.5))
@test f(SVector(0.5,0.5)) ≈ exp(-0.5-2cos(0.5))

f=Fun(xy->exp(-xy[1]-2cos(xy[2])),d,20)
@test f(0.5,0.5) ≈ exp(-0.5-2cos(0.5))
Expand Down Expand Up @@ -285,7 +286,7 @@ using Base: oneto
end

@testset "off domain evaluate" begin
g = Fun(1, Segment(Vec(0,-1) , Vec(π,-1)))
g = Fun(1, Segment(SVector(0,-1) , SVector(π,-1)))
@test g(0.1,-1) ≈ 1
@test g(0.1,1) ≈ 0
end
Expand Down
2 changes: 1 addition & 1 deletion test/UltrasphericalTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using ApproxFunBase
using Test
using SpecialFunctions
using LinearAlgebra
using ApproxFunBase: Vec, maxspace, NoSpace, hasconversion, reverseorientation, ReverseOrientation
using ApproxFunBase: maxspace, NoSpace, hasconversion, reverseorientation, ReverseOrientation
using ApproxFunBaseTest: testbandedbelowoperator, testbandedoperator, testspace, testtransforms,
testfunctional
using ApproxFunOrthogonalPolynomials: jacobip
Expand Down
3 changes: 2 additions & 1 deletion test/VectorTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ using LinearAlgebra
using SpecialFunctions
using Test
using ApproxFunBase: interlace, Multiplication, ConstantSpace, PointSpace,
ArraySpace, blocklengths, ∞, Vec
ArraySpace, blocklengths, ∞
using StaticArrays: SVector

using ApproxFunBaseTest: testblockbandedoperator, testraggedbelowoperator

Expand Down