stan-dev / stan-dev/math

Cleaning up linear access functions

Open
#2,245 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

Now that we're exposing expressions in the language, we need to clean up functions that depend on linear access in Eigen types.

Specifically, with a simple Eigen type like Eigen::MatrixXd, it is possible to instead of looping over ij like so:

Eigen::MatrixXd A;
for(size_t i = 0; i < A.size(); ++i) {
  for(size_t i = 0; j < A.size(); ++j) {
    ... A(i, j) ...;
  }
}

to just do:

Eigen::MatrixXd A;
for(size_t i = 0; i < A.size(); ++i) {
  ... A(i) ...;
}

This was convenient because the same thing worked with matrices, vectors, row vectors.

Now that we have expressions and maps and such we need to be more careful.

There have been two pulls addressing issues like this so far, #2205 and #2223

I made this issue so we would vaguely have a place to discuss:

  1. How we should be testing for this so it doesn't bite us
  2. Track known issues that exist (until there's some sort of general solution in place)
  3. How do we handle row major vs. column major -- now our double loops will be explicitly bad in some cases

And and I do not want to stall #2223 unnecessarily to try to fix everything in one go.

Current Version:

v3.4.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing pulls #2205 and #2223 and the Eigen linear-access examples in the issue. Determine how matrix, vector, expression, map, and row-major or column-major cases should be tested; done requires an agreed testing approach and a tracked set of remaining issues or a general solution.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.