Re: [eigen] Matrix2i mean |

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Matrix2i mean*From*: Janos Meny <janos.meny@xxxxxxxxxxxxxx>*Date*: Tue, 5 Nov 2019 16:59:07 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to; bh=AJOEoR20Tp97Y8QuB9hKPLpRRqHXyBRVrOPfLRArFeM=; b=TeI/JLcD4IlL7U4sCsGQdG3fKfnQdLXMKdqETbq4F23FSEums8sz7Cct7mthyRNrvn zrnlDjiL3C/neITHDWPB6ofy7BjJy2zlifE0CaDop/KadDgWNZtYjh0kFbXSchGvdQZr X48VGUXoc08ExBmsbGq2W9ouBA1/+zSIH38BiJcTUw+zXYbIy8XEPF9w81yK3IsCkQ8K fojR0XTwSO/HmD7t2qeD9FYZYSoEUUfLHrjDjD+eTuy/1Tuc9jmz1znnb/eDaergb0Ff zWQf6+kD3EwDUu9N7YRvS1rzdgcFPXb+jEh3Xl/2pNobz9xDqSlIGOANE0DlC/DF6Eqx 2kJA==

As far as I know, the template parameter list gets mangled into the symbol name, so adding an additional template parameter will break abi.

On Tue 5. Nov 2019 at 16:44, Petr Kubánek <pkubanek@xxxxxxxxx> wrote:

Hi,

I know what's the problem. I am just looking either to document it or

for a solution.

Why would:

template <typename dt> dt sum()

break API/ABI? You will be able to call either sum() or sum<int32_t>(),

shouldn't you? I will try that and submit a patch.

Having sum<dt>() working, one can hopefully create mean<dt_sum,

dt_mean>(), so one can code:

mean<int32_t,double>()

Petr

On Tue, 2019-11-05 at 16:36 +0100, Christoph Hertzberg wrote:

> On 05/11/2019 16.11, Peter wrote:

> > [...]

> >

> > actually, this would also be interesting for the scalar products

> > in

> > general, namely a different

> > type for accumulating the sums within a scalar product, e.g. as

> > yet

> > another template parameter for the matrices.

>

> Adding another template parameter to basic types is not an option.

> This

> would break ABI and API compatibility (even if the parameter has a

> default).

>

> You could create your own custom type `my_int16` for which `my_int16

> *

> my_int16` results in a `my_int32` (this needs to be told to Eigen,

> similar to how real*complex products are handled).

>

> > > [...]

> >

> > I think it's more subtle than that.

> > Even

> >

> > int16_t Two = 2;

> > int16_t Max = INT16_MAX;

> > int16_t mean = ( Max/2 + Max + Two + Two ) / int16_t(4);

> >

> > doesn't produce an overflow.

>

> Yes, because `Max/2` gets implicitly converted to `int`. Actually,

> even

> adding two `int16_t` get implicitly converted to `int` (search for

> integer promotion rules -- I don't know them entirely either). And

> dividing an `int` by an `int16_t` results in an `int` which is only

> afterwards converted to `int16_t`.

>

> In contrast, Eigen::DenseBase::sum() does something (more or less)

> equivalent to:

>

> T sum = T(0);

> for(Index i=0; i< size(); ++i)

> sum+=coeff(i);

> return sum;

>

> i.e., after each addition the result gets reduced to the scalar type

> of

> the matrix, thus it will immediately overflow.

>

> And mean() essentially just takes the return value of `sum()` and

> divides it by the size.

>

>

> Christoph

>

>

**References**:**[eigen] Matrix2i mean***From:*Petr Kubánek

**Re: [eigen] Matrix2i mean***From:*Peter

**Re: [eigen] Matrix2i mean***From:*Christoph Hertzberg

**Re: [eigen] Matrix2i mean***From:*Peter

**Re: [eigen] Matrix2i mean***From:*Christoph Hertzberg

**Re: [eigen] Matrix2i mean***From:*Petr Kubánek

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Matrix2i mean** - Next by Date:
**Re: [eigen] Matrix2i mean** - Previous by thread:
**Re: [eigen] Matrix2i mean** - Next by thread:
**Re: [eigen] Matrix2i mean**

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