On Sunday, March 15, 2015 at 7:29:21 PM UTC-4, Bob Carpenter wrote:
> The general point of doc and testing is complementary. The
> doc should define all the constraints (e.g., what sizes things have to
> be relative to each other), and the tests should test they are
> handled appropriately.
>
> The tests should also check boundary conditions, such as if a size
> zero matrix or vector is allowed, then it should behave properly.
I added tests using check_, but I seem to have missed testing for whatever the gradient-enabled types are... which leads to a question below.
>
> > In the mean time I think this works as intended and I'll see what some test models do with it. Thanks to everyone for getting this sorted out so far!
>
> Great.
I had some trouble getting this working all the way. When linking a real model I get the mess pasted below. It looks like I missed implementing something in sparse_multiply_csr for the autodiff variables. At this point I haven't read up on the autodiff variables so I'd appreciate any suggestions about what's going on here. Probably the easiest way to look at my changes (against develop) is here:
https://github.com/stan-dev/stan/compare/feature/sparse_multiply
Failed model compilation is below, looks like a test model would fail the same way. This is for a full-scale problem with a 90% sparse matrix that I've already run using dense multiplication so I think it'll make a decent test case.
krzysiek@fawkes ~/packages/cmdstan-2.6.2.1 $ make ~/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O3 -o bin/cmdstan/stanc.o src/cmdstan/stanc.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/expression_grammar_inst.o stan/src/stan/lang/grammars/expression_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/program_grammar_inst.o stan/src/stan/lang/grammars/program_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/term_grammar_inst.o stan/src/stan/lang/grammars/term_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/statement_2_grammar_inst.o stan/src/stan/lang/grammars/statement_2_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/var_decls_grammar_inst.o stan/src/stan/lang/grammars/var_decls_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/bare_type_grammar_inst.o stan/src/stan/lang/grammars/bare_type_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/statement_grammar_inst.o stan/src/stan/lang/grammars/statement_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/whitespace_grammar_inst.o stan/src/stan/lang/grammars/whitespace_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/functions_grammar_inst.o stan/src/stan/lang/grammars/functions_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/grammars/expression07_grammar_inst.o stan/src/stan/lang/grammars/expression07_grammar_inst.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O0 -o bin/stan/lang/ast_def.o stan/src/stan/lang/ast_def.cpp
ar -rs bin/libstanc.a bin/stan/lang/grammars/expression_grammar_inst.o bin/stan/lang/grammars/program_grammar_inst.o bin/stan/lang/grammars/term_grammar_inst.o bin/stan/lang/grammars/statement_2_grammar_inst.o bin/stan/lang/grammars/var_decls_grammar_inst.o bin/stan/lang/grammars/bare_type_grammar_inst.o bin/stan/lang/grammars/statement_grammar_inst.o bin/stan/lang/grammars/whitespace_grammar_inst.o bin/stan/lang/grammars/functions_grammar_inst.o bin/stan/lang/grammars/expression07_grammar_inst.o bin/stan/lang/ast_def.o
ar: creating bin/libstanc.a
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -lpthread -O0 -o bin/stanc bin/cmdstan/stanc.o -Lbin -lstanc
--- Translating Stan model to C++ code ---
bin/stanc /home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.stan --o=/home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.hpp
Model name=cjs_seasonality_4a_model
Input file=/home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.stan
Output file=/home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.hpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -c -O3 -o bin/cmdstan/print.o src/cmdstan/print.cpp
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -lpthread -O0 -o bin/print bin/cmdstan/print.o
--- Linking C++ model ---
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan/src -isystem stan/lib/eigen_3.2.4 -isystem stan/lib/boost_1.55.0 -Wall -pipe -DEIGEN_NO_DEBUG -Wno-unused-local-typedefs -lpthread -O3 -o /home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a src/cmdstan/main.cpp -include /home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.hpp
In file included from stan/src/stan/math/prim/mat.hpp:152:0,
from stan/src/stan/model/model_header.hpp:12,
from /home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.hpp:3,
from <command-line>:0:
stan/src/stan/math/prim/mat/fun/sparse_multiply.hpp: In instantiation of ‘Eigen::Matrix<typename boost::math::tools::promote_args<RT1, RT2>::type, -1, 1> stan::math::sparse_multiply_csr(const int&, const int&, const Eigen::Matrix<Scalar, -1, 1>&, const std::vector<int>&, const std::vector<int>&, const std::vector<int>&, const Eigen::Matrix<RhsScalar, -1, 1>&) [with T1 = double; T2 = stan::agrad::var; typename boost::math::tools::promote_args<RT1, RT2>::type = stan::agrad::var]’:
/home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.hpp:643:114: required from ‘T__ cjs_seasonality_4a_model_namespace::cjs_seasonality_4a_model::log_prob(std::vector<T2>&, std::vector<int>&, std::ostream*) const [with bool propto__ = true; bool jacobian__ = true; T__ = stan::agrad::var; std::ostream = std::basic_ostream<char>]’
stan/src/stan/model/util.hpp:110:70: required from ‘double stan::model::log_prob_grad(const M&, std::vector<double>&, std::vector<int>&, std::vector<double>&, std::ostream*) [with bool propto = true; bool jacobian_adjust_transform = true; M = cjs_seasonality_4a_model_namespace::cjs_seasonality_4a_model; std::ostream = std::basic_ostream<char>]’
stan/src/stan/model/util.hpp:290:74: required from ‘int stan::model::test_gradients(const M&, std::vector<double>&, std::vector<int>&, double, double, std::ostream&, std::ostream*) [with bool propto = true; bool jacobian_adjust_transform = true; M = cjs_seasonality_4a_model_namespace::cjs_seasonality_4a_model; std::ostream = std::basic_ostream<char>]’
stan/src/stan/services/command.hpp:200:39: required from ‘int stan::services::command(int, const char**) [with Model = cjs_seasonality_4a_model_namespace::cjs_seasonality_4a_model]’
src/cmdstan/main.cpp:7:57: required from here
stan/src/stan/math/prim/mat/fun/sparse_multiply.hpp:135:51: error: no matching function for call to ‘dot_product(Eigen::Matrix<stan::agrad::var, -1, 1, 0, -1, 1>&, Eigen::Matrix<stan::agrad::var, -1, 1, 0, -1, 1>&)’
y(i) = stan::math::dot_product(w_sub,b_sub);
^
stan/src/stan/math/prim/mat/fun/sparse_multiply.hpp:135:51: note: candidates are:
In file included from stan/src/stan/math/prim/mat.hpp:73:0,
from stan/src/stan/model/model_header.hpp:12,
from /home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.hpp:3,
from <command-line>:0:
stan/src/stan/math/prim/mat/fun/dot_product.hpp:22:19: note: template<int R1, int C1, int R2, int C2> double stan::math::dot_product(const Eigen::Matrix<double, R1, C1>&, const Eigen::Matrix<double, R2, C2>&)
inline double dot_product(const Eigen::Matrix<double, R1, C1>& v1,
^
stan/src/stan/math/prim/mat/fun/dot_product.hpp:22:19: note: template argument deduction/substitution failed:
In file included from stan/src/stan/math/prim/mat.hpp:152:0,
from stan/src/stan/model/model_header.hpp:12,
from /home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.hpp:3,
from <command-line>:0:
stan/src/stan/math/prim/mat/fun/sparse_multiply.hpp:135:51: note: mismatched types ‘double’ and ‘stan::agrad::var’
y(i) = stan::math::dot_product(w_sub,b_sub);
^
stan/src/stan/math/prim/mat/fun/sparse_multiply.hpp:135:51: note: ‘Eigen::Matrix<stan::agrad::var, -1, 1, 0, -1, 1>’ is not derived from ‘const Eigen::Matrix<double, R1, C1>’
In file included from stan/src/stan/math/prim/mat.hpp:73:0,
from stan/src/stan/model/model_header.hpp:12,
from /home/krzysiek/projekty/westbrook_ats_survival/analysis/cjs-seasonality-4a/cjs-seasonality-4a.hpp:3,
>
> - Bob