Skip to content

Commit

Permalink
Use Type not DataType
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffFessler committed May 18, 2024
1 parent 6dd5afa commit 3d1422e
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MIRT"
uuid = "7035ae7a-3787-11e9-139a-5545ed3dc201"
authors = ["fessler <[email protected]>"]
version = "0.17.0"
version = "0.18"

[deps]
AVSfldIO = "b6189060-daf9-4c28-845a-cc0984b81781"
Expand Down Expand Up @@ -30,9 +30,9 @@ FillArrays = "1"
ImageFiltering = "0.7"
ImageTransformations = "0.10"
Interpolations = "0.15"
LazyGrids = "0.5"
LinearMapsAA = "0.11"
LazyGrids = "1"
LinearMapsAA = "0.12"
NFFT = "0.13"
SpecialFunctions = "1, 2"
SpecialFunctions = "2"
Wavelets = "0.10"
julia = "1.10"
4 changes: 2 additions & 2 deletions src/algorithm/general/dot-curv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _curv_type(Tf::Type{<:RealU}, Tx::Type{<:Number}) =


"""
make_dot_curvf(curv::Function, [x, Tf::DataType; w = similar(x)])
make_dot_curvf(curv::Function, [x, Tf::Type; w = similar(x)])
Make a function with arguments `(v, x)`
that computes the dot product between
Expand Down Expand Up @@ -53,7 +53,7 @@ Those units are relevant to defining the work array `w`.
- `x` an array whose `size` and `eltype` is used to allocate `w`
# option
- `Tf::DataType = typeof(one(eltype(x)))`
- `Tf::Type = typeof(one(eltype(x)))`
Specify `eltype` of function `f(x)`, defaulting to unitless.
- `w = similar(x, typeof(oneunit(Tf) / oneunit(eltype(x))^2))`
work space for gradient calculation, with appropriate units (if needed).
Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/general/dot-grad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _grad_type(Tf::Type{<:RealU}, Tx::Type{<:Number}) =


"""
make_dot_gradf(grad::Function, [x, Tf::DataType; w = similar(x)])
make_dot_gradf(grad::Function, [x, Tf::Type; w = similar(x)])
Make a function with arguments `(v, x)`
that computes the dot product between
Expand Down Expand Up @@ -44,7 +44,7 @@ Those units are relevant to defining the work array `w`.
# in
- `grad::Function` see above
- `x` an array whose `size` and `eltype` is used to allocate `w`
- `Tf::DataType = typeof(one(eltype(x)))`
- `Tf::Type = typeof(one(eltype(x)))`
Specify `eltype` of function `f(x)`, defaulting to unitless.
# option
Expand Down
42 changes: 20 additions & 22 deletions src/nufft/dtft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ see also MIRT/time/dtft.jl

export dtft_init, dtft, dtft_adj

#using LinearAlgebra: norm
using Distributed: @sync, @distributed, pmap
using SharedArrays: SharedArray, sdata
using LinearMapsAA: LinearMapAA, LinearMapAO
Expand All @@ -35,7 +34,7 @@ using LinearMapsAA: LinearMapAA, LinearMapAO
"""
function dtft(w::AbstractVector{<:Real}, x::AbstractVector{<:Number}
; n_shift::Real = 0)
return dtft_loop_n(w, x ; n_shift=n_shift)
return dtft_loop_n(w, x ; n_shift)
end


Expand All @@ -59,7 +58,7 @@ where here `n` is a `CartesianIndex`
function dtft(w::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Number}
; n_shift::AbstractVector{<:Real} = zeros(Int, ndims(x)),
)
return dtft_loop_n(w, x ; n_shift=n_shift)
return dtft_loop_n(w, x ; n_shift)
end


Expand All @@ -74,7 +73,7 @@ For 1D DTFT
# option
- `n_shift::Real` often is N/2; default 0
- `T::DataType` default `ComplexF64` for testing NUFFT accuracy
- `T::Type` default `ComplexF64` for testing NUFFT accuracy
# out
- `d::NamedTuple` with fields
Expand All @@ -84,17 +83,17 @@ function dtft_init(
w::AbstractVector{<:Real},
N::Int ;
n_shift::Real = 0,
T::DataType = ComplexF64,
T::Type{<:Complex{<:AbstractFloat}} = ComplexF64,
)

M = length(w)
forw = x -> dtft(w, x ; n_shift=n_shift)
back = y -> dtft_adj(w, y, N ; n_shift=n_shift)
forw = x -> dtft(w, x ; n_shift)
back = y -> dtft_adj(w, y, N ; n_shift)
A = LinearMapAA(forw, back, (M, N),
(name="dtft1", N=(N,)) ; T = ComplexF64,
(name = "dtft1", N = (N,)) ; T = ComplexF64,
operator = true,
)
return (dtft=forw, adjoint=back, A=A)
return (dtft=forw, adjoint=back, A)
end


Expand All @@ -108,7 +107,7 @@ for multi-dimensional DTFT (DSFT)
# option
- `n_shift::AbstractVector{<:Real}` often is N/2; default zeros(D)
- `T::DataType` default `ComplexF64` for testing NUFFT accuracy
- `T::Type` default `ComplexF64` for testing NUFFT accuracy
# out
- `d::NamedTuple` with fields
Expand All @@ -124,13 +123,13 @@ function dtft_init(
length(N) != D && throw(DimensionMismatch("length(N) vs D=$D"))
length(n_shift) != D && throw(DimensionMismatch("length(n_shift) vs D=$D"))
M = size(w,1)
forw = x -> dtft(w, x ; n_shift=n_shift)
back = y -> dtft_adj(w, y, N ; n_shift=n_shift)
forw = x -> dtft(w, x ; n_shift)
back = y -> dtft_adj(w, y, N ; n_shift)
A = LinearMapAA(forw, back, (M, prod(N)),
(name="dtft$(length(N))", N=N) ; T = ComplexF64,
(name = "dtft$(length(N))", N) ; T = ComplexF64,
operator = true, idim = N,
)
return (dtft=forw, adjoint=back, A=A)
return (dtft=forw, adjoint=back, A)
end


Expand All @@ -149,14 +148,14 @@ This is the *adjoint* (transpose) of `dtft`, not an *inverse* DTFT.
# option
- `n_shift::Real` often is N/2; default 0
- `T::DataType` output data type; default `ComplexF64`
- `T::Type` output data type; default `ComplexF64`
# out
- `x::AbstractVector{<:Number} (N)` signal
"""
function dtft_adj(w::AbstractVector{<:Real}, X::AbstractVector{<:Number},
N::Int ; n_shift::Real = 0,
T::DataType = ComplexF64,
T::Type{<:Complex{<:AbstractFloat}} = ComplexF64,
)
M = length(w)
out = similar(X, T, N)
Expand All @@ -183,7 +182,7 @@ where here `n` is a `CartesianIndex`
# option
- `n_shift::AbstractVector{<:Real}` often is `N/2`; default `zeros(D)`
- `T::DataType` default `(eltype(w) == Float64) ? ComplexF64 : ComplexF32`
- `T::Type` default `(eltype(w) == Float64) ? ComplexF64 : ComplexF32`
# out
- `x::AbstractArray{<:Number} [(N)]` `D`-dimensional signal
Expand All @@ -193,7 +192,8 @@ function dtft_adj(
X::AbstractVector{<:Number},
N::Dims ;
n_shift::AbstractVector{<:Real} = zeros(Int, ndims(x)),
T::DataType = (eltype(w) == Float64) ? ComplexF64 : ComplexF32,
T::Type{<:Complex{<:AbstractFloat}} =
(eltype(w) == Float64) ? ComplexF64 : ComplexF32,
)

M, D = size(w)
Expand All @@ -203,8 +203,6 @@ function dtft_adj(

for n in 1:prod(N)
idx = CartesianIndices(N)[n]
tmp = cis.(w * (collect(Tuple(idx)) - nshift1))
tmp = transpose(cis.(w * (collect(Tuple(idx)) - nshift1))) * X
out[idx] = cis.(-w * (collect(Tuple(idx)) - nshift1))' * X
end
return out
Expand Down Expand Up @@ -254,7 +252,7 @@ function dtft_loop_m(
w::AbstractVector{<:Real},
x::AbstractVector{<:Number} ;
n_shift::Real = 0,
T::DataType = ComplexF64,
T::Type{<:Complex{<:AbstractFloat}} = ComplexF64,
)
M = length(w)
N = length(x)
Expand Down Expand Up @@ -296,7 +294,7 @@ function dtft_pmap_m(
x::AbstractVector{<:Number}
; n_shift::Real = 0,
)
tmp = w -> dtft_one_w(w, x ; n_shift=n_shift)
tmp = w -> dtft_one_w(w, x ; n_shift)
return pmap(tmp, w)
end

Expand Down
4 changes: 2 additions & 2 deletions src/nufft/nufft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _start = N -> isodd(N) ? (N-1)÷2 : N÷2 # where the NFFT sum starts


"""
nufft_eltype(::DataType)
nufft_eltype(::Type)
ensure plan_nfft eltype is Float32 or Float64
"""
nufft_eltype(::Type{<:Integer}) = Float32
Expand All @@ -31,7 +31,7 @@ nufft_eltype(T::DataType) = throw("unknown type $T")
# see https://github.com/tknopp/NFFT.jl/pull/33
# todo: may be unnecessary with future version of nfft()
"""
nufft_typer(T::DataType, x::AbstractArray{<:Real} ; warn::Bool=true)
nufft_typer(T::Type, x::AbstractArray{<:Real} ; warn::Bool=true)
type conversion wrapper for `nfft()`
"""
nufft_typer(::Type{T}, x::T ; warn::Bool=true) where {T} = x # cf convert()
Expand Down
4 changes: 2 additions & 2 deletions src/regularize/Aodwt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Create orthogonal discrete wavelet transform (ODWT) `LinearMapAA`
- `level::Int` # of levels; default 3
- `wt` wavelet transform type (see `Wavelets` package); default Haar
- `operator::Bool=true` default to `LinearMapAO`
- `T::DataType` : `Float32` by default; use `ComplexF32` if needed
- `T::Type` : `Float32` by default; use `ComplexF32` if needed
# out
- `A` a `LinearMapAX` object
Expand All @@ -33,7 +33,7 @@ which is useful when imposing scale-dependent regularization
"""
function Aodwt(
dims::Dims ;
T::DataType = Float32,
T::Type{<:Complex{<:AbstractFloat}} = ComplexF32,
level::Int = 3,
wt = wavelet(WT.haar),
operator::Bool = true, # !
Expand Down
8 changes: 4 additions & 4 deletions src/system/Afft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In:
- `fdim = 1:D` apply fft/bfft only along these dimensions
Option:
- `T::DataType = ComplexF32`
- `T::Type = ComplexF32`
- `operator::Bool = true` return a `LinearMapAO`
set to `false` to return a `LinearMapAM`
- `unitary::Bool = false` set to `true` for unitary DFT
Expand All @@ -39,7 +39,7 @@ function Afft(
xdim::Dims{D},
fdim = 1:D,
;
T::DataType = ComplexF32,
T::Type{<:Complex{<:AbstractFloat}} = ComplexF32,
operator::Bool = true, # !
unitary::Bool = false,
work::AbstractArray{Tw,D} = Array{T,D}(undef, xdim),
Expand Down Expand Up @@ -109,7 +109,7 @@ using given sampling pattern `samp`.
Especially for compressed sensing MRI with Cartesian sampling.
Option:
- `T::DataType = ComplexF32`
- `T::Type = ComplexF32`
- `dims = 1:D` apply fft/bfft only along these dimensions
- `fft_forward::Bool = true` Use `false` to have `bfft!` in forward model.
- `operator::Bool = true` set to `false` to return a `LinearMapAM`
Expand All @@ -123,7 +123,7 @@ function Afft(
samp::AbstractArray{<:Bool, D},
;
dims = 1:D,
T::DataType = ComplexF32,
T::Type{<:Complex{<:AbstractFloat}} = ComplexF32,
operator::Bool = true, # !
work::AbstractArray{Tw,D} = similar(samp, T),
fft_forward::Bool = true,
Expand Down
4 changes: 2 additions & 2 deletions src/system/Asense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ or a Vector of `ncoil` arrays of size `size(samp)`.
- `smaps::Vector{<:AbstractArray{<:Number}}` or `AbstractArray{<:Number}`
# Option
- `T::DataType = ComplexF32`
- `T::Type = ComplexF32`
- `dims = 1:D` apply fft/bfft only along these dimensions
- `fft_forward::Bool = true` Use `false` to have `bfft!` in forward model.
- `unitary::Bool = false` set to `true` for unitary DFT
Expand All @@ -40,7 +40,7 @@ function Asense(
smaps::Vector{<:AbstractArray{<:Number}},
;
dims = 1:D,
T::DataType = ComplexF32,
T::Type{<:Complex{<:AbstractFloat}} = ComplexF32,
work1::AbstractArray{Tw,D} = similar(samp, T),
work2::AbstractArray{Tw,D} = similar(samp, T),
unitary::Bool = false,
Expand Down
10 changes: 5 additions & 5 deletions src/utility/downsample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Downsample by averaging by integer factors.
# option
- `warn::Bool` warn if noninteger multiple; default `isinteractive()`
- `T::DataType` specify output eltype; default `eltype(x[1] / down[1])`
- `T::Type` specify output eltype; default `eltype(x[1] / down[1])`
# out
- `y [nx/down ny/down]`
Expand All @@ -102,7 +102,7 @@ function downsample2(
x::AbstractMatrix{<:Number},
down::NTuple{2,Int} ;
warn::Bool = isinteractive(),
T::DataType = eltype(x[1] / down[1])
T::Type{<:Number} = eltype(x[1] / down[1])
)

idim = size(x)
Expand Down Expand Up @@ -148,7 +148,7 @@ Downsample by averaging by integer factors.
# option
- `warn::Bool` warn if noninteger multiple; default true
- `T::DataType` specify output eltype; default `eltype(x[1] / down[1])`
- `T::Type` specify output eltype; default `eltype(x[1] / down[1])`
# out
- `y (nx/down,ny/down,nz/down)`
Expand All @@ -157,7 +157,7 @@ function downsample3(
x::AbstractArray{<:Number,3},
down::NTuple{3,Int} ;
warn::Bool = isinteractive(),
T::DataType = eltype(x[1] / down[1]),
T::Type{<:Number} = eltype(x[1] / down[1]),
)

idim = size(x)
Expand All @@ -176,7 +176,7 @@ downsample3(x::AbstractArray{<:Number,3}, down::Int ; args...) =
function downsample3_loop(
x::AbstractArray{<:Number,3},
down::NTuple{3,Int} ;
T::DataType = eltype(x[1] / down[1]),
T::Type{<:Number} = eltype(x[1] / down[1]),
)

odim = size(x) down
Expand Down

0 comments on commit 3d1422e

Please sign in to comment.