Skip to content

Commit 9f135a8

Browse files
authored
Support size and \ for cheb2leg (#239)
1 parent e3d47a2 commit 9f135a8

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FastTransforms"
22
uuid = "057dd010-8810-581a-b7be-e3fc3b93f78c"
3-
version = "0.15.15"
3+
version = "0.15.16"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/toeplitzhankel.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ ToeplitzHankelPlan{S,N,M}(T::TP, L::LowR, R::LowR, dims::Dims) where {S,N,M,LowR
3333
ToeplitzHankelPlan{S,N}(T, L, R, dims) where {S,N} = ToeplitzHankelPlan{S,N,N+1}(T, L, R, dims)
3434
ToeplitzHankelPlan(T::ToeplitzPlan{S,M}, L::Matrix, R::Matrix, dims=1) where {S,M} = ToeplitzHankelPlan{S,M-1,M}((T,), (L,), (R,), dims)
3535

36+
size(TH::ToeplitzHankelPlan) = size(first(TH.T))
37+
3638

3739
_reshape_broadcast(d, R, ::Val{N}, M) where N = reshape(R,ntuple(k -> k == d ? size(R,1) : 1, Val(N))...,M)
3840
function _th_applymul!(d, v::AbstractArray{<:Any,N}, T, L, R, tmp) where N
@@ -52,6 +54,8 @@ function *(P::ToeplitzHankelPlan{<:Any,N}, v::AbstractArray{<:Any,N}) where N
5254
v
5355
end
5456

57+
*(P::ToeplitzHankelPlan, v::AbstractArray) = error("plan applied to wrong-sized array")
58+
5559

5660
# partial cholesky for a Hankel matrix
5761

@@ -158,6 +162,10 @@ function *(P::ChebyshevToLegendrePlanTH, V::AbstractArray{<:Any,N}) where N
158162
V
159163
end
160164

165+
_add1tod(d::Integer, a, b...) = d == 1 ? (a+1, b...) : (a, _add1tod(d-1, b...)...)
166+
_add1tod(d, a, b...) = _add1tod(first(d), a, b...)
167+
size(P::ChebyshevToLegendrePlanTH) = Base.front(_add1tod(P.toeplitzhankel.dims, size(first(P.toeplitzhankel.T))...))
168+
inv(P::ChebyshevToLegendrePlanTH{T}) where T = plan_th_leg2cheb!(T, size(P), P.toeplitzhankel.dims)
161169

162170

163171
function _leg2chebTH_TLC(::Type{S}, mn, d) where S

test/toeplitzhankeltests.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,23 @@ Random.seed!(0)
164164
@test M Y
165165
end
166166
end
167+
168+
@testset "inv" begin
169+
x = randn(10)
170+
pl = plan_th_cheb2leg!(x)
171+
@test size(pl) == (10,)
172+
@test pl\(pl*x) x
173+
174+
X = randn(10,3)
175+
for pl in (plan_th_cheb2leg!(X), plan_th_cheb2leg!(X, 1), plan_th_cheb2leg!(X, 2))
176+
@test size(pl) == (10,3)
177+
@test pl\(pl*copy(X)) X
178+
end
179+
180+
X = randn(10,3,5)
181+
for pl in (plan_th_cheb2leg!(X), plan_th_cheb2leg!(X, 1), plan_th_cheb2leg!(X, 2), plan_th_cheb2leg!(X, 3))
182+
@test size(pl) == (10,3,5)
183+
@test pl\(pl*copy(X)) X
184+
end
185+
end
167186
end

0 commit comments

Comments
 (0)