本文整理汇总了C++中stan::size_of方法的典型用法代码示例。如果您正苦于以下问题:C++ stan::size_of方法的具体用法?C++ stan::size_of怎么用?C++ stan::size_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stan
的用法示例。
在下文中一共展示了stan::size_of方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(ErrorHandlingScalar, checkConsistentSize_EigenVector) {
using Eigen::Matrix;
using Eigen::Dynamic;
using stan::math::check_consistent_size;
using stan::size_of;
const char* function = "checkConsistentSize";
const char* name1 = "name1";
Matrix<double,Dynamic,1> x(4);
EXPECT_EQ(4U, size_of(x));
EXPECT_TRUE(check_consistent_size(function, name1, x, 4U));
EXPECT_THROW_MSG(check_consistent_size(function, name1, x, 2U),
std::invalid_argument,
"name1 has dimension = 4, expecting dimension = 2");
x.resize(1);
EXPECT_TRUE(check_consistent_size(function, name1, x, 1U));
EXPECT_THROW_MSG(check_consistent_size(function, name1, x, 2U),
std::invalid_argument,
"name1 has dimension = 1, expecting dimension = 2");
x.resize(0);
EXPECT_TRUE(check_consistent_size(function, name1, x, 0U));
EXPECT_THROW_MSG(check_consistent_size(function, name1, x, 1U),
std::invalid_argument,
"name1 has dimension = 0, expecting dimension = 1");
}
示例2: TEST
TEST(AgradRevErrorHandlingScalar, checkConsistentSize) {
using Eigen::Matrix;
using Eigen::Dynamic;
using stan::math::check_consistent_size;
using stan::size_of;
using stan::agrad::var;
const char* function = "check_consistent_size";
const char* name1 = "name1";
Matrix<var,Dynamic,1> v1(4);
v1 << 4.0,5.0,6.0,7.0;
EXPECT_EQ(4U, size_of(v1));
EXPECT_TRUE(check_consistent_size(function, name1, v1, 4U));
EXPECT_THROW(check_consistent_size(function, name1, v1, 2U), std::invalid_argument);
stan::agrad::recover_memory();
}