3
$\begingroup$

Is there any function to create or change a matrix, to have $A_{ij} = \text{abs}(A_{ij})$ in PETSc? If possible it should work with MPIAIJ matrices, not only local.

$\endgroup$

closed as off-topic by GoHokies, Kirill, nicoguaro Mar 15 '18 at 16:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0
$\begingroup$

Though this question is about a particular functionality of an individual library, I stumbled upon the same problem some time ago.

As far as I know, there is no ready matrix function in PETSc (3.8.3) that will do it for you right out-of-the-box. I was surprised not to find a solution back a couple of years ago and now, considering the existence of such functions as:

Considering that element-wise Re, Im, and conjugation operations on matrices are supported, I would assume that all the necessary building blocks for the MatAbs are there, but not formally coded up.

From MatRealPart subroutine source code, the following excerpt is doing the job

(*mat->ops->realpart)(mat);

The list of supported and propagated operations on matrices is stored in include/petscmat.h in MatOperation typedef. Technically, you can code up your own operation and propagate it to the datatypes you require (maybe, even by using custom user matrix MatOperation and MatShellSetOperation). However, the question is if such a development is worth the required time and pain.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.