-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* clean tests * fix lit * DOCUMENTER_KEY * docstring * adjoint rotate * more test work
- Loading branch information
1 parent
bd70f45
commit d1221bd
Showing
13 changed files
with
227 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
[deps] | ||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" | ||
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" | ||
ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
LinearInterpolators = "2fc109c4-9d77-11e9-32ff-e5c650334c16" | ||
LinearMapsAA = "599c1a8e-b958-11e9-0d14-b1e6b2ecea07" | ||
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" | ||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[compat] | ||
BenchmarkTools = "1.2" | ||
FFTW = "1.4.5" | ||
ImageFiltering = "0.7" | ||
LinearInterpolators = "0.1.5" | ||
OffsetArrays = "1.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# adjoint-fftconv.jl | ||
# test adjoint consistency for FFT convolution methods on very small case | ||
|
||
using SPECTrecon: fft_conv!, fft_conv_adj!, Power2 | ||
using FFTW: plan_fft!, plan_ifft! | ||
using LinearMapsAA: LinearMapAA | ||
using Test: @test, @testset | ||
|
||
|
||
@testset "adjoint-fftconv" begin | ||
M = 200 # todo: make smaller | ||
# M = 20 | ||
N = 64 | ||
T = Float32 | ||
fftpadsize = (28, 28, 32, 32) | ||
img_compl = zeros(Complex{T}, 256, 128) | ||
ker_compl = similar(img_compl) | ||
workmat = zeros(T, 256, 128) | ||
workvec1 = zeros(T, 128) | ||
workvec2 = zeros(T, 256) | ||
fft_plan = plan_fft!(img_compl) | ||
ifft_plan = plan_ifft!(img_compl) | ||
|
||
# x = randn(T, M, N) | ||
# output_x = similar(x) | ||
# y = randn(T, M, N) | ||
# output_y = similar(y) | ||
ker = rand(T, 11, 11) # change from 5 -> 11 | ||
ker /= sum(ker) | ||
kerev = reverse(ker) | ||
|
||
forw!(y,x) = fft_conv!(y, workmat, x, | ||
ker, fftpadsize, img_compl, ker_compl, fft_plan, ifft_plan) | ||
|
||
back!(x,y) = fft_conv_adj!(x, workmat, workvec1, workvec2, y, | ||
kerev, fftpadsize, img_compl, ker_compl, fft_plan, ifft_plan) | ||
|
||
idim = (M,N) | ||
odim = (M,N) | ||
A = LinearMapAA(forw!, back!, (prod(odim), prod(idim)); T, odim, idim) | ||
# @test Matrix(A') ≈ Matrix(A)' # todo | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# adjoint-project.jl | ||
# test adjoint consistency for SPECT projector/back-projector on very small case | ||
|
||
using SPECTrecon: project, backproject | ||
using SPECTrecon: project!, backproject! | ||
using SPECTrecon: SPECTplan, Workarray | ||
using LinearMapsAA: LinearMapAA | ||
using Test: @test, @testset | ||
|
||
|
||
#@testset "adjoint" begin | ||
T = Float32 | ||
nx = 16 | ||
ny = 16 | ||
nz = 5 | ||
nview = 7 | ||
|
||
mumap = rand(T, nx, ny, nz) | ||
|
||
nx_psf = 5 | ||
nz_psf = 3 | ||
psfs = rand(T, nx_psf, nz_psf, ny, nview) | ||
psfs = psfs .+ mapslices(reverse, psfs, dims = [1, 2]) # symmetrize | ||
psfs = psfs ./ mapslices(sum, psfs, dims = [1, 2]) | ||
|
||
dy = 4.7952 | ||
|
||
# for interpidx = 1:2 | ||
interpidx = 1 | ||
plan = SPECTplan(mumap, psfs, dy; interpidx) | ||
# workarray = Workarray(plan.T, plan.imgsize, plan.pad_fft, plan.pad_rot) | ||
workarray = [Workarray(plan.T, plan.imgsize, plan.pad_fft, plan.pad_rot) for i in 1:plan.ncore] # allocate | ||
# workarray = [workarray] | ||
forw = x -> project(x, mumap, psfs, dy; interpidx) | ||
back = y -> backproject(y, mumap, psfs, dy; interpidx) | ||
forw! = (y,x) -> project!(y, x, plan, workarray) | ||
back! = (x,y) -> backproject!(x, y, plan, workarray) | ||
idim = (nx,ny,nz) | ||
odim = (nx,nz,nview) | ||
A0 = LinearMapAA(forw, back, (prod(odim),prod(idim)); T, idim, odim) | ||
A! = LinearMapAA(forw!, back!, (prod(odim),prod(idim)); T, idim, odim) | ||
x = 0 * rand(T, idim) | ||
y = Array{T}(undef, odim) | ||
@show extrema(forw(x)) | ||
@show extrema(forw!(y,x)) # NaN values even for 0 input :( | ||
# @test forw!(y,x) ≈ forw(x) | ||
# @test Matrix(A0)' ≈ Matrix(A0') | ||
# @test Matrix(A!)' ≈ Matrix(A!') | ||
# end | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# adjoint-rotate.jl | ||
# test adjoint consistency for rotate methods on very small case | ||
|
||
using SPECTrecon: linearinterp!, rotate_x!, rotate_y! | ||
using SPECTrecon: rotate_x_adj!, rotate_y_adj! | ||
using SPECTrecon: rotl90!, rotr90!, rot180! | ||
using SPECTrecon: imrotate3!, imrotate3_adj! | ||
using LinearAlgebra: dot | ||
using LinearInterpolators: SparseInterpolator, LinearSpline | ||
using LinearMapsAA: LinearMapAA | ||
using Test: @test, @testset | ||
using Random: seed! | ||
|
||
|
||
@testset "adjoint-rotate" begin | ||
Ntest = 7 | ||
θ_list = (0:Ntest-1) / Ntest * 2π | ||
M,N = 16, 16 # todo: test non-square? | ||
T = Float32 | ||
pad_x = ceil(Int, 1 + M * sqrt(2)/2 - M / 2) | ||
pad_y = ceil(Int, 1 + N * sqrt(2)/2 - N / 2) | ||
workvec_x = zeros(T, M + 2 * pad_x) | ||
workvec_y = zeros(T, N + 2 * pad_y) | ||
workmat2_x = Array{T}(undef, M + 2 * pad_x, N + 2 * pad_y) | ||
workmat2_y = Array{T}(undef, M + 2 * pad_x, N + 2 * pad_y) | ||
workmat1_x = Array{T}(undef, M + 2 * pad_x, N + 2 * pad_y) | ||
workmat1_y = Array{T}(undef, M + 2 * pad_x, N + 2 * pad_y) | ||
A_x = SparseInterpolator(LinearSpline(T), workvec_x, length(workvec_x)) | ||
A_y = SparseInterpolator(LinearSpline(T), workvec_y, length(workvec_y)) | ||
|
||
for θ in θ_list | ||
idim = (M,N) | ||
odim = (M,N) | ||
|
||
forw1!(y, x) = imrotate3!(y, workmat1_x, workmat2_x, x, θ) | ||
back1!(x, y) = imrotate3_adj!(x, workmat1_y, workmat2_y, y, θ) | ||
A = LinearMapAA(forw1!, back1!, (prod(odim), prod(idim)); T, odim, idim) | ||
@test Matrix(A') ≈ Matrix(A)' # 3-pass 1D version | ||
|
||
forw2!(y, x) = imrotate3!(y, workmat1_x, workmat2_x, x, θ, A_x, A_y, workvec_x, workvec_y) | ||
back2!(x, y) = imrotate3_adj!(x, workmat1_y, workmat2_y, y, θ, A_x, A_y, workvec_x, workvec_y) | ||
A = LinearMapAA(forw2!, back2!, (prod(odim), prod(idim)); T, odim, idim) | ||
@test Matrix(A') ≈ Matrix(A)' # 2D version | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d1221bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator() register
d1221bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/46166
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: