Skip to content

Commit 8324599

Browse files
authored
Merge pull request #1 from JuliaImageRecon/tk/extensions
Redesign using extensions
2 parents 85b129f + 7745fd8 commit 8324599

File tree

19 files changed

+504
-200
lines changed

19 files changed

+504
-200
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
version:
21-
- '1.6'
22-
- '1.9'
21+
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
2322
- 'nightly'
2423
os:
2524
- ubuntu-latest

Project.toml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,33 @@ authors = ["Tobias Knopp <[email protected]> and contributors"]
44
version = "1.0.0"
55

66
[deps]
7-
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
87
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
98
LinearOperators = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125"
109
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1110
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1211
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
12+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
13+
14+
[weakdeps]
1315
Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a"
16+
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
17+
NFFT = "efe261a4-0d2b-5849-be55-fc731d526b0d"
18+
19+
[extensions]
20+
LinearOperatorWaveletExt = "Wavelets"
21+
LinearOperatorFFTWExt = "FFTW"
22+
LinearOperatorNFFTExt = ["NFFT", "FFTW"]
1423

1524
[compat]
16-
julia = "1.6"
17-
FFTW = "0.2, 1.0"
25+
julia = "1.9"
26+
FFTW = "1.0"
1827
LinearOperators = "2.3.3"
19-
Reexport = "0.2, 1.0"
20-
Wavelets = "0.8, 0.9"
28+
Reexport = "1.0"
29+
Wavelets = "0.9"
30+
NFFT = "0.13"
2131

2232
[extras]
2333
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2434

2535
[targets]
26-
test = ["Test"]
36+
test = ["Test", "FFTW", "Wavelets", "NFFT"]

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,22 @@
22

33
[![Build Status](https://github.com/JuliaImageRecon/LinearOperatorCollection.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/JuliaImageRecon/LinearOperatorCollection.jl/actions/workflows/CI.yml?query=branch%3Amain)
44

5-
[![codecov.io](http://codecov.io/JuliaImageRecon/LinearOperatorCollection.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaImageRecon/LinearOperatorCollection.jl?branch=master)
5+
[![codecov.io](http://codecov.io/JuliaImageRecon/LinearOperatorCollection.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaImageRecon/LinearOperatorCollection.jl?branch=master)
6+
7+
## Purpose
8+
9+
This package contains a collection of linear operators that are in particular useful for multi-dimensional signal and image processing tasks. All operators are build using the LinearOperators.jl base type and derive from `AbstractLinearOperator`. For example this package
10+
provides operators for the FFT (Fast Fourier Transform) and its non-equidistant variant (NFFT), the DCT (Discrete Cosine Transform), and the Wavelet transform. This package, however, does not implement
11+
these transformation itself but uses established libraries for them. So in fact, LinearOperatorCollection's main purpose is to add a wrapper around low-level libraries like
12+
FFTW.jl and NFFT.jl, which allows to use the transformation as if they would be linear operators, i.e. implement `Op * x`, `adjoint(Op) * x` and the `mul!` based in-place variants of the former.
13+
14+
## Installation
15+
16+
Within Julia, use the package manager to install this package:
17+
```julia
18+
using Pkg
19+
Pkg.add("LinearOperatorCollection")
20+
```
21+
22+
## Usage
23+
...

src/DCTOp.jl renamed to ext/LinearOperatorFFTWExt/DCTOp.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export DCTOp
1+
export DCTOpImpl
22

3-
mutable struct DCTOp{T} <: AbstractLinearOperator{T}
3+
mutable struct DCTOpImpl{T} <: DCTOp{T}
44
nrow :: Int
55
ncol :: Int
66
symmetric :: Bool
@@ -20,19 +20,19 @@ mutable struct DCTOp{T} <: AbstractLinearOperator{T}
2020
dcttype::Int
2121
end
2222

23-
LinearOperators.storage_type(op::DCTOp) = typeof(op.Mv5)
23+
LinearOperators.storage_type(op::DCTOpImpl) = typeof(op.Mv5)
2424

2525
"""
26-
DCTOp(T::Type, shape::Tuple, dcttype=2)
26+
DCTOpImpl(T::Type, shape::Tuple, dcttype=2)
2727
28-
returns a `DCTOp <: AbstractLinearOperator` which performs a DCT on a given input array.
28+
returns a `DCTOpImpl <: AbstractLinearOperator` which performs a DCT on a given input array.
2929
3030
# Arguments:
3131
* `T::Type` - type of the array to transform
3232
* `shape::Tuple` - size of the array to transform
3333
* `dcttype` - type of DCT (currently `2` and `4` are supported)
3434
"""
35-
function DCTOp(T::Type, shape::Tuple, dcttype=2)
35+
function LinearOperatorCollection.DCTOp(T::Type; shape::Tuple, dcttype=2)
3636

3737
tmp=Array{Complex{real(T)}}(undef, shape)
3838
if dcttype == 2
@@ -50,7 +50,7 @@ function DCTOp(T::Type, shape::Tuple, dcttype=2)
5050
error("DCT type $(dcttype) not supported")
5151
end
5252

53-
return DCTOp{T}(prod(shape), prod(shape), false, false,
53+
return DCTOpImpl{T}(prod(shape), prod(shape), false, false,
5454
prod!, nothing, tprod!,
5555
0, 0, 0, true, false, true, T[], T[],
5656
plan, dcttype)
@@ -68,6 +68,6 @@ function dct_multiply4(res::Vector{T}, plan::P, x::Vector{T}, tmp::Array{T,D}, f
6868
res .= factor.*vec(tmp)
6969
end
7070

71-
function Base.copy(S::DCTOp)
72-
return DCTOp(eltype(S), size(S.plan), S.dcttype)
71+
function Base.copy(S::DCTOpImpl)
72+
return DCTOpImpl(eltype(S), size(S.plan), S.dcttype)
7373
end

src/DSTOp.jl renamed to ext/LinearOperatorFFTWExt/DSTOp.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export DSTOp
1+
export DSTOpImpl
22

3-
mutable struct DSTOp{T} <: AbstractLinearOperator{T}
3+
mutable struct DSTOpImpl{T} <: DSTOp{T}
44
nrow :: Int
55
ncol :: Int
66
symmetric :: Bool
@@ -20,7 +20,7 @@ mutable struct DSTOp{T} <: AbstractLinearOperator{T}
2020
iplan
2121
end
2222

23-
LinearOperators.storage_type(op::DSTOp) = typeof(op.Mv5)
23+
LinearOperators.storage_type(op::DSTOpImpl) = typeof(op.Mv5)
2424

2525
"""
2626
DSTOp(T::Type, shape::Tuple)
@@ -31,15 +31,15 @@ returns a `LinearOperator` which performs a DST on a given input array.
3131
* `T::Type` - type of the array to transform
3232
* `shape::Tuple` - size of the array to transform
3333
"""
34-
function DSTOp(T::Type, shape::Tuple)
34+
function LinearOperatorCollection.DSTOp(T::Type; shape::Tuple)
3535
tmp=Array{Complex{real(T)}}(undef, shape)
3636

3737
plan = FFTW.plan_r2r!(tmp,FFTW.RODFT10)
3838
iplan = FFTW.plan_r2r!(tmp,FFTW.RODFT01)
3939

4040
w = weights(shape, T)
4141

42-
return DSTOp{T}(prod(shape), prod(shape), true, false
42+
return DSTOpImpl{T}(prod(shape), prod(shape), true, false
4343
, (res,x) -> dst_multiply!(res,plan,x,tmp,w)
4444
, nothing
4545
, (res,x) -> dst_bmultiply!(res,iplan,x,tmp,w)
@@ -72,6 +72,6 @@ function dst_bmultiply!(res::Vector{T}, plan::P, x::Vector{T}, tmp::Array{T,D},
7272
res[:] .= vec(tmp)./(8*length(tmp))
7373
end
7474

75-
function Base.copy(S::DSTOp)
76-
return DSTOp(eltype(S), size(S.plan))
75+
function Base.copy(S::DSTOpImpl)
76+
return DSTOpImpl(eltype(S), size(S.plan))
7777
end

src/FFTOp.jl renamed to ext/LinearOperatorFFTWExt/FFTOp.jl

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

4-
mutable struct FFTOp{T} <: AbstractLinearOperator{T}
4+
mutable struct FFTOpImpl{T} <: FFTOp{T}
55
nrow :: Int
66
ncol :: Int
77
symmetric :: Bool
@@ -23,10 +23,10 @@ mutable struct FFTOp{T} <: AbstractLinearOperator{T}
2323
unitary::Bool
2424
end
2525

26-
LinearOperators.storage_type(op::FFTOp) = typeof(op.Mv5)
26+
LinearOperators.storage_type(op::FFTOpImpl) = typeof(op.Mv5)
2727

2828
"""
29-
FFTOp(T::Type, shape::Tuple, shift=true, unitary=true)
29+
FFTOp(T::Type; shape::Tuple, shift=true, unitary=true)
3030
3131
returns an operator which performs an FFT on Arrays of type T
3232
@@ -36,7 +36,7 @@ returns an operator which performs an FFT on Arrays of type T
3636
* (`shift=true`) - if true, fftshifts are performed
3737
* (`unitary=true`) - if true, FFT is normalized such that it is unitary
3838
"""
39-
function FFTOp(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
4040

4141
#tmpVec = cuda ? CuArray{T}(undef,shape) : Array{Complex{real(T)}}(undef, shape)
4242
tmpVec = Array{Complex{real(T)}}(undef, shape)
@@ -54,7 +54,7 @@ function FFTOp(T::Type, shape::NTuple{D,Int64}, shift::Bool=true; unitary::Bool=
5454
let shape_=shape, plan_=plan, iplan_=iplan, tmpVec_=tmpVec, facF_=facF, facB_=facB
5555

5656
if shift
57-
return FFTOp{T}(prod(shape), prod(shape), false, false
57+
return FFTOpImpl{T}(prod(shape), prod(shape), false, false
5858
, (res, x) -> fft_multiply_shift!(res, plan_, x, shape_, facF_, tmpVec_)
5959
, nothing
6060
, (res, x) -> fft_multiply_shift!(res, iplan_, x, shape_, facB_, tmpVec_)
@@ -64,7 +64,7 @@ function FFTOp(T::Type, shape::NTuple{D,Int64}, shift::Bool=true; unitary::Bool=
6464
, shift
6565
, unitary)
6666
else
67-
return FFTOp{T}(prod(shape), prod(shape), false, false
67+
return FFTOpImpl{T}(prod(shape), prod(shape), false, false
6868
, (res, x) -> fft_multiply!(res, plan_, x, facF_, tmpVec_)
6969
, nothing
7070
, (res, x) -> fft_multiply!(res, iplan_, x, facB_, tmpVec_)
@@ -91,6 +91,6 @@ function fft_multiply_shift!(res::AbstractVector{T}, plan::P, x::AbstractVector{
9191
end
9292

9393

94-
function Base.copy(S::FFTOp)
95-
return FFTOp(eltype(S), size(S.plan), S.shift, unitary=S.unitary)
94+
function Base.copy(S::FFTOpImpl)
95+
return FFTOpImpl(eltype(S), size(S.plan), S.shift, unitary=S.unitary)
9696
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module LinearOperatorFFTWExt
2+
3+
using LinearOperatorCollection, FFTW
4+
5+
include("FFTOp.jl")
6+
include("DCTOp.jl")
7+
include("DSTOp.jl")
8+
9+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module LinearOperatorNFFTExt
2+
3+
using LinearOperatorCollection, NFFT, FFTW
4+
5+
include("NFFTOp.jl")
6+
7+
end

0 commit comments

Comments
 (0)