Skip to content

Add specifications for returning upper (triu) and lower (tril) triangular matrices #243

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 4 commits into from
Sep 20, 2021
Merged
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
82 changes: 70 additions & 12 deletions spec/API_specification/creation_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This function cannot guarantee that the interval does not include the `stop` val

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. Default: `None`.
- device on which to place the created array. Default: `None`.

#### Returns

Expand Down Expand Up @@ -72,7 +72,7 @@ Convert the input to an array.

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. Default: `None`.
- device on which to place the created array. Default: `None`.

- **copy**: _Optional\[ bool ]_

Expand Down Expand Up @@ -102,7 +102,7 @@ Returns an uninitialized array having a specified `shape`.

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. Default: `None`.
- device on which to place the created array. Default: `None`.

#### Returns

Expand All @@ -127,7 +127,7 @@ Returns an uninitialized array with the same `shape` as an input array `x`.

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
- device on which to place the created array. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.

#### Returns

Expand Down Expand Up @@ -160,7 +160,7 @@ Returns a two-dimensional array with ones on the `k`th diagonal and zeros elsewh

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. Default: `None`.
- device on which to place the created array. Default: `None`.

#### Returns

Expand Down Expand Up @@ -210,7 +210,7 @@ Returns a new array having a specified `shape` and filled with `fill_value`.

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. Default: `None`.
- device on which to place the created array. Default: `None`.

#### Returns

Expand Down Expand Up @@ -239,7 +239,7 @@ Returns a new array filled with `fill_value` and having the same `shape` as an i

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
- device on which to place the created array. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.

#### Returns

Expand Down Expand Up @@ -277,7 +277,7 @@ Returns evenly spaced numbers over a specified interval.

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. Default: `None`.
- device on which to place the created array. Default: `None`.

- **endpoint**: _bool_

Expand Down Expand Up @@ -337,7 +337,7 @@ Returns a new array having a specified `shape` and filled with ones.

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. Default: `None`.
- device on which to place the created array. Default: `None`.

#### Returns

Expand All @@ -362,14 +362,72 @@ Returns a new array filled with ones and having the same `shape` as an input arr

- **device**: _Optional\[ <device> ]_

- device to place the created array on, if given. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
- device on which to place the created array. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.

#### Returns

- **out**: _<array>_

- an array having the same shape as `x` and filled with ones.

(function-tril)=
### tril(x, /, *, k=0)

Returns the lower triangular part of a matrix (or a stack of matrices) `x`.

```{note}
The lower triangular part of the matrix is defined as the elements on and below the specified diagonal `k`.
```

#### Parameters

- **x**: _<array>_

- input array having shape `(..., M, N)` and whose innermost two dimensions form `MxN` matrices.

- **k**: _int_

- diagonal above which to zero elements. If `k = 0`, the diagonal is the main diagonal. If `k < 0`, the diagonal is below the main diagonal. If `k > 0`, the diagonal is above the main diagonal. Default: `0`.

```{note}
The main diagonal is defined as the set of indices `{(i, i)}` for `i` on the interval `[0, min(M, N) - 1]`.
```

#### Returns

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

- an array containing the lower triangular part(s). The returned array must have the same shape and data type as `x`. All elements above the specified diagonal `k` must be zeroed. The returned array should be allocated on the same device as `x`.

(function-triu)=
### triu(x, /, *, k=0)

Returns the upper triangular part of a matrix (or a stack of matrices) `x`.

```{note}
The upper triangular part of the matrix is defined as the elements on and above the specified diagonal `k`.
```

#### Parameters

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

- input array having shape `(..., M, N)` and whose innermost two dimensions form `MxN` matrices.

- **k**: _int_

- diagonal below which to zero elements. If `k = 0`, the diagonal is the main diagonal. If `k < 0`, the diagonal is below the main diagonal. If `k > 0`, the diagonal is above the main diagonal. Default: `0`.

```{note}
The main diagonal is defined as the set of indices `{(i, i)}` for `i` on the interval `[0, min(M, N) - 1]`.
```

#### Returns

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

- an array containing the upper triangular part(s). The returned array must have the same shape and data type as `x`. All elements below the specified diagonal `k` must be zeroed. The returned array should be allocated on the same device as `x`.

(function-zeros)=
### zeros(shape, *, dtype=None, device=None)

Expand All @@ -387,7 +445,7 @@ Returns a new array having a specified `shape` and filled with zeros.

- **device**: _Optional\[ &lt;device&gt; ]_

- device to place the created array on, if given. Default: `None`.
- device on which to place the created array. Default: `None`.

#### Returns

Expand All @@ -412,7 +470,7 @@ Returns a new array filled with zeros and having the same `shape` as an input ar

- **device**: _Optional\[ &lt;device&gt; ]_

- device to place the created array on, if given. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.
- device on which to place the created array. If `device` is `None`, the default device must be used, not `x.device`. Default: `None`.

#### Returns

Expand Down