Stream: helpdesk (published)

Topic: Consistent API for dense and sparse arrays


view this post on Zulip Evan Patterson (Jan 23 2021 at 20:11):

I am finding it awkward to write code that works with both dense and sparse arrays because the APIs differ in subtle ways. Two quick examples:

  1. Initializing zero arrays: you have to use zeros or spzeros instead of something like zero(Vector{Int}, n) and zero(SparseVector{Int}, n).
  2. Iterating over non-zero elements: you have findnz for sparse arrays but not dense ones

Do I just have put up with it and write the helper functions, or are there better options?

view this post on Zulip Jeffrey Sarnoff (Jan 23 2021 at 21:20):

Evan Patterson said:

I am finding it awkward to write code that works with both dense and sparse arrays because the APIs differ in subtle ways. Do I just have to ... write the helper functions, or are there better options?

afaik Writing the smoothing, soothing, API unifying helpers that matter most and keeping them brief an in one place and not so many as to be hard to undo as the actual API s converge (one hopes and expects) while providing the specifics to JuliaArrays as separably approachable issues would be the second best option. Best would be a good clean solution through someone on discourse who has done it.

Also the #arrays channel on Slack (I added you, you can remove you as you please) has people who know more than I about this.

view this post on Zulip Evan Patterson (Jan 23 2021 at 21:28):

Thanks, I may also ask there. It's not too big a deal, but I bet I'm not the first or the last person to encounter this situation.


Last updated: Oct 02 2023 at 04:34 UTC