Skip to content

Commit 351b58e

Browse files
committed
Auto-generated commit
1 parent f129e42 commit 351b58e

24 files changed

Lines changed: 4201 additions & 1 deletion

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
<section class="release" id="unreleased">
66

7-
## Unreleased (2026-05-12)
7+
## Unreleased (2026-05-13)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`0d5b82a`](https://github.com/stdlib-js/stdlib/commit/0d5b82a1055d8a5fe51eae4011bedf64844fb48e) - add `onesLike` to namespace
14+
- [`64a9fda`](https://github.com/stdlib-js/stdlib/commit/64a9fda26a1e5411a439fbcff6b567e7ed1ea6b7) - add `ndarray/ones-like`
1315
- [`e38bbc8`](https://github.com/stdlib-js/stdlib/commit/e38bbc844b58b38ccb22be0ee62b0a42aa90fd75) - add `transpose` and `toTransposed` to namespace
1416
- [`c541417`](https://github.com/stdlib-js/stdlib/commit/c5414171e07489c15e73b63e8ae437a24118a1f0) - add `ndarray/to-transposed` [(#12031)](https://github.com/stdlib-js/stdlib/pull/12031)
1517
- [`5c1463c`](https://github.com/stdlib-js/stdlib/commit/5c1463c8c0240b44991231d5b8b120d78c6d8ad1) - add `ndarray/transpose` [(#12030)](https://github.com/stdlib-js/stdlib/pull/12030)
@@ -932,6 +934,8 @@ A total of 49 issues were closed in this release:
932934

933935
<details>
934936

937+
- [`0d5b82a`](https://github.com/stdlib-js/stdlib/commit/0d5b82a1055d8a5fe51eae4011bedf64844fb48e) - **feat:** add `onesLike` to namespace _(by Athan Reines)_
938+
- [`64a9fda`](https://github.com/stdlib-js/stdlib/commit/64a9fda26a1e5411a439fbcff6b567e7ed1ea6b7) - **feat:** add `ndarray/ones-like` _(by Athan Reines)_
935939
- [`65f9d6f`](https://github.com/stdlib-js/stdlib/commit/65f9d6fd963809f82e54cdfd06ed15e15b51525e) - **refactor:** align `ndarray/*` errors and remove `namespace` self-ref [(#12102)](https://github.com/stdlib-js/stdlib/pull/12102) _(by Philipp Burckhardt)_
936940
- [`c77fbd9`](https://github.com/stdlib-js/stdlib/commit/c77fbd9a0ea702e373b40173007fcb4c0639c24e) - **refactor:** align `ndarray/base/diagonal` error message and remove `namespace` self-refs [(#12096)](https://github.com/stdlib-js/stdlib/pull/12096) _(by Philipp Burckhardt, Athan Reines)_
937941
- [`c534f97`](https://github.com/stdlib-js/stdlib/commit/c534f971488b2a5ebacca4dccf73a9d9b4e09bc7) - **docs:** update namespace table of contents [(#12092)](https://github.com/stdlib-js/stdlib/pull/12092) _(by stdlib-bot)_

lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,15 @@ setReadOnly( ns, 'offset', require( './../offset' ) );
666666
*/
667667
setReadOnly( ns, 'ones', require( './../ones' ) );
668668

669+
/**
670+
* @name onesLike
671+
* @memberof ns
672+
* @readonly
673+
* @type {Function}
674+
* @see {@link module:@stdlib/ndarray/ones-like}
675+
*/
676+
setReadOnly( ns, 'onesLike', require( './../ones-like' ) );
677+
669678
/**
670679
* @name order
671680
* @memberof ns

ones-like/README.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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+
# onesLike
22+
23+
> Create a ones-filled [ndarray][@stdlib/ndarray/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var onesLike = require( '@stdlib/ndarray/ones-like' );
41+
```
42+
43+
#### onesLike( x\[, options] )
44+
45+
Creates a ones-filled [ndarray][@stdlib/ndarray/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes] as a provided ndarray.
46+
47+
```javascript
48+
var getShape = require( '@stdlib/ndarray/shape' );
49+
var getDType = require( '@stdlib/ndarray/dtype' );
50+
var zeros = require( '@stdlib/ndarray/zeros' );
51+
52+
var x = zeros( [ 2, 2 ] );
53+
// returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
54+
55+
var y = onesLike( x );
56+
// returns <ndarray>[ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]
57+
58+
var sh = getShape( y );
59+
// returns [ 2, 2 ]
60+
61+
var dt = String( getDType( y ) );
62+
// returns 'float64'
63+
```
64+
65+
The function supports the following options:
66+
67+
- **dtype**: output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes]. Must be a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. Overrides the input ndarray's inferred [data type][@stdlib/ndarray/dtypes].
68+
- **shape**: output [ndarray][@stdlib/ndarray/ctor] shape. Overrides the input ndarray's inferred shape.
69+
- **order**: specifies whether the output [ndarray][@stdlib/ndarray/ctor] should be `'row-major'` (C-style) or `'column-major'` (Fortran-style). Overrides the input ndarray's inferred order.
70+
- **mode**: specifies how to handle indices which exceed array dimensions (see [ndarray][@stdlib/ndarray/ctor]). Default: `'throw'`.
71+
- **submode**: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions (see [ndarray][@stdlib/ndarray/ctor]). If provided fewer modes than dimensions, the constructor recycles modes using modulo arithmetic. Default: `[ options.mode ]`.
72+
- **readonly**: boolean indicating whether an array should be **read-only**. Default: `false`.
73+
74+
To override either the `dtype`, `shape`, or `order`, specify the corresponding option. For example, to override the inferred [data type][@stdlib/ndarray/dtypes],
75+
76+
```javascript
77+
var getShape = require( '@stdlib/ndarray/shape' );
78+
var getDType = require( '@stdlib/ndarray/dtype' );
79+
var zeros = require( '@stdlib/ndarray/zeros' );
80+
81+
var x = zeros( [ 2, 2 ] );
82+
// returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
83+
84+
var dt = String( getDType( x ) );
85+
// returns 'float64'
86+
87+
var y = onesLike( x, {
88+
'dtype': 'int32'
89+
});
90+
// returns <ndarray>[ [ 1, 1 ], [ 1, 1 ] ]
91+
92+
var sh = getShape( y );
93+
// returns [ 2, 2 ]
94+
95+
dt = String( getDType( y ) );
96+
// returns 'int32'
97+
```
98+
99+
</section>
100+
101+
<!-- /.usage -->
102+
103+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
104+
105+
<section class="notes">
106+
107+
</section>
108+
109+
<!-- /.notes -->
110+
111+
<!-- Package usage examples. -->
112+
113+
<section class="examples">
114+
115+
## Examples
116+
117+
<!-- eslint no-undef: "error" -->
118+
119+
```javascript
120+
var dtypes = require( '@stdlib/ndarray/dtypes' );
121+
var zeros = require( '@stdlib/ndarray/zeros' );
122+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
123+
var onesLike = require( '@stdlib/ndarray/ones-like' );
124+
125+
// Get a list of data types:
126+
var dt = dtypes( 'integer_and_generic' );
127+
128+
// Generate ones-filled arrays...
129+
var x;
130+
var y;
131+
var i;
132+
for ( i = 0; i < dt.length; i++ ) {
133+
x = zeros( [ 2, 2 ], {
134+
'dtype': dt[ i ]
135+
});
136+
y = onesLike( x );
137+
console.log( ndarray2array( y ) );
138+
}
139+
```
140+
141+
</section>
142+
143+
<!-- /.examples -->
144+
145+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
146+
147+
<section class="references">
148+
149+
</section>
150+
151+
<!-- /.references -->
152+
153+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
154+
155+
<section class="related">
156+
157+
</section>
158+
159+
<!-- /.related -->
160+
161+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
162+
163+
<section class="links">
164+
165+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
166+
167+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
168+
169+
</section>
170+
171+
<!-- /.links -->

0 commit comments

Comments
 (0)