I have a question on the use of the package LinearOperators.jl. I am writing a code where the performance speed is crucial. The code is based on computing many-times the action of a linear operator over a given vector. Now, I have implemented and optimized ``by hand’’ the action of this linear operator over a random vector by coding a suitable function which does the job quite well. I would like to understand if I should expect a further speedup by wrapping the code into a LinearOperator object, as provided by the package LinearOperators.jl, or not.
More generally, I would like to understand what are the benefits in using the package: is it for improving the performance? or just to better organize the code?
Internally, the package will call your function, so, it cannot add magic speedup to that.
If your vectors are small, you might want to use StaticArrays, if your vectors are large, you should probably pre-allocate the result and make sure your function works also in-place.
So, in principle it is just better organization of your code. However, if the new type gives you access
to useful helpers, that could then lead to speedup. The LinearOperators.jl
package is focused a bit on applications optimisation, e.g. you have special types such as LBFGSOperator
.
There is also a similar package which has a bit closer links to iterative solvers, maybe that is better suited for your case: Home · LinearMaps.jl
Here you can see how creating a LinearMap type allows you to insert your linear map into iterative
solvers and that can be very useful to test your own method or to directly use faster solvers for your problem without having to implement them.
thanks a lot! very useful and clear
1 Like