Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.6.15"
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

Expand Down
1 change: 1 addition & 0 deletions src/StructArrays.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module StructArrays

using Base: tail
import Random

export StructArray, StructVector, LazyRow, LazyRows
export collect_structarray
Expand Down
3 changes: 3 additions & 0 deletions src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ for type in (
end
end

Random.rand(r::Random.AbstractRNG, X::StructArray, dims::Random.Dims) =
Random.rand!(r, similar(X, Random.gentype(X), dims), X)

function showfields(io::IO, fields::NTuple{N, Any}) where N
print(io, "(")
for (i, field) in enumerate(fields)
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ end
@test isempty(s.b)
end

@testset "rand" begin
s = StructVector(a = [1, 2, 3], b = ["a", "b", "c"])
@test rand(s)::NamedTuple ∈ s
@test rand(s, 2)::StructVector ⊆ s
end

@testset "constructor from existing array" begin
v = rand(ComplexF64, 5, 3)
t = @inferred StructArray(v)
Expand Down