|
1 | 1 | module LinearOperatorCollection
|
2 | 2 |
|
3 |
| -# Write your package code here. |
| 3 | +import Base: length, iterate, \ |
| 4 | +using LinearAlgebra |
| 5 | +import LinearAlgebra.BLAS: gemv, gemv! |
| 6 | +import LinearAlgebra: BlasFloat, normalize!, norm, rmul!, lmul! |
| 7 | +using SparseArrays |
| 8 | +using Random |
| 9 | +#using CUDA |
| 10 | + |
| 11 | +using Reexport |
| 12 | +@reexport using Reexport |
| 13 | +@reexport using LinearOperators |
| 14 | +@reexport using FFTW |
| 15 | +@reexport using Wavelets |
| 16 | + |
| 17 | +LinearOperators.use_prod5!(op::opEye) = false |
| 18 | +LinearOperators.has_args5(op::opEye) = false |
| 19 | + |
| 20 | + |
| 21 | +const Trafo = Union{AbstractMatrix, AbstractLinearOperator, Nothing} |
| 22 | +const FuncOrNothing = Union{Function, Nothing} |
| 23 | + |
| 24 | +# Helper function to wrap a prod into a 5-args mul |
| 25 | +function wrapProd(prod::Function) |
| 26 | + λ = (res, x, α, β) -> begin |
| 27 | + if β == zero(β) |
| 28 | + res .= prod(x) .* α |
| 29 | + else |
| 30 | + res .= prod(x) .* α .+ β .* res |
| 31 | + end |
| 32 | + end |
| 33 | + return λ |
| 34 | +end |
| 35 | + |
| 36 | +include("FFTOp.jl") |
| 37 | +include("DCTOp.jl") |
| 38 | +include("DSTOp.jl") |
| 39 | +include("WaveletOp.jl") |
| 40 | +include("GradientOp.jl") |
| 41 | +include("SamplingOp.jl") |
| 42 | +include("WeightingOp.jl") |
| 43 | +include("NormalOp.jl") |
| 44 | + |
| 45 | +export linearOperator, linearOperatorList |
| 46 | + |
| 47 | +linearOperator(op::Nothing,shape,T::Type=ComplexF32) = nothing |
| 48 | + |
| 49 | +""" |
| 50 | + returns a list of currently implemented `LinearOperator`s |
| 51 | +""" |
| 52 | +function linearOperatorList() |
| 53 | + return ["DCT-II", "DCT-IV", "FFT", "DST", "Wavelet", "Gradient"] |
| 54 | +end |
| 55 | + |
| 56 | +""" |
| 57 | + linearOperator(op::AbstractString, shape) |
| 58 | +
|
| 59 | +returns the `LinearOperator` with name `op`. |
| 60 | +
|
| 61 | +# valid names |
| 62 | +* `"FFT"` |
| 63 | +* `"DCT-II"` |
| 64 | +* `"DCT-IV"` |
| 65 | +* `"DST"` |
| 66 | +* `"Wavelet"` |
| 67 | +* `"Gradient"` |
| 68 | +""" |
| 69 | +function linearOperator(op::AbstractString, shape, T::Type=ComplexF32) |
| 70 | + shape_ = tuple(shape...) |
| 71 | + if op == "FFT" |
| 72 | + trafo = FFTOp(T, shape_, false) #FFTOperator(shape) |
| 73 | + elseif op == "DCT-II" |
| 74 | + shape_ = tuple(shape[shape .!= 1]...) |
| 75 | + trafo = DCTOp(T, shape_, 2) |
| 76 | + elseif op == "DCT-IV" |
| 77 | + shape_ = tuple(shape[shape .!= 1]...) |
| 78 | + trafo = DCTOp(T, shape_, 4) |
| 79 | + elseif op == "DST" |
| 80 | + trafo = DSTOp(T, shape_) |
| 81 | + elseif op == "Wavelet" |
| 82 | + trafo = WaveletOp(T,shape_) |
| 83 | + elseif op=="Gradient" |
| 84 | + trafo = GradientOp(T,shape_) |
| 85 | + else |
| 86 | + error("Unknown transformation") |
| 87 | + end |
| 88 | + trafo |
| 89 | +end |
4 | 90 |
|
5 | 91 | end
|
0 commit comments