本文整理汇总了C++中eigen::Matrix::cols方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::cols方法的具体用法?C++ Matrix::cols怎么用?C++ Matrix::cols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::Matrix
的用法示例。
在下文中一共展示了Matrix::cols方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
static inline void _fast_matrix_copy(Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& v_to,
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& v_from) {
int nr = v_from.rows();
int nc = v_from.cols();
v_to.resize(nr, nc);
if (nr > 0 && nc > 0) {
std::memcpy(&v_to(0), &v_from(0), v_from.size() * sizeof(double));
}
}
示例2: eigen
void MatrixMxN<Scalar>::eigenDecomposition(VectorND<Scalar> &eigen_values_real, VectorND<Scalar> &eigen_values_imag,
MatrixMxN<Scalar> &eigen_vectors_real, MatrixMxN<Scalar> &eigen_vectors_imag)
{
unsigned int rows = this->rows(), cols = this->cols();
if(rows != cols)
{
std::cerr<<"Eigen decomposition is only valid for square matrix!\n";
std::exit(EXIT_FAILURE);
}
#ifdef PHYSIKA_USE_EIGEN_MATRIX
//hack: Eigen::EigenSolver does not support integer types, hence we cast Scalar to long double for decomposition
Eigen::Matrix<long double,Eigen::Dynamic,Eigen::Dynamic> temp_matrix(rows,cols);
for(unsigned int i = 0; i < rows; ++i)
for(unsigned int j = 0; j < cols; ++j)
temp_matrix(i,j) = static_cast<long double>((*ptr_eigen_matrix_MxN_)(i,j));
Eigen::EigenSolver<Eigen::Matrix<long double,Eigen::Dynamic,Eigen::Dynamic> > eigen(temp_matrix);
Eigen::Matrix<std::complex<long double>,Eigen::Dynamic,Eigen::Dynamic> vectors = eigen.eigenvectors();
const Eigen::Matrix<std::complex<long double>,Eigen::Dynamic,1> &values = eigen.eigenvalues();
//resize if have to
if(eigen_vectors_real.rows() != vectors.rows() || eigen_vectors_real.cols() != vectors.cols())
eigen_vectors_real.resize(vectors.rows(),vectors.cols());
if(eigen_vectors_imag.rows() != vectors.rows() || eigen_vectors_imag.cols() != vectors.cols())
eigen_vectors_imag.resize(vectors.rows(),vectors.cols());
if(eigen_values_real.dims() != values.rows())
eigen_values_real.resize(values.rows());
if(eigen_values_imag.dims() != values.rows())
eigen_values_imag.resize(values.rows());
//copy the result
for(unsigned int i = 0; i < vectors.rows(); ++i)
for(unsigned int j = 0; j < vectors.cols(); ++j)
{
eigen_vectors_real(i,j) = static_cast<Scalar>(vectors(i,j).real());
eigen_vectors_imag(i,j) = static_cast<Scalar>(vectors(i,j).imag());
}
for(unsigned int i = 0; i < values.rows(); ++i)
{
eigen_values_real[i] = static_cast<Scalar>(values(i,0).real());
eigen_values_imag[i] = static_cast<Scalar>(values(i,0).imag());
}
#elif defined(PHYSIKA_USE_BUILT_IN_MATRIX)
std::cerr<<"Eigen decomposition not implemeted for built in matrix!\n";
std::exit(EXIT_FAILURE);
#endif
}
示例3: save
void save( Archive & ar,
const Eigen::Matrix<T,RowsAtCompileTime,ColsAtCompileTime,Options,MaxRowsAtCompileTime,MaxColsAtCompileTime> & t,
const unsigned int file_version )
{
int n0 = t.rows();
int n1 = t.cols();
ar << BOOST_SERIALIZATION_NVP( n0 );
ar << BOOST_SERIALIZATION_NVP( n1 );
ar << boost::serialization::make_array( t.data(), n0*n1 );
}
示例4: result
inline
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
subtract(const Eigen::Matrix<T1,R,C>& m,
const T2& c) {
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
result(m.rows(),m.cols());
for (int i = 0; i < m.size(); ++i)
result(i) = m(i) - c;
return result;
}
示例5: add
inline
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
add(const T1& c,
const Eigen::Matrix<T2,R,C>& m) {
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R,C>
result(m.rows(),m.cols());
for (int i = 0; i < result.size(); ++i)
result(i) = c + m(i);
return result;
}
示例6: result
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
elt_divide(const Eigen::Matrix<T1,R,C>& m1,
const Eigen::Matrix<T2,R,C>& m2) {
stan::math::validate_matching_dims(m1,m2,"elt_multiply");
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
result(m1.rows(),m2.cols());
for (int i = 0; i < m1.size(); ++i)
result(i) = m1(i) / m2(i);
return result;
}
示例7: multiply
inline
Eigen::Matrix<fvar<typename stan::return_type<T1,T2>::type>, R2, C2>
multiply(const Eigen::Matrix<fvar<T1>, R2, C2>& m, const T2& c) {
Eigen::Matrix<fvar<typename stan::return_type<T1,T2>::type>,R2,C2> res(m.rows(),m.cols());
for(int i = 0; i < m.rows(); i++) {
for(int j = 0; j < m.cols(); j++)
res(i,j) = to_fvar(c) * m(i,j);
}
return res;
}
示例8: result
inline Eigen::Matrix<T,R,C>
cumulative_sum(const Eigen::Matrix<T,R,C>& m) {
Eigen::Matrix<T,R,C> result(m.rows(),m.cols());
if (m.size() == 0)
return result;
result(0) = m(0);
for (int i = 1; i < result.size(); ++i)
result(i) = m(i) + result(i-1);
return result;
}
示例9: matrixString
std::string matrixString(const Eigen::Matrix<T, R, C>& m)
{
if (m.rows() > 0 && m.cols() > 0)
{
return std::string((char *) m.data(), m.size() * sizeof(T));
} else
{
return "";
}
}
示例10: check_square
inline bool check_square(const char* function,
const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
const char* name,
T_result* result) {
check_size_match(function,
y.rows(), "Rows of matrix",
y.cols(), "columns of matrix",
result);
return true;
}
示例11: check_cov_matrix
inline bool check_cov_matrix(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y) {
check_size_match(function,
"Rows of covariance matrix", y.rows(),
"columns of covariance matrix", y.cols());
check_positive(function, "rows", y.rows());
check_symmetric(function, name, y);
check_pos_definite(function, name, y);
return true;
}
示例12: to_fvar
inline
Eigen::Matrix<fvar<T>,R,C>
inverse(const Eigen::Matrix<fvar<T>, R, C>& m) {
using stan::math::multiply;
stan::math::validate_square(m, "inverse");
Eigen::Matrix<T,R,C> m_deriv(m.rows(), m.cols());
Eigen::Matrix<T,R,C> m_inv(m.rows(), m.cols());
for(size_type i = 0; i < m.rows(); i++) {
for(size_type j = 0; j < m.cols(); j++) {
m_inv(i,j) = m(i,j).val_;
m_deriv(i,j) = m(i,j).d_;
}
}
m_inv = m_inv.inverse();
m_deriv = -1 * multiply(multiply(m_inv, m_deriv), m_inv);
return to_fvar(m_inv, m_deriv);
}
示例13: average_onto_vertices
IGL_INLINE void igl::average_onto_vertices(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &V,
const Eigen::Matrix<I, Eigen::Dynamic, Eigen::Dynamic> &F,
const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &S,
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &SV)
{
SV = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>::Zero(V.rows(),S.cols());
Eigen::Matrix<T, Eigen::Dynamic, 1> COUNT = Eigen::Matrix<T, Eigen::Dynamic, 1>::Zero(V.rows());
for (int i = 0; i <F.rows(); ++i)
{
for (int j = 0; j<F.cols(); ++j)
{
SV.row(F(i,j)) += S.row(i);
COUNT[F(i,j)] ++;
}
}
for (int i = 0; i <V.rows(); ++i)
SV.row(i) /= COUNT[i];
};
示例14: result
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
elt_divide(const Eigen::Matrix<T1,R,C>& m1,
const Eigen::Matrix<T2,R,C>& m2) {
stan::math::check_matching_dims("elt_divide(%1%)",m1,"m1",
m2,"m2",(double*)0);
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C>
result(m1.rows(),m2.cols());
for (int i = 0; i < m1.size(); ++i)
result(i) = m1(i) / m2(i);
return result;
}
示例15: check_vector
inline bool check_vector(const char* function,
const char* name,
const Eigen::Matrix<T, R, C>& x) {
if (R == 1)
return true;
if (C == 1)
return true;
if (x.rows() == 1 || x.cols() == 1)
return true;
std::ostringstream msg;
msg << ") has " << x.rows() << " rows and "
<< x.cols() << " columns but it should be a vector so it should "
<< "either have 1 row or 1 column";
std::string msg_str(msg.str());
invalid_argument(function,
name,
typename scalar_type<T>::type(),
"(", msg_str.c_str());
return false;
}