Skip to content

Add specifications for set functions #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion spec/API_specification/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ API specification
out_keyword
elementwise_functions
statistical_functions
linear_algebra_functions
searching_functions
linear_algebra_functions
set_functions
61 changes: 61 additions & 0 deletions spec/API_specification/set_functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Set Functions

> Array API specification for creating and operating on sets.

A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions.

- Positional parameters must be [positional-only](https://www.python.org/dev/peps/pep-0570/) parameters. Positional-only parameters have no externally-usable name. When a function accepting positional-only parameters is called, positional arguments are mapped to these parameters based solely on their order.
- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments.
- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`.

<!-- NOTE: please keep the functions in alphabetical order -->

### <a name="unique" href="#unique">#</a> unique(x, /, *, return_counts=False, return_index=False, return_inverse=False, sorted=True)

Returns the unique elements of an input array `x`.

#### Parameters

- **x**: _&lt;array&gt;_

- input array. If `x` has more than one dimension, the function must flatten `x` and return the unique elements of the flattened array.

- **return_counts**: _bool_

- If `True`, the function must also return the number of times each unique element occurs in `x`. Default: `False`.

- **return_index**: _bool_

- If `True`, the function must also return the indices (first occurrences) of `x` that result in the unique array. Default: `False`.

- **return_inverse**: _bool_

- If `True`, the function must also return the indices of the unique array that reconstruct `x`. Default: `False`.

- **sorted**: _bool_

- If `True`, the function must sort the unique elements in ascending order before returning as output. If `False`, the function must sort the unique elements in the same order that they occur in `x`. Default: `False`.

_TODO: sort order needs discussion. See [gh-40](https://github.com/data-apis/array-api/issues/40)_

#### Returns

- **out**: _Union\[ &lt;array&gt;, Tuple\[ &lt;array&gt;, ... ] ]_

- if `return_counts`, `return_index`, and `return_inverse` are all `False`, an array containing the set of unique elements in `x`; otherwise, a tuple containing two or more of the following arrays (in order):

- **unique**: _&lt;array&gt;_

- an array containing the set of unique elements in `x`.

- **indices**: _&lt;array&gt;_

- an array containing the indices (first occurrences) of `x` that result in `unique`.

- **inverse**: _&lt;array&gt;_

- an array containing the indices of `unique` that reconstruct `x`.

- **counts**: _&lt;array&gt;_

- an array containing the number of times each unique element occurs in `x`.