dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #09885
Matrix aritmetic operators
Hello!
Occasionally we have had some discussion about implementing a basic aritmetic
operators for matrices in DOLFIN. I have been able to add -=, +=, +, -,
operators, for the PETScMatrix interface, using the petsc function MatAXPY. I
also implemented both assignment operators.
I added a public function add(A,a), which add a GenericMatrix, A, scaled by a,
to the present matrix. This is a usefull funtion when combining matrices in a
linear algebra setting. The function is also used to implement the +=,
and -=, which then are used to implement +, - together with the assignment
operator.
Is this something we want? I would at least like it to happen :)
Do I miss any important aspects? What about two distributed matrices? Will
PETSc AXPY take care of this, (supposing of course that the matrices have the
same number of nonzeros)?
If we add the "add" function in the GenericMatrix interface we could implement
the +=, -= operators directly in the GenericMatrix interface, together with
both + and - using +=, -=. This is a good solution for at least PETSc and
Epetra Matrix that do not implement its own += and -=, which uBLAS and MTL4
do.
I have it going for PETScMatrix. Should I implement this interface to
GenericMatrix, and update the other dolfin Matrix classes too? The changes in
GenericMatrix would be:
1) remove explicit from the copy constructor, to allow "return by value"
2) add virtual add(const GenericMatrix, real a) = 0
3) implement +=, -= using the add function.
4) implement +, - using the +=, -=
The changes in the other Matrix classes would be:
For PETSc, and Epetra Matrices.
1) Implement add(A,a)
2) Implement operator=(A)
I can make the changes in GenericMatrix, and implement the interface for
PETSc, Epetra, and I could update GenericMatrix too. If we want to use
uBLAS's += -=, and I suppose we want, we need to overload these functions in
the uBLAS interface, with the proposed implementation. Are there any similare
functionality to PETSc's AXPY in uBLAS, for implementing an "add" function?
I suppose uBLAS and MTL4 are similare with respect to implementation.
Johan
Follow ups