I am running into an error while trying to create a LinearMap where if I put the same function in both the forward and transpose operator arguments, the forward map works but the transpose does not. My eventual goal is to create a LinearMap that does convolution (and the transpose does convolution with a flipped version of the filter), but I’ve simplified the example code to be a little simpler while still getting the error.
Here’s my MWE:
using LinearMaps
using ImageFiltering
N = 10
x = randn(N)
Ck = LinearMap(x -> similar(x,map(n->0:n-1,size(x))),
x -> similar(x,map(n->0:n-1,size(x))), N, N)
# if I change the code to map(n->1:n,size(x)), then both lines below work fine
Ck*x # this line works fine
Ck' * x # this line gives the error below
# note: I also get the error if doing Ck' * (Ck*x)
The error is:
BoundsError: attempt to access 10-element Array{Float64,1} at index [Base.IdentityUnitRange(0:9)]
throw_boundserror(::Array{Float64,1}, ::Tuple{Base.IdentityUnitRange{UnitRange{Int64}}}) at abstractarray.jl:538
checkbounds at abstractarray.jl:503 [inlined]
copyto!(::Array{Float64,1}, ::OffsetArrays.OffsetArray{Float64,1,Array{Float64,1}}) at multidimensional.jl:902
At_mul_B!(::Array{Float64,1}, ::LinearMaps.FunctionMap{Float64,getfield(Main, Symbol(“##351#355”)),getfield(Main, Symbol(“##353#357”))}, ::Array{Float64,1}) at functionmap.jl:65
A_mul_B! at transpose.jl:33 [inlined]
mul!(::Array{Float64,1}, ::LinearMaps.TransposeMap{Float64,LinearMaps.FunctionMap{Float64,getfield(Main, Symbol(“##351#355”)),getfield(Main, Symbol(“##353#357”))}}, ::Array{Float64,1}, ::Float64, ::Float64) at LinearMaps.jl:26
mul!(::Array{Float64,1}, ::LinearMaps.TransposeMap{Float64,LinearMaps.FunctionMap{Float64,getfield(Main, Symbol(“##351#355”)),getfield(Main, Symbol(“##353#357”))}}, ::Array{Float64,1}) at LinearMaps.jl:24
*(::LinearMaps.TransposeMap{Float64,LinearMaps.FunctionMap{Float64,getfield(Main, Symbol(“##351#355”)),getfield(Main, Symbol(“##353#357”))}}, ::Array{Float64,1}) at LinearMaps.jl:22
top-level scope at bilevel_1d.jl:55
Any ideas on what is going on or even how to start debugging this would be much appreciated!