<p dir="auto">I have been looking at the plethora of issues and attempts to fix sparse arrays and broadcast. For anyone not caught up on the general strife, here is a rough (although very incomplete) overview.</p>
<h1 dir="auto">Current Problems:</h1>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="194884848" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/19561" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/19561/hovercard" href="https://github.com/JuliaLang/julia/issues/19561">#19561</a>: broadcasting non numeric arrays causes problems because <code class="notranslate">zero(::Type{Any})</code> doesn't exist<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="190605592" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/19372" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/19372/hovercard" href="https://github.com/JuliaLang/julia/issues/19372">#19372</a>: When should broadcast return dense vs sparse arrays?</p>
<h1 dir="auto">Current Consensus:</h1>
<p dir="auto">Implement zero for strings</p>
<ul dir="auto">
<li><code class="notranslate">f(A)</code> returns sparse if <code class="notranslate">A</code> is sparse, and <code class="notranslate">f</code> is  zero preserving.</li>
<li><code class="notranslate">f(A,B)</code> returns sparse if <code class="notranslate">A</code> and <code class="notranslate">B</code> are sparse, and <code class="notranslate">f</code> is  zero preserving on either both or one of the zeros.</li>
<li>higher order cases get complicated quickly.</li>
</ul>
<h1 dir="auto">Proposed Solution:</h1>
<p dir="auto">Implement a new type of sparse array that can have a custom set default element.<br>
For the first issue, this allows the simple solution of making the default element <code class="notranslate">''</code> which will allow broadcasts to work sensibly.<br>
For the second, we get the quite nice property that <code class="notranslate">f(A,B...X</code>) can be done by iterating over the nonzero values of all the various arrays, and then switching the default value to <code class="notranslate">f(0,0...0)</code>. This will be simple to code, and will contain almost all of the advantages of the current approach.</p>
<p dir="auto">Is there any practical way to achieve this? Consider: I have a very large matrix describing edge weights between all pairs of vertices. This is an NxN matrix and is impractical for graphs with orders of 1e7 without using sparse matrices.</p>
<p dir="auto">If I want the default edge weight of 1.0, I have to code specially around this to make a sparse matrix entry of "0" really be "1" (which is ok in this specific case because an edge weight of 0 is not defined). It would be much easier if I could specify "create this sparse matrix but any unspecified value should be X".</p>
<p dir="auto">Is there already an easy way to do this that I've missed?</p>