Skip to content

Commit

Permalink
use ÷ (#91)
Browse files Browse the repository at this point in the history
* use ÷

* use ÷
  • Loading branch information
JeffFessler authored Feb 24, 2021
1 parent e2a8d07 commit 6c17dcd
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/fbp/image_geom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ function _down_round(
) where {D}
out = val ./ down
# for non-divisors make dim a multiple of 2
fun = out -> out == round(out) ? out : 2 * round(out / 2)
fun = out -> out == round(out) ? out : 2 * (out ÷ 2)
out = fun.(out)
dd = dd .* down
return Int.(out), dd
Expand Down Expand Up @@ -422,7 +422,7 @@ function image_geom_add_unitv(
out[i...] += one(T)
else
any(i .!= 0) && throw("i $i")
tmp = c .+ Int.(floor.(size(out) ./ 2)) .+ 1
tmp = c .+ (size(out) .÷ 2) .+ 1
out[tmp...] += one(T)
end

Expand Down
14 changes: 7 additions & 7 deletions src/fbp/sino_geom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ SinoFanMaker(dfs::Real) =

# common to all
function _downsample(sg::SinoGeom, down::Int)
nb = 2 * round(Int, sg.nb / down / 2) # keep it even
na = round(Int, sg.na / down)
nb = 2 * (sg.nb ÷ 2down) # keep it even
na = sg.na ÷ down
return (sg.units,
nb, na, sg.d * down, sg.orbit, sg.orbit_start, sg.offset,
sg.strip_width * down)
Expand Down Expand Up @@ -249,7 +249,7 @@ end
function sino_geom_fan( ;
units::Symbol = :none,
nb::Int = 128,
na::Int = 2 * floor(Int, nb * pi/2 / 2),
na::Int = 2 * floor(Int, nb * π/2 / 2),
d::Real = 1,
orbit::Union{Symbol,Real} = 360, # [degrees]
orbit_start::Real = 0,
Expand Down Expand Up @@ -289,7 +289,7 @@ end
function sino_geom_par( ;
units::Symbol = :none,
nb::Int = 128,
na::Int = 2 * floor(Int, nb * pi/2 / 2),
na::Int = 2 * floor(Int, nb * π/2 / 2),
down::Int = 1,
d::Real = 1,
orbit::Real = 180, # [degrees]
Expand All @@ -309,7 +309,7 @@ end
function sino_geom_moj( ;
units::Symbol = :none,
nb::Int = 128,
na::Int = 2 * floor(Int, nb * pi/2 / 2),
na::Int = 2 * floor(Int, nb * π/2 / 2),
down::Int = 1,
d::Real = 1, # means dx for :moj
orbit::Real = 180, # [degrees]
Expand Down Expand Up @@ -409,8 +409,8 @@ sinogram with a single ray
"""
function sino_geom_unitv(
sg::SinoGeom ;
ib::Int = round(Int, sg.nb/2+1),
ia::Int = round(Int, sg.na/2+1),
ib::Int = sg.nb ÷ 2 + 1,
ia::Int = sg.na ÷ 2 + 1,
)
out = sg.zeros
out[ib,ia] = 1
Expand Down
10 changes: 6 additions & 4 deletions src/mri/kspace-spiral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ function genspi(D, N ;

# gmax limited approximation
l3 = 0
T=ts
T = ts
if Gmax > gamp
T = ((pi*N/nl)*(pi*N/nl) - thetas*thetas)/(2*gamma*gamp*D/nl) + ts
T = ((π*N/nl)*(π*N/nl) - thetas*thetas)/(2*gamma*gamp*D/nl) + ts
t = (ts+dt):dt:T
theta = sqrt.(thetas * thetas .+ (2 * gamma * gamp * D) .* (t .- ts) / nl)
c = cos.(theta)
Expand All @@ -251,8 +251,10 @@ function genspi(D, N ;
if (maximum(ind2) > length(gy))
gy = [gy; zeros(maximum(ind2) - length(gy))]
end
gx[floor.(Int,ind2)] = gamp.*(c./theta - s)
gy[floor.(Int,ind2)] = gamp.*(s./theta + c)
# gx[floor.(Int,ind2)] = gamp.*(c./theta - s)
# gy[floor.(Int,ind2)] = gamp.*(s./theta + c)
gx[ind2] = gamp.*(c./theta - s)
gy[ind2] = gamp.*(s./theta + c)
l3 = length(t)
end

Expand Down
6 changes: 3 additions & 3 deletions src/mri/sensemap-sim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function ir_mri_sensemap_sim(
orbit, orbit_start, coil_distance, ir_ic_pair)

scale_center = (nz == 0) ?
1 / sqrt(sum(abs2.(smap[round(Int,nx/2),round(Int,ny/2),:]))) :
1 / sqrt(sum(abs2.(smap[round(Int,nx/2),round(Int,ny/2),round(Int,nz/2),:])))
1 / sqrt(sum(abs2.(smap[nx÷2,ny÷2,:]))) :
1 / sqrt(sum(abs2.(smap[nx÷2,ny÷2,nz÷2,:])))

if scale === :ssos_center
smap *= Float32(scale_center)
Expand All @@ -150,7 +150,7 @@ function ir_mri_sensemap_sim_do(
)

T = Float32
nring = Int(ncoil / ncoilpr)
nring = ncoil ÷ ncoilpr
rlist = T(rcoil) * ones(T, ncoilpr, nring) # coil radii

plist = zeros(T, ncoilpr, nring, 3) # position of coil center [x y z]
Expand Down
10 changes: 5 additions & 5 deletions src/plot/jim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function jim(z::AbstractArray{<:Real} ;
xlabel::AbstractString = jim_def[:xlabel],
ylabel::AbstractString = jim_def[:ylabel],
fft0::Bool = jim_def[:fft0],
x = fft0 ? Int.(-size(z,1)/2:size(z,1)/2-1) : (1:size(z,1)),
y = fft0 ? Int.(-size(z,2)/2:size(z,2)/2-1) : (1:size(z,2)),
x = fft0 ? ((-size(z,1)÷2):(size(z,1)÷2-1)) : (1:size(z,1)),
y = fft0 ? ((-size(z,2)÷2):(size(z,2)÷2-1)) : (1:size(z,2)),
xtick = (minimum(x) < 0 && maximum(x) > 0) ?
[minfloor(x),0,maxceil(x)] : [minfloor(x),maxceil(x)],
ytick = (minimum(y) < 0 && maximum(y) > 0) ?
Expand Down Expand Up @@ -162,12 +162,12 @@ function jim(z::AbstractArray{<:Real} ;
m1 = (1+size(z,1)) / n1 # add one because of mosaicview non-edge
m2 = (1+size(z,2)) / n2
plot_box! = (ox, oy) -> plot!(
ox .+ [0,1,1,0,0]*n1 .+ 0.0,
oy .+ [0,0,1,1,0]*n2 .+ 0.0,
ox .+ [0,1,1,0,0] * n1 .+ 0.0,
oy .+ [0,0,1,1,0] * n2 .+ 0.0,
line=jim_def[:line3type], label="")
for ii=0:n3-1
i1 = mod(ii, m1)
i2 = floor(ii / m1)
i2 = ii ÷ m1
plot_box!(i1*n1, i2*n2)
end
end
Expand Down
10 changes: 5 additions & 5 deletions src/utility/downsample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function downsample_dim1(
dim = size(x)
dim1 = dim[1]
x = reshape(x, dim1, :) # [n1 *Nd]
m1 = Int(floor(dim1 / down))
m1 = dim1 ÷ down
if m1 * down < dim1
warn && @warn("truncating input size $dim1 to $(m1 * down)")
x = x[1:(m1*down),:]
Expand Down Expand Up @@ -75,7 +75,7 @@ function downsample1(

dim = size(x)
dim1 = dim[1]
m1 = floor(Int, dim1 / down)
m1 = dim1 ÷ down
if m1 * down < dim1
warn && @warn("truncating input size $dim1 to $(m1 * down)")
y = reshape((@view x[1:(m1*down)]), down, :)
Expand Down Expand Up @@ -111,7 +111,7 @@ function downsample2(
)

idim = size(x)
odim = floor.(Int, idim ./ down)
odim = idim .÷ down

warn && any(odim .* down .!= idim) && @warn("truncating to $odim")

Expand Down Expand Up @@ -178,7 +178,7 @@ function downsample3(
)

idim = size(x)
odim = floor.(Int, idim ./ down)
odim = idim .÷ down

warn && any(odim .* down .!= idim) && @warn("truncating to $odim")

Expand All @@ -196,7 +196,7 @@ function downsample3_loop(
T::DataType = eltype(x[1] / down[1]),
)

odim = floor.(Int, size(x) ./ down)
odim = size(x) .÷ down

y = Array{T}(undef, odim[1], odim[2], odim[3])
d1 = down[1]
Expand Down
4 changes: 2 additions & 2 deletions test/mri/sensemap-sim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function ir_mri_sensemap_sim_show2(smap, x, y, dx, dy, nlist, plist, rlist)
end

ssos = sqrt.(sum(abs2.(smap), dims=ndims(smap)))
ssos = ssos / ssos[Int(end/2),Int(end/2)]
ssos = ssos / ssos[end÷2,end÷2]

p = jim(x, y, ssos, "SSoS (norm.)",
# xlim=[-1,1]*1.1*xmax,
Expand Down Expand Up @@ -320,7 +320,7 @@ function ir_mri_sensemap_sim_test3( ; chat::Bool=false)
tmp = permutedims(tmp, [1,3,2,4]) # [nx nz ny ncoil] z cuts are smooth
jim(ncol=ig.ny, tmp, abswarn=false)
chat && prompt()
jim(ncol=1, tmp[:,:,round(Int,end/2),:], abswarn=false)
jim(ncol=1, tmp[:,:,end÷2,:], abswarn=false)
chat && prompt()
end

Expand Down
2 changes: 1 addition & 1 deletion test/nufft/nufft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ end
#=
# todo MWE for 1D vs 2D
M = 6
x1 = collect((-Int(M/2)):(Int(M/2)-1))/M
x1 = collect((-(M÷2)):((M÷2)-1))/M
N1 = M
p1 = plan_nfft(x1, N1)
# p1 = plan_nfft(x1', (N1,)) # this works too
Expand Down

0 comments on commit 6c17dcd

Please sign in to comment.