←back to thread

132 points zfnmxt | 1 comments | | HN request time: 0.278s | source
Show context
eigenspace ◴[] No.40713949[source]
I’d strongly suggest not going the Numpy route, and instead reading about broadcast in julia [1]. In many contexts, it’s very important to distinguish between the element-wise application of a function, and a function that is applied to an entire array. A classic example would be the matrix exponential[2], versus the element-wise exponential of a matrix.

In julia the former is `exp(M)`, and the latter is `exp.(M)`

[1] https://julialang.org/blog/2017/01/moredots/

[2] https://en.m.wikipedia.org/wiki/Matrix_exponential

replies(4): >>40714080 #>>40714083 #>>40714427 #>>40715920 #
cycomanic ◴[] No.40714427[source]
I actually think Julia's behaviour (partially) copied from matlab is bad. I had to review a lot of matlab/Julia simulation code write by PhD/grad students (as well as my own) and most of the time when things somehow are not working debugging becomes a task of "find the missing dot". If they would have decided on a more obvious symbol (the dot is really just way too easy to overlook) for broadcasting it would be much better, but I still much prefer that broadcast and matrix operation would use entirely different operators/named functions. Instead we have the case that a little annotation can dramatically change the behaviour of the code (the matrix exponential is in fact a great example).

That said I mainly work with fields and calculus so I might be biased because the majority of operations are broadcast and I only rarely use matrix operations.

replies(2): >>40715052 #>>40715192 #
1. setopt ◴[] No.40715192[source]
> most of the time when things somehow are not working debugging becomes a task of "find the missing dot". If they would have decided on a more obvious symbo

I guess you could use your editor’s highlight-regexp function to make the dots more obvious during debugging :)

I personally like the dots because they’re so unintrusive, but I work in a field where most operations are matrix operations, so perhaps you’re right…