# Static array Julia for Optim.jl

**URL:** <https://discourse.julialang.org/t/static-array-julia-for-optim-jl/44711>\
**Category:** Numerics\
**Created:** [August 10, 2020, 9:45pm UTC](https://discourse.julialang.org/t/static-array-julia-for-optim-jl/44711 "2020-08-10T21:45:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [August 10, 2020, 9:45pm UTC](https://discourse.julialang.org/t/static-array-julia-for-optim-jl/44711/1 "2020-08-10T21:45:30Z")

</div>

Hello,

I am using Optim.jl for the nonlinear optimization of a set of coefficients (dim \<30). Can I expect some speed-up if I use StaticArrays to compute the gradients, store the coefficients?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 10, 2020, 10:06pm UTC](https://discourse.julialang.org/t/static-array-julia-for-optim-jl/44711/2 "2020-08-10T22:06:44Z")

</div>

How expensive is your objective function?

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [August 10, 2020, 10:21pm UTC](https://discourse.julialang.org/t/static-array-julia-for-optim-jl/44711/3 "2020-08-10T22:21:23Z")

</div>

The objective function is pretty expensive because it involves the integration of a vector valued function \mathbb{R} \xrightarrow{} \mathbb{R}^{10000} (I am using quadGK with `reltol = 1e-3` to get some speed-up). For 30 coefficients, getting the cost and its gradient takes 2ms.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 11, 2020, 1:07am UTC](https://discourse.julialang.org/t/static-array-julia-for-optim-jl/44711/4 "2020-08-11T01:07:02Z")

</div>

> [@mleprovost](#):
>
> The objective function is pretty expensive

In that case, the vector type that you pass to Optim, or any of the calculations in Optim, will be irrelevant to performance.
