Re: [eigen] Overflow in sum() |

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Overflow in sum()*From*: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>*Date*: Wed, 1 Apr 2009 21:07:32 +0200*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=+hgG9z32CdhpJ0cUV0JASlh2FJupzC5ej12L35NjrLw=; b=XjhT9EaDEQmhiAAu/yDshgh/V3fkLShRf2ubqxqePcs8+uwa88K2wLbKn9GjaVPMK/ lHnhVeUARq+3lhdOitX36N9S6il/sFFvzd9EvMuDlnRtSRPrrOnUF0679gTtqXNNjCvk VyBHd/h005kGRKJViu7HGC+DDE7qBN34AD9OI=*Domainkey-signature*: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=Wg4OJKOfOfurn+wmRfiZXpRvSO44Qg7FkSvrypC1CCKNgQxR0VYPMiC6qa0CKSpCTI iSXRwoC4aaxTkwlYp2YQpljgBQyoyq104mPkVxBPREh6mxpp+BI7CMl0IuNWbAYgBDy0 R0GlY08uvf9fxn8jGIKebris/BwYTmtmBCwBw=

ah that's yet another different problem... with sparse matrices, the overflow problem arises only with a few operations like sum(). But with what you say, dense matrices of uint8, the overflow can happen with a lot more operations: for example, any matrix product will typically overflow! So I guess that a matrix product of unit8 matrices should return a matrix with a bigger scalar type... So how are you dealing with that: -are you simply not doing matrix products? -or do your matrices happen to be sparse? -do you mean that you would need Eigen's matrix product to potentially return a matrix with a different scalar type? The latter would be problematic because there is no universal good choice. The produce of two uint8 matrices should be a uint16 matrix ? or a uint32 matrix? That depends on the matrix size which is not necessarily known at compile time. Only the user knows what's best in his context. So the best approach then would be to let him specify manually the accumulation type for a matrix, but that would be another template parameter, would add more complexity everywhere, etc, so while that seemed potentially OK for sparse matrices i'm very reluctant to do it for dense ones... This is starting to look like a potentially very big discussion that we aren't going to solve easily! Cheers, Benoit 2009/4/1 Patrick Mihelich <patrick.mihelich@xxxxxxxxx>: >> It depends how common your use case is: if many people are going to do >> the same, we could have another template parameter for sparse >> matrices, the "accumulated scalar type", decoupled from the "scalar >> type". > > I also have this use case, and not only for sparse matrices. I often use > uint8 arrays, either because I'm dealing with images or when I have some > floating-point feature vector that I quantize to uint8 for better time & > space efficiency. It would be *awesome* if Eigen had good support (SSE, > etc.) for small integer types; I already have code where I am using Eigen > for manipulating float feature vectors and my own ugly hand-rolled SSE stuff > for the quantized uint8 feature vectors. This does require choosing the > accumulation type intelligently, and maybe the unsigned types have their own > issues. > > An approach that has worked nicely for me is to use a very simple > metaprogram: > > template<typename T> struct Accumulation { typedef T type; } > template<> struct Accumulation<unsigned char> { typedef unsigned int type; } > // etc. > > Then it is very easy for the user to define an accumulated scalar type > different from the custom scalar type using partial specialization, and this > type can be used transparently throughout Eigen. > Patrick >

**Follow-Ups**:**Re: [eigen] Overflow in sum()***From:*Christian Mayer

**References**:**[eigen] Overflow in sum()***From:*Jens Mueller

**Re: [eigen] Overflow in sum()***From:*Benoit Jacob

**Re: [eigen] Overflow in sum()***From:*Patrick Mihelich

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Overflow in sum()** - Next by Date:
**Re: [eigen] Overflow in sum()** - Previous by thread:
**Re: [eigen] Overflow in sum()** - Next by thread:
**Re: [eigen] Overflow in sum()**

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