Skip to content

Commit

Permalink
Merge pull request #5 from bmxam/dev
Browse files Browse the repository at this point in the history
set_owned_values and fill
  • Loading branch information
bmxam authored Sep 6, 2024
2 parents f5984ef + 3a7a137 commit cebe028
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HauntedArrays"
uuid = "88ea1a40-65ed-4bf4-98f2-fb8783b28482"
authors = ["bmxam <[email protected]>"]
version = "0.1.2"
version = "0.1.3"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
2 changes: 2 additions & 0 deletions src/Array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Build a view of the parent array, with the elements that are owned by the curren
"""
@inline owned_values(A::HauntedArray) = view(parent(A), _own_to_local_ndims(A)...)

@inline set_owned_values(A::HauntedArray, B::AbstractArray) = owned_values(A) .= B

"""
Transform a `Vector` index into a Vector of nd-CartesianIndices
(assuming same length in all Array direction)
Expand Down
3 changes: 2 additions & 1 deletion src/HauntedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export HauntedArray,
local_to_global,
local_to_part,
n_local_rows,
n_own_rows
n_own_rows,
set_owned_values

include("./interface.jl")
include("./collective.jl")
Expand Down
8 changes: 8 additions & 0 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ function LinearAlgebra.mul!(
C
end

function LinearAlgebra.norm2(A::HauntedVector)
# MPI.Allreduce(LinearAlgebra.norm2(owned_values(A)), +, get_comm(A))
(mapreduce(abs2, +, A))
end
function LinearAlgebra.dot(A::HauntedVector, B::HauntedVector)
MPI.Allreduce(LinearAlgebra.dot(owned_values(A), owned_values(B)), +, get_comm(A))
end

for f in (:+, :-)
@eval function (Base.$f)(A::HauntedArray, B::HauntedArray)
_C = $f(parent(A), parent(B))
Expand Down
7 changes: 7 additions & 0 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@ function Base.view(A::HauntedVector, I::AbstractVector)

return HauntedArray(array, exchanger, lid2gid, lid2part, oid2lid, cacheType)
end

# Usefull in case of wrapped sparse matrix. Maybe it would more clever to specialize
# directly Base.eachindex?
function Base.fill!(A::HauntedArray, x)
fill!(parent(A), x)
return A
end

0 comments on commit cebe028

Please sign in to comment.