Why `eye` has been deprecated?

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 :stuck_out_tongue:)

6 Likes

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)

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

Matrix{Float64}(I,rows,cols)

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

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.

2 Likes

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

8 Likes

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

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.

1 Like

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”.

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.

9 Likes

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

1 Like
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.

3 Likes

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

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.

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