Skip to content

Commit 77baff9

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

17 files changed

Lines changed: 1487 additions & 0 deletions

CHANGELOG.md

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

1111
### Features
1212

13+
- [`3cefb9e`](https://github.com/stdlib-js/stdlib/commit/3cefb9eb9d4d70f52f80274ddd57a17c707c06d6) - add `nansLike` to namespace
14+
- [`17d522f`](https://github.com/stdlib-js/stdlib/commit/17d522f0eb85a41c1e5e265fdab34cc4b4aa8ffd) - add `ndarray/base/nans-like`
1315
- [`2c835da`](https://github.com/stdlib-js/stdlib/commit/2c835dabc4f37afb4f855dec66742d50d14adf32) - add `nansLike` to namespace
1416
- [`b9ecb29`](https://github.com/stdlib-js/stdlib/commit/b9ecb2970eedca271688dc7fc12ee2247a43cbf3) - add `ndarray/nans-like`
1517
- [`0d5b82a`](https://github.com/stdlib-js/stdlib/commit/0d5b82a1055d8a5fe51eae4011bedf64844fb48e) - add `onesLike` to namespace
@@ -936,6 +938,8 @@ A total of 49 issues were closed in this release:
936938

937939
<details>
938940

941+
- [`3cefb9e`](https://github.com/stdlib-js/stdlib/commit/3cefb9eb9d4d70f52f80274ddd57a17c707c06d6) - **feat:** add `nansLike` to namespace _(by Athan Reines)_
942+
- [`17d522f`](https://github.com/stdlib-js/stdlib/commit/17d522f0eb85a41c1e5e265fdab34cc4b4aa8ffd) - **feat:** add `ndarray/base/nans-like` _(by Athan Reines)_
939943
- [`dfda2f7`](https://github.com/stdlib-js/stdlib/commit/dfda2f76fffbc7450ba3b7c943787de52c05e7b7) - **docs:** update ToC _(by Athan Reines)_
940944
- [`2c835da`](https://github.com/stdlib-js/stdlib/commit/2c835dabc4f37afb4f855dec66742d50d14adf32) - **feat:** add `nansLike` to namespace _(by Athan Reines)_
941945
- [`b9ecb29`](https://github.com/stdlib-js/stdlib/commit/b9ecb2970eedca271688dc7fc12ee2247a43cbf3) - **feat:** add `ndarray/nans-like` _(by Athan Reines)_

base/lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,15 @@ setReadOnly( ns, 'minmaxViewBufferIndex', require( './../../base/minmax-view-buf
904904
*/
905905
setReadOnly( ns, 'nans', require( './../../base/nans' ) );
906906

907+
/**
908+
* @name nansLike
909+
* @memberof ns
910+
* @readonly
911+
* @type {Function}
912+
* @see {@link module:@stdlib/ndarray/base/nans-like}
913+
*/
914+
setReadOnly( ns, 'nansLike', require( './../../base/nans-like' ) );
915+
907916
/**
908917
* @name ndarraylike2ndarray
909918
* @memberof ns

base/nans-like/README.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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 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/base/nans-like' );
41+
```
42+
43+
#### nansLike( x )
44+
45+
Creates a NaN-filled ndarray 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 ones = require( '@stdlib/ndarray/ones' );
50+
51+
var x = ones( [ 2, 2 ] );
52+
// returns <ndarray>[ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]
53+
54+
var y = nansLike( x );
55+
// returns <ndarray>[ [ NaN, NaN ], [ NaN, NaN ] ]
56+
57+
var sh = getShape( y );
58+
// returns [ 2, 2 ]
59+
```
60+
61+
</section>
62+
63+
<!-- /.usage -->
64+
65+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
66+
67+
<section class="notes">
68+
69+
## Notes
70+
71+
- Along with data type, shape, and order, the function infers the "class" of the returned ndarray from the provided ndarray. For example, if provided a "base" [ndarray][@stdlib/ndarray/base/ctor], the function returns a base [ndarray][@stdlib/ndarray/base/ctor]. If provided a non-base [ndarray][@stdlib/ndarray/ctor], the function returns a non-base [ndarray][@stdlib/ndarray/ctor].
72+
73+
</section>
74+
75+
<!-- /.notes -->
76+
77+
<!-- Package usage examples. -->
78+
79+
<section class="examples">
80+
81+
## Examples
82+
83+
<!-- eslint no-undef: "error" -->
84+
85+
```javascript
86+
var ones = require( '@stdlib/ndarray/ones' );
87+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
88+
var nansLike = require( '@stdlib/ndarray/base/nans-like' );
89+
90+
// Specify a list of data types:
91+
var dt = [
92+
'float64',
93+
'float32',
94+
'complex128',
95+
'complex64',
96+
'generic'
97+
];
98+
99+
// Generate NaN-filled arrays...
100+
var x;
101+
var y;
102+
var i;
103+
for ( i = 0; i < dt.length; i++ ) {
104+
x = ones( [ 2, 2 ], {
105+
'dtype': dt[ i ]
106+
});
107+
y = nansLike( x );
108+
console.log( ndarray2array( y ) );
109+
}
110+
```
111+
112+
</section>
113+
114+
<!-- /.examples -->
115+
116+
<!-- 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. -->
117+
118+
<section class="references">
119+
120+
</section>
121+
122+
<!-- /.references -->
123+
124+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
125+
126+
<section class="related">
127+
128+
</section>
129+
130+
<!-- /.related -->
131+
132+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
133+
134+
<section class="links">
135+
136+
[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray/tree/main/base/ctor
137+
138+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
139+
140+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
141+
142+
</section>
143+
144+
<!-- /.links -->
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 ones = require( './../../../base/ones' );
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 = ones( 'float64', [ 0 ], 'row-major' );
39+
40+
b.tic();
41+
for ( i = 0; i < b.iterations; i++ ) {
42+
y = nansLike( x );
43+
if ( y.length !== 0 ) {
44+
b.fail( 'should have length 0' );
45+
}
46+
}
47+
b.toc();
48+
if ( !isndarrayLike( y ) ) {
49+
b.fail( 'should return an ndarray' );
50+
}
51+
b.pass( 'benchmark finished' );
52+
b.end();
53+
});
54+
55+
bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) {
56+
var x;
57+
var y;
58+
var i;
59+
60+
x = ones( 'float32', [ 0 ], 'row-major' );
61+
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
y = nansLike( x );
65+
if ( y.length !== 0 ) {
66+
b.fail( 'should have length 0' );
67+
}
68+
}
69+
b.toc();
70+
if ( !isndarrayLike( y ) ) {
71+
b.fail( 'should return an ndarray' );
72+
}
73+
b.pass( 'benchmark finished' );
74+
b.end();
75+
});
76+
77+
bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) {
78+
var x;
79+
var y;
80+
var i;
81+
82+
x = ones( 'complex128', [ 0 ], 'row-major' );
83+
84+
b.tic();
85+
for ( i = 0; i < b.iterations; i++ ) {
86+
y = nansLike( x );
87+
if ( y.length !== 0 ) {
88+
b.fail( 'should have length 0' );
89+
}
90+
}
91+
b.toc();
92+
if ( !isndarrayLike( y ) ) {
93+
b.fail( 'should return an ndarray' );
94+
}
95+
b.pass( 'benchmark finished' );
96+
b.end();
97+
});
98+
99+
bench( format( '%s:dtype=complex64', pkg ), function benchmark( b ) {
100+
var x;
101+
var y;
102+
var i;
103+
104+
x = ones( 'complex64', [ 0 ], 'row-major' );
105+
106+
b.tic();
107+
for ( i = 0; i < b.iterations; i++ ) {
108+
y = nansLike( x );
109+
if ( y.length !== 0 ) {
110+
b.fail( 'should have length 0' );
111+
}
112+
}
113+
b.toc();
114+
if ( !isndarrayLike( y ) ) {
115+
b.fail( 'should return an ndarray' );
116+
}
117+
b.pass( 'benchmark finished' );
118+
b.end();
119+
});
120+
121+
bench( format( '%s:dtype=generic', pkg ), function benchmark( b ) {
122+
var x;
123+
var y;
124+
var i;
125+
126+
x = ones( 'generic', [ 0 ], 'row-major' );
127+
128+
b.tic();
129+
for ( i = 0; i < b.iterations; i++ ) {
130+
y = nansLike( x );
131+
if ( y.length !== 0 ) {
132+
b.fail( 'should have length 0' );
133+
}
134+
}
135+
b.toc();
136+
if ( !isndarrayLike( y ) ) {
137+
b.fail( 'should return an ndarray' );
138+
}
139+
b.pass( 'benchmark finished' );
140+
b.end();
141+
});

0 commit comments

Comments
 (0)