# Type inference of array slices in 0.6

**URL:** <https://discourse.julialang.org/t/type-inference-of-array-slices-in-0-6/4934>\
**Category:** General Usage\
**Created:** [July 18, 2017, 6:07pm UTC](https://discourse.julialang.org/t/type-inference-of-array-slices-in-0-6/4934 "2017-07-18T18:07:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksmcreynolds](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ksmcreynolds/32/860_2.png) [@ksmcreynolds](https://discourse.julialang.org/u/ksmcreynolds)\
**Post date:** [July 18, 2017, 6:07pm UTC](https://discourse.julialang.org/t/type-inference-of-array-slices-in-0-6/4934/1 "2017-07-18T18:07:01Z")

</div>

I came across this strange behavior in 0.6 where the type of an array slice isn’t inferred when it is assigned in a function. Consider this MWE.

```julia
test(A::Array{Float64, 2}, i::Int64) = A[i,:]
test2(A::Array{Float64, 2}, i::Int64) = Ai = A[i,:]
A = reshape(1:16, 4, 4)

```

When I run `@code_warntype test(A, 2)` I get (with the `Body` section omitted)

```julia
Variables:
  #self#::#test
  A::Array{Float64,2}
  i::Int64

Body:
...
end::Array{Float64,1}

```

The types of the inputs and output are correctly inferred.

However, when I run `@code_warntype test2(A, 2)` I get

```julia
Variables:
  #self#::#test2
  A::Array{Float64,2}
  i::Int64
  Ai::Any

Body:
...
end::Array{Float64,1}

```

The types of the inputs and output are still correctly inferred, but the temporary variable `Ai` is type `Any` even though it is the same as the output. In 0.5 `Ai` is inferred correctly as `Ai::Array{Float64,1}`. Does anyone know what causes this behavior?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 18, 2017, 6:46pm UTC](https://discourse.julialang.org/t/type-inference-of-array-slices-in-0-6/4934/2 "2017-07-18T18:46:46Z")

</div>

I believe this is because `Ai` is eliminated by the type type inference runs on the code. Is there an actual performance issue here or were you just alarmed by the `@code_warntype` output?

---

<div class="post-metadata">

**Author:** ![ksmcreynolds](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ksmcreynolds/32/860_2.png) [@ksmcreynolds](https://discourse.julialang.org/u/ksmcreynolds)\
**Post date:** [July 18, 2017, 8:29pm UTC](https://discourse.julialang.org/t/type-inference-of-array-slices-in-0-6/4934/3 "2017-07-18T20:29:37Z")

</div>

It doesn’t appear that there is a performance issue. I was just surprised when I ran `@code_warntype` on one of my functions and all the array slices (actually views in my case) were typed as `Any` as well as every array calculated from them. I guess since the output type is correct I shouldn’t worry about it.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 18, 2017, 9:32pm UTC](https://discourse.julialang.org/t/type-inference-of-array-slices-in-0-6/4934/4 "2017-07-18T21:32:50Z")

</div>

Yes, it would be nice to not list this alarming type in the future, but for now this is a bit of a known wart when one displays the results of type inference for a variable that ends up being eliminated entirely.

---

<div class="post-metadata">

**Author:** ![ksmcreynolds](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ksmcreynolds/32/860_2.png) [@ksmcreynolds](https://discourse.julialang.org/u/ksmcreynolds)\
**Post date:** [July 19, 2017, 12:53pm UTC](https://discourse.julialang.org/t/type-inference-of-array-slices-in-0-6/4934/5 "2017-07-19T12:53:25Z")

</div>

Ok thanks for the clarification!
