@stdlib/ndarray-zeros-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 +239 -0
- package/docs/repl.txt +53 -0
- package/docs/types/index.d.ts +1037 -0
- package/docs/types/test.ts +167 -0
- package/lib/index.js +50 -0
- package/lib/main.js +131 -0
- package/package.json +107 -0
|
@@ -0,0 +1,167 @@
|
|
|
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 zeros = require( '@stdlib/ndarray-base-zeros' );
|
|
20
|
+
import zerosLike = require( './index' );
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// TESTS //
|
|
24
|
+
|
|
25
|
+
// The function returns an ndarray...
|
|
26
|
+
{
|
|
27
|
+
const sh = [ 2, 2 ];
|
|
28
|
+
const ord = 'row-major';
|
|
29
|
+
|
|
30
|
+
zerosLike( zeros( 'float64', sh, ord ) ); // $ExpectType float64ndarray
|
|
31
|
+
zerosLike( zeros( 'float32', sh, ord ) ); // $ExpectType float32ndarray
|
|
32
|
+
zerosLike( zeros( 'complex128', sh, ord ) ); // $ExpectType complex128ndarray
|
|
33
|
+
zerosLike( zeros( 'complex64', sh, ord ) ); // $ExpectType complex64ndarray
|
|
34
|
+
zerosLike( zeros( 'int32', sh, ord ) ); // $ExpectType int32ndarray
|
|
35
|
+
zerosLike( zeros( 'int16', sh, ord ) ); // $ExpectType int16ndarray
|
|
36
|
+
zerosLike( zeros( 'int8', sh, ord ) ); // $ExpectType int8ndarray
|
|
37
|
+
zerosLike( zeros( 'uint32', sh, ord ) ); // $ExpectType uint32ndarray
|
|
38
|
+
zerosLike( zeros( 'uint16', sh, ord ) ); // $ExpectType uint16ndarray
|
|
39
|
+
zerosLike( zeros( 'uint8', sh, ord ) ); // $ExpectType uint8ndarray
|
|
40
|
+
zerosLike( zeros( 'uint8c', sh, ord ) ); // $ExpectType uint8cndarray
|
|
41
|
+
zerosLike( zeros( 'generic', sh, ord ) ); // $ExpectType typedndarray<number>
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
zerosLike( zeros( 'float64', sh, ord ), {} ); // $ExpectType float64ndarray
|
|
45
|
+
zerosLike( zeros( 'float32', sh, ord ), {} ); // $ExpectType float32ndarray
|
|
46
|
+
zerosLike( zeros( 'complex128', sh, ord ), {} ); // $ExpectType complex128ndarray
|
|
47
|
+
zerosLike( zeros( 'complex64', sh, ord ), {} ); // $ExpectType complex64ndarray
|
|
48
|
+
zerosLike( zeros( 'int32', sh, ord ), {} ); // $ExpectType int32ndarray
|
|
49
|
+
zerosLike( zeros( 'int16', sh, ord ), {} ); // $ExpectType int16ndarray
|
|
50
|
+
zerosLike( zeros( 'int8', sh, ord ), {} ); // $ExpectType int8ndarray
|
|
51
|
+
zerosLike( zeros( 'uint32', sh, ord ), {} ); // $ExpectType uint32ndarray
|
|
52
|
+
zerosLike( zeros( 'uint16', sh, ord ), {} ); // $ExpectType uint16ndarray
|
|
53
|
+
zerosLike( zeros( 'uint8', sh, ord ), {} ); // $ExpectType uint8ndarray
|
|
54
|
+
zerosLike( zeros( 'uint8c', sh, ord ), {} ); // $ExpectType uint8cndarray
|
|
55
|
+
zerosLike( zeros( 'generic', sh, ord ), {} ); // $ExpectType typedndarray<number>
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
zerosLike( zeros( 'float64', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType float64ndarray
|
|
59
|
+
zerosLike( zeros( 'float32', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType float32ndarray
|
|
60
|
+
zerosLike( zeros( 'complex128', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType complex128ndarray
|
|
61
|
+
zerosLike( zeros( 'complex64', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType complex64ndarray
|
|
62
|
+
zerosLike( zeros( 'int32', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType int32ndarray
|
|
63
|
+
zerosLike( zeros( 'int16', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType int16ndarray
|
|
64
|
+
zerosLike( zeros( 'int8', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType int8ndarray
|
|
65
|
+
zerosLike( zeros( 'uint32', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType uint32ndarray
|
|
66
|
+
zerosLike( zeros( 'uint16', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType uint16ndarray
|
|
67
|
+
zerosLike( zeros( 'uint8', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType uint8ndarray
|
|
68
|
+
zerosLike( zeros( 'uint8c', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType uint8cndarray
|
|
69
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'shape': [ 2, 2, 2 ] } ); // $ExpectType typedndarray<number>
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
zerosLike( zeros( 'float64', sh, ord ), { 'order': 'column-major' } ); // $ExpectType float64ndarray
|
|
73
|
+
zerosLike( zeros( 'float32', sh, ord ), { 'order': 'column-major' } ); // $ExpectType float32ndarray
|
|
74
|
+
zerosLike( zeros( 'complex128', sh, ord ), { 'order': 'column-major' } ); // $ExpectType complex128ndarray
|
|
75
|
+
zerosLike( zeros( 'complex64', sh, ord ), { 'order': 'column-major' } ); // $ExpectType complex64ndarray
|
|
76
|
+
zerosLike( zeros( 'int32', sh, ord ), { 'order': 'column-major' } ); // $ExpectType int32ndarray
|
|
77
|
+
zerosLike( zeros( 'int16', sh, ord ), { 'order': 'column-major' } ); // $ExpectType int16ndarray
|
|
78
|
+
zerosLike( zeros( 'int8', sh, ord ), { 'order': 'column-major' } ); // $ExpectType int8ndarray
|
|
79
|
+
zerosLike( zeros( 'uint32', sh, ord ), { 'order': 'column-major' } ); // $ExpectType uint32ndarray
|
|
80
|
+
zerosLike( zeros( 'uint16', sh, ord ), { 'order': 'column-major' } ); // $ExpectType uint16ndarray
|
|
81
|
+
zerosLike( zeros( 'uint8', sh, ord ), { 'order': 'column-major' } ); // $ExpectType uint8ndarray
|
|
82
|
+
zerosLike( zeros( 'uint8c', sh, ord ), { 'order': 'column-major' } ); // $ExpectType uint8cndarray
|
|
83
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'order': 'column-major' } ); // $ExpectType typedndarray<number>
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'float64' } ); // $ExpectType float64ndarray
|
|
87
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'float32' } ); // $ExpectType float32ndarray
|
|
88
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' } ); // $ExpectType complex128ndarray
|
|
89
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' } ); // $ExpectType complex64ndarray
|
|
90
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'int32' } ); // $ExpectType int32ndarray
|
|
91
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'int16' } ); // $ExpectType int16ndarray
|
|
92
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'int8' } ); // $ExpectType int8ndarray
|
|
93
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' } ); // $ExpectType uint32ndarray
|
|
94
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' } ); // $ExpectType uint16ndarray
|
|
95
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' } ); // $ExpectType uint8ndarray
|
|
96
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' } ); // $ExpectType uint8cndarray
|
|
97
|
+
zerosLike( zeros( 'generic', sh, ord ), { 'dtype': 'generic' } ); // $ExpectType typedndarray<number>
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// The compiler throws an error if the function is provided a first argument is not an ndarray which has a recognized/supported data type...
|
|
101
|
+
{
|
|
102
|
+
zerosLike( '10' ); // $ExpectError
|
|
103
|
+
zerosLike( 10 ); // $ExpectError
|
|
104
|
+
zerosLike( false ); // $ExpectError
|
|
105
|
+
zerosLike( true ); // $ExpectError
|
|
106
|
+
zerosLike( null ); // $ExpectError
|
|
107
|
+
zerosLike( [] ); // $ExpectError
|
|
108
|
+
zerosLike( {} ); // $ExpectError
|
|
109
|
+
zerosLike( ( x: number ): number => x ); // $ExpectError
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// The compiler throws an error if the function is provided a second argument is not an options object...
|
|
113
|
+
{
|
|
114
|
+
const x = zeros( 'generic', [ 2, 2 ], 'row-major' );
|
|
115
|
+
|
|
116
|
+
zerosLike( x, '10' ); // $ExpectError
|
|
117
|
+
zerosLike( x, 10 ); // $ExpectError
|
|
118
|
+
zerosLike( x, false ); // $ExpectError
|
|
119
|
+
zerosLike( x, true ); // $ExpectError
|
|
120
|
+
zerosLike( x, [] ); // $ExpectError
|
|
121
|
+
zerosLike( x, ( x: number ): number => x ); // $ExpectError
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// The compiler throws an error if the function is provided a `dtype` option which is not a valid data type...
|
|
125
|
+
{
|
|
126
|
+
const x = zeros( 'generic', [ 2, 2 ], 'row-major' );
|
|
127
|
+
|
|
128
|
+
zerosLike( x, { 'dtype': '10' } ); // $ExpectError
|
|
129
|
+
zerosLike( x, { 'dtype': 10 } ); // $ExpectError
|
|
130
|
+
zerosLike( x, { 'dtype': null } ); // $ExpectError
|
|
131
|
+
zerosLike( x, { 'dtype': false } ); // $ExpectError
|
|
132
|
+
zerosLike( x, { 'dtype': true } ); // $ExpectError
|
|
133
|
+
zerosLike( x, { 'dtype': [] } ); // $ExpectError
|
|
134
|
+
zerosLike( x, { 'dtype': {} } ); // $ExpectError
|
|
135
|
+
zerosLike( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// The compiler throws an error if the function is provided an `order` option which is not a valid order...
|
|
139
|
+
{
|
|
140
|
+
const x = zeros( 'generic', [ 2, 2 ], 'row-major' );
|
|
141
|
+
|
|
142
|
+
zerosLike( x, { 'order': '10' } ); // $ExpectError
|
|
143
|
+
zerosLike( x, { 'order': 10 } ); // $ExpectError
|
|
144
|
+
zerosLike( x, { 'order': false } ); // $ExpectError
|
|
145
|
+
zerosLike( x, { 'order': true } ); // $ExpectError
|
|
146
|
+
zerosLike( x, { 'order': [] } ); // $ExpectError
|
|
147
|
+
zerosLike( x, { 'order': {} } ); // $ExpectError
|
|
148
|
+
zerosLike( x, { 'order': ( x: number ): number => x } ); // $ExpectError
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// The compiler throws an error if the function is provided a `shape` option which is not a valid shape...
|
|
152
|
+
{
|
|
153
|
+
const x = zeros( 'generic', [ 2, 2 ], 'row-major' );
|
|
154
|
+
|
|
155
|
+
zerosLike( x, { 'shape': '10' } ); // $ExpectError
|
|
156
|
+
zerosLike( x, { 'shape': false } ); // $ExpectError
|
|
157
|
+
zerosLike( x, { 'shape': true } ); // $ExpectError
|
|
158
|
+
zerosLike( x, { 'shape': [ '5' ] } ); // $ExpectError
|
|
159
|
+
zerosLike( x, { 'shape': {} } ); // $ExpectError
|
|
160
|
+
zerosLike( x, { 'shape': ( x: number ): number => x } ); // $ExpectError
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// The compiler throws an error if the function is provided an unsupported number of arguments...
|
|
164
|
+
{
|
|
165
|
+
zerosLike(); // $ExpectError
|
|
166
|
+
zerosLike( zeros( 'float64', [ 2, 2 ], 'row-major' ), {}, 1 ); // $ExpectError
|
|
167
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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 zero-filled ndarray having the same shape and data type as a provided ndarray.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/ndarray-zeros-like
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
28
|
+
* var zerosLike = require( '@stdlib/ndarray-zeros-like' );
|
|
29
|
+
*
|
|
30
|
+
* var x = zeros( [ 2, 2 ] );
|
|
31
|
+
* // returns <ndarray>
|
|
32
|
+
*
|
|
33
|
+
* var y = zerosLike( x );
|
|
34
|
+
* // returns <ndarray>
|
|
35
|
+
*
|
|
36
|
+
* var sh = y.shape;
|
|
37
|
+
* // returns [ 2, 2 ]
|
|
38
|
+
*
|
|
39
|
+
* var dt = y.dtype;
|
|
40
|
+
* // returns 'float64'
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
// MODULES //
|
|
44
|
+
|
|
45
|
+
var main = require( './main.js' );
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// EXPORTS //
|
|
49
|
+
|
|
50
|
+
module.exports = main;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );
|
|
24
|
+
var isPlainObject = require( '@stdlib/assert-is-plain-object' );
|
|
25
|
+
var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives;
|
|
26
|
+
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
27
|
+
var shape2strides = require( '@stdlib/ndarray-base-shape2strides' );
|
|
28
|
+
var strides2offset = require( '@stdlib/ndarray-base-strides2offset' );
|
|
29
|
+
var buffer = require( '@stdlib/ndarray-base-buffer' );
|
|
30
|
+
var numel = require( '@stdlib/ndarray-base-numel' );
|
|
31
|
+
var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// MAIN //
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a zero-filled ndarray having the same shape and data type as a provided ndarray.
|
|
38
|
+
*
|
|
39
|
+
* @param {ndarray} x - input array
|
|
40
|
+
* @param {Options} [options] - function options
|
|
41
|
+
* @param {string} [options.dtype] - output array data type (overrides the input array's inferred data type)
|
|
42
|
+
* @param {string} [options.order] - specifies whether the output array should be 'row-major' (C-style) or 'column-major' (Fortran-style) (overrides the input array's inferred order)
|
|
43
|
+
* @param {(NonNegativeIntegerArray|NonNegativeInteger)} [options.shape] - output array shape (overrides the input array's inferred shape)
|
|
44
|
+
* @throws {TypeError} first argument must have a recognized data type
|
|
45
|
+
* @throws {TypeError} options argument must be an object
|
|
46
|
+
* @throws {TypeError} `dtype` option must be a supported ndarray data type
|
|
47
|
+
* @throws {TypeError} `order` option must be a supported order
|
|
48
|
+
* @throws {TypeError} `shape` option must be either a nonnegative integer or an array of nonnegative integers
|
|
49
|
+
* @returns {ndarray} ndarray
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
53
|
+
*
|
|
54
|
+
* var x = zeros( [ 2, 2 ] );
|
|
55
|
+
* // returns <ndarray>
|
|
56
|
+
*
|
|
57
|
+
* var y = zerosLike( x );
|
|
58
|
+
* // returns <ndarray>
|
|
59
|
+
*
|
|
60
|
+
* var sh = y.shape;
|
|
61
|
+
* // returns [ 2, 2 ]
|
|
62
|
+
*
|
|
63
|
+
* var dt = y.dtype;
|
|
64
|
+
* // returns 'float64'
|
|
65
|
+
*/
|
|
66
|
+
function zerosLike( x ) {
|
|
67
|
+
var options;
|
|
68
|
+
var ndims;
|
|
69
|
+
var opts;
|
|
70
|
+
var buf;
|
|
71
|
+
var len;
|
|
72
|
+
var st;
|
|
73
|
+
|
|
74
|
+
if ( !isndarrayLike( x ) ) {
|
|
75
|
+
throw new TypeError( 'invalid argument. First argument must be an ndarray-like object. Value: `' + x + '`.' );
|
|
76
|
+
}
|
|
77
|
+
opts = {};
|
|
78
|
+
if ( arguments.length > 1 ) {
|
|
79
|
+
options = arguments[ 1 ];
|
|
80
|
+
if ( !isPlainObject( options ) ) {
|
|
81
|
+
throw new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
|
|
82
|
+
}
|
|
83
|
+
if ( hasOwnProp( options, 'dtype' ) ) {
|
|
84
|
+
opts.dtype = options.dtype;
|
|
85
|
+
} else {
|
|
86
|
+
opts.dtype = x.dtype;
|
|
87
|
+
}
|
|
88
|
+
if ( hasOwnProp( options, 'shape' ) ) {
|
|
89
|
+
opts.shape = options.shape;
|
|
90
|
+
if ( typeof opts.shape === 'number' ) {
|
|
91
|
+
opts.shape = [ opts.shape ];
|
|
92
|
+
}
|
|
93
|
+
if ( !isNonNegativeIntegerArray( opts.shape ) ) {
|
|
94
|
+
throw new TypeError( 'invalid option. `shape` option must either be a nonnegative integer or an array of nonnegative integers. Option: `' + opts.shape + '`.' );
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
opts.shape = x.shape;
|
|
98
|
+
}
|
|
99
|
+
if ( hasOwnProp( options, 'order' ) ) {
|
|
100
|
+
opts.order = options.order;
|
|
101
|
+
} else {
|
|
102
|
+
opts.order = x.order;
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
opts.dtype = x.dtype;
|
|
106
|
+
opts.shape = x.shape;
|
|
107
|
+
opts.order = x.order;
|
|
108
|
+
}
|
|
109
|
+
ndims = opts.shape.length;
|
|
110
|
+
if ( ndims > 0 ) {
|
|
111
|
+
len = numel( opts.shape );
|
|
112
|
+
if ( len < 0 ) {
|
|
113
|
+
len = 0; // note: we should only get here if an inferred shape is invalid (i.e., contains negative dimension sizes)
|
|
114
|
+
}
|
|
115
|
+
st = shape2strides( opts.shape, opts.order );
|
|
116
|
+
} else {
|
|
117
|
+
// For 0-dimensional arrays, the buffer should contain a single element...
|
|
118
|
+
len = 1;
|
|
119
|
+
st = [ 0 ];
|
|
120
|
+
}
|
|
121
|
+
buf = buffer( opts.dtype, len );
|
|
122
|
+
if ( buf === null ) {
|
|
123
|
+
throw new TypeError( 'invalid argument. First argument must have a recognized data type. Value: `' + opts.dtype + '`.' );
|
|
124
|
+
}
|
|
125
|
+
return new ndarray( opts.dtype, buf, opts.shape, st, strides2offset( opts.shape, st ), opts.order ); // eslint-disable-line max-len
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
// EXPORTS //
|
|
130
|
+
|
|
131
|
+
module.exports = zerosLike;
|
package/package.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/ndarray-zeros-like",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Create a zero-filled ndarray having the same shape and data type as a provided ndarray.",
|
|
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/ndarray-zeros-like.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@stdlib/assert-has-own-property": "^0.0.x",
|
|
41
|
+
"@stdlib/assert-is-ndarray-like": "^0.0.x",
|
|
42
|
+
"@stdlib/assert-is-nonnegative-integer-array": "^0.0.x",
|
|
43
|
+
"@stdlib/assert-is-plain-object": "^0.0.x",
|
|
44
|
+
"@stdlib/ndarray-base-buffer": "^0.0.x",
|
|
45
|
+
"@stdlib/ndarray-base-numel": "^0.0.x",
|
|
46
|
+
"@stdlib/ndarray-base-shape2strides": "^0.0.x",
|
|
47
|
+
"@stdlib/ndarray-base-strides2offset": "^0.0.x",
|
|
48
|
+
"@stdlib/ndarray-ctor": "^0.0.x",
|
|
49
|
+
"@stdlib/types": "^0.0.x"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@stdlib/array-complex128": "^0.0.x",
|
|
53
|
+
"@stdlib/array-complex64": "^0.0.x",
|
|
54
|
+
"@stdlib/array-float32": "^0.0.x",
|
|
55
|
+
"@stdlib/array-float64": "^0.0.x",
|
|
56
|
+
"@stdlib/array-int16": "^0.0.x",
|
|
57
|
+
"@stdlib/array-int32": "^0.0.x",
|
|
58
|
+
"@stdlib/array-int8": "^0.0.x",
|
|
59
|
+
"@stdlib/array-uint16": "^0.0.x",
|
|
60
|
+
"@stdlib/array-uint32": "^0.0.x",
|
|
61
|
+
"@stdlib/array-uint8": "^0.0.x",
|
|
62
|
+
"@stdlib/array-uint8c": "^0.0.x",
|
|
63
|
+
"@stdlib/assert-instance-of": "^0.0.x",
|
|
64
|
+
"@stdlib/bench": "^0.0.x",
|
|
65
|
+
"@stdlib/math-base-special-pow": "^0.0.x",
|
|
66
|
+
"@stdlib/ndarray-base-zeros": "^0.0.x",
|
|
67
|
+
"@stdlib/ndarray-dtypes": "^0.0.x",
|
|
68
|
+
"@stdlib/ndarray-zeros": "^0.0.x",
|
|
69
|
+
"@stdlib/strided-base-reinterpret-complex128": "^0.0.x",
|
|
70
|
+
"@stdlib/strided-base-reinterpret-complex64": "^0.0.x",
|
|
71
|
+
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
72
|
+
"istanbul": "^0.4.1",
|
|
73
|
+
"tap-spec": "5.x.x"
|
|
74
|
+
},
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": ">=0.10.0",
|
|
77
|
+
"npm": ">2.7.0"
|
|
78
|
+
},
|
|
79
|
+
"os": [
|
|
80
|
+
"aix",
|
|
81
|
+
"darwin",
|
|
82
|
+
"freebsd",
|
|
83
|
+
"linux",
|
|
84
|
+
"macos",
|
|
85
|
+
"openbsd",
|
|
86
|
+
"sunos",
|
|
87
|
+
"win32",
|
|
88
|
+
"windows"
|
|
89
|
+
],
|
|
90
|
+
"keywords": [
|
|
91
|
+
"stdlib",
|
|
92
|
+
"stdtypes",
|
|
93
|
+
"types",
|
|
94
|
+
"data",
|
|
95
|
+
"structure",
|
|
96
|
+
"vector",
|
|
97
|
+
"ndarray",
|
|
98
|
+
"matrix",
|
|
99
|
+
"fill",
|
|
100
|
+
"filled",
|
|
101
|
+
"zeros"
|
|
102
|
+
],
|
|
103
|
+
"funding": {
|
|
104
|
+
"type": "patreon",
|
|
105
|
+
"url": "https://www.patreon.com/athan"
|
|
106
|
+
}
|
|
107
|
+
}
|