Skip to content

Commit 9fff7da

Browse files
authored
Add sample_layout (#250)
* Add sample_layout * move code to QuasiArrays.jl and ContinuumArrays.jl * add dims
1 parent 249b4b0 commit 9fff7da

File tree

5 files changed

+13
-46
lines changed

5 files changed

+13
-46
lines changed

Project.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name = "ClassicalOrthogonalPolynomials"
22
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
3+
version = "0.15.8"
34
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.15.7"
5-
65

76
[deps]
87
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -38,7 +37,7 @@ ArrayLayouts = "1.3.1"
3837
BandedMatrices = "1"
3938
BlockArrays = "1"
4039
BlockBandedMatrices = "0.13"
41-
ContinuumArrays = "0.19"
40+
ContinuumArrays = "0.20"
4241
DomainSets = "0.6, 0.7"
4342
DynamicPolynomials = "0.6"
4443
FFTW = "1.1"
@@ -52,10 +51,11 @@ IntervalSets = "0.7"
5251
LazyArrays = "2.8"
5352
LazyBandedMatrices = "0.11"
5453
MutableArithmetics = "1"
55-
QuasiArrays = "0.12"
54+
QuasiArrays = "0.13"
5655
RecurrenceRelationshipArrays = "0.1.2"
5756
RecurrenceRelationships = "0.2"
5857
SpecialFunctions = "1.0, 2"
58+
StatsBase = "0.34.6"
5959
julia = "1.10"
6060

6161
[extras]
@@ -65,7 +65,8 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
6565
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
6666
SemiseparableMatrices = "f8ebbe35-cbfb-4060-bf7f-b10e4670cf57"
6767
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
68+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
6869
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6970

7071
[targets]
71-
test = ["Base64", "Test", "ForwardDiff", "SemiseparableMatrices", "StaticArrays", "Random", "DynamicPolynomials"]
72+
test = ["Base64", "DynamicPolynomials", "ForwardDiff", "Random", "SemiseparableMatrices", "StaticArrays", "StatsBase", "Test"]

examples/detpointprocess.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using ClassicalOrthogonalPolynomials, Plots
2-
using ClassicalOrthogonalPolynomials: sample
1+
using ClassicalOrthogonalPolynomials, StatsBase, Plots
32

43
x = Inclusion(ChebyshevInterval())
54

src/ClassicalOrthogonalPolynomials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, Inclu
3030
ApplyQuasiArray, ApplyQuasiMatrix, LazyQuasiArrayApplyStyle, AbstractQuasiArrayApplyStyle,
3131
LazyQuasiArray, LazyQuasiVector, LazyQuasiMatrix, LazyLayout, LazyQuasiArrayStyle,
3232
_getindex, layout_getindex, AbstractQuasiArray, AbstractQuasiMatrix, AbstractQuasiVector,
33-
AbstractQuasiFill, equals_layout, QuasiArrayLayout, PolynomialLayout, diff_layout
33+
AbstractQuasiFill, equals_layout, QuasiArrayLayout, PolynomialLayout, diff_layout, findall_layout, minimum_layout, maximum_layout, extrema_layout
3434

3535
import InfiniteArrays: OneToInf, InfAxes, Infinity, AbstractInfUnitRange, InfiniteCardinal, InfRanges
3636
import InfiniteLinearAlgebra: chop!, chop, pad, choplength, compatible_resize!, partialcholesky!, SymTridiagonalConjugation, TridiagonalConjugation

src/roots.jl

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,26 @@ function colleaguematrix(P, c)
1818
end
1919

2020

21-
function _findall(::typeof(iszero), ::ExpansionLayout{<:AbstractOPLayout}, f)
21+
function findall_layout(::ExpansionLayout{<:AbstractOPLayout}, ::typeof(iszero), f)
2222
C = colleaguematrix(f.args...)
2323
ax = axes(f,1)
2424
convert(Vector{eltype(ax)}, filter!(in(ax), eigvals(C)))
2525
end
26-
findall(f::Function, v::AbstractQuasiVector) = _findall(f, MemoryLayout(v), v)
27-
28-
# gives a generalization of midpoint for when `a` or `b` is infinite
29-
function genmidpoint(a::T, b::T) where T
30-
if isinf(a) && isinf(b)
31-
zero(T)
32-
elseif isinf(a)
33-
b - 100
34-
elseif isinf(b)
35-
a + 100
36-
else
37-
(a+b)/2
38-
end
39-
end
40-
41-
42-
function _searchsortedfirst(::ExpansionLayout{<:AbstractOPLayout}, f, x; iterations=47)
43-
d = axes(f,1)
44-
a,b = first(d), last(d)
45-
46-
for k=1:iterations #TODO: decide 47
47-
m= genmidpoint(a,b)
48-
(f[m] x) ? (a = m) : (b = m)
49-
end
50-
(a+b)/2
51-
end
52-
searchsortedfirst(f::AbstractQuasiVector, x; kwds...) = _searchsortedfirst(MemoryLayout(f), f, x; kwds...)
53-
54-
function sample(f::AbstractQuasiVector, n...)
55-
g = cumsum(f)
56-
searchsortedfirst.(Ref(g/last(g)), rand(n...))
57-
end
5826

5927
####
6028
# min/max/extrema
6129
####
62-
function minimum(f::AbstractQuasiVector)
30+
function minimum_layout(::ExpansionLayout{<:AbstractOPLayout}, f::AbstractQuasiVector, dims)
6331
r = findall(iszero, diff(f))
6432
min(first(f), minimum(f[r]), last(f))
6533
end
6634

67-
function maximum(f::AbstractQuasiVector)
35+
function maximum_layout(::ExpansionLayout{<:AbstractOPLayout}, f::AbstractQuasiVector, dims)
6836
r = findall(iszero, diff(f))
6937
max(first(f), maximum(f[r]), last(f))
7038
end
7139

72-
function extrema(f::AbstractQuasiVector)
40+
function extrema_layout(::ExpansionLayout{<:AbstractOPLayout}, f::AbstractQuasiVector, dims...)
7341
r = findall(iszero, diff(f))
7442
extrema([first(f); f[r]; last(f)])
7543
end

test/test_roots.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using ClassicalOrthogonalPolynomials, QuasiArrays, Random, Test
2-
using ClassicalOrthogonalPolynomials: sample
1+
using ClassicalOrthogonalPolynomials, QuasiArrays, Random, StatsBase, Test
32

43
Random.seed!(5)
54

0 commit comments

Comments
 (0)