Algebraic-Programming / ALP

Home of ALP/GraphBLAS and ALP/Pregel, featuring shared- and distributed-memory auto-parallelisation of linear algebraic and vertex-centric programs. Soon with more to come!
Apache License 2.0
24 stars 4 forks source link

Provide the implementation of maxPerRow(Matrix result, Matrix input) #296

Open aleksamilisavljevic opened 5 months ago

aleksamilisavljevic commented 5 months ago

Provide the implementation of the function that keeps only the maximal value per row of the input matrix.

In the case of ties, the one with the greatest column index is kept.

anyzelman commented 5 months ago

Hi Aleksa -- for this one, I believe the implementation can be put on top of the core primitives, rather than providing a new core primitive (I'm not sure which road you're taking at the moment).

The idea would be to use a foldl (or foldr) that goes from a matrix to a vector using a max-monoid. For that reason, it may also not really be necessary to provide this as a separate function-- or is there some compelling reason or intended functionality that I might be overlooking?

aleksamilisavljevic commented 5 months ago

Hi, regarding this, yes that approach is mentioned by David in his thesis. However, that approach also requires using operators on indices (to break ties between multiple maximums in the same row).

Do we support this kind of functionality, i.e. operators on indices?

anyzelman commented 5 months ago

The eWiseLambda (on matrices) could do that. If I recall correctly, the idea was we'd use foldl to figure out the max, then once we have the max, copy the matrix and replace the max values with their column indices + 1, and then do another foldl to figure out the "tie-broken" indices that correspond to the max. (Here 0 dubs as "this is not a max", hence the +1 -- perhaps more elegant is to tie-break using minimum instead, so that we can use SIZE_MAX as the "this is not a max".) I don't recall any other more elegant way of doing it

aleksamilisavljevic commented 5 months ago

Sure, that's the road I'll take then. Also, please correct me if I'm wrong, but we don't have a primitive of folding from matrix to vector, but it should be easily implementable, right?