JuliaLinearAlgebra / LinearMaps.jl

A Julia package for defining and working with linear maps, also known as linear transformations or linear operators acting on vectors. The only requirement for a LinearMap is that it can act on a vector (by multiplication) efficiently.
Other
303 stars 42 forks source link

Suggestions for debugging a version-dependent DimensionMismatch("") #189

Closed ezaron closed 2 years ago

ezaron commented 2 years ago

Greetings LinearMaps.jl Enthusiasts:

I have a piece of code which uses LinearMaps v3.3.0 inside Julia version 1.6.1. This version of the code works without error.

When I run this identical code on another machine using LinearMaps v3.8.0 inside Julia version 1.7.2, I receive an error:

ERROR: LoadError: DimensionMismatch("")
Stacktrace:
 [1] *(A::LinearMaps.FunctionMap{Float64, var"#Fb1t#277"{Dict{Symbol, Any}, Vector{Any}}, Nothing}, x::Vector{Float64})
   @ LinearMaps ~/.julia/packages/LinearMaps/BT89E/src/functionmap.jl:46

The line in question in functionmap.jl is doing a very simple check of dimensions of the linear operator compared to the input vector. My caller is just attempting to compute A*x. The operator A is based a simple function call that operates on a vector of Float64; it is instantiated with a simple call, e.g., Gb1t = LinearMap(Fb1t,length(D1[:id1])), where Fb1t is the function.

This use case is so simple, I wonder if there was some fundamental change to LinearMaps from v3.3.0 to v.3.8.0. Maybe you have seen something like this before?

Using Infiltrator I have been able to verify that the sizes of the A and x objects are correct before the call to A*x in both the working and non-working cases. I have not studied the functionmap.jl code extensively, but I wonder if some kind of type aliasing may occur prior to the test at line 46 which somehow alters the apparent dimensions, or something like that.

-Ed

ezaron commented 2 years ago

Aha -- In the new version of the LinearMaps.jl package, it is necessary to instantiate the linear map with both dimensions of the operator, e.g., Gb1t = LinearMap(Fb1t,M,N) for the non-square case.

dkarrasch commented 2 years ago

Strange. I think it always used to be like that. So, Fb1t is a Matrix? I see usage of length, where perhaps size would be more appropriate?

ezaron commented 2 years ago

-thx, Daniel. For some reason the old code worked when I merely specified the size of the input vector. The new code works if I explicitly pass the sizes of the domain and range when I instantiate the LinearMap. Fb1t is a function.