Skip to content

Commit 3a5a843

Browse files
committed
Make WeightingOp custom type for dispatch
1 parent 0f6ba62 commit 3a5a843

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/LinearOperatorCollection.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ using SparseArrays
77
using Random
88
using InteractiveUtils
99

10+
import Base: *, copy, getproperty, setproperty!
11+
import LinearOperators: storage_type
12+
1013
using Reexport
1114
@reexport using LinearOperators
1215

@@ -37,7 +40,6 @@ abstract type DSTOp{T} <: AbstractLinearOperatorFromCollection{T} end
3740
abstract type NFFTOp{T} <: AbstractLinearOperatorFromCollection{T} end
3841
abstract type SamplingOp{T} <: AbstractLinearOperatorFromCollection{T} end
3942
abstract type NormalOp{T} <: AbstractLinearOperatorFromCollection{T} end
40-
abstract type WeightingOp{T} <: AbstractLinearOperatorFromCollection{T} end
4143
abstract type GradientOp{T} <: AbstractLinearOperatorFromCollection{T} end
4244

4345

@@ -81,7 +83,6 @@ function createLinearOperator(op::String, ::Type{T}; kargs...) where T <: Number
8183
end
8284

8385

84-
8586
include("GradientOp.jl")
8687
include("SamplingOp.jl")
8788
include("WeightingOp.jl")

src/WeightingOp.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
"""
2-
WeightingOp(::Type{T}; weights::Vector{T}, rep::Int=1) where T
2+
WeightingOp(::Type{T}; weights::Vector{T}, rep::Int=1) where T
33
44
generates a `LinearOperator` which multiplies an input vector index-wise with `weights`
55
66
# Arguments
77
* `weights::Vector{T}` - weights vector
88
* `rep::Int=1` - number of sub-arrays that need to be multiplied with `weights`
99
"""
10-
function WeightingOp(::Type{T}; weights::vecT, rep::Int=1) where {T <: Number, vecT<:AbstractVector}
11-
weights_cat = repeat(weights,rep)
12-
return opDiagonal(weights_cat)
10+
mutable struct WeightingOp{T} <: AbstractLinearOperatorFromCollection{T}
11+
op::LinearOperator{T}
12+
weights::Vector{T}
13+
function WeightingOp(weights::vecT, rep::Int=1) where {T <: Number, vecT<:AbstractVector{T}}
14+
weights_cat = repeat(weights,rep)
15+
return new{T}(opDiagonal(weights_cat), weights_cat)
16+
end
1317
end
18+
19+
function Base.getproperty(wop::WeightingOp, field::Symbol)
20+
if in(field, (:op, :weights))
21+
return getfield(wop, field)
22+
else
23+
return getproperty(getfield(wop, :op), field)
24+
end
25+
end
26+
Base.setproperty!(wop::WeightingOp, field::Symbol, value) = setproperty!(wop.op, field, value)
27+
28+
storage_type(wop::WeightingOp) = storage_type(wop.op)

0 commit comments

Comments
 (0)