2 ms·
The miracle of python is that it has standard syntax for vectorized code across many packages. For i in range(100): mask = lib.abs2(z) < 4 subset =
by QuadmasterXLII 3y ago
The miracle of python is that it has standard syntax for vectorized code across many packages.
For i in range(100):
mask = lib.abs2(z) < 4
subset = z[mask]
subc = c[mask]
subcounts = 0
for j in range(100):
subcounts = subcounts + lib.abs2 (subset )< 4
subz = subz**2 + subc
Z[mask] = subset
Counts[mask] += subcounts
Was that code using numpy, tensorflow, torch, arrayfire, or some proprietary amd gpu lib? It’s hard to say!
Try the same with eigen vs arrayfire in C++ or math.js vs tensorflow.js and you will have to do a hell of a lot more than change the value of lib
- aidos 3y agoI’m confused by seeing talk of vectorisation next to example code full of for loops
- QuadmasterXLII 3y agoI forgot c = lib.arange(-2, 2, .01) c += 1j * c.transpose() at the beginning, and appear to have eaten some downvotes as a result lol
- medo-bear 3y ago> The miracle of python is that it has standard syntax for vectorized code across many packages. If you care about performance you should care about how vectorization is implemented. Python makes vectorization look like magic, but scientists shouldnt do magic. In Steel Bank Common Lisp I can implement SIMD procedures in a straightforward manner. The language is more high level and more low level (yes) than python, and much much faster.
- QuadmasterXLII 3y agoI mean that's exactly how python won. Everyone wrote code and got used to slicing idioms without understanding how they were implemented in SIMD, and then when the implementation got changed from SIMD to GPGPU, the high level code and more importantly idioms didn't have to change.
- medo-bear 3y agoExcept I dont think that is a feature. I think optimizing compilers is something numerical scientists should excell at and that it will be a much sought after quality. Python seems to do everything it can to hide those details from the user