[no subject]

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


=D1=81=D1=80, 22 =D0=B8=D1=8E=D0=BD. 2022 =D0=B3. =D0=B2 20:22, Oleg Shirok=
obrod <oleg.shirokobrod@xxxxxxxxx>:

> Hi Rasmus,
>
> You are right. This abbreviated declaration of Jet
>
> template <typename T, int N>
> struct Jet {
>   enum { DIMENSION =3D N };
>   using Scalar =3D T;
>
>   // Default-construct "a" because otherwise this can lead to false error=
s
> about
>   // uninitialized uses when other classes relying on default constructed=
 T
>   // (where T is a Jet<T, N>). This usually only happens in opt mode. Not=
e
> that
>   // the C++ standard mandates that e.g. default constructed doubles are
>   // initialized to 0.0; see sections 8.5 of the C++03 standard.
>   Jet() : a() { v.setConstant(Scalar()); }
>
>   // Constructor from scalar: a + 0.
>   explicit Jet(const T& value) {
>     a =3D value;
>     v.setConstant(Scalar());
>   }
>   // The scalar part.
>   T a;
>
>   // The infinitesimal part.
>   Eigen::Matrix<T, N, 1> v;
> };
> It has default zero initialized CTOR and CTOR initializing Jet from
> floating value. Of course instead of using Mat::Zero() -> return
> Mat::Constant(0) I can use Mat::Constant(0.0).
>
> =D1=81=D1=80, 22 =D0=B8=D1=8E=D0=BD. 2022 =D0=B3. =D0=B2 19:00, Rasmus Mu=
nk Larsen <rmlarsen@xxxxxxxxxx>:
>
>> BTW: What happens if you do Mat x =3D Mat::Zero(10.0); ? Perhaps convers=
ion
>> 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 cal=
l
>>> function DenseBase<Derived>::Constant which uses Scalar(0) for
>>> zero-initialization. It gives compilation error for this line
>>> using Mat =3D Eigen::Matrix<std::complex<ceres::Jet<double, 3>>, -1, 1,=
 0,
>>> -1, 1>;
>>> Mat x =3D 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 tempor=
ary
>>> which is zero-initialized. It is likely that for custom numerical class
>>> types Scalar() provides zero-initialized temporary. This is the case fo=
r
>>> 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
>>>
>>>

--000000000000cb5d4a05e20d155a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Antonio, You are right=C2=A0<div>auto z2 =3D std::complex =
&lt; ceres::Jet&lt;double, 3&gt;&gt;(0.0);<br></div><div>does not work, but=
</div><div>auto z2 =3D std::complex &lt; ceres::Jet&lt;double, 3&gt;&gt;();=
<br></div><div>does work.</div><div><br></div><div>From this discussion=C2=
=A0it seems that the general idea of Zero for custom numerical values is no=
t well=C2=A0defined. Maybe this function must be marked as deprecated=C2=A0=
and only used for primitive types like int, float and double.</div></div><b=
r><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">=D1=81=
=D1=80, 22 =D0=B8=D1=8E=D0=BD. 2022 =D0=B3. =D0=B2 20:22, Oleg Shirokobrod =
&lt;<a href=3D"mailto:oleg.shirokobrod@xxxxxxxxx";>oleg.shirokobrod@xxxxxxxx=
m</a>&gt;:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div =
dir=3D"ltr">Hi Rasmus,<div><br></div><div>You are right. This abbreviated d=
eclaration=C2=A0of Jet</div><div><br></div><div>template &lt;typename T, in=
t N&gt;<br>struct Jet {<br>=C2=A0 enum { DIMENSION =3D N };<br>=C2=A0 using=
 Scalar =3D T;<br><br>=C2=A0 // Default-construct &quot;a&quot; because oth=
erwise this can lead to false errors about<br>=C2=A0 // uninitialized uses =
when other classes relying on default constructed T<br>=C2=A0 // (where T i=
s a Jet&lt;T, N&gt;). This usually only happens in opt mode. Note that<br>=
=C2=A0 // the C++ standard mandates that e.g. default constructed doubles a=
re<br>=C2=A0 // initialized to 0.0; see sections 8.5 of the C++03 standard.=
<br>=C2=A0 Jet() : a() { v.setConstant(Scalar()); }<br><br>=C2=A0 // Constr=
uctor from scalar: a + 0.<br>=C2=A0 explicit Jet(const T&amp; value) {<br>=
=C2=A0 =C2=A0 a =3D value;<br>=C2=A0 =C2=A0 v.setConstant(Scalar());<br>=C2=
=A0 }<br></div><div>=C2=A0 // The scalar part.<br>=C2=A0 T a;<br><br>=C2=A0=
 // The infinitesimal part.<br>=C2=A0 Eigen::Matrix&lt;T, N, 1&gt; v;<br></=
div><div>};</div><div>It has default zero initialized=C2=A0CTOR and CTOR in=
itializing Jet from floating value. Of course instead of using Mat::Zero() =
-&gt; return Mat::Constant(0) I can use Mat::Constant(0.0).</div></div><br>=
<div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">=D1=81=D1=
=80, 22 =D0=B8=D1=8E=D0=BD. 2022 =D0=B3. =D0=B2 19:00, Rasmus Munk Larsen &=
lt;<a href=3D"mailto:rmlarsen@xxxxxxxxxx"; target=3D"_blank">rmlarsen@google=
..com</a>&gt;:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0p=
x 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><d=
iv dir=3D"ltr">BTW: What happens if you do=C2=A0Mat x =3D Mat::Zero(10.0); =
? Perhaps conversion from double or float work, because those types are &qu=
ot;differentiable&quot;, as opposed to int.</div><br><div class=3D"gmail_qu=
ote"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, Jun 22, 2022 at 5:13 AM =
Oleg Shirokobrod &lt;<a href=3D"mailto:oleg.shirokobrod@xxxxxxxxx"; target=
=3D"_blank">oleg.shirokobrod@xxxxxxxxx</a>&gt; wrote:<br></div><blockquote =
class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px sol=
id rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">Hi,<div><br></div><d=
iv>In the file CwiseNullaryOp.h the functions=C2=A0DenseBase&lt;Derived&gt;=
::Zero call function=C2=A0DenseBase&lt;Derived&gt;::Constant which uses Sca=
lar(0) for zero-initialization. It gives compilation error for this line=C2=
=A0</div><div>using Mat =3D Eigen::Matrix&lt;std::complex&lt;ceres::Jet&lt;=
double, 3&gt;&gt;, -1, 1, 0, -1, 1&gt;;=C2=A0</div><div>Mat x =3D Mat::Zero=
(10);<br></div><div>Here ceres::Jet&lt;double, 3&gt; is autodif type in cer=
es-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() p=
rovides a temporary which is zero-initialized. It is likely=C2=A0that for c=
ustom numerical class types Scalar() provides zero-initialized temporary. T=
his is the case for Jet. When I replaced=C2=A0</div><div><br></div><div>ret=
urn Constant(size, Scalar(0));=C2=A0</div><div><br></div><div>with=C2=A0</d=
iv><div><br></div><div>return Constant(size, Scalar());=C2=A0</div><div><br=
></div><div>in all=C2=A0Zero and setZero functions, code was=C2=A0compiled=
=C2=A0without errors.</div><div><br></div><div>Best,</div><div><br></div><d=
iv>Oleg</div><div><br></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>

--000000000000cb5d4a05e20d155a--



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