initial docs for omit_nan() and omit_nonfinite()

This commit is contained in:
conrad
2025-06-23 14:18:33 +10:00
parent 869c46e39b
commit 42022c75e3
+118 -70
View File
@@ -418,42 +418,43 @@ Conrad Sanderson and Ryan Curtin.
<tr><td><a href="#logmat">logmat</a></td><td>&nbsp;</td><td>matrix logarithm</td></tr>
<tr><td><a href="#logmat_sympd">logmat_sympd</a></td><td>&nbsp;</td><td>matrix logarithm of symmetric matrix</td></tr>
<tr><td><a href="#min_and_max">min&nbsp;/&nbsp;max</a></td><td>&nbsp;</td><td>return extremum values</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#nonzeros">nonzeros</a></td><td>&nbsp;</td><td>return non-zero values</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#norm">norm</a></td><td>&nbsp;</td><td>various norms of vectors and matrices</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#norm2est">norm2est</a></td><td>&nbsp;</td><td>fast estimate of the matrix 2-norm</td></tr>
<tr><td><a href="#normalise">normalise</a></td><td>&nbsp;</td><td>normalise vectors to unit <i>p</i>-norm</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#normalise">normalise</a></td><td>&nbsp;</td><td>normalise vectors to unit <i>p</i>-norm</td></tr>
<tr><td><a href="#nonzeros">nonzeros</a></td><td>&nbsp;</td><td>extract all non-zero values</td></tr>
<tr><td><a href="#omit_nan_nonfinite">omit_nan / nonfinite</a></td><td>&nbsp;</td><td>extract all values that are non-NaN / only finite</td></tr>
<tr><td><a href="#pow">pow</a></td><td>&nbsp;</td><td>element-wise power</td></tr>
<tr><td><a href="#powmat">powmat</a></td><td>&nbsp;</td><td>matrix power</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#powmat">powmat</a></td><td>&nbsp;</td><td>matrix power</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#prod">prod</a></td><td>&nbsp;</td><td>product of elements</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#rank">rank</a></td><td>&nbsp;</td><td>rank of matrix</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#rcond">rcond</a></td><td>&nbsp;</td><td>reciprocal condition number</td></tr>
<tr><td><a href="#rcond">rcond</a></td><td>&nbsp;</td><td>reciprocal condition number</td></tr>
<tr><td><a href="#repelem">repelem</a></td><td>&nbsp;</td><td>replicate elements</td></tr>
<tr><td><a href="#replace_standalone">replace</a></td><td>&nbsp;</td><td>replace specific elements with a new value</td></tr>
<tr><td><a href="#repmat">repmat</a></td><td>&nbsp;</td><td>replicate matrix in block-like fashion</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#repmat">repmat</a></td><td>&nbsp;</td><td>replicate matrix in block-like fashion</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#reshape">reshape</a></td><td>&nbsp;</td><td>change size while keeping elements</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#resize">resize</a></td><td>&nbsp;</td><td>change size while keeping elements and preserving layout</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#reverse">reverse</a></td><td>&nbsp;</td><td>reverse order of elements</td></tr>
<tr><td><a href="#reverse">reverse</a></td><td>&nbsp;</td><td>reverse order of elements</td></tr>
<tr><td><a href="#roots">roots</a></td><td>&nbsp;</td><td>roots of polynomial</td></tr>
<tr><td><a href="#shift">shift</a></td><td>&nbsp;</td><td>circular shift of elements</td></tr>
<tr><td><a href="#shuffle">shuffle</a></td><td>&nbsp;</td><td>randomly shuffle elements</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#shuffle">shuffle</a></td><td>&nbsp;</td><td>randomly shuffle elements</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#size">size</a></td><td>&nbsp;</td><td>obtain dimensions of given object</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#sort">sort</a></td><td>&nbsp;</td><td>sort elements</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#sort_index">sort_index</a></td><td>&nbsp;</td><td>vector describing sorted order of elements</td></tr>
<tr><td><a href="#sort_index">sort_index</a></td><td>&nbsp;</td><td>vector describing sorted order of elements</td></tr>
<tr><td><a href="#sqrtmat">sqrtmat</a></td><td>&nbsp;</td><td>square root of matrix</td></tr>
<tr><td><a href="#sqrtmat_sympd">sqrtmat_sympd</a></td><td>&nbsp;</td><td>square root of symmetric matrix</td></tr>
<tr><td><a href="#sum">sum</a></td><td>&nbsp;</td><td>sum of elements</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#sum">sum</a></td><td>&nbsp;</td><td>sum of elements</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#sub2ind">sub2ind</a></td><td>&nbsp;</td><td>convert subscripts to linear index</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#symmat">symmatu&nbsp;/&nbsp;symmatl</a></td><td>&nbsp;</td><td>generate symmetric matrix from given matrix</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#trace">trace</a></td><td>&nbsp;</td><td>sum of diagonal elements</td></tr>
<tr><td><a href="#trace">trace</a></td><td>&nbsp;</td><td>sum of diagonal elements</td></tr>
<tr><td><a href="#trans">trans</a></td><td>&nbsp;</td><td>transpose of matrix</td></tr>
<tr><td><a href="#trapz">trapz</a></td><td>&nbsp;</td><td>trapezoidal numerical integration</td></tr>
<tr><td><a href="#trimat">trimatu&nbsp;/&nbsp;trimatl</a></td><td>&nbsp;</td><td>copy upper/lower triangular part</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#trimat">trimatu&nbsp;/&nbsp;trimatl</a></td><td>&nbsp;</td><td>copy upper/lower triangular part</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#trimat_ind">trimatu_ind&nbsp;/&nbsp;trimatl_ind</a></td><td>&nbsp;</td><td>obtain indices of upper/lower triangular part</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#unique">unique</a></td><td>&nbsp;</td><td>return unique elements</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#vecnorm">vecnorm</a></td><td>&nbsp;</td><td>obtain vector norm of each row or column of a matrix</td></tr>
<tr><td><a href="#vecnorm">vecnorm</a></td><td>&nbsp;</td><td>obtain vector norm of each row or column of a matrix</td></tr>
<tr><td><a href="#vectorise">vectorise</a></td><td>&nbsp;</td><td>flatten matrix into vector</td></tr>
<tr><td><a href="#misc_fns">misc&nbsp;functions</a></td><td>&nbsp;</td><td>miscellaneous element-wise functions:&nbsp;exp,&nbsp;log,&nbsp;sqrt,&nbsp;round,&nbsp;sign,&nbsp;...</td></tr>
<tr><td><a href="#trig_fns">trig&nbsp;functions</a></td><td>&nbsp;</td><td>trigonometric element-wise functions:&nbsp;cos,&nbsp;sin,&nbsp;tan,&nbsp;...</td></tr>
<tr style="background-color: #F5F5F5;"><td><a href="#trig_fns">trig&nbsp;functions</a></td><td>&nbsp;</td><td>trigonometric element-wise functions:&nbsp;cos,&nbsp;sin,&nbsp;tan,&nbsp;...</td></tr>
</tbody>
</table>
</ul>
@@ -10124,12 +10125,12 @@ See also:
<br><b>join_slices( cube C, mat M )</b>
<ul>
<li>
for two cubes <i>C</i> and <i>D</i>: join the slices of <i>C</i> with the slices of <i>D</i>;
For two cubes <i>C</i> and <i>D</i>: join the slices of <i>C</i> with the slices of <i>D</i>;
cubes <i>C</i> and <i>D</i> must have the same number of rows and columns (ie. all slices must have the same size)
</li>
<br>
<li>
for two matrices <i>M</i> and <i>N</i>: treat <i>M</i> and <i>N</i> as cube slices and join them to form a cube with 2 slices;
For two matrices <i>M</i> and <i>N</i>: treat <i>M</i> and <i>N</i> as cube slices and join them to form a cube with 2 slices;
matrices <i>M</i> and <i>N</i> must have the same number of rows and columns
</li>
<br>
@@ -10514,60 +10515,6 @@ See also:
<br>
</ul>
<div class="pagebreak"></div><div class="noprint"><hr class="greyline"><br></div>
<a name="nonzeros"></a>
<b>nonzeros( X )</b>
<ul>
<li>
Return a column vector containing the non-zero <b>values</b> of <i>X</i>
</li>
<br>
<li>
<i>X</i> can be a sparse or dense matrix
</li>
<br>
<li>
<b>Caveats:</b>
<ul>
<li>
for dense matrices/vectors,
to obtain the <b>number</b> of non-zero elements,
the expression <code><a href="#accu">accu</a>(X != 0)</code> is more efficient
</li>
<li>
for sparse matrices,
to obtain the <b>number</b> of non-zero elements,
the <code><a href="#attributes">.n_nonzero</a></code> attribute is more efficient, eg. <code>X.n_nonzero</code>
</li>
</ul>
</li>
<br>
<li>
Examples:
<ul>
<pre>
sp_mat A = sprandu&lt;sp_mat&gt;(100, 100, 0.1);
vec a = nonzeros(A);
mat B(100, 100, fill::eye);
vec b = nonzeros(B);
</pre>
</ul>
</li>
<br>
<li>
See also:
<ul>
<li><a href="#find">find()</a>
<li><a href="#unique">unique()</a></li>
<li><a href="#vectorise">vectorise()</a>
<li><a href="#clean">.clean()</a>
<li><a href="#for_each">.for_each()</a>
</ul>
</li>
<br>
</ul>
<div class="pagebreak"></div><div class="noprint"><hr class="greyline"><br></div>
<a name="norm"></a>
<b>norm( X )</b>
@@ -10738,6 +10685,106 @@ See also:
<br>
</ul>
<div class="pagebreak"></div><div class="noprint"><hr class="greyline"><br></div>
<a name="nonzeros"></a>
<b>nonzeros( X )</b>
<ul>
<li>
Return a column vector containing the non-zero <b>values</b> of <i>X</i>
</li>
<br>
<li>
<i>X</i> can be a sparse or dense matrix
</li>
<br>
<li>
<b>Caveats:</b>
<ul>
<li>
for dense matrices/vectors,
to obtain the <b>number</b> of non-zero elements,
the expression <code><a href="#accu">accu</a>(X != 0)</code> is more efficient
</li>
<li>
for sparse matrices,
to obtain the <b>number</b> of non-zero elements,
the <code><a href="#attributes">.n_nonzero</a></code> attribute is more efficient, eg. <code>X.n_nonzero</code>
</li>
</ul>
</li>
<br>
<li>
Examples:
<ul>
<pre>
sp_mat A = sprandu&lt;sp_mat&gt;(100, 100, 0.1);
vec a = nonzeros(A);
mat B(100, 100, fill::eye);
vec b = nonzeros(B);
</pre>
</ul>
</li>
<br>
<li>
See also:
<ul>
<li><a href="#find">find()</a>
<li><a href="#unique">unique()</a></li>
<li><a href="#vectorise">vectorise()</a>
<li><a href="#clean">.clean()</a>
<li><a href="#for_each">.for_each()</a>
</ul>
</li>
<br>
</ul>
<div class="pagebreak"></div><div class="noprint"><hr class="greyline"><br></div>
<a name="omit_nan_nonfinite"></a>
<b>omit_nan( X )</b>
<br><b>omit_nonfinite( X )</b>
<ul>
<li>
<i>omit_nan()</i>: return a column vector containing all values of <i>X</i> that are non-NaN
</li>
<br>
<li>
<i>omit_nonfinite()</i>: return a column vector containing all values of <i>X</i> that are finite (ie. excluding NaN and &plusmn;infinity)
</li>
<br>
<li>
<i>X</i> can be a sparse or dense matrix
</li>
<br>
<li>
Examples:
<ul>
<pre>
vec A(100, fill::randu);
A(1) = datum::nan;
A(2) = datum::inf;
vec B = omit_nan(A); // obtain all elements of A except for NaN
double mu = mean( omit_nonfinite(A) ); // obtain mean of A using only finite values
</pre>
</ul>
</li>
<br>
<li>
See also:
<ul>
<li><a href="#find_nan_nonnan">find_nan() / find_nonnan()</a>
<li><a href="#find_finite_nonfinite">find_finite() / find_nonfinite()</a>
<li><a href="#nonzeros">nonzeros()</a>
<li><a href="#vectorise">vectorise()</a>
<li><a href="#for_each">.for_each()</a>
</ul>
</li>
<br>
</ul>
<div class="pagebreak"></div><div class="noprint"><hr class="greyline"><br></div>
<a name="pow"></a>
<table>
@@ -20241,8 +20288,9 @@ List of additions and changes for each version:
<li>(under development)</li>
<li>added <a href="#balance">balance()</a> for producing balanced matrices where column and row norms are roughly the same</li>
<li>added <a href="#find_nan_nonnan">find_nonnan()</a> for finding indices of non-NaN elements</li>
<li>added <a href="#omit_nan_nonfinite">omit_nan()</a> to extract all non-NaN values</li>
<li>added <a href="#omit_nan_nonfinite">omit_nonfinite()</a> to extract all finite values</li>
<li>added standalone <a href="#replace_standalone">replace()</a> function</li>
<li>...</li>
</ul>
</li>
<br>