stdlib-js / array

@@ -0,0 +1,85 @@
Loading
1 +
/**
2 +
* @license Apache-2.0
3 +
*
4 +
* Copyright (c) 2023 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 dtype = require( './../../dtype' );
24 +
var full = require( './../../full' );
25 +
var Complex128 = require( '@stdlib/complex/float64' );
26 +
var Complex64 = require( '@stdlib/complex/float32' );
27 +
var format = require( '@stdlib/string/format' );
28 +
29 +
30 +
// VARIABLES //
31 +
32 +
var Z128 = new Complex128( NaN, NaN );
33 +
var Z64 = new Complex64( NaN, NaN );
34 +
var DTYPES = [ 'float64', 'float32', 'complex128', 'complex64', 'generic' ];
35 +
36 +
37 +
// MAIN //
38 +
39 +
/**
40 +
* Creates an array filled with NaNs and having the same length and data type as a provided input array.
41 +
*
42 +
* @param {(Array|TypedArray|ComplexArray)} x - input array
43 +
* @param {string} [dtype] - data type
44 +
* @throws {TypeError} first argument must be an array or typed array
45 +
* @throws {TypeError} second argument must be a supported data type
46 +
* @returns {(TypedArray|Array|ComplexArray)} array or typed array
47 +
*
48 +
* @example
49 +
* var arr = nansLike( [ 0.0, 0.0 ] );
50 +
* // returns [ NaN, NaN ]
51 +
*
52 +
* @example
53 +
* var arr = nansLike( [ 0.0, 0.0 ], 'float32' );
54 +
* // returns <Float32Array>[ NaN, NaN ]
55 +
*/
56 +
function nansLike( x ) {
57 +
	var dt;
58 +
	var v;
59 +
60 +
	dt = dtype( x ); // delegate input argument validation to dtype resolution
61 +
	if ( dt === null ) {
62 +
		throw new TypeError( format( 'invalid argument. First argument must be either an array, typed array, or complex typed array. Value: `%s`.', x ) );
63 +
	}
64 +
	if ( arguments.length > 1 ) {
65 +
		dt = arguments[ 1 ];
66 +
		if ( DTYPES.indexOf( dt ) === -1 ) {
67 +
			throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', DTYPES.join( '", "' ), dt ) );
68 +
		}
69 +
	} else if ( DTYPES.indexOf( dt ) === -1 ) {
70 +
		throw new TypeError( format( 'invalid argument. First argument must be one of the following data types: "%s". Value: `%s`.', DTYPES.join( '", "' ), dt ) );
71 +
	}
72 +
	if ( dt === 'complex128' ) {
73 +
		v = Z128;
74 +
	} else if ( dt === 'complex64' ) {
75 +
		v = Z64;
76 +
	} else {
77 +
		v = NaN;
78 +
	}
79 +
	return full( x.length, v, dt );
80 +
}
81 +
82 +
83 +
// EXPORTS //
84 +
85 +
module.exports = nansLike;

@@ -0,0 +1,46 @@
Loading
1 +
/**
2 +
* @license Apache-2.0
3 +
*
4 +
* Copyright (c) 2023 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 +
/**
22 +
* Create an array filled with NaNs and having the same length and data type as a provided input array.
23 +
*
24 +
* @module @stdlib/array/nans-like
25 +
*
26 +
* @example
27 +
* var nansLike = require( '@stdlib/array/nans-like' );
28 +
*
29 +
* var arr = nansLike( [ 0.0, 0.0 ] );
30 +
* // returns [ NaN, NaN ]
31 +
*
32 +
* @example
33 +
* var nansLike = require( '@stdlib/array/nans-like' );
34 +
*
35 +
* var arr = nansLike( [ 0.0, 0.0 ], 'float32' );
36 +
* // returns <Float32Array>[ NaN, NaN ]
37 +
*/
38 +
39 +
// MODULES //
40 +
41 +
var main = require( './main.js' );
42 +
43 +
44 +
// EXPORTS //
45 +
46 +
module.exports = main;

@@ -274,6 +274,15 @@
Loading
274 274
*/
275 275
setReadOnly( ns, 'anans', require( './../nans' ) );
276 276
277 +
/**
278 +
* @name anansLike
279 +
* @memberof ns
280 +
* @readonly
281 +
* @constructor
282 +
* @see {@link module:@stdlib/array/nans-like}
283 +
*/
284 +
setReadOnly( ns, 'anansLike', require( './../nans-like' ) );
285 +
277 286
/**
278 287
* @name arrayNextDataType
279 288
* @memberof ns
Files Coverage
base 100.00%
buffer/lib 100.00%
complex128/lib 99.78%
complex64/lib 99.78%
convert-same/lib 100.00%
convert/lib 100.00%
ctors/lib 100.00%
dataview/lib 100.00%
datespace/lib 100.00%
dtype/lib 100.00%
dtypes/lib 100.00%
filled-by/lib 100.00%
filled/lib 100.00%
float32/lib 100.00%
float64/lib 100.00%
from-iterator/lib 100.00%
full-like/lib 100.00%
full/lib 100.00%
incrspace/lib 100.00%
int16/lib 100.00%
int32/lib 100.00%
int8/lib 100.00%
linspace/lib 100.00%
logspace/lib 100.00%
min-dtype/lib 100.00%
nans-like/lib 96.55%
nans/lib 100.00%
next-dtype/lib 100.00%
ones-like/lib 100.00%
ones/lib 100.00%
pool/lib 98.93%
promotion-rules/lib 100.00%
reviver/lib 100.00%
safe-casts/lib 100.00%
same-kind-casts/lib 100.00%
shape/lib 100.00%
shared-buffer/lib 100.00%
to-circular-iterator/lib 99.07%
to-iterator-right/lib 98.46%
to-iterator/lib 100.00%
to-json/lib 100.00%
to-sparse-iterator-right/lib 98.63%
to-sparse-iterator/lib 98.63%
to-strided-iterator/lib 98.67%
to-view-iterator-right/lib 99.00%
to-view-iterator/lib 99.00%
typed-complex-ctors/lib 100.00%
typed-complex-dtypes/lib 100.00%
typed-complex/lib 100.00%
typed-ctors/lib 100.00%
typed-dtypes/lib 100.00%
typed-float-ctors/lib 100.00%
typed-float-dtypes/lib 100.00%
typed-integer-ctors/lib 100.00%
typed-integer-dtypes/lib 100.00%
typed-real-ctors/lib 100.00%
typed-real-dtypes/lib 100.00%
typed-real-float-ctors/lib 100.00%
typed-real-float-dtypes/lib 100.00%
typed-real/lib 100.00%
typed-signed-integer-ctors/lib 100.00%
typed-signed-integer-dtypes/lib 100.00%
typed-unsigned-integer-ctors/lib 100.00%
typed-unsigned-integer-dtypes/lib 100.00%
typed/lib 100.00%
uint16/lib 100.00%
uint32/lib 100.00%
uint8/lib 100.00%
uint8c/lib 100.00%
zeros-like/lib 100.00%
zeros/lib 100.00%
lib/index.js 100.00%
Project Totals (233 files) 99.71%
4094134300
unittests

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading