Re: [eigen] Overflow in sum()

[ Thread Index | Date Index | More Archives ]

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

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.


Mail converted by MHonArc 2.6.19+