# Why does eigvals(::Number) return a vector?

**URL:** <https://discourse.julialang.org/t/why-does-eigvals-number-return-a-vector/11731>\
**Category:** Internals & Design\
**Created:** [June 17, 2018, 8:51am UTC](https://discourse.julialang.org/t/why-does-eigvals-number-return-a-vector/11731 "2018-06-17T08:51:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [June 17, 2018, 8:51am UTC](https://discourse.julialang.org/t/why-does-eigvals-number-return-a-vector/11731/1 "2018-06-17T08:51:22Z")

</div>

Is there a reason why `eigvals` returns a vector of length 1 instead of a scalar when given a scalar input? For example: `typeof(eigvals(1.0)) == Array{Float64,1}`.

It seems a bit inconsistent compared to `svdvals` which returns a scalar. For example: `typeof(svdvals(1.0)) == Float64`.

I personally like the behavior of `svdvals` much better, as it avoids allocating arrays unnecessarily, and allows for ending recursion based on the return type, rather than checking the size. It also aligns with the general Julia behavior of returning the most efficient type that can be cleanly inferred from the input type(s).

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasnoack/32/27_2.png) [@andreasnoack](https://discourse.julialang.org/u/andreasnoack)\
**Post date:** [June 17, 2018, 4:52pm UTC](https://discourse.julialang.org/t/why-does-eigvals-number-return-a-vector/11731/2 "2018-06-17T16:52:05Z")

</div>

I don’t know why that is the case. Most likely, it is not intentional. I agree that it should just be a `Number` similarly to what `svdvals` does.

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [June 18, 2018, 8:36am UTC](https://discourse.julialang.org/t/why-does-eigvals-number-return-a-vector/11731/3 "2018-06-18T08:36:32Z")

</div>

Looking at the code, it seems somebody explicitly put brackets around the return value to create a vector.  
[https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/eigen.jl#L215](https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/eigen.jl#L215)

Maybe there’s a historical reason. Currently, Julia allows for superfluous indexes, as long as those indexes are equal to one. For example: `1.0[1] == 1.0`. (Hence, if the return type of `eigvals(::Number)` were to be changed form vector to scalar, most existing would continue to work.) But I don’t know if this was always the case.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [June 18, 2018, 10:04am UTC](https://discourse.julialang.org/t/why-does-eigvals-number-return-a-vector/11731/4 "2018-06-18T10:04:16Z")

</div>

> [@Per](#):
>
> Maybe there’s a historical reason. Currently, Julia allows for superfluous indexes, as long as those indexes are equal to one. For example: `1.0[1] == 1.0` . (Hence, if the return type of `eigvals(::Number)` were to be changed form vector to scalar, most existing would continue to work.) But I don’t know if this was always the case.

The history happened here:

> <https://github.com/JuliaLang/julia/commit/6fb7fbde1225f74e0a5e3832b29b40e4b7101899>
>
> improve type-related properties of that code

At that point both `eigvals` and `svdvals` were changed to return a vector for scalar input. Whatever reasoning reverted this for `svdvals` should probably apply to `eigvals` as well.

---

<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:** [June 19, 2018, 3:25pm UTC](https://discourse.julialang.org/t/why-does-eigvals-number-return-a-vector/11731/5 "2018-06-19T15:25:44Z")

</div>

Would you mind opening an issue about this?

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [June 20, 2018, 12:34pm UTC](https://discourse.julialang.org/t/why-does-eigvals-number-return-a-vector/11731/6 "2018-06-20T12:34:07Z")

</div>

[https://github.com/JuliaLang/julia/issues/27687](https://github.com/JuliaLang/julia/issues/27687)
