Boost logo

Ublas :

Subject: Re: [ublas] (plus) assign a value with m(i, j) = x and with m.insert_element(i, j, x) in mapped_matrix?
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-02-03 11:02:04

Tim Odenthal wrote:

> Hi!
> Why should(n't) I use m.insert_element(i,j, x) to assign an element to the
> mapped_matrix m? What is the advantage/ difference compared to using
> m(i,j) = x?
> Thanks in advance
> Tim

I'm not very familiar with the mapped_matrix, but as the name states it, I
would bet on m.insert_element(i,j, x) being more efficient than m(i,j) = x.

As you may know, operator[] on a map is equivalent to


i.e., it inserts an empty element to be able to return a reference to
.second which then gets a value copied to if you do the assignment. With
.insert, there's just the immediate insertion. On the other hand, the
operator[] syntax is much more convenient, so when it's not too time
critical, you could choose for the latter.