Skip to content

Commit bbd5414

Browse files
usefulhyunandreasnoack
authored andcommitted
Constructor for SharedMatrix and SharedVector (#28133)
* Constructor by value for SharedVector and SharedMatrix type * Constructor of SharedVector and SharedMatrix * Update SharedArrays.jl * Add tests for new aliased constructors Add tests for SharedVector and SharedMatrix * Update runtests.jl * Update SharedArrays.jl * Update runtests.jl * Update runtests.jl * Update runtests.jl
1 parent 3ee8798 commit bbd5414

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

stdlib/SharedArrays/src/SharedArrays.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,12 @@ function finalize_refs(S::SharedArray{T,N}) where T where N
275275
S
276276
end
277277

278-
279278
const SharedVector{T} = SharedArray{T,1}
280279
const SharedMatrix{T} = SharedArray{T,2}
281280

281+
SharedVector(A::Vector) = SharedArray(A)
282+
SharedMatrix(A::Matrix) = SharedArray(A)
283+
282284
length(S::SharedArray) = prod(S.dims)
283285
size(S::SharedArray) = S.dims
284286
ndims(S::SharedArray) = length(S.dims)

stdlib/SharedArrays/test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,9 @@ let S = SharedArray(Int64[]) # Issue #26582
308308
@test sprint(show, S) == "Int64[]"
309309
@test sprint(show, "text/plain", S, context = :module=>@__MODULE__) == "0-element SharedArray{Int64,1}:\n"
310310
end
311+
312+
#28133
313+
@test SharedVector([1; 2; 3]) == [1; 2; 3]
314+
@test SharedMatrix([0.1 0.2; 0.3 0.4]) == [0.1 0.2; 0.3 0.4]
315+
@test_throws MethodError SharedVector(rand(4,4))
316+
@test_throws MethodError SharedMatrix(rand(4))

0 commit comments

Comments
 (0)