Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support map with GPU arrays #305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ function Base.showarg(io::IO, s::StructArray{T}, toplevel) where T
toplevel && print(io, " with eltype ", T)
end

Base.map(f, s::StructArray) = f.(s)

# broadcast
import Base.Broadcast: BroadcastStyle, AbstractArrayStyle, Broadcasted, DefaultArrayStyle, Unknown, ArrayConflict
using Base.Broadcast: combine_styles
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,15 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayS
@test @inferred(bcmul2(sa)) isa StructArray
@test backend(bcmul2(sa)) === backend(sa)
@test (sa .+= 1) === sa

@test_broken collect(sa)

a2 = map(x -> real(x) + 1, sa)
@test a2::JLArray == sa.re .+ 1
sa2 = map(x -> x + 1, sa)
@test sa2.re::JLArray == sa.re .+ 1
sa3 = map(x -> (a=x + 1, b=x.re + x.im), sa)
@test sa3.b::JLArray == sa.re .+ sa.im
end

@testset "StructSparseArray" begin
Expand Down
Loading