Row-wise operation using `map`?

I am translating my CPU code to GPU. One of the things I did in CPU is to apply map to a Vector{Matrix{Real}} data for row-wise operations. For instance:

julia> aa = [[1. 2. 3.],
             [4. 5. 6.]]
2-element Vector{Matrix{Float64}}:
 [1.0 2.0 3.0]
 [4.0 5.0 6.0]

julia> map(x->sum(x), aa)
2-element Vector{Float64}:
  6.0
 15.0

. However, Cuda does not take Vector{Matrix{..}} type of arrays. I am wondering whether there are ways to work around the issue and allow me to use map for row-wise operations.

I know I can use sum(aa, dims=2) in Cuda instead of map to get the same result, but the sum in the above MWE is really just an example for illustrative purposes. In my real work, it’s more like map(x -> myfun(x), aa), where myfun() takes in a vector and returns a scalar, and I want to apply it to every row of aa.

Thanks in advance.

How about mapslices

julia> aa = [1. 2. 3.; 4. 5. 6.]
2×3 Matrix{Float64}:
 1.0  2.0  3.0
 4.0  5.0  6.0

julia> mapslices(sum, aa; dims=2)
2×1 Matrix{Float64}:
  6.0
 15.0
3 Likes

It looks to be the answer. Thanks a lot!