# Matrix exponential slower in Julia 0.7 / 1.0?

**URL:** <https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762>\
**Category:** Performance\
**Created:** [September 10, 2018, 12:16pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762 "2018-09-10T12:16:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [September 10, 2018, 12:16pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762/1 "2018-09-10T12:16:47Z")

</div>

In Julia 0.6.4:

```julia
julia> @btime expm([1 0; 2 0])
  3.601 μs (46 allocations: 4.55 KiB)

```

In Julia 0.7 and 1.0:

```julia
julia> @btime exp([1 0; 2 0])
  16.710 μs (67 allocations: 4.55 KiB)

```

Any idea what’s causing this? Perhaps the implementation changed as part of the rename?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [September 10, 2018, 12:36pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762/2 "2018-09-10T12:36:53Z")

</div>

I could reproduce.

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [September 10, 2018, 1:42pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762/3 "2018-09-10T13:42:06Z")

</div>

Thanks. I filed a [github issue](https://github.com/JuliaLang/julia/issues/29113).

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [September 10, 2018, 2:42pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762/4 "2018-09-10T14:42:42Z")

</div>

By the way, if tiny matrix exponentials are actually your target use case, then StaticArrays are 40X faster than even the 0.6 version:

```julia
julia> using StaticArrays

julia> m = @SMatrix [1 0; 2 0]
2×2 SArray{Tuple{2,2},Int64,2,4}:
 1 0
 2 0

julia> using BenchmarkTools

julia> @btime exp($m)
  87.196 ns (0 allocations: 0 bytes)
2×2 SArray{Tuple{2,2},Float64,2,4}:
 2.71828 0.0
 3.43656 1.0

```

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [September 10, 2018, 2:55pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762/5 "2018-09-10T14:55:05Z")

</div>

Thanks. That’s very interesting.

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [September 12, 2018, 3:04pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762/6 "2018-09-12T15:04:15Z")

</div>

And thanks to @kristoffer.carlsson for the quick resolution of the github issue!

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 12, 2018, 8:13pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762/7 "2018-09-12T20:13:45Z")

</div>

Can someone explain this, by the way?

```julia
julia> m = @SMatrix [1 0; 2 0];

julia> @btime exp($m);
  93.038 ns (0 allocations: 0 bytes)

julia> @btime exp(@SMatrix [1 0; 2 0]);
  60.237 ns (0 allocations: 0 bytes)

```

This seems backwards to me.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 12, 2018, 8:18pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762/8 "2018-09-12T20:18:25Z")

</div>

It is not backwards. It is the difference between

```julia
f(m) = exp(m)

```

and

```julia
f() = exp(@SMatrix [1 0; 2 0]);

```

In the second, the matrix is a known constant and the function can be further optimized.
