问题描述
使用Eigen库时出现错误,我要做的就是从Eigen :: VectorXf中减去标量。因此,我的代码如下:
I am having an error when using the Eigen library and all I am trying to do is subtract a scalar from an Eigen::VectorXf. So, my code is something as follows:
#define VECTOR_TYPE Eigen::VectorXf
#define MATRIX_TYPE Eigen::MatrixXf
// myMat is of MATRIX_TYPE
JacobiSVD<MATRIX_TYPE> jacobi_svd(myMat,ComputeThinU | ComputeThinV);
const float offset = 3.0f;
VECTOR_TYPE singular_values = jacobi_svd.singularValues();
VECTOR_TYPE test = singular_values - offset;
最后一行导致编译错误为:
The last line results in a compilation error as:
Eigen / src / Core /../ plugins / CommonCwiseBinaryOps.h:19:28:注意:
候选模板已忽略:与$ b不匹配$ b'MatrixBase'与'float'
EIGEN_MAKE_CWISE_BINARY_OP(operator-,internal :: scalar_difference_op)
Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h:19:28: note: candidate template ignored: could not match 'MatrixBase' against 'float' EIGEN_MAKE_CWISE_BINARY_OP(operator-,internal::scalar_difference_op)
推荐答案
最简单的方法是转到所谓的 array 世界:
The simplest is to move to the so called "array" world:
VECTOR_TYPE test = singular_values.array() - offset;
这篇关于本征:从向量中减去标量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!