[petsc-users] Sum of the absolute values of each row's components

Matthew Knepley knepley at gmail.com
Mon May 24 20:21:04 CDT 2021


On Mon, May 24, 2021 at 9:19 PM Matthew Knepley <knepley at gmail.com> wrote:

> On Mon, May 24, 2021 at 9:08 PM Salazar De Troya, Miguel via petsc-users <
> petsc-users at mcs.anl.gov> wrote:
>
>> Hello,
>>
>>
>>
>> I am simply interested in obtaining a vector with x_i = \sum_j | A_{i, j}
>> | for each row “i” in the matrix A. I found MatGetColumnNorms(), but no row
>> version. I am wondering if it is more efficient to calculate the transpose
>> A^T and then MatGetColumnNorms() or maybe iterate through each row with
>> MatGetRow() and calculate \sum_j | A_{i, j} | by hand by myself.
>>
>
> Vec ones, sums;
>
> MatCreateVecs(A, &ones, &sums);
> VecSet(ones, 1.0);
> MatMult(A, ones, sums);
> VecDestroy(&ones);
> VecDestroy(&sums);
>

This does the row sum, not the absolute value. If you want the absolute
value, you can just call MatGetRow() and sum the values.

  Thanks,

     Matt


>   Thanks,
>
>     Matt
>
>
>>
>>
>> Thanks
>>
>> Miguel
>>
>>
>>
>> Miguel A. Salazar de Troya
>>
>> Postdoctoral Researcher, Lawrence Livermore National Laboratory
>>
>> B141
>>
>> Rm: 1085-5
>>
>> Ph: 1(925) 422-6411
>>
>
>
> --
> 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/>
>


-- 
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/20210524/7923f999/attachment-0001.html>


More information about the petsc-users mailing list