Re: [eigen] SparseMatrix<> constructor

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


Hello Bernard,

sorry for the delay,

yes such a "triplet" constructor has already been requested/suggested
a few weeks ago. However, I'm still not sure how to expose it:

- via a simple ctor
- via a tiny "TripletSparseWrapper" with some more advanced features....*

or maybe both, the former being implemented on top of the later...

Also, once we have the triplet it is probably more efficient to run a
quick sort on them rather than doing random insertions....

gael

On Fri, Jul 16, 2010 at 2:19 PM,  <bernard.hugueney@xxxxxxxxxx> wrote:
>
> Hi,
>
>
>
> I'd have a need for such a constructor :
>
> template<typename ValIt, typename Idx1It, typename Idx2It>
>
> SparseMatrix(ValIt vals_begin, ValIt vals_end, Idx1It idx1_begin,
>
> Idx2_begin);
>
>
>
> that would be equivalent to :
>
>
>
> template<typename SparseType, typename ValIt, typename RowsIt, typename
>
> ColsIt>
>
> SparseType construct(typename ei_traits<SparseType>::Index rows_size,
>
> typename ei_traits<SparseType>::Index cols_size
>
> , ValIt vals_begin, ValIt vals_end, RowsIt rows_begin, ColsIt cols_begin){
>
>
>
> SparseType r(rows_size, cols_size);
>
> {
>
>   RandomSetter<SparseType > setter(r);
>
>   for(; vals_begin != vals_end; ++vals_begin, ++rows_begin,
>
> ++cols_begin){
>
>        setter(*rows_begin, *cols_begin)= *vals_begin;
>
>   }
>
> }
>
> return r;
>
> }
>
>
>
> Isn't such use case common enough to warrant an appropriate constructor
>
> for SparseMatrix ?
>
>
>
> Best Regards,
>
> Bernard
>
>
>



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