# UniformScaling to identity matrix

**URL:** <https://discourse.julialang.org/t/uniformscaling-to-identity-matrix/19112>\
**Category:** General Usage\
**Tags:** proposal\
**Created:** [December 30, 2018, 9:30am UTC](https://discourse.julialang.org/t/uniformscaling-to-identity-matrix/19112 "2018-12-30T09:30:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [December 30, 2018, 9:30am UTC](https://discourse.julialang.org/t/uniformscaling-to-identity-matrix/19112/1 "2018-12-30T09:30:42Z")

</div>

Sometimes, it is necessary to convert a `UniformScaling` to an actual matrix of values. In these cases, I call some form of `Matrix(I, n, n)`.  
While this is not that bad, it can make otherwise very readable code slightly less so. However with call overloading, it is possible to emulate the old functionality of `eye` when necessary:

```julia
(I::UniformScaling)(T::DataType, n::Integer, m::Integer) = Matrix(one(T)*I, n, m)
(I::UniformScaling)(T::DataType, n::Integer) = I(T, n, n)
(I::UniformScaling)(n::Integer, m::Integer) = I(Bool, n, m)
(I::UniformScaling)(n::Integer) = I(n, n)

julia> I(3)
3×3 Array{Bool,2}:
  true false false
 false true false
 false false true

julia> I(Int8, 2)
2×2 Array{Int8,2}:
 1 0
 0 1

```

I am not aware of all of the reasons for eliminating `eye` in favor of `I` (not that I’m complaining!) but since it is inevitable to sometimes need hard values, I think this could be a convenient addition to `LinearAgebra.`

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [December 30, 2018, 9:34am UTC](https://discourse.julialang.org/t/uniformscaling-to-identity-matrix/19112/2 "2018-12-30T09:34:19Z")

</div>

Yep, this is being discussed [https://github.com/JuliaLang/julia/issues/23156](https://github.com/JuliaLang/julia/issues/23156)

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [January 1, 2019, 10:13pm UTC](https://discourse.julialang.org/t/uniformscaling-to-identity-matrix/19112/3 "2019-01-01T22:13:28Z")

</div>

Well would you look at that!  
Thanks for the link.
