# \#inference

**URL:** https://discourse.julialang.org/tag/inference/79.md?page=1

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 2

---

## [Why doesn't \`vect\` return a union-typed result if the number of elements is small?](https://discourse.julialang.org/t/why-doesnt-vect-return-a-union-typed-result-if-the-number-of-elements-is-small/87155)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 3\
**Last updated:** [September 13, 2022, 3:28pm UTC](https://discourse.julialang.org/t/why-doesnt-vect-return-a-union-typed-result-if-the-number-of-elements-is-small/87155 "2022-09-13T15:28:41Z")

</div>

Eg.: julia\> struct A end julia\> struct B end julia\> \[A(), B()\] 2-element Vector{Any}: A() B() Would it not be better to return julia\> Union{A,B}\[A(), B()\] 2-element Vector{Union{A, B}}: A() B() instead, as this…

---

## [Constructors for \`\<:Function\` types when possible, like in C++](https://discourse.julialang.org/t/constructors-for-function-types-when-possible-like-in-c/86611)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 7\
**Last updated:** [September 1, 2022, 2:13am UTC](https://discourse.julialang.org/t/constructors-for-function-types-when-possible-like-in-c/86611 "2022-09-01T02:13:32Z")

</div>

I was thinking about how C++20 added support for default constructors for stateless (with no captures) lambdas, meaning that nowadays all function object families may be default-constructible in C++. Then I realized tha…

---

## [Improve this function for merging tuples so that the return type could be accurately inferred](https://discourse.julialang.org/t/improve-this-function-for-merging-tuples-so-that-the-return-type-could-be-accurately-inferred/84893)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 1\
**Last updated:** [July 28, 2022, 6:57am UTC](https://discourse.julialang.org/t/improve-this-function-for-merging-tuples-so-that-the-return-type-could-be-accurately-inferred/84893 "2022-07-28T06:57:35Z")

</div>

I implemented the function merged\_tuples for merging tuples in given order while preserving intra-tuple order. It seems that Julia isn’t able to infer the return types accurately, however (using Test.@inferred): julia\> …

---

## [JET is unhappy with broadcast assigning a matrix to a submatrix, rooted in \`abstractarray.jl\`](https://discourse.julialang.org/t/jet-is-unhappy-with-broadcast-assigning-a-matrix-to-a-submatrix-rooted-in-abstractarray-jl/83750)

<div class="topic-metadata">

**Author:** [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Replies:** 0\
**Last updated:** [July 4, 2022, 4:34pm UTC](https://discourse.julialang.org/t/jet-is-unhappy-with-broadcast-assigning-a-matrix-to-a-submatrix-rooted-in-abstractarray-jl/83750 "2022-07-04T16:34:13Z")

</div>

This seems like a pretty innocent piece of code but JET reports a possible issue. julia\> function f1(n) # Vectors work fine m = zeros(2n) sub = zeros(n) m\[n+1:2n\] .= sub m …

---

## [Interpreting \`JET\` warnings on a simple \`Polyester\` multithreaded loop](https://discourse.julialang.org/t/interpreting-jet-warnings-on-a-simple-polyester-multithreaded-loop/83681)

<div class="topic-metadata">

**Author:** [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Replies:** 7\
**Last updated:** [July 4, 2022, 3:12am UTC](https://discourse.julialang.org/t/interpreting-jet-warnings-on-a-simple-polyester-multithreaded-loop/83681 "2022-07-04T03:12:23Z")

</div>

Polyester seems to be one of the bigger sources of TTFX in some of my libraries. It is similarly the main source of warnings when using JET. Below is a very simple multi-threaded loop that causes a large number of JET wa…

---

## [Incomplete description of type vector of pairs](https://discourse.julialang.org/t/incomplete-description-of-type-vector-of-pairs/82706)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 6\
**Last updated:** [June 15, 2022, 9:41pm UTC](https://discourse.julialang.org/t/incomplete-description-of-type-vector-of-pairs/82706 "2022-06-15T21:41:55Z")

</div>

Why does Julia not fully describe the type of the elements of the pair vector? shouldn’t it be the union of the types of the individual elements of the vector? Pair{Tuple{Char, Int64, Int64}, Float64} #and Pair{Tuple{C…

---

## [Easier use of generated\_quantities](https://discourse.julialang.org/t/easier-use-of-generated-quantities/81305)

<div class="topic-metadata">

**Author:** [@wc4wc4wc4](https://discourse.julialang.org/u/wc4wc4wc4)\
**Replies:** 0\
**Last updated:** [May 19, 2022, 10:17am UTC](https://discourse.julialang.org/t/easier-use-of-generated-quantities/81305 "2022-05-19T10:17:40Z")

</div>

Hi, I’ve had a problem where I had to deal with generated\_quantities and I’ve come up with a solution myself, but I pretty sure that it’s not the optimal way of doing it. No matter what, I think it would be a great help…

---

## [Need help on understanding type inference / performance](https://discourse.julialang.org/t/need-help-on-understanding-type-inference-performance/80600)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 13\
**Last updated:** [May 10, 2022, 9:54am UTC](https://discourse.julialang.org/t/need-help-on-understanding-type-inference-performance/80600 "2022-05-10T09:54:29Z")

</div>

Hi there, I am the author of ExtensibleEffects.jl and several people approached me that it would be great to improve performance (it is currently super slow). I made a first attempt on inspecting and found the followin…

---

## [A simple inference bug with Dates.Period?](https://discourse.julialang.org/t/a-simple-inference-bug-with-dates-period/79966)

<div class="topic-metadata">

**Author:** [@braydenware](https://discourse.julialang.org/u/braydenware)\
**Replies:** 2\
**Last updated:** [April 25, 2022, 3:36am UTC](https://discourse.julialang.org/t/a-simple-inference-bug-with-dates-period/79966 "2022-04-25T03:36:02Z")

</div>

In some simple arithmetic subtracting types with Dates.CompoundPeriod, a bug arises when you try to subtract a Dates.CompoundPeriod that is equal to 0. However, it does not seem to be a problem with the Dates code but ra…

---

## [ANN: SimulatedNeuralMoments](https://discourse.julialang.org/t/ann-simulatedneuralmoments/52032)

<div class="topic-metadata">

**Author:** [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Replies:** 3\
**Last updated:** [April 2, 2022, 7:02am UTC](https://discourse.julialang.org/t/ann-simulatedneuralmoments/52032 "2022-04-02T07:02:55Z")

</div>

I’m happy to announce that the package SimulatedNeuralMoments is available in the general registry. This is a package for inference methods that can be thought of as approximate Bayesian computing (ABC), with a particula…

---

## [Why isn't \`size\` always inferred to be an Integer?](https://discourse.julialang.org/t/why-isnt-size-always-inferred-to-be-an-integer/75139)

<div class="topic-metadata">

**Author:** [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Replies:** 24\
**Last updated:** [January 24, 2022, 11:57pm UTC](https://discourse.julialang.org/t/why-isnt-size-always-inferred-to-be-an-integer/75139 "2022-01-24T23:57:09Z")

</div>

I have also spent an endless number of hours in SnooptCompile to achieve improvements of 1-2 seconds in compile time. One thing that I really can’t understand is why taking the size or length of a var that is Any returns…

---

## [Why is Julia not inferring the output type of f(x,y)=x+y?](https://discourse.julialang.org/t/why-is-julia-not-inferring-the-output-type-of-f-x-y-x-y/73634)

<div class="topic-metadata">

**Author:** [@vedantroy](https://discourse.julialang.org/u/vedantroy)\
**Replies:** 11\
**Last updated:** [December 26, 2021, 6:27am UTC](https://discourse.julialang.org/t/why-is-julia-not-inferring-the-output-type-of-f-x-y-x-y/73634 "2021-12-26T06:27:55Z")

</div>

I’m playing around with type inference in Julia. I have the following simple function: f(x,y) = x+y function q2() x = Number\[1.0,3\] a = 4 b = 2 c = f(x\[1\],a) d = f(b,c) f(d,x\[2\]) end @code\_warntype q2() He…

---

## [How to debug internal runtime error?](https://discourse.julialang.org/t/how-to-debug-internal-runtime-error/73511)

<div class="topic-metadata">

**Author:** [@grahamas](https://discourse.julialang.org/u/grahamas)\
**Replies:** 4\
**Last updated:** [December 23, 2021, 7:11am UTC](https://discourse.julialang.org/t/how-to-debug-internal-runtime-error/73511 "2021-12-23T07:11:02Z")

</div>

Can anyone point me to how to find the source of a runtime error? Meaning, is there some tool I can use to interrogate this, like I would with @code\_typed or a debugger, if it weren’t a runtime error? I’m struggling to …

---

## [Inference problem with findall](https://discourse.julialang.org/t/inference-problem-with-findall/73262)

<div class="topic-metadata">

**Author:** [@etienne\_dg](https://discourse.julialang.org/u/etienne_dg)\
**Replies:** 5\
**Last updated:** [December 17, 2021, 2:38pm UTC](https://discourse.julialang.org/t/inference-problem-with-findall/73262 "2021-12-17T14:38:06Z")

</div>

Hi, the following code is not correctly inferred in julia 1.7.0. function test() k = 1 if k == 1 k = 2 end return findall(x -\> x \>= k, \[1\]) end julia\> @code\_warntype(test()) MethodInstance for t…

---

## [Why is the type of factors not being inferred while multiplying an AbstractQ with a vector?](https://discourse.julialang.org/t/why-is-the-type-of-factors-not-being-inferred-while-multiplying-an-abstractq-with-a-vector/68981)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 3\
**Last updated:** [September 30, 2021, 11:39am UTC](https://discourse.julialang.org/t/why-is-the-type-of-factors-not-being-inferred-while-multiplying-an-abstractq-with-a-vector/68981 "2021-09-30T11:39:00Z")

</div>

julia\> using LinearAlgebra julia\> Q = qr(rand(30,30)); julia\> Q2 = Q.Q; julia\> @code\_warntype Q2 \* rand(size(Q2,2)) MethodInstance for \*(::LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}}, ::Vector{Float64}) fro…

---

## [Trying to understand the return type of an array comprehension if the function being called returns a Union](https://discourse.julialang.org/t/trying-to-understand-the-return-type-of-an-array-comprehension-if-the-function-being-called-returns-a-union/63424)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 1\
**Last updated:** [June 23, 2021, 9:02am UTC](https://discourse.julialang.org/t/trying-to-understand-the-return-type-of-an-array-comprehension-if-the-function-being-called-returns-a-union/63424 "2021-06-23T09:02:43Z")

</div>

On nightly: julia\> f(x) = x \> 3 ? x : nothing f (generic function with 1 method) julia\> g(imax) = \[f(i) for i in 1:imax\] g (generic function with 1 method) julia\> @code\_warntype g(5) MethodInstance for g(::Int64) fr…

---

## [\[ANN\] JET.jl: the next generation of code checker for Julia](https://discourse.julialang.org/t/ann-jet-jl-the-next-generation-of-code-checker-for-julia/58913)

<div class="topic-metadata">

**Author:** [@aviatesk](https://discourse.julialang.org/u/aviatesk)\
**Replies:** 11\
**Last updated:** [April 21, 2021, 2:31pm UTC](https://discourse.julialang.org/t/ann-jet-jl-the-next-generation-of-code-checker-for-julia/58913 "2021-04-21T14:31:34Z")

</div>

Julia’s extreme expressiveness and composability come from its dynamism — at the cost of that, a static type-level analysis of Julia code has been remained as a longstanding problem. JET.jl is a fresh approach to static…

---

## [Inference on field types?](https://discourse.julialang.org/t/inference-on-field-types/53448)

<div class="topic-metadata">

**Author:** [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Replies:** 10\
**Last updated:** [January 18, 2021, 12:47am UTC](https://discourse.julialang.org/t/inference-on-field-types/53448 "2021-01-18T00:47:38Z")

</div>

I often have to “categorise” a vector of struct elements by a specific field and I wanted to get rid of some duplicated logic and generalise the categorisation, however I hit the penalty of runtime (dynamic) lookup of th…

---

## [How to debug inlining fails?](https://discourse.julialang.org/t/how-to-debug-inlining-fails/50658)

<div class="topic-metadata">

**Author:** [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Replies:** 1\
**Last updated:** [November 24, 2020, 6:11pm UTC](https://discourse.julialang.org/t/how-to-debug-inlining-fails/50658 "2020-11-24T18:11:23Z")

</div>

I have a trait based system in LazyArrays.jl that isn’t inlining, which seems to be breaking type inference. Are there any tips for debugging why this is? Sorry for the non-MWE but the code is below. For some reason @i…

---

## [Type inference for nested iterators](https://discourse.julialang.org/t/type-inference-for-nested-iterators/47082)

<div class="topic-metadata">

**Author:** [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Replies:** 16\
**Last updated:** [September 25, 2020, 9:16pm UTC](https://discourse.julialang.org/t/type-inference-for-nested-iterators/47082 "2020-09-25T21:16:36Z")

</div>

In this thread, I wrote this function: using Base.Iterators function foo(itr, n, fillvalue) ntake = ceil(Int, length(itr)/n) extended\_itr = flatten( ( itr, repeated(fillvalue) ) ) take(partition(extended\_it…

---

## [Possible bug in type inference? (4 line MWE)](https://discourse.julialang.org/t/possible-bug-in-type-inference-4-line-mwe/46353)

<div class="topic-metadata">

**Author:** [@tomohiro\_soejima](https://discourse.julialang.org/u/tomohiro_soejima)\
**Replies:** 9\
**Last updated:** [September 10, 2020, 3:17am UTC](https://discourse.julialang.org/t/possible-bug-in-type-inference-4-line-mwe/46353 "2020-09-10T03:17:11Z")

</div>

Hello! I came across a weird type inference failure when using generators. Here is a MWE. function example() col = 2 ss = (col for \_ in 1:5) col += 3 return col, ss end function example2() col = 2 …

---

## [Type instability for singleton tuple argument](https://discourse.julialang.org/t/type-instability-for-singleton-tuple-argument/46147)

<div class="topic-metadata">

**Author:** [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Replies:** 5\
**Last updated:** [September 6, 2020, 4:09pm UTC](https://discourse.julialang.org/t/type-instability-for-singleton-tuple-argument/46147 "2020-09-06T16:09:47Z")

</div>

why do I get type instability for the function (x-\>x.^2).((1,))? if my input argument is a singleton tuple, then @code\_warntype (x-\>x.^2).((1,)) gives │ %4 = Base.materialize(%3)::Tuple{Any} └── return %4 If the…

---

## [Profiling compilation/inference](https://discourse.julialang.org/t/profiling-compilation-inference/44496)

<div class="topic-metadata">

**Author:** [@mhauru](https://discourse.julialang.org/u/mhauru)\
**Replies:** 10\
**Last updated:** [August 24, 2020, 10:07pm UTC](https://discourse.julialang.org/t/profiling-compilation-inference/44496 "2020-08-24T22:07:29Z")

</div>

I have a package for which running the test script results in around 20 minutes of compilation. Presumably somewhere in my package there’s something that’s giving inference a very hard time. I’ve done some work trying to…

---

## [Why doesn't the compiler infer the type of this function?](https://discourse.julialang.org/t/why-doesnt-the-compiler-infer-the-type-of-this-function/35005)

<div class="topic-metadata">

**Author:** [@benninkrs](https://discourse.julialang.org/u/benninkrs)\
**Replies:** 6\
**Last updated:** [February 25, 2020, 3:23am UTC](https://discourse.julialang.org/t/why-doesnt-the-compiler-infer-the-type-of-this-function/35005 "2020-02-25T03:23:52Z")

</div>

On Julia v1.2.0: fib1(n::Int64) = n\<=1 ? (1,) : (n, fib1(n-1)...) run1() = fib1(5) fib2(::Type{Val{n}}) where {n} = n\<=1 ? (1,) : (n, fib2(Val{n-1})...) run2() = fib2(Val{5}) julia\> @code\_warntype run1() Variables #…

---

## [Thoughts around ways of ensuring compile time evaluation / const prop / inference?](https://discourse.julialang.org/t/thoughts-around-ways-of-ensuring-compile-time-evaluation-const-prop-inference/28904)

<div class="topic-metadata">

**Author:** [@jackf](https://discourse.julialang.org/u/jackf)\
**Replies:** 17\
**Last updated:** [November 10, 2019, 12:06pm UTC](https://discourse.julialang.org/t/thoughts-around-ways-of-ensuring-compile-time-evaluation-const-prop-inference/28904 "2019-11-10T12:06:36Z")

</div>

When writing julia code, I find a lot of my time is spent on a common themes: trying to ensure some piece of code is either constant propagating or inferring as I intend / expect. I find this stuff quite difficult to sys…

---

## [Understanding do notation, type-stability for function with other functions as arguments](https://discourse.julialang.org/t/understanding-do-notation-type-stability-for-function-with-other-functions-as-arguments/7640)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 5\
**Last updated:** [July 8, 2019, 5:11am UTC](https://discourse.julialang.org/t/understanding-do-notation-type-stability-for-function-with-other-functions-as-arguments/7640 "2019-07-08T05:11:49Z")

</div>

If I do function apply\_fn2a(fns::Tuple,a) Tuple(fn(a) for fn in fns) end using StatsBase const x = rand(1:5,1000) @code\_warntype apply\_fn2a((countmap, sum, mean), x) then the output type is simply a generic Tuple.…

---

## [Type inference of tables /w missing cells](https://discourse.julialang.org/t/type-inference-of-tables-w-missing-cells/20769)

<div class="topic-metadata">

**Author:** [@cce](https://discourse.julialang.org/u/cce)\
**Replies:** 4\
**Last updated:** [February 17, 2019, 2:32pm UTC](https://discourse.julialang.org/t/type-inference-of-tables-w-missing-cells/20769 "2019-02-17T14:32:42Z")

</div>

This is a feature suggestion. I’m modeling database tables as a Vector of NamedTuple. I’m wondering if Julia could more smartly infer the type of these structures when values are missing. For starters, I note that Julia…

---

## [Getter function of \`Ref\` field not inferred](https://discourse.julialang.org/t/getter-function-of-ref-field-not-inferred/19962)

<div class="topic-metadata">

**Author:** [@cnliao](https://discourse.julialang.org/u/cnliao)\
**Replies:** 5\
**Last updated:** [January 24, 2019, 9:18pm UTC](https://discourse.julialang.org/t/getter-function-of-ref-field-not-inferred/19962 "2019-01-24T21:18:24Z")

</div>

Using Ref{T} to get a mutable field in an otherwise immutable struct is causing inference problems (Julia v1.03/v1.1.0), MWE: using Test struct A i::Ref{Int} end get\_i(x) = x.i\[\] @inferred get\_i(A(2)) # ERROR: retur…

---

## [Help resolving Dict access type inference](https://discourse.julialang.org/t/help-resolving-dict-access-type-inference/19452)

<div class="topic-metadata">

**Author:** [@jackf](https://discourse.julialang.org/u/jackf)\
**Replies:** 9\
**Last updated:** [January 10, 2019, 4:41am UTC](https://discourse.julialang.org/t/help-resolving-dict-access-type-inference/19452 "2019-01-10T04:41:26Z")

</div>

I have some code that starts with a loosely type Dict (e.g. something returned from a web service). I want to write a function that will extract a certain key from it, convert that key into a concretely-typed array (Arra…

---

## [Argument types not inferred when constrained in function signature](https://discourse.julialang.org/t/argument-types-not-inferred-when-constrained-in-function-signature/19020)

<div class="topic-metadata">

**Author:** [@cnliao](https://discourse.julialang.org/u/cnliao)\
**Replies:** 5\
**Last updated:** [December 28, 2018, 4:02pm UTC](https://discourse.julialang.org/t/argument-types-not-inferred-when-constrained-in-function-signature/19020 "2018-12-28T16:02:40Z")

</div>

It is a curious case when I tried to see how julia handles type constraints: julia\> f(a::A, b::B) where{B\<:Tuple{C}} where {A,C\<:A} = (A, B, C) f (generic function with 1 method) julia\> @code\_warntype f(1, (2,)) Body::…

[Previous page](https://discourse.julialang.org/tag/inference/79.md?match_all_tags=true&tags%5B%5D=inference)

[Next page](https://discourse.julialang.org/tag/inference/79.md?match_all_tags=true&page=2&tags%5B%5D=inference)
