Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy evaluation chain #1101

Open
multimeric opened this issue Nov 4, 2021 · 2 comments
Open

Lazy evaluation chain #1101

multimeric opened this issue Nov 4, 2021 · 2 comments

Comments

@multimeric
Copy link

Motivation

Following from discussion starting here: #1042 (comment)

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

  • We move a subset of the ArrayBase methods into an ArrayOps trait. Note: this probably can't be all methods because it can only work for methods that return an array, so axes, as_slice, get etc don't necessarily make sense
  • This trait gets implemented by ArrayBase, but also a new struct called LazyChain (or something idk)
  • LazyChain gets created by ArrayBase.chain()
  • LazyChain will own (?) an ArrayBase, as well as a list of operations that will be sequentially applied to it
  • Then, LazyChain.eval() runs these operations sequentially on each element of the owned array, and then returns the modified array

Decision Points

  • Names for structs and traits
  • Should LazyChain return a copy or a modified in-place array?
  • Should LazyChain own the array or just borrow it? Should we have two different types do each?
@bluss
Copy link
Member

bluss commented Nov 5, 2021

  • possibly take inspiration from how polars does lazy eval
  • What's the relationship to multi-array operations, Zip etc? We don't need to create the world fully formed in one change, but maybe a thought in which way one thing can lead to the other later

@hameer-spire
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants