Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-09-20 15:08:20


Am Donnerstag, 20. September 2007 11:44 schrieb Vardan Akopian:
> Given 2 sparse
> matrices a and b, it looks like doing
> noalias(b) = a
> does not transfer a's full structure to b, i.e. a's structural 0's
> are lost. For example after that assignment a.nnz() may not be equal
> to b.nnz(). Note that, "b = a" works as expected. So is this intended
> behavior?

The answer can be found in matrix_assign.hpp at line 922. There is a
check if the value to be assigned is zero. When this is true the
assignment is skipped.

The expression noalias(b)=a is equivalent to b.assign(a) which directly
calls the matrix_assign mentioned above. Thus all stored zeroes are
dropped.

The expression b=a does the same in most cases. Only if b and a are of
the same type the assignment is optimized (see matrix.hpp line 2862) to
exactly copy all internal arrays. Thus the structure is preserved.

We can now discuss whether this is a bug (missing optimization of
assign) or a design decision. What do you think?

IMO the behavior of operator = () and assign should be identical.

mfg
Gunter