Skip to content

Commit 1fec2cf

Browse files
committed
Auto-generated commit
1 parent 77baff9 commit 1fec2cf

18 files changed

Lines changed: 2412 additions & 2 deletions

CHANGELOG.md

Lines changed: 6 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-13)
7+
## Unreleased (2026-05-14)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`4c997ac`](https://github.com/stdlib-js/stdlib/commit/4c997accfed0300c421104372e2621ec943c6ecf) - add `nans` to namespace
14+
- [`360877d`](https://github.com/stdlib-js/stdlib/commit/360877d131df2be59d1c0e4bf77928309519a341) - add `ndarray/nans`
1315
- [`3cefb9e`](https://github.com/stdlib-js/stdlib/commit/3cefb9eb9d4d70f52f80274ddd57a17c707c06d6) - add `nansLike` to namespace
1416
- [`17d522f`](https://github.com/stdlib-js/stdlib/commit/17d522f0eb85a41c1e5e265fdab34cc4b4aa8ffd) - add `ndarray/base/nans-like`
1517
- [`2c835da`](https://github.com/stdlib-js/stdlib/commit/2c835dabc4f37afb4f855dec66742d50d14adf32) - add `nansLike` to namespace
@@ -938,6 +940,9 @@ A total of 49 issues were closed in this release:
938940

939941
<details>
940942

943+
- [`a75c0b8`](https://github.com/stdlib-js/stdlib/commit/a75c0b8cb3f05a5b11f9c07eb2227c8ed86e796f) - **docs:** update ToC _(by Athan Reines)_
944+
- [`4c997ac`](https://github.com/stdlib-js/stdlib/commit/4c997accfed0300c421104372e2621ec943c6ecf) - **feat:** add `nans` to namespace _(by Athan Reines)_
945+
- [`360877d`](https://github.com/stdlib-js/stdlib/commit/360877d131df2be59d1c0e4bf77928309519a341) - **feat:** add `ndarray/nans` _(by Athan Reines)_
941946
- [`3cefb9e`](https://github.com/stdlib-js/stdlib/commit/3cefb9eb9d4d70f52f80274ddd57a17c707c06d6) - **feat:** add `nansLike` to namespace _(by Athan Reines)_
942947
- [`17d522f`](https://github.com/stdlib-js/stdlib/commit/17d522f0eb85a41c1e5e265fdab34cc4b4aa8ffd) - **feat:** add `ndarray/base/nans-like` _(by Athan Reines)_
943948
- [`dfda2f7`](https://github.com/stdlib-js/stdlib/commit/dfda2f76fffbc7450ba3b7c943787de52c05e7b7) - **docs:** update ToC _(by Athan Reines)_

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|nans-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|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 nans
599+
* @memberof ns
600+
* @readonly
601+
* @type {Function}
602+
* @see {@link module:@stdlib/ndarray/nans}
603+
*/
604+
setReadOnly( ns, 'nans', require( './../nans' ) );
605+
597606
/**
598607
* @name nansLike
599608
* @memberof ns

nans/README.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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+
# nans
22+
23+
> Create a NaN-filled [ndarray][@stdlib/ndarray/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes].
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 nans = require( '@stdlib/ndarray/nans' );
41+
```
42+
43+
#### nans( shape\[, options] )
44+
45+
Creates a NaN-filled [ndarray][@stdlib/ndarray/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes].
46+
47+
```javascript
48+
var getShape = require( '@stdlib/ndarray/shape' );
49+
var getDType = require( '@stdlib/ndarray/dtype' );
50+
51+
var arr = nans( [ 2, 2 ] );
52+
// returns <ndarray>[ [ NaN, NaN ], [ NaN, NaN ] ]
53+
54+
var sh = getShape( arr );
55+
// returns [ 2, 2 ]
56+
57+
var dt = String( getDType( arr ) );
58+
// returns 'float64'
59+
```
60+
61+
The specified output [ndarray][@stdlib/ndarray/ctor] shape may be either an array-like object or an integer value.
62+
63+
```javascript
64+
var getShape = require( '@stdlib/ndarray/shape' );
65+
var getDType = require( '@stdlib/ndarray/dtype' );
66+
67+
var arr = nans( 2 );
68+
// returns <ndarray>[ NaN, NaN ]
69+
70+
var sh = getShape( arr );
71+
// returns [ 2 ]
72+
73+
var dt = String( getDType( arr ) );
74+
// returns 'float64'
75+
```
76+
77+
The function accepts the following options:
78+
79+
- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be a floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. Default: `'float64'`.
80+
- **order**: specifies whether an [ndarray][@stdlib/ndarray/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). Default: `'row-major'`.
81+
- **mode**: specifies how to handle indices which exceed array dimensions (see [ndarray][@stdlib/ndarray/ctor]). Default: `'throw'`.
82+
- **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 ]`.
83+
- **readonly**: boolean indicating whether an array should be **read-only**. Default: `false`.
84+
85+
By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [`float64`][@stdlib/ndarray/dtypes] data type. To specify an alternative [data type][@stdlib/ndarray/dtypes], provide a `dtype` option.
86+
87+
```javascript
88+
var getShape = require( '@stdlib/ndarray/shape' );
89+
var getDType = require( '@stdlib/ndarray/dtype' );
90+
91+
var arr = nans( [ 2, 2 ], {
92+
'dtype': 'float32'
93+
});
94+
// returns <ndarray>[ [ NaN, NaN ], [ NaN, NaN ] ]
95+
96+
var sh = getShape( arr );
97+
// returns [ 2, 2 ]
98+
99+
var dt = String( getDType( arr ) );
100+
// returns 'float32'
101+
```
102+
103+
</section>
104+
105+
<!-- /.usage -->
106+
107+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
108+
109+
<section class="notes">
110+
111+
</section>
112+
113+
<!-- /.notes -->
114+
115+
<!-- Package usage examples. -->
116+
117+
<section class="examples">
118+
119+
## Examples
120+
121+
<!-- eslint no-undef: "error" -->
122+
123+
```javascript
124+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
125+
var nans = require( '@stdlib/ndarray/nans' );
126+
127+
// Specify a list of data types:
128+
var dt = [
129+
'float64',
130+
'float32',
131+
'complex128',
132+
'complex64',
133+
'generic'
134+
];
135+
136+
// Generate NaN-filled arrays...
137+
var arr;
138+
var i;
139+
for ( i = 0; i < dt.length; i++ ) {
140+
arr = nans( [ 2, 2 ], {
141+
'dtype': dt[ i ]
142+
});
143+
console.log( ndarray2array( arr ) );
144+
}
145+
```
146+
147+
</section>
148+
149+
<!-- /.examples -->
150+
151+
<!-- 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. -->
152+
153+
<section class="references">
154+
155+
</section>
156+
157+
<!-- /.references -->
158+
159+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
160+
161+
<section class="related">
162+
163+
</section>
164+
165+
<!-- /.related -->
166+
167+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
168+
169+
<section class="links">
170+
171+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
172+
173+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
174+
175+
</section>
176+
177+
<!-- /.links -->

nans/benchmark/benchmark.js

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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 format = require( '@stdlib/string/format' );
26+
var pkg = require( './../package.json' ).name;
27+
var nans = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var arr;
34+
var i;
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
arr = nans( [ 0 ] );
38+
if ( arr.length !== 0 ) {
39+
b.fail( 'should have length 0' );
40+
}
41+
}
42+
b.toc();
43+
if ( !isndarrayLike( arr ) ) {
44+
b.fail( 'should return an ndarray' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
49+
50+
bench( format( '%s:dtype=float64', pkg ), function benchmark( b ) {
51+
var arr;
52+
var i;
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
arr = nans( [ 0 ], {
56+
'dtype': 'float64'
57+
});
58+
if ( arr.length !== 0 ) {
59+
b.fail( 'should have length 0' );
60+
}
61+
}
62+
b.toc();
63+
if ( !isndarrayLike( arr ) ) {
64+
b.fail( 'should return an ndarray' );
65+
}
66+
b.pass( 'benchmark finished' );
67+
b.end();
68+
});
69+
70+
bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) {
71+
var arr;
72+
var i;
73+
b.tic();
74+
for ( i = 0; i < b.iterations; i++ ) {
75+
arr = nans( [ 0 ], {
76+
'dtype': 'float32'
77+
});
78+
if ( arr.length !== 0 ) {
79+
b.fail( 'should have length 0' );
80+
}
81+
}
82+
b.toc();
83+
if ( !isndarrayLike( arr ) ) {
84+
b.fail( 'should return an ndarray' );
85+
}
86+
b.pass( 'benchmark finished' );
87+
b.end();
88+
});
89+
90+
bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) {
91+
var arr;
92+
var i;
93+
b.tic();
94+
for ( i = 0; i < b.iterations; i++ ) {
95+
arr = nans( [ 0 ], {
96+
'dtype': 'complex128'
97+
});
98+
if ( arr.length !== 0 ) {
99+
b.fail( 'should have length 0' );
100+
}
101+
}
102+
b.toc();
103+
if ( !isndarrayLike( arr ) ) {
104+
b.fail( 'should return an ndarray' );
105+
}
106+
b.pass( 'benchmark finished' );
107+
b.end();
108+
});
109+
110+
bench( format( '%s:dtype=complex64', pkg ), function benchmark( b ) {
111+
var arr;
112+
var i;
113+
b.tic();
114+
for ( i = 0; i < b.iterations; i++ ) {
115+
arr = nans( [ 0 ], {
116+
'dtype': 'complex64'
117+
});
118+
if ( arr.length !== 0 ) {
119+
b.fail( 'should have length 0' );
120+
}
121+
}
122+
b.toc();
123+
if ( !isndarrayLike( arr ) ) {
124+
b.fail( 'should return an ndarray' );
125+
}
126+
b.pass( 'benchmark finished' );
127+
b.end();
128+
});
129+
130+
bench( format( '%s:dtype=generic', pkg ), function benchmark( b ) {
131+
var arr;
132+
var i;
133+
b.tic();
134+
for ( i = 0; i < b.iterations; i++ ) {
135+
arr = nans( [ 0 ], {
136+
'dtype': 'generic'
137+
});
138+
if ( arr.length !== 0 ) {
139+
b.fail( 'should have length 0' );
140+
}
141+
}
142+
b.toc();
143+
if ( !isndarrayLike( arr ) ) {
144+
b.fail( 'should return an ndarray' );
145+
}
146+
b.pass( 'benchmark finished' );
147+
b.end();
148+
});

0 commit comments

Comments
 (0)