# Performance LinearOperators.jl

**URL:** <https://discourse.julialang.org/t/performance-linearoperators-jl/84271>\
**Category:** Numerics\
**Tags:** question, performance\
**Created:** [July 15, 2022, 1:43pm UTC](https://discourse.julialang.org/t/performance-linearoperators-jl/84271 "2022-07-15T13:43:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dario-Rosa85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dario-rosa85/32/32358_2.png) [@Dario-Rosa85](https://discourse.julialang.org/u/Dario-Rosa85)\
**Post date:** [July 15, 2022, 1:43pm UTC](https://discourse.julialang.org/t/performance-linearoperators-jl/84271/1 "2022-07-15T13:43:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [July 16, 2022, 11:49am UTC](https://discourse.julialang.org/t/performance-linearoperators-jl/84271/2 "2022-07-16T11:49:10Z")

</div>

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](https://julialinearalgebra.github.io/LinearMaps.jl/stable/)  
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.

---

<div class="post-metadata">

**Author:** ![Dario-Rosa85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dario-rosa85/32/32358_2.png) [@Dario-Rosa85](https://discourse.julialang.org/u/Dario-Rosa85)\
**Post date:** [July 16, 2022, 11:56am UTC](https://discourse.julialang.org/t/performance-linearoperators-jl/84271/3 "2022-07-16T11:56:49Z")

</div>

thanks a lot! very useful and clear
