# Why \`eye\` has been deprecated?

**URL:** https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824
**Category:** Internals & Design
**Created:** [August 2, 2018, 2:12pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824 "2018-08-02T14:12:13Z")
**Posts on this page:** 12
**Page:** 5

<div class="post-metadata">

### Author: ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)
#### Post date: [August 10, 2018, 9:23pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/113 "2018-08-10T21:23:31Z")

</div>

> [@gabrielgellner](#):
>
> I really dislike making my own private Julia idioms

Just make your own definition and use it for code development, the find and replace with the standard idiom.

(Or wait for 1.1… with the current release cycle rate it’s already 1 day late 😛)

---

<div class="post-metadata">

### Author: ![tbenst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbenst/32/3029_2.png) [@tbenst](https://discourse.julialang.org/u/tbenst)
#### Post date: [November 2, 2018, 7:32pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/114 "2018-11-02T19:32:36Z")

</div>

I found myself needing `eye` in order to contruct a matrix that had identity as a component (as you cannot do A[rows,cols] = I, is this a bug?). As an easy workaround, try: `one(zeros(n,n))` which is the same as `eye(n)`

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [November 2, 2018, 7:40pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/115 "2018-11-02T19:40:51Z")

</div>

No, this is not a bug. If you want to construct an identity matrix, use:

```julia
Matrix{Float64}(I,rows,cols)

```

However, usually you do not have to do this, because you can use `I` in matrix operations, like:

```julia-repl
julia> A = [1 2 3; 4 5 6; 7 8 9];
julia> B = A + 3*I
3×3 Array{Int64,2}:
 4 2 3
 4 8 6
 7 8 12

```

which saves some allocations.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 2, 2018, 8:19pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/116 "2018-11-02T20:19:24Z")

</div>

It would be nice to be able to do `a[2:3, 2:3] = I` though.

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [November 2, 2018, 8:28pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/117 "2018-11-02T20:28:00Z")

</div>

How do you know which “piece” of I to use?

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [November 2, 2018, 8:45pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/118 "2018-11-02T20:45:01Z")

</div>

The whole thing — just like you use the whole of the matrix `B` when you assign `A[rows, cols] = B`. I’ve wanted to try to add broadcast support to `I` at some point — then we’d get `A[rows, cols] .= I` for free. That said, it’d probably be easier to piecemeal support into normal nonscalar assignment.

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [November 2, 2018, 10:07pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/119 "2018-11-02T22:07:52Z")

</div>

But it’s more like writing A[2:3, 2:3] = B when B is a matrix that’s bigger than A. (In the case of I, infinitely big.) In that case there is no “whole thing”.

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [November 2, 2018, 10:14pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/120 "2018-11-02T22:14:55Z")

</div>

I think of `I` as dynamically “snapping” to an appropriate size once it’s known. E.g., in `A + I` you’re not adding an infinitely large matrix to `A`, you’re adding the identity of size `A`.

---

<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: [November 2, 2018, 10:56pm UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/121 "2018-11-02T22:56:34Z")

</div>

Agree, I don’t think of `I` as infinitely large, it’s whatever size it needs to be.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 3, 2018, 3:34am UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/122 "2018-11-03T03:34:09Z")

</div>

```julia
julia> using LinearAlgebra

julia> a = rand(2,2);

julia> [I a;
        a I]
4×4 Array{Float64,2}:
 1.0 0.0 0.779878 0.959605
 0.0 1.0 0.509001 0.809747
 0.779878 0.959605 1.0 0.0     
 0.509001 0.809747 0.0 1.0 

```

`I` is what it has to be to fit.

---

<div class="post-metadata">

### Author: ![Sean\_McBane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sean_mcbane/32/4580_2.png) [@Sean\_McBane](https://discourse.julialang.org/u/Sean_McBane)
#### Post date: [November 3, 2018, 4:40am UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/123 "2018-11-03T04:40:06Z")

</div>

Yes please to broadcasting! I’ll add that the example from long ago in this thread where

```julia
A = ones(2, 2)
A .+ I

```

is not valid. Usually I would probably not be forming such a matrix, but if I needed to the broadcasting syntax is much nicer than an explicit loop over the diagonal.

---

<div class="post-metadata">

### Author: ![Azamat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/azamat/32/6892_2.png) [@Azamat](https://discourse.julialang.org/u/Azamat)
#### Post date: [November 3, 2018, 6:02am UTC](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824/124 "2018-11-03T06:02:56Z")

</div>

Is there issue to track progress on adding syntax like `A[2:3, 2:3] = I`?

[Previous page](https://discourse.julialang.org/t/why-eye-has-been-deprecated/12824.md?page=4)
