[petsc-users] Multiplying a row-vector to each row in a dense matrix, sliced or full

Matthew Knepley knepley at gmail.com
Tue Dec 8 12:26:35 CST 2020


On Tue, Dec 8, 2020 at 1:13 PM Roland Richter <roland.richter at ntnu.no>
wrote:

> Hei,
>
> I would like to multiply a row-vector to each row in a dense matrix,
> either full or sliced (i.e. if the row-vector is larger than the row
> length of the matrix). Armadillo offers a each_row()-function, where I
> can iterate over all rows in a matrix and multiply the vector to them
> (similar to the operation VecPointwiseMult()). Is there a similar
> operation in PETSc? Ideally with the option of only multiplying a
> part/slice of the row vector to each row, if the corresponding row of
> the target matrix is shorter than the initial row vector.
>

It helps to write in linear algebra notation so that we can be sure we are
talking
about the same thing. Say we have the matrix A and vector v

  A = / a b \  v = <m, n>
        \ c d /

and you want

  A * m = / ma nb \ = / a b \ / m 0 \ = A . diag(v)
               \ mc nd /    \ c d /  \ 0  n /

which you can get using
https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatDiagonalScale.html

is that what you want? I do not have a clear picture of what you want
slicing for.

  Thanks,

     Matt


> Thanks,
>
> Roland
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20201208/9552b031/attachment.html>


More information about the petsc-users mailing list