Skip to content

Add copy, dot, axpy! and arithmetic for Vec and Mat - #322

Merged
filoferra merged 1 commit into
JuliaParallel:mainfrom
filoferra:vec-mat-algebra
Oct 28, 2026
Merged

filoferra merged 1 commit into
JuliaParallel:mainfrom
filoferra:vec-mat-algebra

Conversation

@filoferra

Copy link
Copy Markdown
Collaborator

PetscVec gets copy, dot, axpy!, axpby!, rmul!, lmul! and x + y, x - y, -x, α * x, x / α. An assembled PetscMat gets copy, A + B, A - B, -A and α * A.

  • They call the PETSc routines (VecDot, VecAXPY, VecAXPBY, VecScale, VecWAXPY, MatDuplicate, MatAXPY, MatScale), so they're collective and work on distributed objects.
  • dot(x, y) conjugates x, as for Julia arrays (PETSc's VecDot(x, y) is yᴴx, so the call swaps the arguments).
  • x / α divides each entry, so it matches xs ./ α exactly instead of scaling by 1/α.
  • A ± B works when A and B have different nonzero patterns; the result has the union of the two.
  • copy and the operators return a new object. Like a constructor's result, it has a finalizer only on one rank, so on more ranks call destroy! on it.
  • The docs' C-to-Julia index now lists Base and LinearAlgebra methods under their own names (it showed LinearAlgebra.norm as PETSc.LinearAlgebra).

PetscVec gets copy, dot, axpy!, axpby!, rmul!, lmul! and the operators
x + y, x - y, -x, α * x and x / α; an assembled PetscMat gets copy,
A + B, A - B, -A and α * A. They call the PETSc routines (VecDot,
VecAXPY, VecWAXPY, MatAXPY, MatScale, ...), so they are collective and
work on distributed objects, and dot conjugates its first argument as
it does for Julia arrays. The docs index now lists Base and
LinearAlgebra methods under their own names.

Purely additive
@filoferra
filoferra merged commit 7141eeb into JuliaParallel:main Oct 28, 2026
5 checks passed
@filoferra
filoferra deleted the vec-mat-algebra branch October 28, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant