Skip to content
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

Type Stability of Normal Operator #51

Open
JakobAsslaender opened this issue Jan 20, 2022 · 1 comment
Open

Type Stability of Normal Operator #51

JakobAsslaender opened this issue Jan 20, 2022 · 1 comment

Comments

@JakobAsslaender
Copy link
Member

I am wondering if we should also re-write the way we construct the normal operator depending on whether we want to use a Toeplitz Operator or not. Unfortunately, the function

function SparsityOperators.normalOperator(S::NFFTOp, W::UniformScaling=I)
if S.toeplitz
return Toeplitz_NormalOp(S,W)
else
return NormalOp(S,W)
end
end

is not type stable:

julia> @code_warntype SparsityOperators.normalOperator(F_nfft)
Variables
  #self#::Core.Const(SparsityOperators.normalOperator)
  S::NFFTOp{ComplexF64}

Body::Union{NormalOp{NFFTOp{ComplexF64}, UniformScaling{Bool}}, MRIReco.Toeplitz_NormalOp{_A, _B, UniformScaling{Bool}} where {_A, _B}}
1 ─ %1 = (#self#)(S, MRIReco.I)::Union{NormalOp{NFFTOp{ComplexF64}, UniformScaling{Bool}}, MRIReco.Toeplitz_NormalOp{_A, _B, UniformScaling{Bool}} where {_A, _B}}
└──      return %1

Any ideas on how we could do this?

@tknopp
Copy link
Member

tknopp commented Jan 20, 2022

Type instabilities are not always evil and actually it is a feature of Julia that you can mix dynamic and static code. In this particular case I don't think that it will be an issue. The question is what happens with the return type of normalOperator. If you pass it to a solver the code within the solver will be fast because there was a function barrier.

Basically a reconstruction chain on a high-level will always be dynamic, i.e. the operator types being constructed will depend on the input parameters (e.g. non equidistant sampling points -> NFFT, otherwise -> FFT). One the operators a constructed all low-level code should be fast.

The danger is if one has type-unstable structs and passes them from high to low level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants