Re: [eigen] DenseBase<Derived>::Zero initialization problem

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


BTW: What happens if you do Mat x = Mat::Zero(10.0); ? Perhaps conversion from double or float work, because those types are "differentiable", as opposed to int.

On Wed, Jun 22, 2022 at 5:13 AM Oleg Shirokobrod <oleg.shirokobrod@xxxxxxxxx> wrote:
Hi,

In the file CwiseNullaryOp.h the functions DenseBase<Derived>::Zero call function DenseBase<Derived>::Constant which uses Scalar(0) for zero-initialization. It gives compilation error for this line 
using Mat = Eigen::Matrix<std::complex<ceres::Jet<double, 3>>, -1, 1, 0, -1, 1>; 
Mat x = Mat::Zero(10);
Here ceres::Jet<double, 3> is autodif type in ceres-solver. The problem is that it is not always possible to make conversion from int. From the other side for non-class-type scalar values, Scalar() provides a temporary which is zero-initialized. It is likely that for custom numerical class types Scalar() provides zero-initialized temporary. This is the case for Jet. When I replaced 

return Constant(size, Scalar(0)); 

with 

return Constant(size, Scalar()); 

in all Zero and setZero functions, code was compiled without errors.

Best,

Oleg



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/