当前位置: 首页>>代码示例>>C++>>正文


C++ stan::size_of方法代码示例

本文整理汇总了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");
}
开发者ID:javaosos,项目名称:stan,代码行数:29,代码来源:check_consistent_size_test.cpp

示例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();
}
开发者ID:javaosos,项目名称:stan,代码行数:18,代码来源:check_consistent_size_test.cpp


注:本文中的stan::size_of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。