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 issue with kron #185

Closed
JeffFessler opened this issue Jun 22, 2022 · 2 comments
Closed

Type issue with kron #185

JeffFessler opened this issue Jun 22, 2022 · 2 comments

Comments

@JeffFessler
Copy link
Member

It seems that kron may not be inheriting the eltype of component linear maps:

using FFTW: fft
using LinearMaps
M,N = 64, 32 # image size
T = ComplexF64
Ax = LinearMap(T, x -> fft(x), M, M)
Ay = LinearMap(T, x -> fft(x), N, N)
Ak = kron(Ay, Ax) # has wrong eltype (non-complex)
Ak * rand(T, M*N) # fails with MethodError, perhaps due to type issue?

I was working on a suggestion for #183 when I hit this issue.

@dkarrasch
Copy link
Member

dkarrasch commented Jun 22, 2022

The eltype parameter needs to be in curly brackets, otherwise it will interpret T as the "forward" map, and fft as the adjoint. 😄 When no eltype is given, the default Float64 is picked.

using FFTW: fft
using LinearMaps
M,N = 64, 32 # image size
T = ComplexF64
Ax = LinearMap{T}(fft, M, M)
Ay = LinearMap{T}(fft, N, N)
Ak = kron(Ay, Ax) # has wrong eltype (non-complex)
Ak * rand(T, M*N) # fails with MethodError, perhaps due to type issue?

@JeffFessler
Copy link
Member Author

Oh gosh, I am so used to seeing T as the first (optional) type argument in the Julia ecosystem, e.g., ones(T, ...) and rand(T, ...), that I forgot the {T} syntax for LM. Doh!

But I am surprised that A = LinearMap(Float64, cumsum, 8, 8) even works and returns a FunctionMap. I'm proposing #186 so that next time anyone makes this mistake they will get an error at construct time, instead of a useless FunctionMap.

I realize that a type actually is a kind of function, cf, Float32(3), even though Float32 isa Function is false. Hard to imagine a use case for a type as the function in a FunctionMap though...

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