@stdlib/array-full-like 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +481 -0
- package/NOTICE +1 -0
- package/README.md +224 -0
- package/docs/repl.txt +45 -0
- package/docs/types/index.d.ts +724 -0
- package/docs/types/test.ts +97 -0
- package/lib/index.js +46 -0
- package/lib/main.js +77 -0
- package/package.json +145 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022 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
|
+
import Complex128Array = require( '@stdlib/array-complex128' );
|
|
20
|
+
import Complex64Array = require( '@stdlib/array-complex64' );
|
|
21
|
+
import Complex128 = require( '@stdlib/complex-float64' );
|
|
22
|
+
import Complex64 = require( '@stdlib/complex-float32' );
|
|
23
|
+
import fullLike = require( './index' );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// TESTS //
|
|
27
|
+
|
|
28
|
+
// The function returns an array or typed array...
|
|
29
|
+
{
|
|
30
|
+
fullLike( [ 0, 0 ], 1 ); // $ExpectType any[]
|
|
31
|
+
fullLike( new Float64Array( [ 0, 0 ] ), 1 ); // $ExpectType Float64Array
|
|
32
|
+
fullLike( new Float32Array( [ 0, 0 ] ), 1 ); // $ExpectType Float32Array
|
|
33
|
+
fullLike( new Complex128Array( [ 0, 0 ] ), 1 ); // $ExpectType Complex128Array
|
|
34
|
+
fullLike( new Complex128Array( [ 0, 0 ] ), new Complex128( 1.0, 1.0 ) ); // $ExpectType Complex128Array
|
|
35
|
+
fullLike( new Complex64Array( [ 0, 0 ] ), 1 ); // $ExpectType Complex64Array
|
|
36
|
+
fullLike( new Complex64Array( [ 0, 0 ] ), new Complex64( 1.0, 1.0 ) ); // $ExpectType Complex64Array
|
|
37
|
+
fullLike( new Int32Array( [ 0, 0 ] ), 1 ); // $ExpectType Int32Array
|
|
38
|
+
fullLike( new Int16Array( [ 0, 0 ] ), 1 ); // $ExpectType Int16Array
|
|
39
|
+
fullLike( new Int8Array( [ 0, 0 ] ), 1 ); // $ExpectType Int8Array
|
|
40
|
+
fullLike( new Uint32Array( [ 0, 0 ] ), 1 ); // $ExpectType Uint32Array
|
|
41
|
+
fullLike( new Uint16Array( [ 0, 0 ] ), 1 ); // $ExpectType Uint16Array
|
|
42
|
+
fullLike( new Uint8Array( [ 0, 0 ] ), 1 ); // $ExpectType Uint8Array
|
|
43
|
+
fullLike( new Uint8ClampedArray( [ 0, 0 ] ), 1 ); // $ExpectType Uint8ClampedArray
|
|
44
|
+
|
|
45
|
+
fullLike( [ 0, 0 ], 1, 'float64' ); // $ExpectType Float64Array
|
|
46
|
+
fullLike( [ 0, 0 ], 1, 'float32' ); // $ExpectType Float32Array
|
|
47
|
+
fullLike( [ 0, 0 ], 1, 'complex128' ); // $ExpectType Complex128Array
|
|
48
|
+
fullLike( [ 0, 0 ], new Complex128( 1.0, 1.0 ), 'complex128' ); // $ExpectType Complex128Array
|
|
49
|
+
fullLike( [ 0, 0 ], 1, 'complex64' ); // $ExpectType Complex64Array
|
|
50
|
+
fullLike( [ 0, 0 ], new Complex64( 1.0, 1.0 ), 'complex64' ); // $ExpectType Complex64Array
|
|
51
|
+
fullLike( [ 0, 0 ], 1, 'int32' ); // $ExpectType Int32Array
|
|
52
|
+
fullLike( [ 0, 0 ], 1, 'int16' ); // $ExpectType Int16Array
|
|
53
|
+
fullLike( [ 0, 0 ], 1, 'int8' ); // $ExpectType Int8Array
|
|
54
|
+
fullLike( [ 0, 0 ], 1, 'uint32' ); // $ExpectType Uint32Array
|
|
55
|
+
fullLike( [ 0, 0 ], 1, 'uint16' ); // $ExpectType Uint16Array
|
|
56
|
+
fullLike( [ 0, 0 ], 1, 'uint8' ); // $ExpectType Uint8Array
|
|
57
|
+
fullLike( [ 0, 0 ], 1, 'uint8c' ); // $ExpectType Uint8ClampedArray
|
|
58
|
+
fullLike( [ 0, 0 ], 1, 'generic' ); // $ExpectType any[]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The compiler throws an error if the function is not provided an array or typed array for the first argument...
|
|
62
|
+
{
|
|
63
|
+
fullLike( '5', 1 ); // $ExpectError
|
|
64
|
+
fullLike( 5, 1 ); // $ExpectError
|
|
65
|
+
fullLike( false, 1 ); // $ExpectError
|
|
66
|
+
fullLike( true, 1 ); // $ExpectError
|
|
67
|
+
fullLike( null, 1 ); // $ExpectError
|
|
68
|
+
fullLike( undefined, 1 ); // $ExpectError
|
|
69
|
+
fullLike( {}, 1 ); // $ExpectError
|
|
70
|
+
fullLike( ( x: number ): number => x, 1 ); // $ExpectError
|
|
71
|
+
|
|
72
|
+
fullLike( '5', 1, 'float32' ); // $ExpectError
|
|
73
|
+
fullLike( 5, 1, 'float32' ); // $ExpectError
|
|
74
|
+
fullLike( false, 1, 'float32' ); // $ExpectError
|
|
75
|
+
fullLike( true, 1, 'float32' ); // $ExpectError
|
|
76
|
+
fullLike( null, 1, 'float32' ); // $ExpectError
|
|
77
|
+
fullLike( undefined, 1, 'float32' ); // $ExpectError
|
|
78
|
+
fullLike( {}, 1, 'float32' ); // $ExpectError
|
|
79
|
+
fullLike( ( x: number ): number => x, 1, 'float32' ); // $ExpectError
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The compiler throws an error if the function is provided a third argument which is an unrecognized/unsupported data type...
|
|
83
|
+
{
|
|
84
|
+
fullLike( [ 0, 0 ], 1, '10' ); // $ExpectError
|
|
85
|
+
fullLike( [ 0, 0 ], 1, 10 ); // $ExpectError
|
|
86
|
+
fullLike( [ 0, 0 ], 1, false ); // $ExpectError
|
|
87
|
+
fullLike( [ 0, 0 ], 1, true ); // $ExpectError
|
|
88
|
+
fullLike( [ 0, 0 ], 1, null ); // $ExpectError
|
|
89
|
+
fullLike( [ 0, 0 ], 1, [] ); // $ExpectError
|
|
90
|
+
fullLike( [ 0, 0 ], 1, {} ); // $ExpectError
|
|
91
|
+
fullLike( [ 0, 0 ], 1, ( x: number ): number => x ); // $ExpectError
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// The compiler throws an error if the function is provided an unsupported number of arguments...
|
|
95
|
+
{
|
|
96
|
+
fullLike( [ 0, 0 ], 1, 'float64', 1 ); // $ExpectError
|
|
97
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022 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 a filled array having the same length and data type as a provided input array.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/array-full-like
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var fullLike = require( '@stdlib/array-full-like' );
|
|
28
|
+
*
|
|
29
|
+
* var arr = fullLike( [ 0.0, 0.0 ], 1.0 );
|
|
30
|
+
* // returns [ 1.0, 1.0 ]
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* var fullLike = require( '@stdlib/array-full-like' );
|
|
34
|
+
*
|
|
35
|
+
* var arr = fullLike( [ 0.0, 0.0 ], 1.0, 'float32' );
|
|
36
|
+
* // returns <Float32Array>[ 1.0, 1.0 ]
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// MODULES //
|
|
40
|
+
|
|
41
|
+
var main = require( './main.js' );
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// EXPORTS //
|
|
45
|
+
|
|
46
|
+
module.exports = main;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022 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( '@stdlib/array-dtype' );
|
|
24
|
+
var full = require( '@stdlib/array-full' );
|
|
25
|
+
var Complex128 = require( '@stdlib/complex-float64' );
|
|
26
|
+
var Complex64 = require( '@stdlib/complex-float32' );
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// MAIN //
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a filled array having the same length and data type as a provided input array.
|
|
33
|
+
*
|
|
34
|
+
* @param {(Array|TypedArray|ComplexArray)} x - input array
|
|
35
|
+
* @param {number} value - fill value
|
|
36
|
+
* @param {string} [dtype] - data type
|
|
37
|
+
* @throws {TypeError} first argument must be an array or typed array
|
|
38
|
+
* @throws {TypeError} third argument must be a recognized data type
|
|
39
|
+
* @returns {(TypedArray|Array|ComplexArray)} array or typed array
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var arr = fullLike( [ 0.0, 0.0 ], 1.0 );
|
|
43
|
+
* // returns [ 1.0, 1.0 ]
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var arr = fullLike( [ 0.0, 0.0 ], 1.0, 'float32' );
|
|
47
|
+
* // returns <Float32Array>[ 1.0, 1.0 ]
|
|
48
|
+
*/
|
|
49
|
+
function fullLike( x, value ) {
|
|
50
|
+
var dt;
|
|
51
|
+
var v;
|
|
52
|
+
|
|
53
|
+
dt = dtype( x ); // delegate input argument validation to dtype resolution
|
|
54
|
+
if ( dt === null ) {
|
|
55
|
+
throw new TypeError( 'invalid argument. First argument must be either an array, typed array, or complex typed array. Value: `' + x + '`.' );
|
|
56
|
+
}
|
|
57
|
+
if ( arguments.length > 2 ) {
|
|
58
|
+
dt = arguments[ 2 ];
|
|
59
|
+
}
|
|
60
|
+
if ( typeof value === 'number' ) {
|
|
61
|
+
if ( dt === 'complex128' ) {
|
|
62
|
+
v = new Complex128( value, 0.0 );
|
|
63
|
+
} else if ( dt === 'complex64' ) {
|
|
64
|
+
v = new Complex64( value, 0.0 );
|
|
65
|
+
} else {
|
|
66
|
+
v = value;
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
v = value;
|
|
70
|
+
}
|
|
71
|
+
return full( x.length, v, dt );
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
// EXPORTS //
|
|
76
|
+
|
|
77
|
+
module.exports = fullLike;
|
package/package.json
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/array-full-like",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Create a filled array having the same length and data type as a provided array.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"benchmark": "./benchmark",
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"example": "./examples",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"test": "./test"
|
|
23
|
+
},
|
|
24
|
+
"types": "./docs/types",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "make test",
|
|
27
|
+
"test-cov": "make test-cov",
|
|
28
|
+
"examples": "make examples",
|
|
29
|
+
"benchmark": "make benchmark"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://stdlib.io",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git://github.com/stdlib-js/array-full-like.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@stdlib/array-dtype": "^0.0.x",
|
|
41
|
+
"@stdlib/array-full": "^0.0.x",
|
|
42
|
+
"@stdlib/complex-float32": "^0.0.x",
|
|
43
|
+
"@stdlib/complex-float64": "^0.0.x",
|
|
44
|
+
"@stdlib/types": "^0.0.x"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@stdlib/array-complex128": "^0.0.x",
|
|
48
|
+
"@stdlib/array-complex64": "^0.0.x",
|
|
49
|
+
"@stdlib/array-dtypes": "^0.0.x",
|
|
50
|
+
"@stdlib/array-float32": "^0.0.x",
|
|
51
|
+
"@stdlib/array-float64": "^0.0.x",
|
|
52
|
+
"@stdlib/array-int16": "^0.0.x",
|
|
53
|
+
"@stdlib/array-int32": "^0.0.x",
|
|
54
|
+
"@stdlib/array-int8": "^0.0.x",
|
|
55
|
+
"@stdlib/array-uint16": "^0.0.x",
|
|
56
|
+
"@stdlib/array-uint32": "^0.0.x",
|
|
57
|
+
"@stdlib/array-uint8": "^0.0.x",
|
|
58
|
+
"@stdlib/array-uint8c": "^0.0.x",
|
|
59
|
+
"@stdlib/array-zeros": "^0.0.x",
|
|
60
|
+
"@stdlib/assert-instance-of": "^0.0.x",
|
|
61
|
+
"@stdlib/assert-is-array": "^0.0.x",
|
|
62
|
+
"@stdlib/assert-is-typed-array": "^0.0.x",
|
|
63
|
+
"@stdlib/assert-is-typed-array-like": "^0.0.x",
|
|
64
|
+
"@stdlib/bench": "^0.0.x",
|
|
65
|
+
"@stdlib/math-base-special-pow": "^0.0.x",
|
|
66
|
+
"@stdlib/strided-base-reinterpret-complex128": "^0.0.x",
|
|
67
|
+
"@stdlib/strided-base-reinterpret-complex64": "^0.0.x",
|
|
68
|
+
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
69
|
+
"istanbul": "^0.4.1",
|
|
70
|
+
"tap-spec": "5.x.x"
|
|
71
|
+
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"node": ">=0.10.0",
|
|
74
|
+
"npm": ">2.7.0"
|
|
75
|
+
},
|
|
76
|
+
"os": [
|
|
77
|
+
"aix",
|
|
78
|
+
"darwin",
|
|
79
|
+
"freebsd",
|
|
80
|
+
"linux",
|
|
81
|
+
"macos",
|
|
82
|
+
"openbsd",
|
|
83
|
+
"sunos",
|
|
84
|
+
"win32",
|
|
85
|
+
"windows"
|
|
86
|
+
],
|
|
87
|
+
"keywords": [
|
|
88
|
+
"stdlib",
|
|
89
|
+
"stdtypes",
|
|
90
|
+
"types",
|
|
91
|
+
"data",
|
|
92
|
+
"structure",
|
|
93
|
+
"typed",
|
|
94
|
+
"array",
|
|
95
|
+
"typed array",
|
|
96
|
+
"typed-array",
|
|
97
|
+
"vector",
|
|
98
|
+
"ndarray",
|
|
99
|
+
"matrix",
|
|
100
|
+
"float64array",
|
|
101
|
+
"float32array",
|
|
102
|
+
"int32array",
|
|
103
|
+
"uint32array",
|
|
104
|
+
"int16array",
|
|
105
|
+
"uint16array",
|
|
106
|
+
"int8array",
|
|
107
|
+
"uint8array",
|
|
108
|
+
"uint8clampedarray",
|
|
109
|
+
"complex128array",
|
|
110
|
+
"complex64array",
|
|
111
|
+
"complex128",
|
|
112
|
+
"complex64",
|
|
113
|
+
"complex",
|
|
114
|
+
"cmplx",
|
|
115
|
+
"float64",
|
|
116
|
+
"double",
|
|
117
|
+
"precision",
|
|
118
|
+
"double-precision",
|
|
119
|
+
"single",
|
|
120
|
+
"float",
|
|
121
|
+
"single-precision",
|
|
122
|
+
"float32",
|
|
123
|
+
"ieee754",
|
|
124
|
+
"integer",
|
|
125
|
+
"int32",
|
|
126
|
+
"signed",
|
|
127
|
+
"unsigned",
|
|
128
|
+
"uint32",
|
|
129
|
+
"int16",
|
|
130
|
+
"uint16",
|
|
131
|
+
"int8",
|
|
132
|
+
"uint8",
|
|
133
|
+
"uint8c",
|
|
134
|
+
"clamped",
|
|
135
|
+
"short",
|
|
136
|
+
"long",
|
|
137
|
+
"generic",
|
|
138
|
+
"fill",
|
|
139
|
+
"filled"
|
|
140
|
+
],
|
|
141
|
+
"funding": {
|
|
142
|
+
"type": "patreon",
|
|
143
|
+
"url": "https://www.patreon.com/athan"
|
|
144
|
+
}
|
|
145
|
+
}
|