Skip to content

Commit 93cee98

Browse files
committed
Auto-generated commit
1 parent d3e3f29 commit 93cee98

11 files changed

Lines changed: 1485 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`b186702`](https://github.com/stdlib-js/stdlib/commit/b186702222b3b2cd2039d886b62ce78bd2f6af3b) - add `ndarray/base/assign-diagonal` [(#11993)](https://github.com/stdlib-js/stdlib/pull/11993)
1314
- [`e08276d`](https://github.com/stdlib-js/stdlib/commit/e08276d789ba1671769175bf5d2c3c5f587f6dca) - update `ndarray` TypeScript declarations [(#12593)](https://github.com/stdlib-js/stdlib/pull/12593)
1415

1516
</section>
@@ -34,6 +35,7 @@
3435

3536
<details>
3637

38+
- [`b186702`](https://github.com/stdlib-js/stdlib/commit/b186702222b3b2cd2039d886b62ce78bd2f6af3b) - **feat:** add `ndarray/base/assign-diagonal` [(#11993)](https://github.com/stdlib-js/stdlib/pull/11993) _(by Muhammad Haris, Athan Reines)_
3739
- [`07a3349`](https://github.com/stdlib-js/stdlib/commit/07a3349f6ab025490bafad9cd3b2d08df70f1fed) - **fix:** use correct export names [(#12665)](https://github.com/stdlib-js/stdlib/pull/12665) _(by Philipp Burckhardt, Athan Reines)_
3840
- [`104ec96`](https://github.com/stdlib-js/stdlib/commit/104ec966cbe5e4530a183aed20422da4b129ac6e) - **refactor:** align parameter names in `ndarray/base/nullary-loop-interchange-order` [(#12668)](https://github.com/stdlib-js/stdlib/pull/12668) _(by Philipp Burckhardt)_
3941
- [`a9e03ed`](https://github.com/stdlib-js/stdlib/commit/a9e03edc48bf43a1c290ed1ec1e2f69186678b15) - **refactor:** add missing generic type-parameter defaults in `ndarray` reverse declarations [(#12666)](https://github.com/stdlib-js/stdlib/pull/12666) _(by Philipp Burckhardt)_
@@ -60,9 +62,10 @@
6062

6163
### Contributors
6264

63-
A total of 2 people contributed to this release. Thank you to the following contributors:
65+
A total of 3 people contributed to this release. Thank you to the following contributors:
6466

6567
- Athan Reines
68+
- Muhammad Haris
6669
- Philipp Burckhardt
6770

6871
</section>

base/assign-diagonal/README.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# assignDiagonal
22+
23+
> Assign elements from a broadcasted input [`ndarray`][@stdlib/ndarray/ctor] to a specified diagonal of an output [`ndarray`][@stdlib/ndarray/ctor].
24+
25+
<section class="intro">
26+
27+
For an `M`-by-`N` matrix `A`, the `k`-th diagonal is defined as
28+
29+
<!-- <equation class="equation" label="eq:diagonal_definition" align="center" raw="D_k = \{\, A_{i,j} : j - i = k \,\}" alt="Definition of the k-th diagonal of a matrix."> -->
30+
31+
```math
32+
D_k = \{\, A_{i,j} : j - i = k \,\}
33+
```
34+
35+
<!-- <div class="equation" align="center" data-raw-text="D_k = \{\, A_{i,j} : j - i = k \,\}" data-equation="eq:diagonal_definition">
36+
<img src="" alt="Definition of the k-th diagonal of a matrix.">
37+
<br>
38+
</div> -->
39+
40+
<!-- </equation> -->
41+
42+
where `k = 0` corresponds to the main diagonal, `k > 0` corresponds to the super-diagonals (above the main diagonal), and `k < 0` corresponds to the sub-diagonals (below the main diagonal).
43+
44+
</section>
45+
46+
<!-- /.intro -->
47+
48+
<section class="usage">
49+
50+
## Usage
51+
52+
```javascript
53+
var assignDiagonal = require( '@stdlib/ndarray/base/assign-diagonal' );
54+
```
55+
56+
#### assignDiagonal( arrays, dims, k )
57+
58+
Assigns elements from a broadcasted input [`ndarray`][@stdlib/ndarray/ctor] to a specified diagonal of an output [`ndarray`][@stdlib/ndarray/ctor].
59+
60+
```javascript
61+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
62+
var zeros = require( '@stdlib/ndarray/zeros' );
63+
64+
var x = scalar2ndarray( 1.0 );
65+
// returns <ndarray>
66+
67+
var y = zeros( [ 3, 3 ] );
68+
// returns <ndarray>[ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ]
69+
70+
var out = assignDiagonal( [ x, y ], [ 0, 1 ], 0 );
71+
// returns <ndarray>[ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ]
72+
73+
var bool = ( out === y );
74+
// returns true
75+
```
76+
77+
The function accepts the following arguments:
78+
79+
- **arrays**: array-like object containing one input ndarray and one output ndarray.
80+
- **dims**: dimension indices defining the plane in which to assign elements to the diagonal.
81+
- **k**: diagonal offset.
82+
83+
</section>
84+
85+
<!-- /.usage -->
86+
87+
<section class="notes">
88+
89+
## Notes
90+
91+
- The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension.
92+
- Each provided dimension index must reside on the interval `[-ndims, ndims-1]`.
93+
- The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function assigns to the main diagonal; when `k > 0`, the function assigns to a diagonal above the main diagonal; and when `k < 0`, the function assigns to a diagonal below the main diagonal.
94+
- The input ndarray must be [broadcast compatible][@stdlib/ndarray/base/broadcast-shapes] with the output ndarray view defined by the specified diagonal.
95+
96+
</section>
97+
98+
<!-- /.notes -->
99+
100+
<section class="examples">
101+
102+
## Examples
103+
104+
<!-- eslint no-undef: "error" -->
105+
106+
```javascript
107+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
108+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
109+
var zeros = require( '@stdlib/ndarray/zeros' );
110+
var assignDiagonal = require( '@stdlib/ndarray/base/assign-diagonal' );
111+
112+
// Create a stack of matrices:
113+
var y = zeros( [ 2, 3, 3 ] );
114+
console.log( ndarray2array( y ) );
115+
116+
// Assign a scalar to each main diagonal:
117+
assignDiagonal( [ scalar2ndarray( 1.0 ), y ], [ 1, 2 ], 0 );
118+
console.log( ndarray2array( y ) );
119+
120+
// Assign a scalar to each super-diagonal:
121+
assignDiagonal( [ scalar2ndarray( 2.0 ), y ], [ 1, 2 ], 1 );
122+
console.log( ndarray2array( y ) );
123+
124+
// Assign a scalar to each sub-diagonal:
125+
assignDiagonal( [ scalar2ndarray( 3.0 ), y ], [ 1, 2 ], -1 );
126+
console.log( ndarray2array( y ) );
127+
```
128+
129+
</section>
130+
131+
<!-- /.examples -->
132+
133+
<section class="references">
134+
135+
</section>
136+
137+
<!-- /.references -->
138+
139+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
140+
141+
<section class="related">
142+
143+
</section>
144+
145+
<!-- /.related -->
146+
147+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
148+
149+
<section class="links">
150+
151+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
152+
153+
[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray/tree/main/base/broadcast-shapes
154+
155+
</section>
156+
157+
<!-- /.links -->

0 commit comments

Comments
 (0)