You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<dd><p>Returns the unique elements of an input array <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>, the first occurring indices for each unique element in <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>, the indices from the set of unique elements that reconstruct <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>, and the corresponding counts for each unique element in <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>.</p>
<p>The shapes of two of the output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See <aclass="reference internal" href="../../design_topics/data_dependent_output_shapes.html#data-dependent-output-shapes"><spanclass="std std-ref">Data-dependent output shapes</span></a> section for more details.</p>
478
+
<p>The shapes of two of the output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, et cetera) can find this function difficult to implement without knowing array values. Accordingly, such libraries <strong>may</strong> choose to omit this function. See <aclass="reference internal" href="../../design_topics/data_dependent_output_shapes.html#data-dependent-output-shapes"><spanclass="std std-ref">Data-dependent output shapes</span></a> section for more details.</p>
479
479
</div>
480
-
<divclass="admonition note">
481
-
<pclass="admonition-title">Note</p>
482
-
<p>Uniqueness should be determined based on value equality (see <aclass="reference internal" href="array_api.equal.html#array_api.equal" title="array_api.equal"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">equal()</span></code></a>). For input arrays having floating-point data types, value-based equality implies the following behavior.</p>
483
-
<ulclass="simple">
484
-
<li><p>As <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> values compare as <codeclass="docutils literal notranslate"><spanclass="pre">False</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> values should be considered distinct.</p></li>
485
-
<li><p>As complex floating-point values having at least one <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> component compare as <codeclass="docutils literal notranslate"><spanclass="pre">False</span></code>, complex floating-point values having <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> components should be considered distinct.</p></li>
486
-
<li><p>As <codeclass="docutils literal notranslate"><spanclass="pre">-0</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">+0</span></code> compare as <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>, signed zeros should not be considered distinct, and the corresponding unique element will be implementation-dependent (e.g., an implementation could choose to return <codeclass="docutils literal notranslate"><spanclass="pre">-0</span></code> if <codeclass="docutils literal notranslate"><spanclass="pre">-0</span></code> occurs before <codeclass="docutils literal notranslate"><spanclass="pre">+0</span></code>).</p></li>
487
-
</ul>
488
-
<p>As signed zeros are not distinct, using <codeclass="docutils literal notranslate"><spanclass="pre">inverse_indices</span></code> to reconstruct the input array is not guaranteed to return an array having the exact same values.</p>
489
-
<p>Each <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> value and each complex floating-point value having a <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> component should have a count of one, while the counts for signed zeros should be aggregated as a single count.</p>
<ddclass="field-odd"><p><strong>x</strong> (<em>array</em>) – input array. If <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code> has more than one dimension, the function must flatten <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code> and return the unique elements of the flattened array.</p>
482
+
<ddclass="field-odd"><p><strong>x</strong> (<em>array</em>) – input array. If <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code> has more than one dimension, the function <strong>must</strong> flatten <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code> and return the unique elements of the flattened array.</p>
<li><p>first element must have the field name <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code> and must be a one-dimensional array containing the unique elements of <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>. The array must have the same data type as <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>.</p></li>
499
-
<li><p>second element must have the field name <codeclass="docutils literal notranslate"><spanclass="pre">indices</span></code> and must be an array containing the indices (first occurrences) of a flattened <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code> that result in <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code>. The array must have the same shape as <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code> and must have the default array index data type.</p></li>
500
-
<li><p>third element must have the field name <codeclass="docutils literal notranslate"><spanclass="pre">inverse_indices</span></code> and must be an array containing the indices of <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code> that reconstruct <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>. The array must have the same shape as <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code> and must have the default array index data type.</p></li>
501
-
<li><p>fourth element must have the field name <codeclass="docutils literal notranslate"><spanclass="pre">counts</span></code> and must be an array containing the number of times each unique element occurs in <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>. The order of the returned counts must match the order of <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code>, such that a specific element in <codeclass="docutils literal notranslate"><spanclass="pre">counts</span></code> corresponds to the respective unique element in <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code>. The returned array must have same shape as <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code> and must have the default array index data type.</p></li>
487
+
<li><p>first element <strong>must</strong> have the field name <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code> and <strong>must</strong> be a one-dimensional array containing the unique elements of <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>. The array <strong>must</strong> have the same data type as <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>.</p></li>
488
+
<li><p>second element <strong>must</strong> have the field name <codeclass="docutils literal notranslate"><spanclass="pre">indices</span></code> and <strong>must</strong> be an array containing the indices (first occurrences) of a flattened <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code> that result in <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code>. The array <strong>must</strong> have the same shape as <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code> and <strong>must</strong> have the default array index data type.</p></li>
489
+
<li><p>third element <strong>must</strong> have the field name <codeclass="docutils literal notranslate"><spanclass="pre">inverse_indices</span></code> and <strong>must</strong> be an array containing the indices of <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code> that reconstruct <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>. The array <strong>must</strong> have the same shape as <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code> and <strong>must</strong> have the default array index data type.</p></li>
490
+
<li><p>fourth element <strong>must</strong> have the field name <codeclass="docutils literal notranslate"><spanclass="pre">counts</span></code> and <strong>must</strong> be an array containing the number of times each unique element occurs in <codeclass="docutils literal notranslate"><spanclass="pre">x</span></code>. The order of the returned counts <strong>must</strong> match the order of <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code>, such that a specific element in <codeclass="docutils literal notranslate"><spanclass="pre">counts</span></code> corresponds to the respective unique element in <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code>. The returned array <strong>must</strong> have same shape as <codeclass="docutils literal notranslate"><spanclass="pre">values</span></code> and <strong>must</strong> have the default array index data type.</p></li>
502
491
</ul>
503
-
<divclass="admonition note">
504
-
<pclass="admonition-title">Note</p>
505
-
<p>The order of unique elements is not specified and may vary between implementations.</p>
506
-
</div>
507
492
</dd>
508
493
</dl>
509
494
<pclass="rubric">Notes</p>
495
+
<ul>
496
+
<li><p>The order of unique elements returned by this function is unspecified and thus implementation-defined. As a consequence, element order <strong>may</strong> vary between implementations.</p></li>
497
+
<li><p>Uniqueness <strong>should</strong> be determined based on value equality (see <aclass="reference internal" href="array_api.equal.html#array_api.equal" title="array_api.equal"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">equal()</span></code></a>). For input arrays having floating-point data types, value-based equality implies the following behavior.</p>
498
+
<ulclass="simple">
499
+
<li><p>As <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> values compare as <codeclass="docutils literal notranslate"><spanclass="pre">False</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> values <strong>should</strong> be considered distinct.</p></li>
500
+
<li><p>As complex floating-point values having at least one <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> component compare as <codeclass="docutils literal notranslate"><spanclass="pre">False</span></code>, complex floating-point values having <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> components <strong>should</strong> be considered distinct.</p></li>
501
+
<li><p>As <codeclass="docutils literal notranslate"><spanclass="pre">-0</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">+0</span></code> compare as <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>, signed zeros <strong>should not</strong> be considered distinct, and the corresponding unique element <strong>may</strong> be implementation-defined (e.g., an implementation <strong>may</strong> choose to return <codeclass="docutils literal notranslate"><spanclass="pre">-0</span></code> if <codeclass="docutils literal notranslate"><spanclass="pre">-0</span></code> occurs before <codeclass="docutils literal notranslate"><spanclass="pre">+0</span></code>).</p></li>
502
+
</ul>
503
+
<p>As signed zeros are not distinct, using <codeclass="docutils literal notranslate"><spanclass="pre">inverse_indices</span></code> to reconstruct the input array is not guaranteed to return an array having the exact same values.</p>
504
+
<p>Each <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> value and each complex floating-point value having a <codeclass="docutils literal notranslate"><spanclass="pre">nan</span></code> component <strong>should</strong> have a count of one, while the counts for signed zeros <strong>should</strong> be aggregated as a single count.</p>
505
+
</li>
506
+
</ul>
510
507
<divclass="versionchanged">
511
508
<p><spanclass="versionmodified changed">Changed in version 2022.12: </span>Added complex data type support.</p>
0 commit comments