Boost logo

Ublas :

Subject: Re: [ublas] prod function usage
From: Umut Tabak (u.tabak_at_[hidden])
Date: 2011-05-23 02:57:55

On 05/23/2011 08:20 AM, Ungermann, Jörn wrote:
> Hi Umut,
>> Ok I guess I located the source of the problem, how should I conduct an
>> operation like,
>> A = A - shift * B;
>> efficiently in ublas where A and B are compressed_matrix<double> and
>> shift is a scalar.
Hi Jorn,

Thanks for the explanation
> If you have really big matrices, this is actually a bit difficult. If A and
> B have the same sparsity structure, or at least if every non-zero element of
> B is also non-zero in A, you might get around with
> A.minus_assign(shift * B)
> However, I fear that this might be very inefficient (haven't tested it).
> Under said pre-condition, one should be able to write a rather efficient
> routine, though, in case the above expression doesn't perform.

You mean some kind of iterating over rows of the sparse matrix?
> One usually only multiplies such a sparse matrices with vectors, but does
> not modify it.
That is right, this is the result of a shift operation for a lanczos
eigenvalue solver, where A might be singular, so just to get rid of the
> I try to avoid such scenarios but not modifying a matrix, but by instead
> defining a functor that behaves as my target matrix, but which is
> constructed from subelements.
This is a bit vague for me , can you give a small example, along with
some code preferably?

Best regards,