Skip to content

Commit a6a84b6

Browse files
authored
Merge pull request #23 from JuliaImageRecon/nh/updateOpFields
Update operators to fit LinearOperators v2.13 structure
2 parents 70dac39 + e690a25 commit a6a84b6

13 files changed

Lines changed: 158 additions & 183 deletions

File tree

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LinearOperatorCollection"
22
uuid = "a4a2c56f-fead-462a-a3ab-85921a5f2575"
33
authors = ["Tobias Knopp <tobias.knopp@tuhh.de> and contributors"]
4-
version = "2.3.2"
4+
version = "2.4"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -31,7 +31,7 @@ KernelAbstractions = "0.9"
3131
JLArrays = "0.2"
3232
AbstractNFFTs = "0.9"
3333
LinearAlgebra = "1"
34-
LinearOperators = "2"
34+
LinearOperators = "2.13"
3535
OhMyThreads = "0.8"
3636
NonuniformFFTs = "0.9"
3737
NFFT = "0.14"
@@ -54,7 +54,7 @@ FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
5454
RadonKA = "86de8297-835b-47df-b249-c04e8db91db5"
5555

5656
[targets]
57-
test = ["Test", "Aqua", "FFTW", "Wavelets", "NFFT", "NonuniformFFTs", "JLArrays", "RadonKA"]
57+
test = ["Test", "Aqua", "FFTW", "Wavelets", "NFFT", "NonuniformFFTs", "RadonKA"]
5858

5959
[extensions]
6060
LinearOperatorNFFTExt = ["AbstractNFFTs", "FFTW"]

ext/LinearOperatorFFTWExt/DCTOp.jl

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
export DCTOpImpl
22

3-
mutable struct DCTOpImpl{T} <: DCTOp{T}
4-
nrow :: Int
5-
ncol :: Int
6-
symmetric :: Bool
7-
hermitian :: Bool
8-
prod! :: Function
9-
tprod! :: Nothing
10-
ctprod! :: Function
3+
mutable struct DCTOpImpl{T, vecT, P} <: DCTOp{T}
4+
const nrow :: Int
5+
const ncol :: Int
6+
const symmetric :: Bool
7+
const hermitian :: Bool
8+
const prod! :: Function
9+
const tprod! :: Nothing
10+
const ctprod! :: Function
1111
nprod :: Int
1212
ntprod :: Int
1313
nctprod :: Int
14-
args5 :: Bool
15-
use_prod5! :: Bool
16-
allocated5 :: Bool
17-
Mv5 :: Vector{T}
18-
Mtu5 :: Vector{T}
19-
plan
20-
dcttype::Int
14+
Mv :: vecT
15+
Mtu :: vecT
16+
const plan :: P
17+
const dcttype::Int
2118
end
2219

23-
LinearOperators.storage_type(op::DCTOpImpl) = typeof(op.Mv5)
20+
LinearOperators.storage_type(::DCTOpImpl{T, vecT}) where {T,vecT} = vecT
2421

2522
"""
2623
DCTOpImpl(T::Type, shape::Tuple, dcttype=2)
@@ -50,9 +47,9 @@ function LinearOperatorCollection.DCTOp(T::Type; shape::Tuple, S = Array{T}, dct
5047
error("DCT type $(dcttype) not supported")
5148
end
5249

53-
return DCTOpImpl{T}(prod(shape), prod(shape), false, false,
50+
return DCTOpImpl{T, S, typeof(plan)}(prod(shape), prod(shape), false, false,
5451
prod!, nothing, tprod!,
55-
0, 0, 0, true, false, true, T[], T[],
52+
0, 0, 0, S(undef, 0), S(undef, 0),
5653
plan, dcttype)
5754
end
5855

ext/LinearOperatorFFTWExt/DSTOp.jl

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
export DSTOpImpl
22

3-
mutable struct DSTOpImpl{T} <: DSTOp{T}
4-
nrow :: Int
5-
ncol :: Int
6-
symmetric :: Bool
7-
hermitian :: Bool
8-
prod! :: Function
9-
tprod! :: Nothing
10-
ctprod! :: Function
3+
mutable struct DSTOpImpl{T, vecT, P, IP} <: DSTOp{T}
4+
const nrow :: Int
5+
const ncol :: Int
6+
const symmetric :: Bool
7+
const hermitian :: Bool
8+
const prod! :: Function
9+
const tprod! :: Nothing
10+
const ctprod! :: Function
1111
nprod :: Int
1212
ntprod :: Int
1313
nctprod :: Int
14-
args5 :: Bool
15-
use_prod5! :: Bool
16-
allocated5 :: Bool
17-
Mv5 :: Vector{T}
18-
Mtu5 :: Vector{T}
19-
plan
20-
iplan
14+
Mv :: vecT
15+
Mtu :: vecT
16+
const plan :: P
17+
const iplan :: IP
2118
end
2219

23-
LinearOperators.storage_type(op::DSTOpImpl) = typeof(op.Mv5)
20+
LinearOperators.storage_type(::DSTOpImpl{T, vecT}) where {T, vecT} = vecT
2421

2522
"""
2623
DSTOp(T::Type, shape::Tuple)
@@ -39,11 +36,11 @@ function LinearOperatorCollection.DSTOp(T::Type; shape::Tuple, S = Array{T})
3936

4037
w = weights(shape, T)
4138

42-
return DSTOpImpl{T}(prod(shape), prod(shape), true, false
39+
return DSTOpImpl{T, S, typeof(plan), typeof(iplan)}(prod(shape), prod(shape), true, false
4340
, (res,x) -> dst_multiply!(res,plan,x,tmp,w)
4441
, nothing
4542
, (res,x) -> dst_bmultiply!(res,iplan,x,tmp,w)
46-
, 0, 0, 0, true, false, true, T[], T[]
43+
, 0, 0, 0, S(undef,0), S(undef, 0)
4744
, plan
4845
, iplan)
4946
end

ext/LinearOperatorFFTWExt/FFTOp.jl

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
export FFTOpImpl
22

33
mutable struct FFTOpImpl{T, vecT, P <: AbstractFFTs.Plan{T}, IP <: AbstractFFTs.Plan{T}} <: FFTOp{T}
4-
nrow :: Int
5-
ncol :: Int
6-
symmetric :: Bool
7-
hermitian :: Bool
8-
prod! :: Function
9-
tprod! :: Nothing
10-
ctprod! :: Function
4+
const nrow :: Int
5+
const ncol :: Int
6+
const symmetric :: Bool
7+
const hermitian :: Bool
8+
const prod! :: Function
9+
const tprod! :: Nothing
10+
const ctprod! :: Function
1111
nprod :: Int
1212
ntprod :: Int
1313
nctprod :: Int
14-
args5 :: Bool
15-
use_prod5! :: Bool
16-
allocated5 :: Bool
17-
Mv5 :: vecT
18-
Mtu5 :: vecT
19-
plan :: P
20-
iplan :: IP
21-
shift::Bool
22-
unitary::Bool
14+
Mv :: vecT
15+
Mtu :: vecT
16+
const plan :: P
17+
const iplan :: IP
18+
const shift::Bool
19+
const unitary::Bool
2320
end
2421

25-
LinearOperators.storage_type(op::FFTOpImpl) = typeof(op.Mv5)
22+
LinearOperators.storage_type(::FFTOpImpl{T, vecT}) where {T,vecT} = vecT
2623

2724
"""
2825
FFTOp(T::Type; shape::Tuple, shift=true, unitary=true)
@@ -60,7 +57,7 @@ function LinearOperatorCollection.FFTOp(T::Type; shape::NTuple{D,Int64}, shift::
6057

6158
return FFTOpImpl(prod(shape), prod(shape), false, false, (res, x) -> fun!(res, plan_, x, shape_, facF_, tmpVec_),
6259
nothing, (res, x) -> fun!(res, iplan_, x, shape_, facB_, tmpVec_),
63-
0, 0, 0, true, false, true, similar(tmpVec, 0), similar(tmpVec, 0), plan, iplan, shift, unitary)
60+
0, 0, 0, similar(tmpVec, 0), similar(tmpVec, 0), plan, iplan, shift, unitary)
6461
end
6562
end
6663

ext/LinearOperatorNFFTExt/NFFTOp.jl

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,23 @@ function LinearOperatorCollection.NFFTOp(::Type{T};
2020
end
2121

2222
mutable struct NFFTOpImpl{T, vecT, P} <: NFFTOp{T, P}
23-
nrow :: Int
24-
ncol :: Int
25-
symmetric :: Bool
26-
hermitian :: Bool
27-
prod! :: Function
28-
tprod! :: Nothing
29-
ctprod! :: Function
23+
const nrow :: Int
24+
const ncol :: Int
25+
const symmetric :: Bool
26+
const hermitian :: Bool
27+
const prod! :: Function
28+
const tprod! :: Nothing
29+
const ctprod! :: Function
3030
nprod :: Int
3131
ntprod :: Int
3232
nctprod :: Int
33-
args5 :: Bool
34-
use_prod5! :: Bool
35-
allocated5 :: Bool
36-
Mv5 :: vecT
37-
Mtu5 :: vecT
38-
plan :: P
33+
Mv :: vecT
34+
Mtu :: vecT
35+
const plan :: P
3936
toeplitz :: Bool
4037
end
4138

42-
LinearOperators.storage_type(op::NFFTOpImpl) = typeof(op.Mv5)
39+
LinearOperators.storage_type(::NFFTOpImpl{T, vecT}) where {T, vecT} = vecT
4340

4441
function NFFTOpImpl(shape::Tuple, tr::AbstractMatrix{T}; toeplitz, oversamplingFactor, kernelSize, S = Vector{Complex{T}}, kargs...) where {T}
4542

@@ -51,7 +48,7 @@ function NFFTOpImpl(shape::Tuple, tr::AbstractMatrix{T}; toeplitz, oversamplingF
5148
, (res,x) -> produ!(res,plan,x)
5249
, nothing
5350
, (res,y) -> ctprodu!(res,plan,y)
54-
, 0, 0, 0, false, false, false, S(undef, 0), S(undef, 0)
51+
, 0, 0, 0, S(undef, 0), S(undef, 0)
5552
, plan, toeplitz)
5653
end
5754

@@ -70,7 +67,7 @@ function Base.copy(S::NFFTOpImpl{T, vecT, P}) where {T, vecT, P}
7067
, (res,x) -> produ!(res,plan,x)
7168
, nothing
7269
, (res,y) -> ctprodu!(res,plan,y)
73-
, 0, 0, 0, false, false, false, vecT(undef, 0), vecT(undef, 0)
70+
, 0, 0, 0, vecT(undef, 0), vecT(undef, 0)
7471
, plan, S.toeplitz)
7572
end
7673

@@ -80,22 +77,19 @@ end
8077
### Toeplitz Operator ###
8178
#########################################################################
8279

83-
mutable struct NFFTToeplitzNormalOp{T,D,W, vecT <: AbstractVector{T}, matT <: AbstractArray{T, D}, P <: AbstractFFTs.Plan, IP <: AbstractFFTs.Plan} <: AbstractLinearOperator{T}
84-
nrow :: Int
85-
ncol :: Int
86-
symmetric :: Bool
87-
hermitian :: Bool
88-
prod! :: Function
89-
tprod! :: Nothing
90-
ctprod! :: Nothing
80+
mutable struct NFFTToeplitzNormalOp{T, vecT <: AbstractVector{T}, D,W, matT <: AbstractArray{T, D}, P <: AbstractFFTs.Plan, IP <: AbstractFFTs.Plan} <: AbstractLinearOperator{T}
81+
const nrow :: Int
82+
const ncol :: Int
83+
const symmetric :: Bool
84+
const hermitian :: Bool
85+
const prod! :: Function
86+
const tprod! :: Nothing
87+
const ctprod! :: Nothing
9188
nprod :: Int
9289
ntprod :: Int
9390
nctprod :: Int
94-
args5 :: Bool
95-
use_prod5! :: Bool
96-
allocated5 :: Bool
97-
Mv5 :: vecT
98-
Mtu5 :: vecT
91+
Mv :: vecT
92+
Mtu :: vecT
9993
shape::NTuple{D,Int}
10094
weights::W
10195
fftplan :: P
@@ -105,7 +99,7 @@ mutable struct NFFTToeplitzNormalOp{T,D,W, vecT <: AbstractVector{T}, matT <: Ab
10599
xL2::matT
106100
end
107101

108-
LinearOperators.storage_type(op::NFFTToeplitzNormalOp) = typeof(op.Mv5)
102+
LinearOperators.storage_type(::NFFTToeplitzNormalOp{T, vecT}) where {T, vecT} = vecT
109103

110104
function LinearOperatorCollection.NFFTToeplitzNormalOp(shape, W, fftplan, ifftplan, λ, xL1::matT, xL2::matT) where {T, D, matT <: AbstractArray{T, D}}
111105

@@ -126,14 +120,15 @@ function LinearOperatorCollection.NFFTToeplitzNormalOp(shape, W, fftplan, ifftpl
126120
, (res,x) -> produ!(res, shape, fftplan, ifftplan, λ, xL1, xL2, x)
127121
, nothing
128122
, nothing
129-
, 0, 0, 0, false, false, false, T[], T[]
123+
, 0, 0, 0, T[], T[]
130124
, shape, W, fftplan, ifftplan, λ, xL1, xL2)
131125
end
132126

127+
# TODO: use vecT for toeplitz op
133128
function LinearOperatorCollection.NFFTToeplitzNormalOp(nfft::NFFTOp{T}, W=nothing; kwargs...) where {T}
134129
shape = size_in(nfft.plan)
135130

136-
tmpVec = similar(nfft.Mv5, (2 .* shape)...)
131+
tmpVec = similar(nfft.Mv, (2 .* shape)...)
137132
tmpVec .= zero(T)
138133

139134
# plan the FFTs
@@ -172,7 +167,7 @@ function LinearOperatorCollection.normalOperator(S::NFFTOpImpl{T}, W = nothing;
172167
end
173168
end
174169

175-
function Base.copy(A::NFFTToeplitzNormalOp{T,D,W}) where {T,D,W}
170+
function Base.copy(A::NFFTToeplitzNormalOp{T,vecT,D,W}) where {T,vecT,D,W}
176171
fftplan = plan_fft( zeros(T, 2 .* A.shape); flags=FFTW.MEASURE)
177172
ifftplan = plan_ifft(zeros(T, 2 .* A.shape); flags=FFTW.MEASURE)
178173
return LinearOperatorCollection.NFFTToeplitzNormalOp(A.shape, A.weights, fftplan, ifftplan, A.λ, copy(A.xL1), copy(A.xL2))

ext/LinearOperatorNonuniformFFTsExt/LinearOperatorNonuniformFFTsExt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ module LinearOperatorNonuniformFFTsExt
22

33
using LinearOperatorCollection, AbstractNFFTs, NonuniformFFTs, NonuniformFFTs.Kernels, FFTW
44

5-
function LinearOperatorCollection.NFFTToeplitzNormalOp(nfft::NFFTOp{T, P}, W=nothing; kwargs...) where {T, vecT, P <: NonuniformFFTs.NFFTPlan}
5+
function LinearOperatorCollection.NFFTToeplitzNormalOp(nfft::NFFTOp{T, P}, W=nothing; kwargs...) where {T, P <: NonuniformFFTs.NFFTPlan}
66
shape = size_in(nfft.plan)
77

8-
tmpVec = similar(nfft.Mv5, (2 .* shape)...)
8+
tmpVec = similar(nfft.Mv, (2 .* shape)...)
99
tmpVec .= zero(T)
1010

1111
# plan the FFTs

ext/LinearOperatorRadonKAExt/RadonOp.jl

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,24 @@ function LinearOperatorCollection.RadonOp(::Type{T}; shape::NTuple{N, Int}, angl
1717
end
1818

1919
mutable struct RadonOpImpl{T, vecT <: AbstractVector{T}, vecT2, G, A} <: RadonOp{T}
20-
nrow :: Int
21-
ncol :: Int
22-
symmetric :: Bool
23-
hermitian :: Bool
24-
prod! :: Function
25-
tprod! :: Nothing
26-
ctprod! :: Function
20+
const nrow :: Int
21+
const ncol :: Int
22+
const symmetric :: Bool
23+
const hermitian :: Bool
24+
const prod! :: Function
25+
const tprod! :: Nothing
26+
const ctprod! :: Function
2727
nprod :: Int
2828
ntprod :: Int
2929
nctprod :: Int
30-
args5 :: Bool
31-
use_prod5! :: Bool
32-
allocated5 :: Bool
33-
Mv5 :: vecT
34-
Mtu5 :: vecT
35-
angles :: vecT2
36-
geometry :: G
37-
μ :: A
30+
Mv :: vecT
31+
Mtu :: vecT
32+
const angles :: vecT2
33+
const geometry :: G
34+
const μ :: A
3835
end
3936

40-
LinearOperators.storage_type(op::RadonOpImpl) = typeof(op.Mv5)
37+
LinearOperators.storage_type(::RadonOpImpl{T, vecT}) where {T, vecT} = vecT
4138

4239
function RadonOpImpl(T::Type; shape::NTuple{N, Int64}, angles, geometry, μ, S) where N
4340
N_sinogram = length(geometry.in_height)
@@ -49,7 +46,7 @@ function RadonOpImpl(T::Type; shape::NTuple{N, Int64}, angles, geometry, μ, S)
4946
(res, x) -> prod_radon!(res, x, shape, angles, geometry, μ),
5047
nothing,
5148
(res, x) -> ctprod_radon!(res, x, (N_sinogram, N_angles, d), angles, geometry, μ),
52-
0, 0, 0, true, false, true, S(undef, 0), S(undef, 0), angles, geometry, μ)
49+
0, 0, 0, S(undef, 0), S(undef, 0), angles, geometry, μ)
5350
end
5451

5552
prod_radon!(res::vecT, x::vecT, shape, angles::vecT2, geometry::G, μ::A) where {vecT, vecT2, G, A} = copyto!(res, radon(reshape(x, shape), angles; geometry, μ))

0 commit comments

Comments
 (0)