Skip to content

Commit eb4a416

Browse files
bug fixes and help file additions
1 parent 0e296f2 commit eb4a416

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SeparableFunctions"
22
uuid = "c8c7ead4-852c-491e-a42d-3d43bc74259e"
33
authors = ["RainerHeintzmann <heintzmann@gmail.com>"]
4-
version = "0.4"
4+
version = "0.4.1"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/specific.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ end
263263

264264
## Here some individual versions based on copy_corners! stuff. They only exist in the _cor version as they are not separable in X and Y.
265265
"""
266-
propagator_col([]::Type{TA},] sz::NTuple{N, Int}; Δz=one(eltype(TA)), k_max=0.5f0, scale=0.5f0 ./ (max.(sz ./ 2, 1))) where{TA, N}
266+
propagator_col([]::Type{TA},] sz::NTuple{N, Int}; Δz=one(eltype(TA)), k_max=0.5f0, scale=0.5f0 ./ (max.(sz ./ 2, 1)), ref_idx = (length(sz) < 3) ? 1 : sz[3]÷2+1, use_sep=use_sep) where{TA, N}
267267
268268
generates a propagator for propagating optical fields via exp(i kz Δz) with kz=sqrt(k0^2-kx^2-ky^2). The k-space radius is stated by
269269
k_max relative to the Nyquist frequency, as long as the scale remains to be 1 ./ (2 max.(sz ./ 2, 1))).
@@ -279,18 +279,21 @@ Note that there is no `propagator_sep` version of this function, since this prop
279279
+ `Δz`: distance in Z to propagate per slice.
280280
+ `k_max`: maximum propagation radius in k-space. I.e. limit of the k-sphere. This is not the aperture limit!
281281
+ `scale`: specifies how to interpret k-space positions. Should remain to be 1 ./ (2 max.(sz ./ 2, 1))).
282+
+ `ref_idx`: reference index at which the propagator has no effect. E.g. `ref_idx=1` means the first slice of the result array does not propagate. By default, the (Fourier space) center position along Z is chosen.
283+
+ `use_sep`: This boolean flag switches to an algorithm using rr2_sep and no corner copies. In CUDA this is a little faster.
284+
282285
"""
283-
function propagator_col(::Type{TA}, sz::NTuple{N, Int}; Δz=one(eltype(TA)), k_max=0.5f0, scale=0.5f0 ./ (max.(sz ./ 2, 1)), ref_idx = (length(sz) < 3) ? 1 : sz[3]÷2+1) where{TA, N}
286+
function propagator_col(::Type{TA}, sz::NTuple{N, Int}; Δz=one(eltype(TA)), k_max=0.5f0, scale=0.5f0 ./ (max.(sz ./ 2, 1)), ref_idx = (length(sz) < 3) ? 1 : sz[3]÷2+1, use_sep=false) where{TA, N}
284287
# function propagator_col(::Type{TA}, sz::NTuple{N, Int}; Δz=1.0, k_max=0.5, scale=0.5 ./ (max.(sz ./ 2, 1))) where{TA, N}
285288
if length(sz) > 3
286289
error("propagators are only allowed up to the third dimension. If you need to propagate several stacks, use broadcasting.")
287290
end
288291
arr = TA(undef, sz)
289-
propagator_col!(arr; Δz=Δz, k_max=k_max, scale=scale, ref_idx = ref_idx)
292+
propagator_col!(arr; Δz=Δz, k_max=k_max, scale=scale, ref_idx = ref_idx, use_sep=use_sep)
290293
end
291294

292-
function propagator_col(sz::NTuple{N, Int}; Δz=1.0, k_max=0.5, scale=0.5 ./ (max.(sz ./ 2, 1)), ref_idx = (length(sz) < 3) ? 1 : sz[3]÷2+1) where{N}
293-
propagator_col(DefaultComplexArrType, sz; Δz=Δz, k_max=k_max, scale=scale, ref_idx = ref_idx)
295+
function propagator_col(sz::NTuple{N, Int}; Δz=1.0, k_max=0.5, scale=0.5 ./ (max.(sz ./ 2, 1)), ref_idx = (length(sz) < 3) ? 1 : sz[3]÷2+1, use_sep=false) where{N}
296+
propagator_col(DefaultComplexArrType, sz; Δz=Δz, k_max=k_max, scale=scale, ref_idx = ref_idx, use_sep=use_sep)
294297
end
295298

296299
"""
@@ -307,10 +310,10 @@ Note that there is no `propagator_sep` version of this function, since this prop
307310
# Arguments
308311
+ `arr`: the array to fill with propagators. If a 3rd dimension is present, a stack a propagators is returned, one for each multiple of Δz.
309312
+ `Δz`: distance in Z to propagate per slice in relation to the wavelength. Nyquist sampling would be 0.5.
310-
+ `ref_idx`: reference index at which the propagator has no effect. E.g. `ref_idx=1` means the first slice of the result array does not propagate. By default, the (Fourier space) center position along Z is chosen.
311313
+ `k_max`: maximum propagation radius in k-space. I.e. limit of the k-sphere in relation to sampling frequency. This is not the aperture limit!
312314
k_max = 0.5 corresponds to the Nyquist limit.
313315
+ `scale`: specifies how to interpret k-space positions. Should remain to be 1 ./ (2 max.(sz ./ 2, 1))).
316+
+ `ref_idx`: reference index at which the propagator has no effect. E.g. `ref_idx=1` means the first slice of the result array does not propagate. By default, the (Fourier space) center position along Z is chosen.
314317
+ `use_sep`: This boolean flag switches to an algorithm using rr2_sep and no corner copies. In CUDA this is a little faster.
315318
316319
# Example
@@ -459,7 +462,7 @@ julia> # Note that a 2D propagator is always propagating by one Δz, thus corres
459462
julia> p = propagator_col((100,50,30), sampling, λ)
460463
```
461464
"""
462-
function propagator_col(::Type{TA}, sz::NTuple{N, Int}, sampling::NTuple{3}, λ; ref_idx = size(arr,3)÷2+1, use_sep=false) where{TA, N}
465+
function propagator_col(::Type{TA}, sz::NTuple{N, Int}, sampling::NTuple{3}, λ; ref_idx = sz[3]÷2+1, use_sep=false) where{TA, N}
463466
if length(sz) > 3
464467
error("propagators are only allowed up to the third dimension. If you need to propagate several stacks, use broadcasting.")
465468
end

test/runtests.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,24 @@ end
149149
w = propagator_col!(rand(ComplexF32, 10,10,10), Δz = Δz)
150150
q = propagator_col!(zeros(ComplexF32, 10,10,1), Δz = Δz)
151151
q1 = propagator_col!(ones(ComplexF32, 10,10,10), Δz = Δz, ref_idx=1)
152-
q2 = propagator_col!(rand(ComplexF32, 10,10,10), Δz = Δz, ref_idx=10, use_sep=true)
152+
q2 = propagator_col((10,10,10), Δz = Δz, ref_idx=10, use_sep=true)
153153
@test q[:,:,1] == w[:,:,7]
154154
@test q[:,:,1] == q1[:,:,2]
155155
@test q[:,:,1] conj.(q2[:,:,9])
156156
w1 = propagator_col((10,10,10), Δz = Δz)
157157
@test w1 == w
158-
q1 = propagator_col((10,10,1), Δz = Δz)
159-
@test q1 == q
158+
q1 = propagator_col((10,10), Δz = Δz)
159+
@test q1[:,:,1] q
160160

161161
sampling = (0.25,0.25,0.25)
162162
λ = 0.5
163163
q2 = propagator_col((10, 10, 10), sampling, λ)
164164
tmp = rand(ComplexF32, 10,10,10)
165165
q3 = propagator_col!(tmp, sampling, λ)
166+
q4 = propagator_col((10,10,10), sampling, λ)
166167
@test w == q2
167168
@test w == q3
169+
@test q4 == q3
168170
@test w == tmp
169171
end
170172

@@ -175,14 +177,15 @@ end
175177
q1 = phase_kz_col!(ones(Float32, 10,10,10), Δz = Δz, ref_idx=1)
176178
q2 = phase_kz_col!(rand(Float32, 10,10,10), Δz = Δz, ref_idx=10, use_sep=true)
177179
@test q[:,:,1] == w[:,:,7]
178-
@test q[:,:,1] == q1[:,:,2]
180+
q = phase_kz_col!(rand(Float32, 10,10), Δz = Δz)
181+
@test q[:,:] == q1[:,:,2]
179182
@test q[:,:,1] .-(q2[:,:,9])
180183

181184
w1 = phase_kz_col((10,10,10), Δz = Δz)
182185
w = phase_kz_col!(rand(Float32, 10,10,10), Δz = Δz)
183186
@test w1 == w
184-
q1 = phase_kz_col((10,10,1), Δz = Δz)
185-
@test q1 == q
187+
q1 = phase_kz_col((10,10), Δz = Δz)
188+
@test q1 == q[:,:,1]
186189
# does phase_kz agree to propagator_col
187190

188191
sampling = (0.25,0.25,0.25)

0 commit comments

Comments
 (0)