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

Roland Richter roland.richter at ntnu.no
Tue Dec 8 16:16:29 CST 2020


Yes, that would be exactly what I need, I have not thought about that
possibility, thanks!

Concerning slicing: Assumed my matrix A and vector v are defined by

A = |a b|
       |c d|
v = |w x y z|

After v is larger than the row size of A, I only can take some elements
for multiplication and therefore I have to use only a slice of vector v:

A*v[1:2] =  |xa yb|
                    |xc yd|

or

A*v[0:1] =    |wa xb|
                      |wc xd|

How could I do that?

Thanks,

Roland


Am 08.12.2020 um 19:26 schrieb Matthew Knepley:
> On Tue, Dec 8, 2020 at 1:13 PM Roland Richter <roland.richter at ntnu.no
> <mailto: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
> <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/a73b8caf/attachment.html>


More information about the petsc-users mailing list