Boost logo

Boost :

From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2002-05-02 07:01:47


On Wednesday 01 May 2002 21:17, Joerg Walter wrote:
> ----- Original Message -----
> From: "Toon Knapen" <toon.knapen_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Tuesday, April 30, 2002 6:09 PM
> Subject: [boost] ublas: matrix clear() and operator=
>
> > Currently, the matrices can be clear()-ed such that all elements are set
> > to 0. I would find it even more convenient to be able to use
> > operator=(some_value_type) to assign a specific value to all the entries
> > in the matrix.
>
> How would you define the semantics of such an assignment operator for
> sparse matrices?

I think it should set all non-zeros to 0.

>
> > But I figure there's some good reason one has to use clear()
> > instead of operator=() ?
>
> Do you think, it would be worthy to add something like zero_vector<> and
> zero_matrix<> to allow for syntactic sugar like m = zero_matrix<>()?

This would be fine. Indeed as peter remarked, using operator=(double) it
might not be clear if only the diagonal elements are assigned or the whole
matrix. But although I regularly have to set all elements to 0, it should be
possible to use the same operation to set all elements to some specific
value, eventually different from 0.

As to why I need this clear() functionality : When assembling all local
contributions of my finite elements into a large sparse matrix, I'm looping
over a routine which gets as an (writeable) argument a matrix big enough to
store its contribution in (to prevent allocating a new matrix at every call).
In some occasions, not all elements in this matrix will be assigned to and
thus I have to be sure that these other entries are set to zero. The best way
to do this is to clear the matrix before assigning to some of the entries in
the matrix. And although I also would fancy initialising constructors, this
is not sufficient in my case.

toon


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk