You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**order**: specifies whether an [ndarray][@stdlib/ndarray/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). Default: `'row-major'`.
75
+
-**mode**: specifies how to handle indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`.
76
+
-**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 ]`.
77
+
-**readonly**: `boolean` indicating whether an array should be **read-only**. Default: `false`.
75
78
76
79
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.
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/ndarray/zeros/lib/main.js
+25-10Lines changed: 25 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -46,10 +46,14 @@ var ORDER = 'row-major';
46
46
* @param {Options} [options] - options
47
47
* @param {string} [options.dtype='float64'] - data type
48
48
* @param {string} [options.order='row-major'] - array order
49
+
* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions
50
+
* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis
51
+
* @param {boolean} [options.readonly=false] - boolean indicating whether an array should be read-only
49
52
* @throws {TypeError} first argument must be either a nonnegative integer or an array of nonnegative integers
50
53
* @throws {TypeError} options argument must be an object
51
54
* @throws {TypeError} `dtype` option must be a recognized data type
52
55
* @throws {TypeError} `order` option must be a recognized array order
56
+
* @throws {TypeError} must provide valid options
53
57
* @returns {ndarray} ndarray
54
58
*
55
59
* @example
@@ -64,6 +68,8 @@ var ORDER = 'row-major';
64
68
*/
65
69
functionzeros(shape){
66
70
varoptions;
71
+
vardtype;
72
+
varorder;
67
73
varndims;
68
74
varopts;
69
75
varbuf;
@@ -78,18 +84,27 @@ function zeros( shape ) {
78
84
thrownewTypeError(format('invalid argument. Options argument must be an object. Value: `%s`.',options));
79
85
}
80
86
if(hasOwnProp(options,'dtype')){
81
-
opts.dtype=options.dtype;
87
+
dtype=options.dtype;
82
88
}else{
83
-
opts.dtype=DTYPE;
89
+
dtype=DTYPE;
84
90
}
85
91
if(hasOwnProp(options,'order')){
86
-
opts.order=options.order;
92
+
order=options.order;
87
93
}else{
88
-
opts.order=ORDER;
94
+
order=ORDER;
95
+
}
96
+
if(hasOwnProp(options,'mode')){
97
+
opts.mode=options.mode;
98
+
}
99
+
if(hasOwnProp(options,'submode')){
100
+
opts.submode=options.submode;
101
+
}
102
+
if(hasOwnProp(options,'readonly')){
103
+
opts.readonly=options.readonly;
89
104
}
90
105
}else{
91
-
opts.dtype=DTYPE;
92
-
opts.order=ORDER;
106
+
dtype=DTYPE;
107
+
order=ORDER;
93
108
}
94
109
if(typeofshape==='number'){
95
110
sh=[shape];
@@ -105,17 +120,17 @@ function zeros( shape ) {
105
120
// We should only get here if we've been provided an invalid shape (e.g., an array containing negative integers, etc)...
106
121
thrownewTypeError(format('invalid argument. First argument must be either a nonnegative integer or an array of nonnegative integers. Value: `%s`.',shape));
107
122
}
108
-
st=shape2strides(sh,opts.order);
123
+
st=shape2strides(sh,order);
109
124
}else{
110
125
// For 0-dimensional arrays, the buffer should contain a single element...
111
126
len=1;
112
127
st=[0];
113
128
}
114
-
buf=buffer(opts.dtype,len);
129
+
buf=buffer(dtype,len);
115
130
if(buf===null){
116
-
thrownewTypeError(format('invalid option. `%s` option must be a recognized data type. Option: `%s`.','dtype',opts.dtype));
131
+
thrownewTypeError(format('invalid option. `%s` option must be a recognized data type. Option: `%s`.','dtype',dtype));
0 commit comments