Eigen 是否具有 Python 中的 numpy.arange() 之类的排列函数
Does Eigen have arange function like numpy.arange() in Python
你知道Eigen有没有自己的arange
函数,如果没有,为什么?
目前,我已经使用 Eigen::VectorXd::LinSpaced()
编写了自己的排列函数
/*
* Return evenly spaced values within a given interval.
* Values are generated within the half-open interval [start, stop)
* (in other words, the interval including start but excluding stop).
*/
template <typename Scalar>
Eigen::VectorXd arange(const Scalar start, const Scalar stop, const Scalar step) {
if(step == 0)
throw std::domain_error("Arange's step cannot be 0");
Scalar delta = stop - start;
size_t size = ceil(delta / step);
return Eigen::VectorXd::LinSpaced(size, start, start+(size-1)*step);
}
目前确实有 LinSpaced
可用于此类操作,但在 Eigen 中显然没有 arange
的直接等价物。有working notes related to this (eg. range and iota) but so far nothing appear to be included in the code for that. In the new Eigen 3.4 with a recent C++ version, you can use std::iota
since Eigen now support STL iterators。因此,没有必要在 Eigen 中添加像 arange
这样的功能(实际上 LinSpaced
通常对大多数用户来说已经足够了)。
你知道Eigen有没有自己的arange
函数,如果没有,为什么?
目前,我已经使用 Eigen::VectorXd::LinSpaced()
/*
* Return evenly spaced values within a given interval.
* Values are generated within the half-open interval [start, stop)
* (in other words, the interval including start but excluding stop).
*/
template <typename Scalar>
Eigen::VectorXd arange(const Scalar start, const Scalar stop, const Scalar step) {
if(step == 0)
throw std::domain_error("Arange's step cannot be 0");
Scalar delta = stop - start;
size_t size = ceil(delta / step);
return Eigen::VectorXd::LinSpaced(size, start, start+(size-1)*step);
}
目前确实有 LinSpaced
可用于此类操作,但在 Eigen 中显然没有 arange
的直接等价物。有working notes related to this (eg. range and iota) but so far nothing appear to be included in the code for that. In the new Eigen 3.4 with a recent C++ version, you can use std::iota
since Eigen now support STL iterators。因此,没有必要在 Eigen 中添加像 arange
这样的功能(实际上 LinSpaced
通常对大多数用户来说已经足够了)。