本文整理汇总了C++中stan::length方法的典型用法代码示例。如果您正苦于以下问题:C++ stan::length方法的具体用法?C++ stan::length怎么用?C++ stan::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stan
的用法示例。
在下文中一共展示了stan::length方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
示例2: a_double
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]);
}
示例3: 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);
}
示例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());
}
示例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));
}
示例6: a_var
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]);
}
示例7: 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);
}
示例8: a_double
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);
}
示例9: a_var
TEST(MetaTraits, DoubleVectorView_false_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<false,true> dvv1(length(a_var));
EXPECT_THROW(dvv1[0], std::runtime_error);
DoubleVectorView<false,true> dvv2(length(a_std_vector));
EXPECT_THROW(dvv2[0], std::runtime_error);
DoubleVectorView<false,true> dvv3(length(a_vector));
EXPECT_THROW(dvv3[0], std::runtime_error);
DoubleVectorView<false,true> dvv4(length(a_row_vector));
EXPECT_THROW(dvv4[0], std::runtime_error);
}
示例10: 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;
}
示例11: TEST
TEST(MetaTraits, length) {
using stan::length;
EXPECT_EQ(1U, length(27.0));
EXPECT_EQ(1U, length(3));
std::vector<double> x(10);
EXPECT_EQ(10U, length(x));
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));
}