<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="863801721" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/19948" data-hovercard-type="pull_request" data-hovercard-url="/scikit-learn/scikit-learn/pull/19948/hovercard" href="https://github.com/scikit-learn/scikit-learn/pull/19948">#19948</a> introduces <code class="notranslate">available_if</code> which fixes some issues and is easier to write and understand. We should use it instead of <code class="notranslate">if_delegate_has_method</code> in our own codebase, and encourage third party developers to use it as well.</p>
<p dir="auto">This issue is to let people replace the usage one module at a time, and update the documentation of <code class="notranslate">if_delegate_has_method</code> to reflect that people should use <code class="notranslate">available_if</code> instead.</p>
<p dir="auto">Any thoughts before we open this for contributors <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jnothman/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jnothman">@jnothman</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/thomasjpfan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/thomasjpfan">@thomasjpfan</a> ?</p>
<h4 dir="auto">Description</h4>
<ul dir="auto">
<li>
<p dir="auto">There is code / logic duplication between <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/dict_learning.py#L387"><code class="notranslate">decomposition.dict_learning.py.dict_learning</code> </a>and <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/dict_learning.py#L561"><code class="notranslate">dict_learning_online</code></a>. Formally, the code should be equivalent except, that</p>
<ul dir="auto">
<li>for the former the codes should be computed all at once (<code class="notranslate">batch_size = n_samples</code>) and this process iterated (alternating BCD, as it's already done), whilst</li>
<li>for the latter the each sample point's code is computed as the sample is pooled-in. The <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/dict_learning.py#L312">dictionary update function </a>should the same in both case (<a href="https://hal.inria.fr/inria-00408716v1/document" rel="nofollow">Alg2 of the ref paper</a>.)</li>
</ul>
</li>
<li>
<p dir="auto">As a side effect of this code duplication, there prototype of backend <code class="notranslate">_update_dict</code> function is somewhat "dangling". E.g the shape of argument <code class="notranslate">code</code> can be <code class="notranslate">(n_components, n_features)</code> or <code class="notranslate">(n_components, n_features)</code> depending on whether it's called from within  <code class="notranslate">dict_learning</code> or <code class="notranslate">dict_learning_online</code> resp.</p>
</li>
</ul>
<h4 dir="auto">Proposal</h4>
<p dir="auto">Have a single function <code class="notranslate">dict_learning_online(batch_size=some_default)</code> which reproduces full-batch mode (the current  <code class="notranslate">dict_learning</code> function)  when <code class="notranslate">batch_size == n_samples</code>.</p>