ginkgo icon indicating copy to clipboard operation
ginkgo copied to clipboard

Add array collection type

Open MarcelKoch opened this issue 1 year ago • 6 comments

This PR adds a type collection::array which is a std::vector like class that stores multiple arrays. These arrays are all subviews of a shared buffer.

I think technically this could be considered as a batch::array, but I'm not sure if we want to go that way. As a batch::array this would interleave the dependencies between the batched and non-batched stuff, and I'm not sure if that is a good idea.

Used in: #1543

MarcelKoch avatar Feb 14 '24 16:02 MarcelKoch

Do you actually need these individual sub-ranges to be materialized as array views? Because otherwise this is just the typical row_ptr - col_idxs structure, and we might be better served with a fully functional std::span replacement and a range-of-ranges interface

upsj avatar Feb 14 '24 18:02 upsj

At least for CPU kernels the arrays are quite handy. But you're right, something like std::span would be better suited.

MarcelKoch avatar Feb 14 '24 18:02 MarcelKoch

I've had it in my mind to provide a nice abstraction over these segmented arrays (including range-for support) for a while already, if you want I can resurrect my prototype code

upsj avatar Feb 14 '24 18:02 upsj

Sure, if it's not too much work, we could use that. I can also take that over if you want.

MarcelKoch avatar Feb 14 '24 18:02 MarcelKoch

~~@upsj maybe this could be formulated using ranges and accessors. Accessing the segmented array could be thought of as [i][j], where i is the array index, and j the index within the array. But I don't know enough of ranges and accessor to judge if that would be appropriate.~~

I don't think that is a good abstraction, since the size per dimension isn't constant.

MarcelKoch avatar Feb 16 '24 15:02 MarcelKoch

@upsj I don't think this will change with the segmented ranges at all. The ranges are only relevant on the backend side. The index_map has this type as constructor parameter, and accessors to it, so I would not put it into the detail namespace.

MarcelKoch avatar May 02 '24 16:05 MarcelKoch

Maybe also update the PR name ?

pratikvn avatar May 03 '24 09:05 pratikvn