3 ms·
I don't see how not having innate language support for an infix matrix multiplication matters. In R all "infix" operators are really functions anyway[1] so you
by j2kun 12y ago
I don't see how not having innate language support for an infix matrix multiplication matters. In R all "infix" operators are really functions anyway[1] so you could write your library that way. Alternatively, you could use python's overloading for infix operators. (Also, since when was Python considered not iterative? And for that matter, doesn't R's widespread use of *apply make it more functional anyway?)
[1]: Here is a simple example of that for +, note the very strange overloading of quotes.
R version 2.15.2
> "+"(7,5)
[1] 12
- x0x0 12y agoI well understand R's operators, but why on earth is that relevant? math: S = ( H β − r )^T * ( H V H^T )^{-1} * ( H β − r ) python, ugly mess S = (H.dot(beta) - r).T.dot(inv(H.dot(V).dot(H.T))).dot(H.dot(beta) - r) python, better: (although @ is an ugly matrix operator) S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r) the latter is an order of magnitude easier to understand, and looks just like the math. Having one layer of indirection: math to code, is far better than two: math to code to obfuscated code because you won't create infix operators. Edit: examples stolen from the matrix operator pep
- j2kun 12y agoThe problem is that you want to do everything in one line. The proper way to do this would be to save things like H.dot(beta) - r in a separate variable and compute it just once. Moreover, if it's hidden in a library then why does the user care if it's ugly? It's the library designer's job to test it and make sure it's right.
- x0x0 12y agoNo, I simply want my math to look like math instead of a bunch of code that, after careful reading and some notes, implements some math. It's not a library function, it's the code I write. R, matlab, julia all allow users to write something that looks very close to the actual math. Python doesn't see that as a priority.