Search papers, labs, and topics across Lattice.
The authors develop Vectorizer, a source-to-source program transformation tool that automatically translates imperative, loop-based NumPy operations into efficient, vectorized expressions. Manually vectorizing numerical Python requires complex reasoning over array shapes, broadcasting semantics, and advanced indexing, which creates substantial performance bottlenecks in scientific computing and ML pipelines. Evaluated on 150 benchmarks, Vectorizer successfully rewritten 144 programs in an average of 0.53 seconds each, delivering an average runtime speedup of 74.83x.
Imperative Python loops can now be deterministically converted into idiomatic, vectorized tensor operations in under a second, unlocking an average 75x speedup without relying on trial-and-error rewriting.
NumPy is a widely used Python library for numerical scientific computing, known for its declarative APIs and its optimized implementations. However, writing efficient NumPy programs, which often entails using vectorized array operations instead of explicit Python loops, may not be straightforward. This can be difficult for programmers who are accustomed to imperative array traversal, especially when vectorized API invocations require careful reasoning about shapes, broadcasting, and advanced indexing. This paper presents a rewrite-based approach for vectorizing Numpy programs with explicit loops over array data. Our approach vectorizes loops from the inside out, using array shapes and dataflow analysis to guide a source-to-source transformation that replaces loop bodies with vectorized statements. Following a set of rewrite rules that are correct by construction, our approach is consistently fast. We have implemented the approach as a tool called Vectorizer and evaluated it on 150 benchmarks collected from prior work and Stack Overflow. The evaluation shows that Vectorizer vectorizes 142 of the 150 benchmarks directly and 2 more after minor changes to the original benchmarks, with only 0.53 seconds on average to rewrite each one. The resulting programs are, on average, 74.83x faster than the original loop-based implementations.