|
1 | | -function LinearOperatorCollection.GradientOp(::Type{T}; |
2 | | - shape::Tuple, dims=nothing) where T <: Number |
3 | | - if dims == nothing |
4 | | - return GradientOpImpl(T, shape) |
5 | | - else |
6 | | - return GradientOpImpl(T, shape, dims) |
7 | | - end |
8 | | -end |
9 | | - |
10 | 1 | """ |
11 | | - GradOp(T::Type, shape::NTuple{N,Int64}) |
| 2 | + GradientOp(T::Type; shape::Tuple, dims=1:length(shape)) |
12 | 3 |
|
13 | | -Nd gradient operator for an array of size `shape` |
14 | | -""" |
15 | | -function GradientOpImpl(T::Type, shape) |
16 | | - shape = typeof(shape) <: Number ? (shape,) : shape # convert Number to Tuple |
17 | | - return vcat([GradientOpImpl(T, shape, i) for i ∈ eachindex(shape)]...) |
18 | | -end |
| 4 | +directional gradient operator along the dimensions `dims` for an array of size `shape`. |
19 | 5 |
|
20 | | -""" |
21 | | - GradOp(T::Type, shape::NTuple{N,Int64}, dims) |
| 6 | +# Required Argument |
| 7 | + * `T` - type of elements, .e.g. `Float64` for `ComplexF32` |
| 8 | +
|
| 9 | +# Required Keyword argument |
| 10 | + * `shape::NTuple{N,Int}` - shape of the array (e.g., image) |
22 | 11 |
|
23 | | -directional gradient operator along the dimensions `dims` |
24 | | -for an array of size `shape` |
| 12 | +# Optional Keyword argument |
| 13 | + * `dims` - dimension(s) along which the gradient is applied; default is `1:length(shape)` |
25 | 14 | """ |
26 | | -function GradientOpImpl(T::Type, shape::NTuple{N,Int64}, dims) where N |
| 15 | +function GradientOp(::Type{T}; shape::NTuple{N,Int}, dims=1:length(shape)) where {T <: Number, N} |
| 16 | + return GradientOpImpl(T, shape, dims) |
| 17 | +end |
| 18 | + |
| 19 | +function GradientOpImpl(T::Type, shape::NTuple{N,Int}, dims) where N |
27 | 20 | return vcat([GradientOpImpl(T, shape, dim) for dim ∈ dims]...) |
28 | 21 | end |
29 | | -function GradientOpImpl(T::Type, shape::NTuple{N,Int64}, dim::Integer) where N |
| 22 | + |
| 23 | +function GradientOpImpl(T::Type, shape::NTuple{N,Int}, dim::Int) where N |
30 | 24 | nrow = div( (shape[dim]-1)*prod(shape), shape[dim] ) |
31 | 25 | ncol = prod(shape) |
32 | 26 | return LinearOperator{T}(nrow, ncol, false, false, |
|
0 commit comments