Hi Andreas,
As a user I would like to write
B = eye(10000) * A
and have the performance of
B = A
90% of the users won't be aware of this 1-character variable "I" defined in Base nor use it. Also, I can guarantee that "I" is much easier to overwrite than a well known function name.
-Júlio
I still think that having a "global variable" named "I" is not robust. I've read so many scripts in matlab that do I = eye(n). This approach is not gonna work.
-Júlio
I'd like to understand the existence of eye() in Julia, it is still not clear to me. Is it because one wants type stability when updating a matrix iteratively? Is this possibly a limitation from the design of the language?
-Júlio
I'd like to understand the existence of eye() in Julia, it is still not clear to me. Is it because one wants type stability when updating a matrix iteratively? Is this possibly a limitation from the design of the language?
-Júlio
m = m + lambda*eye(m)
Andreas, is there a way to get the best of both worlds? Let's say eye() is deprecated, can we somehow set off-diagonal terms in a type that is smart like UniformScaling and supports indexing with operator []?
-Júlio
It is more than sparse, it acts as scalar at first, maybe the operator [] modifies the type to sparse?
-Júlio
You mean a sparse matrix?
Why would one want dense identity matrix?
m = m + lambda*eye(m)
Tim,
Would it make sense to have "I" as an object that acts like UniformScaling and doesn't require any memory allocation, but is only transformed into sparse matrix via the [] operator? Maybe something similar to arrays -> subarrays?
-Júlio
Evan, this is exactly where you should use I, i.e.m = m + λ*IThe reason is that eye(m) will first allocate a dense matrix of size(m,1)^2 elements. Then * will do size(m,1)^2 multiplications of lambda and allocate a new size(m,1)^2 matrix for the result. Finally, size(m,1)^2 additions will be computed for the elements in m and lambda*eye(m).In contrast λ*I will only make a single multiplication, store the result in a tiny stack allocated scalar and only add this to the diagonal of m, i.e. size(m,1) additions.
Christoph,
Can you elaborate on why you want to have both? Also, why you wanted the non-lazy linspace? If I understood correctly, you're talking about returning a array with allocated memory versus a range object, isn't the latter always preferred? I don't understand.
-Júlio
Yes, they are all personal preference. None of the reasons you mentioned is strong for the existence of both.
Furthermore, I'm glad Julia doesn't need to be backward compatible with MATLAB. This is the exact reason I quited GNU Octave, no point in repeating mistakes.
-Júlio
Why is it so important to have all this machinery around linspace and eye? collect is more than enough in my opinion and all the proposals for keeping both versions and pass a type as a parameter are diluting the main issue here: the need for a smart mechanism that handles things efficiently and seamlessly for the user. Teaching is a completely separate matter, let's not enter in this territory, which is much more delicate and hard to be done right.
Recaping the issue:
B = I*A should be as efficient as B = copy(A). Right now it is not.
-Júlio
So maybe add a dimension or create a type that makes more sense for the application?
-Júlio
Sorry for the combative tone Christoph. I thought it was necessary in order to not deviate too much from the core issue. Thank you for your participation and for raising your personal opinions about the topic.
-Júlio
I don't think there is anything like pushing the language to computer scientists, it's the exact opposite, making it seamlessly fast without forcing the user to manipulate types. Again, you write B = I*A and get B = copy(A) performance. That is the original proposal.
Most of us follow the same development strategy while doing science, we write something quick and profile later. The fact that Julia can be fast from the beginning is the best thing about it, no need for rewriting code.
-Júlio
I agree with Chris, though I prefer Matrix(eye(5)) to collect(eye(5)).