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

Backport assign to Stan Math #2149

Closed
wants to merge 5 commits into from
Closed

Conversation

SteveBronder
Copy link
Collaborator

Summary

This backports (up-ports?) the assign functions from the Stan repo into this repo and refactors the assign() function to allow for better slice indexing

The scheme here is that for slicing like A[2:5, 1:10] Vector[1:10] we want to translate that directly into Eigen's block() or .segment() functions. For functions that slice over rows and columns like A[, {1, 3, 8}] and A[1:N, :N] So that Eigen knows what columns it's slicing by first and then the slice of rows.

Tests

Tests were added for the new overloads and can be run with

./runTests.py ./test/unit/math/prim/fun/assign_test.cpp
./runTests.py ./test/unit/math/prim/ -f index
./runTests.py ./test/unit/math/prim/ -f rvalue

@t4c1 would you have time to help me add the assign() functions here to the expression testing framework? It's not clear to me how to add all the combinations of index types

Side Effects

This should have no side effects until we change the compiler to use the assign function in the stan::math namespace instead of the ones defined in the stan::model namespace

Release notes

Assign statements in Stan have better support for slice indexing

Checklist

  • Math issue #(issue number)

  • Copyright holder: Steve Bronder

    The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
    - Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
    - Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

  • the basic tests are passing

    • unit tests pass (to run, use: ./runTests.py test/unit)
    • header checks pass, (make test-headers)
    • dependencies checks pass, (make test-math-dependencies)
    • docs build, (make doxygen)
    • code passes the built in C++ standards checks (make cpplint)
  • the code is written in idiomatic C++ and changes are documented in the doxygen

  • the new changes are tested

@SteveBronder SteveBronder changed the title Backport assign to Stan Backport assign to Stan Math Oct 14, 2020
@t4c1
Copy link
Contributor

t4c1 commented Oct 15, 2020

Assign is a bit different than other math functions. It does not return, it modifies one of the arguments and it accepts the weird index types. So it would be hard to modify expression tests to handle all that. I suggest writing expression tests for this function by hand (you might still want to use expression_test_helpers.hpp).

I would suggest putting all indexing related stuff into its own folder within fun. Also I just noticed assign and lvalue indexing look the same to me. What is the difference between the two?

@rok-cesnovar
Copy link
Member

rok-cesnovar commented Oct 15, 2020

I like the idea of moving this to Math. If we stay with the current repo structure, my opinion is that Stan should only be algorithms/services stuff, no utility functions.

I am a bit scared how this will play with rstan and StanHeaders and all the CRAN related update issues. Rstan still has problems that occured when moving prim/mat/fun/Eigen.hpp. We might be able to do this once Rstan catches up, before that this could only live in Math as duplicated code from /stan. I dont want to cause more issues to Ben and rstan.

@t4c1
Copy link
Contributor

t4c1 commented Oct 15, 2020

Hmm, if that is the case I would suggest leaving this in stan repo for now. I don't like duplicated code.

@SteveBronder
Copy link
Collaborator Author

Cool just opened up a PR for this in the stan repo

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

Successfully merging this pull request may close these issues.

None yet

4 participants