math icon indicating copy to clipboard operation
math copied to clipboard

[WIP] Adds specializations for handling sparse matrix unary operations

Open SteveBronder opened this issue 4 years ago • 2 comments

Summary

This is a WIP for supporting sparse matrix unary operations in Stan math. Related to #2597 , this API will return a sparse matrix with all values filled in for sparse matrices when the function does not have a f(0) -> 0 mapping. The scheme here just adds a bool ApplyZero template parameter to apply_scalar_unary where if ApplyZero is true, a dense matrix is returned and for false a sparse matrix is returned.

Though note if we want to change the API to always be Sparse -> Sparse that's pretty easy here

Tests

The tests have been modified for atan() and acos() to take a vector input and the usual lambda functor we use for testing and make a sparse matrix with the vector values along the diagonal via a helper function make_sparse_mat_func().

Side Effects

Release notes

Adds support for Unary sparse matrix functions

Checklist

  • [x] Math issue #2597

  • [x] 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/)

  • [x] 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)
  • [x] the code is written in idiomatic C++ and changes are documented in the doxygen

  • [x] the new changes are tested

SteveBronder avatar Oct 05 '21 22:10 SteveBronder

@andrjohns would you mind taking a look at this?

SteveBronder avatar Apr 20 '22 22:04 SteveBronder

Moving to draft; it's still marked at "WIP." Please move it out of draft when you're ready.

syclik avatar May 19 '23 14:05 syclik