# Computing Inverse of a stack of matrices

**URL:** https://discourse.julialang.org/t/computing-inverse-of-a-stack-of-matrices/45580
**Category:** General Usage
**Tags:** performance, linearalgebra
**Created:** [August 26, 2020, 4:23pm UTC](https://discourse.julialang.org/t/computing-inverse-of-a-stack-of-matrices/45580 "2020-08-26T16:23:17Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)
#### Post date: [August 26, 2020, 5:00pm UTC](https://discourse.julialang.org/t/computing-inverse-of-a-stack-of-matrices/45580/5 "2020-08-26T17:00:47Z")

</div>

> [@stevengj](#):
>
> (I’m still surprised that it is reporting 4002 allocations, however; not sure why it requires a heap allocation for each element.)

Because `SMatrix{3,3,Float64}` is an abstract type.

```julia
julia> SMatrix{3,3,Float64}
SArray{Tuple{3,3},Float64,2,L} where L

julia> A = rand(SMatrix{3,3,Float64}, 1000,4);

julia> @btime inv.($A);
  161.200 μs (4002 allocations: 593.83 KiB)

julia> A = rand(SMatrix{3,3,Float64,9}, 1000,4);

julia> @btime inv.($A);
  48.200 μs (2 allocations: 281.33 KiB)

```

---

_[View the full topic](https://discourse.julialang.org/t/computing-inverse-of-a-stack-of-matrices/45580)._
