Optimize code by merging expressions
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 160
- Forks
- 59
- Avg merge
- 21h 45m
- Merged PRs (30d)
- 26
Description
Now that we are using Eigen expressions in Stan Math it makes sense for compiler to merge multiple expressions into singe one where possible to avoid unnecessary memory accesses. This is possible where we have a variable of matrix, vector or row_vector type (or if using OpenCL any type that is replaced with a matrix_cl) that is used in exactly one place in further code. Such a variable can be removed and its use case replaced with the expression that was assigned to the variable.
For example from stan code:
matrix a, b;
matrix c = a + b;
matrix d = c * 3;
We want to generate (assuming c is not used anywhere else):
Eigen::MatrixXd a, b;
Eigen::MatrixXd d = (a + b) * 3;
instead of:
Eigen::MatrixXd a, b;
Eigen::MatrixXd c = a + b;
Eigen::MatrixXd d = c * 3;
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Stan-to-C++ expression-generation path illustrated by the matrix, vector, and row_vector examples, and trace how single-use variables are represented. Done means eligible assignments are merged into later expressions to reduce memory accesses, while variables used in multiple places remain available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, ocaml
- Domain
- compilers, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100