Skip to content

Commit 99e7209

Browse files
authored
Support norms and fix empty local minima (#263)
* Support norms and fix empty local minima * Update Project.toml
1 parent 10546e0 commit 99e7209

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ClassicalOrthogonalPolynomials"
22
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
3-
version = "0.15.13"
3+
version = "0.15.14"
44
authors = ["Sheehan Olver <[email protected]>"]
55

66
[deps]
@@ -51,7 +51,7 @@ IntervalSets = "0.7"
5151
LazyArrays = "2.8"
5252
LazyBandedMatrices = "0.11"
5353
MutableArithmetics = "1"
54-
QuasiArrays = "0.13"
54+
QuasiArrays = "0.13.2"
5555
RecurrenceRelationshipArrays = "0.1.2"
5656
RecurrenceRelationships = "0.2"
5757
SpecialFunctions = "1.0, 2"

src/roots.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
function colleaguematrix(P, c)
1212
cₙ = paddeddata(c)
13+
isempty(cₙ) && return Matrix{eltype(P)}(undef, 0, 0)
1314
n = findlast(!iszero, cₙ)-1
1415
J = jacobimatrix(P)'
1516
C = Matrix(J[1:n,1:n])
@@ -29,15 +30,27 @@ end
2930
####
3031
function minimum_layout(::ExpansionLayout{<:AbstractOPLayout}, f::AbstractQuasiVector, dims)
3132
r = findall(iszero, diff(f))
32-
min(first(f), minimum(f[r]), last(f))
33+
if isempty(r)
34+
min(first(f), last(f))
35+
else
36+
min(first(f), minimum(f[r]), last(f))
37+
end
3338
end
3439

3540
function maximum_layout(::ExpansionLayout{<:AbstractOPLayout}, f::AbstractQuasiVector, dims)
3641
r = findall(iszero, diff(f))
37-
max(first(f), maximum(f[r]), last(f))
42+
if isempty(r)
43+
max(first(f), last(f))
44+
else
45+
max(first(f), maximum(f[r]), last(f))
46+
end
3847
end
3948

4049
function extrema_layout(::ExpansionLayout{<:AbstractOPLayout}, f::AbstractQuasiVector, dims...)
4150
r = findall(iszero, diff(f))
42-
extrema([first(f); f[r]; last(f)])
51+
if isempty(r)
52+
extrema([first(f); last(f)])
53+
else
54+
extrema([first(f); f[r]; last(f)])
55+
end
4356
end

test/test_legendre.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,16 @@ import QuasiArrays: MulQuasiArray
237237
f = P * (P \ exp.(x))
238238
@test P \ cumsum(f) P \ (exp.(x) .- exp(-1))
239239
end
240+
241+
@testset "norm" begin
242+
f = expand(Legendre(), x -> exp(im*x))
243+
@test norm(f) isa Float64
244+
@test norm(f,1) isa Float64
245+
@test norm(f,3) isa Float64
246+
@test norm(f,Inf) isa Float64
247+
@test norm(f) norm(expand(legendre(-1..1), x -> exp(im*x))) sqrt(2)
248+
@test norm(f,1) 2
249+
@test norm(f,Inf) 1
250+
@test norm(f,3) cbrt(2)
251+
end
240252
end

test/test_roots.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ end
3737
@test minimum(f) -2.682833127491678
3838
@test maximum(f) 2.6401248792053362
3939
@test extrema(f) == (minimum(f), maximum(f))
40+
41+
f = expand(ChebyshevT(), exp)
42+
@test minimum(f) 1/
43+
@test maximum(f)
44+
@test extrema(f) == (minimum(f), maximum(f))
4045
end

0 commit comments

Comments
 (0)