Skip to content

Commit 13c14fb

Browse files
committed
resizedata! before getindex
1 parent e42344f commit 13c14fb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/choleskyQR.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ orthogonalpolynomial(w::SubQuasiArray) = orthogonalpolynomial(parent(w))[parenti
3939
OrthogonalPolynomial(w::Function, P::AbstractQuasiMatrix) = OrthogonalPolynomial(w.(axes(P,1)), P)
4040
orthogonalpolynomial(w::Function, P::AbstractQuasiMatrix) = orthogonalpolynomial(w.(axes(P,1)), P)
4141

42+
resizedata!(P::ConvertedOrthogonalPolynomial, ::Colon, n::Int) = resizedata!(P.X.dv, n)
43+
4244

4345
"""
4446
cholesky_jacobimatrix(w, P)

src/clenshaw.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
resizedata!(P::OrthogonalPolynomial, x, n) = P # default is no-op
2+
13

24
# Assume 1 normalization
35
_p0(A) = one(eltype(A))
@@ -16,6 +18,7 @@ end
1618
function copyto!(dest::AbstractVector, V::SubArray{<:Any,1,<:OrthogonalPolynomial,<:Tuple{<:Number,<:OneTo}})
1719
P = parent(V)
1820
x,n = parentindices(V)
21+
resizedata!(P, :, last(n))
1922
A,B,C = recurrencecoefficients(P)
2023
forwardrecurrence!(dest, A, B, C, x, _p0(P))
2124
end
@@ -24,6 +27,7 @@ function forwardrecurrence_copyto!(dest::AbstractMatrix, V)
2427
checkbounds(dest, axes(V)...)
2528
P = parent(V)
2629
xr,jr = parentindices(V)
30+
resizedata!(P, :, maximum(jr))
2731
A,B,C = recurrencecoefficients(P)
2832
shift = first(jr)
2933
Ã,B̃,C̃ = A[shift:∞],B[shift:∞],C[shift:∞]
@@ -40,6 +44,7 @@ function copyto!(dest::AbstractVector, V::SubArray{<:Any,1,<:OrthogonalPolynomia
4044
checkbounds(dest, axes(V)...)
4145
P = parent(V)
4246
x,jr = parentindices(V)
47+
resizedata!(P, :, last(jr))
4348
A,B,C = recurrencecoefficients(P)
4449
shift = first(jr)
4550
Ã,B̃,C̃ = A[shift:∞],B[shift:∞],C[shift:∞]
@@ -65,7 +70,10 @@ Base.unsafe_getindex(P::OrthogonalPolynomial, x::Number, n::AbstractVector) = Ba
6570
Base.unsafe_getindex(P::OrthogonalPolynomial, x::AbstractVector, n::AbstractVector) = Base.unsafe_getindex(P,x,oneto(maximum(n)))[:,n]
6671
Base.unsafe_getindex(P::OrthogonalPolynomial, x::AbstractVector, n::Number) = Base.unsafe_getindex(P, x, 1:n)[:,end]
6772
Base.unsafe_getindex(P::OrthogonalPolynomial, x::Number, ::Colon) = Base.unsafe_getindex(P, x, axes(P,2))
68-
Base.unsafe_getindex(P::OrthogonalPolynomial, x::Number, n::Number) = initiateforwardrecurrence(n-1, recurrencecoefficients(P)..., x, _p0(P))[end]
73+
function Base.unsafe_getindex(P::OrthogonalPolynomial, x::Number, n::Number)
74+
resizedata!(P, :, n)
75+
initiateforwardrecurrence(n-1, recurrencecoefficients(P)..., x, _p0(P))[end]
76+
end
6977

7078
getindex(P::OrthogonalPolynomial, x::Number, jr::AbstractInfUnitRange{Int}) = view(P, x, jr)
7179
getindex(P::OrthogonalPolynomial, x::AbstractVector, jr::AbstractInfUnitRange{Int}) = view(P, x, jr)
@@ -83,11 +91,15 @@ end
8391

8492
function unsafe_getindex(f::Mul{<:AbstractOPLayout,<:AbstractPaddedLayout}, x::Number)
8593
P,c = f.A,f.B
86-
_p0(P)*clenshaw(paddeddata(c), recurrencecoefficients(P)..., x)
94+
data = paddeddata(c)
95+
resizedata!(P, :, length(data))
96+
_p0(P)*clenshaw(data, recurrencecoefficients(P)..., x)
8797
end
8898

8999
function unsafe_getindex(f::Mul{<:AbstractOPLayout,<:AbstractPaddedLayout}, x::Number, jr)
90100
P,c = f.A,f.B
101+
data = paddeddata(c)
102+
resizedata!(P, :, maximum(jr))
91103
_p0(P)*clenshaw(view(paddeddata(c),:,jr), recurrencecoefficients(P)..., x)
92104
end
93105

0 commit comments

Comments
 (0)