Code
[1, 4, 4]
DSAN 5500: Data Structures, Objects, and Algorithms in Python
Monday, April 8, 2024
\[ \begin{align*} x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} = \frac{-7 \pm \sqrt{49 - 4(6)(-3)}}{2(6)} = \frac{-7 \pm 11}{12} = \left\{\frac{1}{3},-\frac{3}{2}\right\} \end{align*} \]
\(\leadsto\) If code is not embarrassingly parallel (instinctually requiring laborious serial execution), | \(\underbrace{6x^2 + 7x - 3 = 0}_{\text{Solve using Quadratic Eqn}}\) |
But can be split into… | \((3x - 1)(2x + 3) = 0\) |
Embarrassingly parallel pieces which combine to same result, | \(\underbrace{3x - 1 = 0}_{\text{Solve directly}}, \underbrace{2x + 3 = 0}_{\text{Solve directly}}\) |
We can use map-reduce to achieve ultra speedup (running “pieces” on GPU!) | \(\underbrace{(3x-1)(2x+3) = 0}_{\text{Solutions satisfy this product}}\) |
[1, 4, 4]
map()
and reduce()
are “meta-functions”: functions that take in other functions as inputslambda
):When a program doesn’t work, each function is an interface point where you can check that the data are correct. You can look at the intermediate inputs and outputs to quickly isolate the function that’s responsible for a bug.
(from Python’s “Functional Programming HowTo”)
# Convert to lowercase
Easy case: found typo in punctuation removal code. Fix the error, add comment like # Remove punctuation
Rule 1 of FP: transform these comments into function names
Hard case: Something in load_text()
modifies a variable that later on breaks remove_punct()
(Called a side-effect)
Rule 2 of FP: NO SIDE-EFFECTS!
remove_punct()
!!! 😎 ⏱️ = 💰DSAN 5500 Week 11: Parallel Pipelines and Map-Reduce