Adding function signatures to Stan


#1

I’m having trouble getting adding some function signatures to Stan.

I added the function signature to the function signatures header file and made a test model (all the changes are here https://github.com/bbbales2/stan/commit/f31370ca2eac2c56a88ac8391721e3da47d719c8 – I’ll move the stuff to a regular Stan repo when it’s time for the pull req.)

When I go to run the model tests (./runTests.py src/test/unit/lang/parser/matrix_functions_test.cpp), I get this in the output:

[==========] Running 90 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 90 tests from lang_parser
...
[ RUN      ] lang_parser.append_array_matrix_function_signatures
unknown file: Failure
C++ exception with description "" thrown in the test body.
[  FAILED  ] lang_parser.append_array_matrix_function_signatures (49 ms)
[ RUN      ] lang_parser.append_col_matrix_function_signatures
...

[----------] Global test environment tear-down
[==========] 90 tests from 1 test case ran. (5586 ms total)
[  PASSED  ] 89 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] lang_parser.append_array_matrix_function_signatures

Any clue what’s blowing up here or what I might have done wrong? I’m following the directions here: https://github.com/stan-dev/stan/wiki/Contributing-New-Functions-to-Stan . I’m probably missing something obvious.

Roughly the function I’m adding is (with specializations so it works with int/real/vector/row_vector/matrix types):

     /**
     * Return the concatenation of two specified vectors in the order of
     *   the arguments.
     *
     * @tparam T1 Scalar type of first vector
     * @tparam T2 Scalar type of second vector
     * @param x First vector
     * @param y Second vector
     * @return A vector of x and y concatenated together (in that order)
     */
    template <typename T1, typename T2>
    inline typename std::vector<typename return_type<T1, T2>::type>
    append_array(const std::vector<T1>& x, const std::vector<T2>& y) {
      std::vector<typename return_type<T1, T2>::type> z;
      z.reserve(x.size() + y.size());
      z.insert(z.end(), x.begin(), x.end());
      z.insert(z.end(), y.begin(), y.end());
      return z;
    }

Thanks!


#2

there’s a typo in your test program -
transformed data - dint should be d_int
everything else looks OK


#3

in general, when you get this from a test that invokes the test-parsable function, it indicates a parser error, so check your test file first. another way to do this is build cmdstan with your branch of stan and then use cmdstan to try to compile the file. unfortunately, the way the unit tests work, you lose the error messages from the parser for that particular function.


#4

transformed data - dint should be d_int

Oh jeez, blush, my bad. Thanks for looking at this.

in general, when you get this from a test that invokes the test-parsable function…

Gotcha, makes sense, thanks!