Skip to content

Commit 1e7b5ea

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

18 files changed

Lines changed: 2612 additions & 1 deletion

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Features
1212

13+
- [`2c835da`](https://github.com/stdlib-js/stdlib/commit/2c835dabc4f37afb4f855dec66742d50d14adf32) - add `nansLike` to namespace
14+
- [`b9ecb29`](https://github.com/stdlib-js/stdlib/commit/b9ecb2970eedca271688dc7fc12ee2247a43cbf3) - add `ndarray/nans-like`
1315
- [`0d5b82a`](https://github.com/stdlib-js/stdlib/commit/0d5b82a1055d8a5fe51eae4011bedf64844fb48e) - add `onesLike` to namespace
1416
- [`64a9fda`](https://github.com/stdlib-js/stdlib/commit/64a9fda26a1e5411a439fbcff6b567e7ed1ea6b7) - add `ndarray/ones-like`
1517
- [`e38bbc8`](https://github.com/stdlib-js/stdlib/commit/e38bbc844b58b38ccb22be0ee62b0a42aa90fd75) - add `transpose` and `toTransposed` to namespace
@@ -934,6 +936,9 @@ A total of 49 issues were closed in this release:
934936

935937
<details>
936938

939+
- [`dfda2f7`](https://github.com/stdlib-js/stdlib/commit/dfda2f76fffbc7450ba3b7c943787de52c05e7b7) - **docs:** update ToC _(by Athan Reines)_
940+
- [`2c835da`](https://github.com/stdlib-js/stdlib/commit/2c835dabc4f37afb4f855dec66742d50d14adf32) - **feat:** add `nansLike` to namespace _(by Athan Reines)_
941+
- [`b9ecb29`](https://github.com/stdlib-js/stdlib/commit/b9ecb2970eedca271688dc7fc12ee2247a43cbf3) - **feat:** add `ndarray/nans-like` _(by Athan Reines)_
937942
- [`0d5b82a`](https://github.com/stdlib-js/stdlib/commit/0d5b82a1055d8a5fe51eae4011bedf64844fb48e) - **feat:** add `onesLike` to namespace _(by Athan Reines)_
938943
- [`64a9fda`](https://github.com/stdlib-js/stdlib/commit/64a9fda26a1e5411a439fbcff6b567e7ed1ea6b7) - **feat:** add `ndarray/ones-like` _(by Athan Reines)_
939944
- [`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)_

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var o = ns;
7676

7777
The namespace exports the following functions to create multidimensional arrays:
7878

79-
<!-- <toc pattern="+(array|copy|ctor|empty|empty-like|fancy|from-scalar|from-scalar-like|ndarraylike2ndarray|ones|ones-like|to-fancy|zeros|zeros-like)"> -->
79+
<!-- <toc pattern="+(array|copy|ctor|empty|empty-like|fancy|from-scalar|from-scalar-like|nans-like|ndarraylike2ndarray|ones|ones-like|to-fancy|zeros|zeros-like)"> -->
8080

8181
<div class="namespace-toc">
8282

lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,15 @@ setReadOnly( ns, 'minDataType', require( './../min-dtype' ) );
594594
*/
595595
setReadOnly( ns, 'mostlySafeCasts', require( './../mostly-safe-casts' ) );
596596

597+
/**
598+
* @name nansLike
599+
* @memberof ns
600+
* @readonly
601+
* @type {Function}
602+
* @see {@link module:@stdlib/ndarray/nans-like}
603+
*/
604+
setReadOnly( ns, 'nansLike', require( './../nans-like' ) );
605+
597606
/**
598607
* @name ndarraylike2ndarray
599608
* @memberof ns

nans-like/README.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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+
# nansLike
22+
23+
> Create a NaN-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 nansLike = require( '@stdlib/ndarray/nans-like' );
41+
```
42+
43+
#### nansLike( x\[, options] )
44+
45+
Creates a NaN-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 = nansLike( x );
56+
// returns <ndarray>[ [ NaN, NaN ], [ NaN, NaN ] ]
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 floating-point 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 = nansLike( x, {
88+
'dtype': 'float32'
89+
});
90+
// returns <ndarray>[ [ NaN, NaN ], [ NaN, NaN ] ]
91+
92+
var sh = getShape( y );
93+
// returns [ 2, 2 ]
94+
95+
dt = String( getDType( y ) );
96+
// returns 'float32'
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 zeros = require( '@stdlib/ndarray/zeros' );
121+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
122+
var nansLike = require( '@stdlib/ndarray/nans-like' );
123+
124+
// Specify a list of data types:
125+
var dt = [
126+
'float64',
127+
'float32',
128+
'complex128',
129+
'complex64',
130+
'generic'
131+
];
132+
133+
// Generate NaN-filled arrays...
134+
var x;
135+
var y;
136+
var i;
137+
for ( i = 0; i < dt.length; i++ ) {
138+
x = zeros( [ 2, 2 ], {
139+
'dtype': dt[ i ]
140+
});
141+
y = nansLike( x );
142+
console.log( ndarray2array( y ) );
143+
}
144+
```
145+
146+
</section>
147+
148+
<!-- /.examples -->
149+
150+
<!-- 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. -->
151+
152+
<section class="references">
153+
154+
</section>
155+
156+
<!-- /.references -->
157+
158+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
159+
160+
<section class="related">
161+
162+
</section>
163+
164+
<!-- /.related -->
165+
166+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
167+
168+
<section class="links">
169+
170+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
171+
172+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
173+
174+
</section>
175+
176+
<!-- /.links -->

nans-like/benchmark/benchmark.js

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
25+
var zeros = require( './../../zeros' );
26+
var format = require( '@stdlib/string/format' );
27+
var pkg = require( './../package.json' ).name;
28+
var nansLike = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( format( '%s:dtype=float64', pkg ), function benchmark( b ) {
34+
var x;
35+
var y;
36+
var i;
37+
38+
x = zeros( [ 0 ], {
39+
'dtype': 'float64'
40+
});
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
y = nansLike( x );
45+
if ( y.length !== 0 ) {
46+
b.fail( 'should have length 0' );
47+
}
48+
}
49+
b.toc();
50+
if ( !isndarrayLike( y ) ) {
51+
b.fail( 'should return an ndarray' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
56+
57+
bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) {
58+
var x;
59+
var y;
60+
var i;
61+
62+
x = zeros( [ 0 ], {
63+
'dtype': 'float32'
64+
});
65+
66+
b.tic();
67+
for ( i = 0; i < b.iterations; i++ ) {
68+
y = nansLike( x );
69+
if ( y.length !== 0 ) {
70+
b.fail( 'should have length 0' );
71+
}
72+
}
73+
b.toc();
74+
if ( !isndarrayLike( y ) ) {
75+
b.fail( 'should return an ndarray' );
76+
}
77+
b.pass( 'benchmark finished' );
78+
b.end();
79+
});
80+
81+
bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) {
82+
var x;
83+
var y;
84+
var i;
85+
86+
x = zeros( [ 0 ], {
87+
'dtype': 'complex128'
88+
});
89+
90+
b.tic();
91+
for ( i = 0; i < b.iterations; i++ ) {
92+
y = nansLike( x );
93+
if ( y.length !== 0 ) {
94+
b.fail( 'should have length 0' );
95+
}
96+
}
97+
b.toc();
98+
if ( !isndarrayLike( y ) ) {
99+
b.fail( 'should return an ndarray' );
100+
}
101+
b.pass( 'benchmark finished' );
102+
b.end();
103+
});
104+
105+
bench( format( '%s:dtype=complex64', pkg ), function benchmark( b ) {
106+
var x;
107+
var y;
108+
var i;
109+
110+
x = zeros( [ 0 ], {
111+
'dtype': 'complex64'
112+
});
113+
114+
b.tic();
115+
for ( i = 0; i < b.iterations; i++ ) {
116+
y = nansLike( x );
117+
if ( y.length !== 0 ) {
118+
b.fail( 'should have length 0' );
119+
}
120+
}
121+
b.toc();
122+
if ( !isndarrayLike( y ) ) {
123+
b.fail( 'should return an ndarray' );
124+
}
125+
b.pass( 'benchmark finished' );
126+
b.end();
127+
});
128+
129+
bench( format( '%s:dtype=generic', pkg ), function benchmark( b ) {
130+
var x;
131+
var y;
132+
var i;
133+
134+
x = zeros( [ 0 ], {
135+
'dtype': 'generic'
136+
});
137+
138+
b.tic();
139+
for ( i = 0; i < b.iterations; i++ ) {
140+
y = nansLike( x );
141+
if ( y.length !== 0 ) {
142+
b.fail( 'should have length 0' );
143+
}
144+
}
145+
b.toc();
146+
if ( !isndarrayLike( y ) ) {
147+
b.fail( 'should return an ndarray' );
148+
}
149+
b.pass( 'benchmark finished' );
150+
b.end();
151+
});

0 commit comments

Comments
 (0)