# Help with type instabilities

**URL:** <https://discourse.julialang.org/t/help-with-type-instabilities/3897>\
**Category:** General Usage\
**Created:** [May 24, 2017, 3:21am UTC](https://discourse.julialang.org/t/help-with-type-instabilities/3897 "2017-05-24T03:21:53Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)\
**Post date:** [May 27, 2017, 1:54pm UTC](https://discourse.julialang.org/t/help-with-type-instabilities/3897/8 "2017-05-27T13:54:15Z")

</div>

Hey thanks for the reply. I had indeed looked at TensorOperations, but I do need everything in 2D matrix form. I improved the code further (with some [help](https://discourse.julialang.org/t/type-stable-difference-of-tuples/3933/6)) and managed to get the partial trace even faster:

```julia
julia> using Schrodinger, BenchmarkTools
julia> A = rand(36,36); out = (2,); sysdims = (2,9,2);
julia> @benchmark ptrace($A,$out,$sysdims)
BenchmarkTools.Trial:
  memory estimate: 480 bytes
  allocs estimate: 5
  --------------
  minimum time: 1.275 μs (0.00% GC)
  median time: 1.431 μs (0.00% GC)
  mean time: 1.520 μs (2.17% GC)
  maximum time: 181.442 μs (97.48% GC)
  --------------
  samples: 10000
  evals/sample: 10

```

The code is now available [here](https://github.com/jebej/Schrodinger.jl/blob/master/src/math/ptrace.jl) (the package itself is not fully ready for prime time) for those interested.

---

_[View the full topic](https://discourse.julialang.org/t/help-with-type-instabilities/3897)._
