Skip to content

Clarify map/mapreduce's documentation with respect to memoization #55238

@mbauman

Description

@mbauman

This is split out from #53945 (comment):

Both map and mapreduce sometimes re-use return values — most notably with sparse data structures. map's docs don't mention this, whereas mapreduce explicitly allows for it — but neither documentation is ideal. It'd be nice to more finely scope this behavior along the lines of @MasonProtter's comment:

I think it's a sensible corner case to make it clear to people that we're not normally in the buisness of memoizing reductions, but if a datastructure has its own memoization scheme then we'll reserve the right to also take advantage of that.

There are probably more functions like these — including broadcast — that'd be good to evaluate at the same time.

julia> using SparseArrays

julia> map(x->x+rand(), spzeros(3))
3-element SparseVector{Float64, Int64} with 3 stored entries:
  [1]  =  0.538611
  [2]  =  0.538611
  [3]  =  0.538611

julia> broadcast(x->x+rand(), spzeros(3))
3-element SparseVector{Float64, Int64} with 3 stored entries:
  [1]  =  0.983621
  [2]  =  0.983621
  [3]  =  0.983621

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis change adds or pertains to documentationfoldsum, maximum, reduce, foldl, etc.sparseSparse arrays

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions