• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ stan类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中stan的典型用法代码示例。如果您正苦于以下问题:C++ stan类的具体用法?C++ stan怎么用?C++ stan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了stan类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: TEST

TEST(MetaTraits, DoubleVectorView_true_false) {
  using std::vector;
  using stan::DoubleVectorView;
  using Eigen::Matrix;
  using Eigen::Dynamic;

  double a_double(1);
  std::vector<double> a_std_vector(3);
  Matrix<double,Dynamic,1> a_vector(4);
  Matrix<double,1,Dynamic> a_row_vector(5);

  DoubleVectorView<true,false> dvv1(length(a_double));
  EXPECT_FLOAT_EQ(0.0, dvv1[0]);
  EXPECT_FLOAT_EQ(0.0, dvv1[1]);
  EXPECT_FLOAT_EQ(0.0, dvv1[100]);

  DoubleVectorView<true,false> dvv2(length(a_std_vector));
  EXPECT_FLOAT_EQ(0.0, dvv2[0]);
  EXPECT_FLOAT_EQ(0.0, dvv2[1]);
  EXPECT_FLOAT_EQ(0.0, dvv2[2]);  
  
  DoubleVectorView<true,false> dvv3(length(a_vector));
  EXPECT_FLOAT_EQ(0.0, dvv3[0]);
  EXPECT_FLOAT_EQ(0.0, dvv3[1]);
  EXPECT_FLOAT_EQ(0.0, dvv3[2]);  
  
  DoubleVectorView<true,false> dvv4(length(a_row_vector));
  EXPECT_FLOAT_EQ(0.0, dvv4[0]);
  EXPECT_FLOAT_EQ(0.0, dvv4[1]);
  EXPECT_FLOAT_EQ(0.0, dvv4[2]);
}
开发者ID:HerraHuu,项目名称:stan,代码行数:31,代码来源:traits_test.cpp


示例2: TEST

TEST(MetaTraits, VectorBuilderHelper_true_false) {
  using stan::VectorBuilderHelper;
  using stan::length;
  using Eigen::Matrix;
  using Eigen::Dynamic;

  Matrix<double,Dynamic,1> a_vector(4);
  Matrix<double,1,Dynamic> a_row_vector(5);

  VectorBuilderHelper<double,true,false> dvv3(length(a_vector));
  EXPECT_FLOAT_EQ(0.0, dvv3[0]);
  EXPECT_FLOAT_EQ(0.0, dvv3[1]);
  EXPECT_FLOAT_EQ(0.0, dvv3[2]);
  double data3 = 0;
  EXPECT_NO_THROW(data3 = dvv3.data());
  EXPECT_FLOAT_EQ(0.0, data3);
  
  VectorBuilderHelper<double,true,false> dvv4(length(a_row_vector));
  EXPECT_FLOAT_EQ(0.0, dvv4[0]);
  EXPECT_FLOAT_EQ(0.0, dvv4[1]);
  EXPECT_FLOAT_EQ(0.0, dvv4[2]);
  double data4 = 0;
  EXPECT_NO_THROW(data4 = dvv4.data());
  EXPECT_FLOAT_EQ(0.0, data4);
}
开发者ID:aseyboldt,项目名称:math,代码行数:25,代码来源:VectorBuilderHelper_test.cpp


示例3: TEST

TEST(MetaTraits, VectorBuilder_true_true) {
  using std::vector;
  using stan::VectorBuilder;
  using stan::math::var;
  using stan::length;

  var a_var(1);
  std::vector<var> a_std_vector(3);

  VectorBuilder<true,double,std::vector<var> > dvv1(length(a_var));
  dvv1[0] = 0.0;
  EXPECT_FLOAT_EQ(0.0, dvv1[0]);
  std::vector<double> data1;
  EXPECT_NO_THROW(data1 = dvv1.data());
  EXPECT_EQ(length(a_var), data1.size());
  
  VectorBuilder<true,double,std::vector<var> > dvv2(length(a_std_vector));
  dvv2[0] = 0.0;
  dvv2[1] = 1.0;
  dvv2[2] = 2.0;
  EXPECT_FLOAT_EQ(0.0, dvv2[0]);
  EXPECT_FLOAT_EQ(1.0, dvv2[1]);
  EXPECT_FLOAT_EQ(2.0, dvv2[2]);  
  std::vector<double> data2;
  EXPECT_NO_THROW(data2 = dvv2.data());
  EXPECT_EQ(length(a_std_vector), data2.size());
}
开发者ID:aseyboldt,项目名称:math,代码行数:27,代码来源:VectorBuilder_test.cpp


示例4: TEST

TEST(MetaTraits, VectorBuilder_true_true) {
    using stan::VectorBuilder;
    using Eigen::Matrix;
    using Eigen::Dynamic;
    using stan::math::var;
    using stan::length;

    Matrix<var,Dynamic,1> a_vector(4);
    Matrix<var,1,Dynamic> a_row_vector(5);

    VectorBuilder<true,double,Matrix<var,Dynamic,1> > dvv3(length(a_vector));
    dvv3[0] = 0.0;
    dvv3[1] = 1.0;
    dvv3[2] = 2.0;
    EXPECT_FLOAT_EQ(0.0, dvv3[0]);
    EXPECT_FLOAT_EQ(1.0, dvv3[1]);
    EXPECT_FLOAT_EQ(2.0, dvv3[2]);
    std::vector<double> data3;
    EXPECT_NO_THROW(data3 = dvv3.data());
    EXPECT_EQ(length(a_vector), data3.size());

    VectorBuilder<true,double,Matrix<var,1,Dynamic> > dvv4(length(a_row_vector));
    dvv4[0] = 0.0;
    dvv4[1] = 1.0;
    dvv4[2] = 2.0;
    EXPECT_FLOAT_EQ(0.0, dvv4[0]);
    EXPECT_FLOAT_EQ(1.0, dvv4[1]);
    EXPECT_FLOAT_EQ(2.0, dvv4[2]);
    std::vector<double> data4;
    EXPECT_NO_THROW(data4 = dvv4.data());
    EXPECT_EQ(length(a_row_vector), data4.size());
}
开发者ID:stan-dev,项目名称:math,代码行数:32,代码来源:VectorBuilder_test.cpp


示例5: TEST

TEST(MetaTraits, length) {
  using stan::length;

  Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> m(2,3);
  m << 1, 2, 3, 4, 5, 6;
  EXPECT_EQ(6U, length(m));

  Eigen::Matrix<double,Eigen::Dynamic,1> rv(2);
  rv << 1, 2;
  EXPECT_EQ(2U, length(rv));

  Eigen::Matrix<double,1,Eigen::Dynamic> v(2);
  v << 1, 2;
  EXPECT_EQ(2U, length(v));
}
开发者ID:aseyboldt,项目名称:math,代码行数:15,代码来源:length_test.cpp


示例6: 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


示例7: TEST

TEST(MetaTraits, DoubleVectorView_true_true) {
  using std::vector;
  using stan::DoubleVectorView;
  using Eigen::Matrix;
  using Eigen::Dynamic;
  using stan::agrad::var;

  var a_var(1);
  std::vector<var> a_std_vector(3);
  Matrix<var,Dynamic,1> a_vector(4);
  Matrix<var,1,Dynamic> a_row_vector(5);

  DoubleVectorView<true,true> dvv1(length(a_var));
  dvv1[0] = 0.0;
  dvv1[1] = 1.0;
  dvv1[2] = 2.0;
  EXPECT_FLOAT_EQ(0.0, dvv1[0]);
  EXPECT_FLOAT_EQ(1.0, dvv1[1]);
  EXPECT_FLOAT_EQ(2.0, dvv1[2]);

  DoubleVectorView<true,true> dvv2(length(a_std_vector));
  dvv2[0] = 0.0;
  dvv2[1] = 1.0;
  dvv2[2] = 2.0;
  EXPECT_FLOAT_EQ(0.0, dvv2[0]);
  EXPECT_FLOAT_EQ(1.0, dvv2[1]);
  EXPECT_FLOAT_EQ(2.0, dvv2[2]);  
  
  DoubleVectorView<true,true> dvv3(length(a_vector));
  dvv3[0] = 0.0;
  dvv3[1] = 1.0;
  dvv3[2] = 2.0;
  EXPECT_FLOAT_EQ(0.0, dvv3[0]);
  EXPECT_FLOAT_EQ(1.0, dvv3[1]);
  EXPECT_FLOAT_EQ(2.0, dvv3[2]);  
  
  DoubleVectorView<true,true> dvv4(length(a_row_vector));
  dvv4[0] = 0.0;
  dvv4[1] = 1.0;
  dvv4[2] = 2.0;
  EXPECT_FLOAT_EQ(0.0, dvv4[0]);
  EXPECT_FLOAT_EQ(1.0, dvv4[1]);
  EXPECT_FLOAT_EQ(2.0, dvv4[2]);
}
开发者ID:aflaxman,项目名称:stan,代码行数:44,代码来源:traits_test.cpp


示例8: TEST

TEST(MetaTraits, VectorBuilderHelper_false_false) {
  using std::vector;
  using stan::VectorBuilderHelper;
  using stan::length;

  std::vector<double> a_std_vector(3);

  VectorBuilderHelper<double,false,false> dvv2(length(a_std_vector));
  EXPECT_THROW(dvv2[0], std::logic_error);
  EXPECT_THROW(dvv2.data(), std::logic_error);
}
开发者ID:aseyboldt,项目名称:math,代码行数:11,代码来源:VectorBuilderHelper_test.cpp


示例9: check

        static bool check(const char* function,
                          const char* name,
                          const T_y& y,
                          const T_low& low,
                          const T_high& high) {
          using stan::length;
          using stan::get;

          VectorView<const T_low> low_vec(low);
          VectorView<const T_high> high_vec(high);
          for (size_t n = 0; n < length(y); n++) {
            if (!(low_vec[n] <= get(y, n) && get(y, n) <= high_vec[n])) {
              std::stringstream msg;
              msg << ", but must be between ";
              msg << "(" << low_vec[n] << ", " << high_vec[n] << ")";
              std::string msg_str(msg.str());
              domain_error_vec(function, name, y, n,
                               "is ", msg_str.c_str());
            }
          }
          return true;
        }
开发者ID:javaosos,项目名称:stan,代码行数:22,代码来源:check_bounded.hpp


示例10: TEST

TEST(MetaTraits, VectorBuilder_false_false) {
  using std::vector;
  using stan::VectorBuilder;
  using Eigen::Matrix;
  using Eigen::Dynamic;

  double a_double(1);
  std::vector<double> a_std_vector(3);
  Matrix<double,Dynamic,1> a_vector(4);
  Matrix<double,1,Dynamic> a_row_vector(5);

  VectorBuilder<false,double,double> dvv1(length(a_double));
  EXPECT_THROW(dvv1[0], std::logic_error);

  VectorBuilder<false,double,double> dvv2(length(a_std_vector));
  EXPECT_THROW(dvv2[0], std::logic_error);
  
  VectorBuilder<false,double,double> dvv3(length(a_vector));
  EXPECT_THROW(dvv3[0], std::logic_error);
  
  VectorBuilder<false,double,double> dvv4(length(a_row_vector));
  EXPECT_THROW(dvv4[0], std::logic_error);
}
开发者ID:javaosos,项目名称:stan,代码行数:23,代码来源:traits_test.cpp


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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ state类代码示例发布时间:2022-05-31
下一篇:
C++ stack类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap