rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations
https://docs.rs/ndarray/
Apache License 2.0
3.56k stars 300 forks source link

Lazy evaluation chain #1101

Open multimeric opened 2 years ago

multimeric commented 2 years ago

Motivation

Following from discussion starting here: https://github.com/rust-ndarray/ndarray/pull/1042#issuecomment-957134294

With contemporary systems, moving the data from memory into caches and registers often dominates the runtime of numerical algorithms depending on how many arithmetic operations they perform relative to each memory access. Fusing operations from multiple passes into a single pass increases this ratio and thereby the likelihood of efficient CPU utilisation. [1]

In theory this problem is solved using loops and/or mapv, but this doesn't provide a very user-friendly interface. Users who want to work at a high level still want to be able to use arr.pow(), arr.log() etc, but also retain the speed of this per-element processing (rather than applying each operation to each element and then the next operation to each element).

Proposed Changes

Decision Points

bluss commented 2 years ago
hameer-spire commented 2 years ago

I will just drop something in the C++ world that does lazy eval rather well: xtensor (source, docs). It's one of the major reasons I have not moved to ndarray yet.