Skip to content

GradOp Cleanup + docstring #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions src/GradientOp.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
function LinearOperatorCollection.GradientOp(::Type{T};
shape::Tuple, dims=nothing) where T <: Number
if dims == nothing
return GradientOpImpl(T, shape)
else
return GradientOpImpl(T, shape, dims)
end
end

"""
GradOp(T::Type, shape::NTuple{N,Int64})
GradientOp(T::Type; shape::Tuple, dims=1:length(shape))

Nd gradient operator for an array of size `shape`
"""
function GradientOpImpl(T::Type, shape)
shape = typeof(shape) <: Number ? (shape,) : shape # convert Number to Tuple
return vcat([GradientOpImpl(T, shape, i) for i ∈ eachindex(shape)]...)
end
directional gradient operator along the dimensions `dims` for an array of size `shape`.

"""
GradOp(T::Type, shape::NTuple{N,Int64}, dims)
# Required Argument
* `T` - type of elements, .e.g. `Float64` for `ComplexF32`

# Required Keyword argument
* `shape::NTuple{N,Int}` - shape of the array (e.g., image)

directional gradient operator along the dimensions `dims`
for an array of size `shape`
# Optional Keyword argument
* `dims` - dimension(s) along which the gradient is applied; default is `1:length(shape)`
"""
function GradientOpImpl(T::Type, shape::NTuple{N,Int64}, dims) where N
function GradientOp(::Type{T}; shape::NTuple{N,Int}, dims=1:length(shape)) where {T <: Number, N}
return GradientOpImpl(T, shape, dims)
end

function GradientOpImpl(T::Type, shape::NTuple{N,Int}, dims) where N
return vcat([GradientOpImpl(T, shape, dim) for dim ∈ dims]...)
end
function GradientOpImpl(T::Type, shape::NTuple{N,Int64}, dim::Integer) where N

function GradientOpImpl(T::Type, shape::NTuple{N,Int}, dim::Int) where N
nrow = div( (shape[dim]-1)*prod(shape), shape[dim] )
ncol = prod(shape)
return LinearOperator{T}(nrow, ncol, false, false,
Expand Down