Even then, creating the 5x5 dense matrix to then copy it into A[1:5,1:5] is not what you'd want to do. Ideally would just have eye(5) return something like I which has a size, and just sets A[i,j]=1 if i=j 0 otherwise, with checks that it's the right size. Actually, the current I would do it if you defined a dispatch on setindex!. You still don't need the dense matrix there...
Tim Holy had the only example where you need the dense matrix, and it's when you want to make a dense matrix to start with and them modify the off diagonals of that same matrix. Even then, collect(eye(5)) where eye returned some smart type instead of a matrix wouldn't be bad syntax to do so, and it would be consistent with the rest of the library. I agree that there can be a teaching problem with Julia. A lot of things happen like fast magic to "mathematicians not trained in CS". I don't think the right way to go is to fill Base with methods that shouldn't be used in most cases: someone could make their own "helper libraries" if they really think it's an issue (another example is "EasyFloats" which are not type stable, so they will just turn into complex numbers when needed like in MATLAB. It might help new users from MATLAB see less errors, but I'd never want to see it in Base.) Instead I think it comes down to documentation and extensive tutorials to fix the problem (and filling up StackOverflow with answers). On Tuesday, August 30, 2016 at 10:15:08 AM UTC-7, Christoph Ortner wrote: > > > If this is your only use-case of I, then you don't need it anyways. Just > write 1.0 * A instead; same effect, independent of what type of array A is. > > But what if I use I in a different way? Suppose I want to A[1:5,1:5] = > eye(5); I can't do that with I. Of course we could give it another type > parameters, and then do the whole collect thing again. But then we are back > to what I said before above about needless distractions. > > I don't understand why there is such a resistance to providing both the > explicit arrays and the lazy functionalities in Julia. > > Christoph > > > On Tuesday, 30 August 2016 17:32:37 UTC+1, Júlio Hoffimann wrote: >> >> 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 >> >
