stan-dev / stan-dev/math

Add variadic version of `scalar_seq_view`

Open
#2,951 3 comments 0 reactions 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

Description

In the finite-diff framework PR (and some other functions that I'm planning), we need to be able to sequentially iterate through each element of all arguments passed to a function.

The current approach is to use the serializer/deserializer framework which copies all values to a single Eigen::VectorXd and then re-constructs the arguments to the appropriate shape/size by passing in the original arguments. This obviously introduces pretty significant overhead in both copy and memory costs.

A better alternative would be to extend scalar_seq_view to take a variadic number of arguments, and then in the []/() index operator use a hash table to map the input index to the appropriate value in the appropriate argument

Example

In Math pseudo-code, something like:

Eigen::VectorXd a_vec(2);
Eigen::MatrixXd b_mat(2,2);

scalar_seq_view<Eigen::VectorXd, Eigen::MatrixXd> args_view(a_vec, b_mat);

args_view[0]; // Returns a_vec[0]
args_view[1]; // Returns a_vec[1]
args_view[2]; // Returns b_mat(0, 0)
args_view[3]; // Returns b_mat(1, 0)
args_view[4]; // Returns b_mat(0, 1)
args_view[5]; // Returns b_mat(1, 1)
Current Version:

v4.7.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 locating the existing scalar_seq_view implementation and its []/() indexing entry points, then read the finite-diff framework PR #2929 context. Done means a variadic view provides the example’s sequential ordering across vector and matrix arguments without the serializer/deserializer copying approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.