From 81b94a71426bf884b05f8f1aec4e6a05e9c2f695 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 18 Nov 2022 13:54:39 +0400 Subject: [PATCH] Use `SVector` instead of `Vec` (#846) * Use SVector instead of Vec * Lower compat bound for BandedMatrices --- Project.toml | 11 +++- examples/Eigenvalue_symmetric.jl | 3 +- examples/PDE_Helmholtz.jl | 2 +- src/ApproxFun.jl | 100 ++++++++++--------------------- src/Extras/dualnumbers.jl | 7 +-- src/Plot/Plot.jl | 2 +- test/runtests.jl | 5 +- 7 files changed, 49 insertions(+), 81 deletions(-) diff --git a/Project.toml b/Project.toml index 18e551b40..73c3769e3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ApproxFun" uuid = "28f2ccd6-bb30-5033-b560-165f7b14dc2f" -version = "0.13.11" +version = "0.13.12" [deps] AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c" @@ -8,6 +8,7 @@ ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05" ApproxFunFourier = "59844689-9c9d-51bf-9583-5b794ec66d30" ApproxFunOrthogonalPolynomials = "b70543e2-c0d9-56b8-a290-0d4d6d4de211" ApproxFunSingularities = "f8fcb915-6b99-5be2-b79a-d6dbef8e6e7e" +BandedMatrices = "aae01518-5342-5314-be14-df237901396f" Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9" DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf" DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74" @@ -17,15 +18,17 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [compat] AbstractFFTs = "1.0" -ApproxFunBase = "0.7.30" +ApproxFunBase = "0.7.34" ApproxFunBaseTest = "0.1" ApproxFunFourier = "0.3" ApproxFunOrthogonalPolynomials = "0.5" ApproxFunSingularities = "0.3" Aqua = "0.5" +BandedMatrices = "0.16, 0.17" Calculus = "0.5" DomainSets = "0.3, 0.4, 0.5" DualNumbers = "0.6.2" @@ -34,14 +37,16 @@ FastTransforms = "0.13, 0.14" RecipesBase = "1.0" Reexport = "1.0" SpecialFunctions = "1.1, 2" +StaticArrays = "1" julia = "1.6" [extras] ApproxFunBaseTest = "a931bfaf-0cfd-4a5c-b69c-bf2eed002b43" Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["ApproxFunBaseTest", "Aqua", "Documenter", "Random", "Test"] +test = ["ApproxFunBaseTest", "Aqua", "BlockBandedMatrices", "Documenter", "Random", "Test"] diff --git a/examples/Eigenvalue_symmetric.jl b/examples/Eigenvalue_symmetric.jl index 821b8a9ba..8b476cbc2 100644 --- a/examples/Eigenvalue_symmetric.jl +++ b/examples/Eigenvalue_symmetric.jl @@ -10,6 +10,7 @@ using ApproxFun using LinearAlgebra +using BandedMatrices # Define parameters ω = 25.0 @@ -32,7 +33,7 @@ R = D1*Q; # This inversion is computed approximately, such that # ``\mathrm{C}^{-1} \mathrm{C} ≈ \mathrm{I}`` up to a certain bandwidth C = Conversion(domainspace(L), rangespace(L)) -P = cache(PartialInverseOperator(C, (0, ApproxFun.bandwidth(L, 1) + ApproxFun.bandwidth(R, 1) + ApproxFun.bandwidth(C, 2)))); +P = cache(PartialInverseOperator(C, (0, bandwidth(L, 1) + bandwidth(R, 1) + bandwidth(C, 2)))); A = R'D1*P*L*D2*R B = R'R; diff --git a/examples/PDE_Helmholtz.jl b/examples/PDE_Helmholtz.jl index fed6f9b0a..0d2b386d7 100644 --- a/examples/PDE_Helmholtz.jl +++ b/examples/PDE_Helmholtz.jl @@ -18,7 +18,7 @@ L = [Dirichlet(d); Laplacian()+100I]; # We compute the QR decomposition of the operator to speed up the solution Q = qr(L); -ApproxFun.resizedata!(Q,:,4000); +ApproxFunBase.resizedata!(Q,:,4000); # The boundary condition is a function that is equal to one on each edge boundary_cond = ones(∂(d)); diff --git a/src/ApproxFun.jl b/src/ApproxFun.jl index 39822bf1f..acee54d94 100644 --- a/src/ApproxFun.jl +++ b/src/ApproxFun.jl @@ -10,84 +10,53 @@ import Calculus @reexport using ApproxFunOrthogonalPolynomials @reexport using ApproxFunSingularities -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, - AbstractTransformPlan, TransformPlan, ITransformPlan, - ConcreteConversion, ConcreteMultiplication, ConcreteDerivative, ConcreteIntegral, CalculusOperator, - 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, DirichletWrapper, - TridiagonalOperator, SubOperator, Space, @containsconstants, spacescompatible, - 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, - 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, mul_coefficients, coefficients, coefficientmatrix, 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, choosedomainspace, - block, blockstart, blockstop, blocklengths, isblockbanded, pointscompatible, +import ApproxFunBase: Fun, UnsetSpace, VFun, UnivariateSpace, SumSpace, Space, + HeavisideSpace, PointSpace, IntervalOrSegment, ArraySpace, + TransformPlan, ITransformPlan, Evaluation, + Conversion, default_Fun, Derivative, Integral, + Dirichlet, domain, plan_transform, + plan_itransform, transform, domainspace, + rangespace, boundary, points, differentiate, integrate, + Segment, arclength, fromcanonical, checkpoints, evaluate, + coefficients, coefficientmatrix, clenshaw, ClenshawPlan, + SpaceOperator, InterlaceOperator, cfstype, pad!, + isapproxinteger, components, promotedomainspace, choosedomainspace, AbstractProductSpace, MultivariateFun, BivariateSpace, - @wrapperstructure, @wrapperspaces, @wrapper, @calculus_operator, resizedata!, slnorm, - sample, chop!, isbanded, colrange, bandwidth, - ∇, 𝒟, Δ, ∫, ⨜, Σ, ∮, ⨍, ⨎ + @calculus_operator, slnorm, sample, chop!, 𝒟, ∫, ⨜, ⨍ export ∫, ⨜, ⨍, 𝒟 import ApproxFunOrthogonalPolynomials: order +import BandedMatrices: bandwidths 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 FFTW: plan_fft, plan_ifft, plan_ifft! -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, 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 Base: convert, getindex, *, +, -, /, ^, \, sum, cumsum, + first, last, isempty, zeros, promote_rule, real, + # the following functions names are listed in Calculus.symbolic_derivatives_1arg(), + # and methods are added to them here + sqrt, cbrt, abs2, inv, log, log10, log2, log1p, + exp, exp2, expm1, sin, cos, tan, sec, csc, cot, + sind, cosd, tand, secd, cscd, cotd, asin, acos, atan, asec, acsc, acot, + asind, acosd, atand, asecd, acscd, acotd, sinh, cosh, tanh, sech, csch, + coth, asinh, acosh, atanh, asech, acsch, acoth, deg2rad, rad2deg -import Base.Broadcast: BroadcastStyle, Broadcasted, AbstractArrayStyle, broadcastable, - DefaultArrayStyle, broadcasted +import LinearAlgebra: eigvals, dot, adjoint - - -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 SpecialFunctions: erf, erfinv, erfc, erfcinv, erfi, gamma, lgamma, digamma, invdigamma, + trigamma, airyai, airybi, airyaiprime, airybiprime, besselj0, besselj1, + bessely0, bessely1, erfcx, dawson # import Arpack: eigs -import FastTransforms: ChebyshevTransformPlan, IChebyshevTransformPlan, plan_chebyshevtransform, - plan_chebyshevtransform!, plan_ichebyshevtransform, plan_ichebyshevtransform! +import FastTransforms: ChebyshevTransformPlan, plan_chebyshevtransform, + plan_chebyshevtransform!, plan_ichebyshevtransform, + plan_ichebyshevtransform! + +using StaticArrays: SVector """ `Curve` Represents a domain defined by the image of a Fun. Example @@ -106,11 +75,6 @@ Curve(f::Fun{<:Space{<:ChebyshevInterval}}) = IntervalCurve(f) export Curve - - -import Base: view - - ##Testing export bisectioninv diff --git a/src/Extras/dualnumbers.jl b/src/Extras/dualnumbers.jl index 311b3e00f..dd14c01bc 100644 --- a/src/Extras/dualnumbers.jl +++ b/src/Extras/dualnumbers.jl @@ -71,10 +71,7 @@ function dualFun(f,S,n) end function dualcfsFun(f,S) - T = float(eltype(domain(S))) - if T <: Complex - T = T.parameters[1] #get underlying real representation - end + T = real(float(eltype(domain(S)))) r=checkpoints(S) f0=f(first(r)) @@ -82,7 +79,7 @@ function dualcfsFun(f,S) return dualcfsFun(f,Space(fill(S,size(f0)))) end - tol =T==Any ? 100eps() : 100eps(T) + tol = 100eps(T) fr=typeof(f0)[f(x) for x=r] diff --git a/src/Plot/Plot.jl b/src/Plot/Plot.jl index 43679ee5e..63506ce16 100644 --- a/src/Plot/Plot.jl +++ b/src/Plot/Plot.jl @@ -110,7 +110,7 @@ end # end end -@recipe function f(dd::Segment{<:Vec{2}}) +@recipe function f(dd::Segment{<:SVector{2}}) a,b = endpoints(dd) [a[1],b[1]], [a[2],b[2]] end diff --git a/test/runtests.jl b/test/runtests.jl index 4bb2ad20a..a9a772ced 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using ApproxFun, Random, Test using ApproxFunBase: testbandedblockbandedoperator, blocklengths, ∞ +using BlockBandedMatrices: blockbandwidths, subblockbandwidths using Aqua @testset "Project quality" begin @@ -99,8 +100,8 @@ end sp = Space(dom) Dr = Derivative(sp, [1,0]) - @test ApproxFunBase.blockbandwidths(Dr) == (-1,1) - @test ApproxFunBase.subblockbandwidths(Dr) == (1,3) + @test blockbandwidths(Dr) == (-1,1) + @test subblockbandwidths(Dr) == (1,3) Dθ = Derivative(sp, [0,1]) Mr = Multiplication(Fun( (r, θ) -> r, sp ), sp)