Skip to content

Commit 3c95e72

Browse files
committed
reintroduce the old interface but still allow to use the factory method
1 parent a040376 commit 3c95e72

File tree

15 files changed

+66
-92
lines changed

15 files changed

+66
-92
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LinearOperators = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125"
99
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1010
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1111
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
12+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1213

1314
[weakdeps]
1415
Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a"
@@ -18,7 +19,7 @@ NFFT = "efe261a4-0d2b-5849-be55-fc731d526b0d"
1819
[extensions]
1920
LinearOperatorWaveletExt = "Wavelets"
2021
LinearOperatorFFTWExt = "FFTW"
21-
LinearOperatorNFFTExt = "NFFT"
22+
LinearOperatorNFFTExt = ["NFFT", "FFTW"]
2223

2324
[compat]
2425
julia = "1.6"

ext/LinearOperatorFFTWExt/DCTOp.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
export DCTOpImpl
22

3-
function LinearOperatorCollection.constructLinearOperator(::Type{Op};
4-
shape::Tuple, dcttype::Int) where Op <: DCTOp{T} where T <: Number
5-
return DCTOpImpl(T, shape, dcttype)
6-
end
7-
83
mutable struct DCTOpImpl{T} <: DCTOp{T}
94
nrow :: Int
105
ncol :: Int
@@ -37,7 +32,7 @@ returns a `DCTOpImpl <: AbstractLinearOperator` which performs a DCT on a given
3732
* `shape::Tuple` - size of the array to transform
3833
* `dcttype` - type of DCT (currently `2` and `4` are supported)
3934
"""
40-
function DCTOpImpl(T::Type, shape::Tuple, dcttype=2)
35+
function LinearOperatorCollection.DCTOp(T::Type; shape::Tuple, dcttype=2)
4136

4237
tmp=Array{Complex{real(T)}}(undef, shape)
4338
if dcttype == 2

ext/LinearOperatorFFTWExt/DSTOp.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
export DSTOpImpl
22

3-
function LinearOperatorCollection.constructLinearOperator(::Type{Op};
4-
shape::Tuple, shift::Bool=true, unitary::Bool=true, cuda::Bool=false) where Op <: DSTOp{T} where T <: Number
5-
return DSTOpImpl(T, shape)
6-
end
7-
83
mutable struct DSTOpImpl{T} <: DSTOp{T}
94
nrow :: Int
105
ncol :: Int
@@ -28,15 +23,15 @@ end
2823
LinearOperators.storage_type(op::DSTOpImpl) = typeof(op.Mv5)
2924

3025
"""
31-
DSTOpImpl(T::Type, shape::Tuple)
26+
DSTOp(T::Type, shape::Tuple)
3227
3328
returns a `LinearOperator` which performs a DST on a given input array.
3429
3530
# Arguments:
3631
* `T::Type` - type of the array to transform
3732
* `shape::Tuple` - size of the array to transform
3833
"""
39-
function DSTOpImpl(T::Type, shape::Tuple)
34+
function LinearOperatorCollection.DSTOp(T::Type; shape::Tuple)
4035
tmp=Array{Complex{real(T)}}(undef, shape)
4136

4237
plan = FFTW.plan_r2r!(tmp,FFTW.RODFT10)

ext/LinearOperatorFFTWExt/FFTOp.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
export FFTOpImpl
22
import Base.copy
33

4-
function LinearOperatorCollection.constructLinearOperator(::Type{Op};
5-
shape::Tuple, shift::Bool=true, unitary::Bool=true, cuda::Bool=false) where Op <: FFTOp{T} where T <: Number
6-
return FFTOpImpl(T, shape, shift; unitary, cuda)
7-
end
8-
94
mutable struct FFTOpImpl{T} <: FFTOp{T}
105
nrow :: Int
116
ncol :: Int
@@ -31,7 +26,7 @@ end
3126
LinearOperators.storage_type(op::FFTOpImpl) = typeof(op.Mv5)
3227

3328
"""
34-
FFTOpImpl(T::Type, shape::Tuple, shift=true, unitary=true)
29+
FFTOp(T::Type; shape::Tuple, shift=true, unitary=true)
3530
3631
returns an operator which performs an FFT on Arrays of type T
3732
@@ -41,7 +36,7 @@ returns an operator which performs an FFT on Arrays of type T
4136
* (`shift=true`) - if true, fftshifts are performed
4237
* (`unitary=true`) - if true, FFT is normalized such that it is unitary
4338
"""
44-
function FFTOpImpl(T::Type, shape::NTuple{D,Int64}, shift::Bool=true; unitary::Bool=true, cuda::Bool=false) where D
39+
function LinearOperatorCollection.FFTOp(T::Type; shape::NTuple{D,Int64}, shift::Bool=true, unitary::Bool=true, cuda::Bool=false) where D
4540

4641
#tmpVec = cuda ? CuArray{T}(undef,shape) : Array{Complex{real(T)}}(undef, shape)
4742
tmpVec = Array{Complex{real(T)}}(undef, shape)

ext/LinearOperatorNFFTExt/LinearOperatorNFFTExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module LinearOperatorNFFTExt
22

3-
using LinearOperatorCollection, NFFT
3+
using LinearOperatorCollection, NFFT, FFTW
44

55
include("NFFTOp.jl")
66

ext/LinearOperatorNFFTExt/NFFTOp.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
export NFFTOpImpl
21
import Base.adjoint
32

4-
function LinearOperatorCollection.constructLinearOperator(::Type{Op};
5-
shape::Tuple, nodes::AbstractMatrix{T}, toeplitz=false, oversamplingFactor=1.25,
6-
kernelSize=3, kargs...) where Op <: NFFTOp{T} where T <: Number
7-
return NFFTOpImpl(T, shape, nodes; toeplitz, oversamplingFactor, kernelSize, kargs... )
3+
function LinearOperatorCollection.createLinearOperator(::Type{Op}; kargs...) where Op <: NFFTOp{T} where T <: Number
4+
return NFFTOp(T; kargs...)
5+
end
6+
7+
function LinearOperatorCollection.NFFTOp(::Type{T};
8+
shape::Tuple, nodes::AbstractMatrix{U}, toeplitz=false, oversamplingFactor=1.25,
9+
kernelSize=3, kargs...) where {U <: Number, T <: Number}
10+
return NFFTOpImpl(shape, nodes; toeplitz, oversamplingFactor, kernelSize, kargs... )
811
end
912

1013
mutable struct NFFTOpImpl{T} <: NFFTOp{T}
@@ -155,7 +158,7 @@ function LinearOperatorCollection.normalOperator(S::NFFTOpImpl{T}, W=opEye(T,siz
155158
if S.toeplitz
156159
return NFFTToeplitzNormalOp(S,W)
157160
else
158-
return NormalOp(S,W)
161+
return LinearOperatorCollection.NormalOpImpl(S,W)
159162
end
160163
end
161164

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module LinearOperatorWaveletExt
2-
2+
3+
using LinearOperatorCollection, Wavelets
4+
35
include("WaveletOp.jl")
46

57
end

ext/LinearOperatorWaveletExt/WaveletOp.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
export WaveletOpImpl
2-
3-
using LinearOperatorCollection, Wavelets
4-
5-
function LinearOperatorCollection.constructLinearOperator(::Type{Op};
6-
shape::Tuple, wt=wavelet(WT.db2)) where Op <: WaveletOp{T} where T <: Number
7-
return WaveletOpImpl(T, shape, wt)
8-
end
91

102
"""
113
WaveletOp(shape, wt=wavelet(WT.db2))
@@ -18,7 +10,7 @@ a given input array.
1810
* `shape` - size of the Array to transform
1911
* (`wt=wavelet(WT.db2)`) - Wavelet to apply
2012
"""
21-
function WaveletOpImpl(T::Type, shape, wt=wavelet(WT.db2))
13+
function LinearOperatorCollection.WaveletOp(::Type{T}; shape::Tuple, wt=wavelet(WT.db2)) where T <: Number
2214
return LinearOperator(T, prod(shape), prod(shape), false, false
2315
, (res,x)->dwt!(reshape(res,shape), reshape(x,shape), wt)
2416
, nothing

src/GradientOp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function LinearOperatorCollection.constructLinearOperator(::Type{Op};
2-
shape::Tuple, dim::Union{Nothing,Int64}=nothing) where Op <: GradientOp{T} where T <: Number
1+
function LinearOperatorCollection.GradientOp(::Type{T};
2+
shape::Tuple, dim::Union{Nothing,Int64}=nothing) where T <: Number
33
if dim == nothing
44
return GradientOpImpl(T, shape)
55
else

src/LinearOperatorCollection.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import LinearAlgebra.BLAS: gemv, gemv!
66
import LinearAlgebra: BlasFloat, normalize!, norm, rmul!, lmul!
77
using SparseArrays
88
using Random
9+
using InteractiveUtils
910

1011
using Reexport
1112
@reexport using Reexport
@@ -26,7 +27,7 @@ function wrapProd(prod::Function)
2627
return λ
2728
end
2829

29-
export linearOperatorList, constructLinearOperator
30+
export linearOperatorList, createLinearOperator
3031
export AbstractLinearOperatorFromCollection, WaveletOp, FFTOp, DCTOp, DSTOp, NFFTOp,
3132
SamplingOp, NormalOp, WeightingOp, GradientOp
3233

@@ -41,9 +42,6 @@ abstract type NormalOp{T} <: AbstractLinearOperatorFromCollection{T} end
4142
abstract type WeightingOp{T} <: AbstractLinearOperatorFromCollection{T} end
4243
abstract type GradientOp{T} <: AbstractLinearOperatorFromCollection{T} end
4344

44-
function constructLinearOperator(::Type{<:AbstractLinearOperatorFromCollection}, args...; kargs...)
45-
error("Operator can't be constructed. You need to load another package!")
46-
end
4745

4846
"""
4947
returns a list of currently implemented `LinearOperator`s
@@ -52,6 +50,16 @@ function linearOperatorList()
5250
return subtypes(AbstractLinearOperatorFromCollection)
5351
end
5452

53+
# Next we create the factory methods. We probably want to given
54+
# a better error message if the extension module is not loaded
55+
for op in linearOperatorList()
56+
@eval begin
57+
function createLinearOperator(::Type{ Op }; kargs...) where Op <: $op{T} where T <: Number
58+
return $op(T; kargs...)
59+
end
60+
end
61+
end
62+
5563
include("GradientOp.jl")
5664
include("SamplingOp.jl")
5765
include("WeightingOp.jl")

0 commit comments

Comments
 (0)