@stdlib/ndarray-base 0.0.7 → 0.2.0
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 +0 -304
- package/NOTICE +1 -1
- package/README.md +185 -11
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +1959 -242
- package/lib/index.js +400 -0
- package/package.json +269 -164
- package/docs/types/test.ts +0 -29
package/docs/types/index.d.ts
CHANGED
|
@@ -16,14 +16,18 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
// TypeScript Version:
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
20
|
|
|
21
|
-
/*
|
|
22
|
-
/* tslint:disable:max-file-line-count */
|
|
21
|
+
/* eslint-disable max-lines */
|
|
23
22
|
|
|
24
23
|
import assert = require( '@stdlib/ndarray-base-assert' );
|
|
24
|
+
import assign = require( '@stdlib/ndarray-base-assign' );
|
|
25
|
+
import binaryLoopOrder = require( '@stdlib/ndarray-base-binary-loop-interchange-order' );
|
|
26
|
+
import binaryBlockSize = require( '@stdlib/ndarray-base-binary-tiling-block-size' );
|
|
25
27
|
import bind2vind = require( '@stdlib/ndarray-base-bind2vind' );
|
|
26
28
|
import broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' );
|
|
29
|
+
import broadcastArrays = require( '@stdlib/ndarray-base-broadcast-arrays' );
|
|
30
|
+
import broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );
|
|
27
31
|
import broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );
|
|
28
32
|
import buffer = require( '@stdlib/ndarray-base-buffer' );
|
|
29
33
|
import bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' );
|
|
@@ -33,6 +37,8 @@ import bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );
|
|
|
33
37
|
import char2dtype = require( '@stdlib/ndarray-base-char2dtype' );
|
|
34
38
|
import clampIndex = require( '@stdlib/ndarray-base-clamp-index' );
|
|
35
39
|
import ndarray = require( '@stdlib/ndarray-base-ctor' );
|
|
40
|
+
import data = require( '@stdlib/ndarray-base-data-buffer' );
|
|
41
|
+
import dtype = require( '@stdlib/ndarray-base-dtype' );
|
|
36
42
|
import dtypeChar = require( '@stdlib/ndarray-base-dtype-char' );
|
|
37
43
|
import dtypeDesc = require( '@stdlib/ndarray-base-dtype-desc' );
|
|
38
44
|
import dtypeEnum2Str = require( '@stdlib/ndarray-base-dtype-enum2str' );
|
|
@@ -41,24 +47,70 @@ import dtypeResolveStr = require( '@stdlib/ndarray-base-dtype-resolve-str' );
|
|
|
41
47
|
import dtypeStr2Enum = require( '@stdlib/ndarray-base-dtype-str2enum' );
|
|
42
48
|
import dtype2c = require( '@stdlib/ndarray-base-dtype2c' );
|
|
43
49
|
import dtypes2signatures = require( '@stdlib/ndarray-base-dtypes2signatures' );
|
|
50
|
+
import empty = require( '@stdlib/ndarray-base-empty' );
|
|
51
|
+
import emptyLike = require( '@stdlib/ndarray-base-empty-like' );
|
|
52
|
+
import expandDimensions = require( '@stdlib/ndarray-base-expand-dimensions' );
|
|
53
|
+
import flag = require( '@stdlib/ndarray-base-flag' );
|
|
54
|
+
import flags = require( '@stdlib/ndarray-base-flags' );
|
|
55
|
+
import fliplr = require( '@stdlib/ndarray-base-fliplr' );
|
|
56
|
+
import flipud = require( '@stdlib/ndarray-base-flipud' );
|
|
57
|
+
import scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' );
|
|
44
58
|
import ind = require( '@stdlib/ndarray-base-ind' );
|
|
45
59
|
import ind2sub = require( '@stdlib/ndarray-base-ind2sub' );
|
|
46
60
|
import iterationOrder = require( '@stdlib/ndarray-base-iteration-order' );
|
|
47
61
|
import maxViewBufferIndex = require( '@stdlib/ndarray-base-max-view-buffer-index' );
|
|
62
|
+
import maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );
|
|
63
|
+
import maybeBroadcastArrays = require( '@stdlib/ndarray-base-maybe-broadcast-arrays' );
|
|
48
64
|
import metaDataProps = require( '@stdlib/ndarray-base-meta-data-props' );
|
|
49
65
|
import minViewBufferIndex = require( '@stdlib/ndarray-base-min-view-buffer-index' );
|
|
50
66
|
import minmaxViewBufferIndex = require( '@stdlib/ndarray-base-minmax-view-buffer-index' );
|
|
67
|
+
import ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );
|
|
68
|
+
import ndims = require( '@stdlib/ndarray-base-ndims' );
|
|
69
|
+
import nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' );
|
|
51
70
|
import nonsingletonDimensions = require( '@stdlib/ndarray-base-nonsingleton-dimensions' );
|
|
71
|
+
import normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );
|
|
72
|
+
import nullary = require( '@stdlib/ndarray-base-nullary' );
|
|
73
|
+
import nullaryLoopOrder = require( '@stdlib/ndarray-base-nullary-loop-interchange-order' );
|
|
74
|
+
import nullaryBlockSize = require( '@stdlib/ndarray-base-nullary-tiling-block-size' );
|
|
52
75
|
import numel = require( '@stdlib/ndarray-base-numel' );
|
|
76
|
+
import numelDimension = require( '@stdlib/ndarray-base-numel-dimension' );
|
|
77
|
+
import offset = require( '@stdlib/ndarray-base-offset' );
|
|
78
|
+
import order = require( '@stdlib/ndarray-base-order' );
|
|
79
|
+
import outputPolicyEnum2Str = require( '@stdlib/ndarray-base-output-policy-enum2str' );
|
|
80
|
+
import outputPolicyResolveEnum = require( '@stdlib/ndarray-base-output-policy-resolve-enum' );
|
|
81
|
+
import outputPolicyResolveStr = require( '@stdlib/ndarray-base-output-policy-resolve-str' );
|
|
82
|
+
import outputPolicyStr2Enum = require( '@stdlib/ndarray-base-output-policy-str2enum' );
|
|
83
|
+
import prependSingletonDimensions = require( '@stdlib/ndarray-base-prepend-singleton-dimensions' );
|
|
84
|
+
import removeSingletonDimensions = require( '@stdlib/ndarray-base-remove-singleton-dimensions' );
|
|
85
|
+
import reverse = require( '@stdlib/ndarray-base-reverse' );
|
|
86
|
+
import reverseDimension = require( '@stdlib/ndarray-base-reverse-dimension' );
|
|
53
87
|
import serializeMetaData = require( '@stdlib/ndarray-base-serialize-meta-data' );
|
|
88
|
+
import shape = require( '@stdlib/ndarray-base-shape' );
|
|
54
89
|
import shape2strides = require( '@stdlib/ndarray-base-shape2strides' );
|
|
55
90
|
import singletonDimensions = require( '@stdlib/ndarray-base-singleton-dimensions' );
|
|
91
|
+
import slice = require( '@stdlib/ndarray-base-slice' );
|
|
92
|
+
import sliceAssign = require( '@stdlib/ndarray-base-slice-assign' );
|
|
93
|
+
import sliceDimension = require( '@stdlib/ndarray-base-slice-dimension' );
|
|
94
|
+
import sliceDimensionFrom = require( '@stdlib/ndarray-base-slice-dimension-from' );
|
|
95
|
+
import sliceDimensionTo = require( '@stdlib/ndarray-base-slice-dimension-to' );
|
|
96
|
+
import sliceFrom = require( '@stdlib/ndarray-base-slice-from' );
|
|
97
|
+
import sliceTo = require( '@stdlib/ndarray-base-slice-to' );
|
|
98
|
+
import stride = require( '@stdlib/ndarray-base-stride' );
|
|
99
|
+
import strides = require( '@stdlib/ndarray-base-strides' );
|
|
56
100
|
import strides2offset = require( '@stdlib/ndarray-base-strides2offset' );
|
|
57
101
|
import strides2order = require( '@stdlib/ndarray-base-strides2order' );
|
|
58
102
|
import sub2ind = require( '@stdlib/ndarray-base-sub2ind' );
|
|
59
103
|
import ndarray2array = require( '@stdlib/ndarray-base-to-array' );
|
|
104
|
+
import transpose = require( '@stdlib/ndarray-base-transpose' );
|
|
105
|
+
import unary = require( '@stdlib/ndarray-base-unary' );
|
|
106
|
+
import unaryBy = require( '@stdlib/ndarray-base-unary-by' );
|
|
107
|
+
import unaryLoopOrder = require( '@stdlib/ndarray-base-unary-loop-interchange-order' );
|
|
108
|
+
import unaryOutputDataType = require( '@stdlib/ndarray-base-unary-output-dtype' );
|
|
109
|
+
import unaryBlockSize = require( '@stdlib/ndarray-base-unary-tiling-block-size' );
|
|
60
110
|
import vind2bind = require( '@stdlib/ndarray-base-vind2bind' );
|
|
61
111
|
import wrapIndex = require( '@stdlib/ndarray-base-wrap-index' );
|
|
112
|
+
import zeros = require( '@stdlib/ndarray-base-zeros' );
|
|
113
|
+
import zerosLike = require( '@stdlib/ndarray-base-zeros-like' );
|
|
62
114
|
|
|
63
115
|
/**
|
|
64
116
|
* Interface describing the `base` namespace.
|
|
@@ -69,6 +121,108 @@ interface Namespace {
|
|
|
69
121
|
*/
|
|
70
122
|
assert: typeof assert;
|
|
71
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Assigns elements in an ndarray to elements in an ndarray.
|
|
126
|
+
*
|
|
127
|
+
* @param arrays - array-like object containing one input ndarray and one output ndarray
|
|
128
|
+
* @throws arrays must have the same number of dimensions
|
|
129
|
+
* @throws arrays must have the same shape
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
133
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
134
|
+
*
|
|
135
|
+
* // Create data buffers:
|
|
136
|
+
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
|
|
137
|
+
* var ybuf = new Float64Array( 6 );
|
|
138
|
+
*
|
|
139
|
+
* // Define the shape of the input and output arrays:
|
|
140
|
+
* var shape = [ 3, 1, 2 ];
|
|
141
|
+
*
|
|
142
|
+
* // Define the array strides:
|
|
143
|
+
* var sx = [ 4, 4, 1 ];
|
|
144
|
+
* var sy = [ 2, 2, 1 ];
|
|
145
|
+
*
|
|
146
|
+
* // Define the index offsets:
|
|
147
|
+
* var ox = 1;
|
|
148
|
+
* var oy = 0;
|
|
149
|
+
*
|
|
150
|
+
* // Create the input and output ndarrays:
|
|
151
|
+
* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );
|
|
152
|
+
* var y = ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' );
|
|
153
|
+
*
|
|
154
|
+
* // Copy elements:
|
|
155
|
+
* ns.assign( [ x, y ] );
|
|
156
|
+
*
|
|
157
|
+
* console.log( y.data );
|
|
158
|
+
* // => <Float64Array>[ 2.0, 3.0, 6.0, 7.0, 10.0, 11.0 ]
|
|
159
|
+
*/
|
|
160
|
+
assign: typeof assign;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Reorders ndarray dimensions and associated strides for loop interchange.
|
|
164
|
+
*
|
|
165
|
+
* ## Notes
|
|
166
|
+
*
|
|
167
|
+
* - The returned object has the following properties:
|
|
168
|
+
*
|
|
169
|
+
* - **sh**: dimensions sorted in loop order.
|
|
170
|
+
* - **sx**: first input ndarray strides sorted in loop order.
|
|
171
|
+
* - **sy**: second input ndarray strides sorted in loop order.
|
|
172
|
+
* - **sz**: output ndarray strides sorted in loop order.
|
|
173
|
+
*
|
|
174
|
+
* - When iterating over the elements of a multi-dimensional array, accessing elements which are closer in memory can improve performance. To this end, loop interchange is a technique used in loop nest optimization to improve locality of reference and take advantage of CPU cache.
|
|
175
|
+
*
|
|
176
|
+
* The purpose of this function is to order ndarray dimensions according to the magnitude of array strides. By using the ordered dimensions and associated strides, one can construct nested loops (one for each dimension) such that the innermost loop iterates over the dimension in which array elements are closest in memory and the outermost loop iterates over the dimension in which array elements are farthest apart in memory. As a consequence, element iteration is optimized to minimize cache misses and ensure locality of reference.
|
|
177
|
+
*
|
|
178
|
+
* - Cache performance may be degraded if the layout order (i.e., row-major or column-major) differs for the input and output ndarrays. This function is intended to optimize cache performance for the most common layout order. Accordingly, if the output ndarray has a different layout order (e.g., if the input ndarrays are row-major and the output ndarray is column-major), cache misses are likely for the output ndarray. In general, to ensure best performance, input and output ndarrays should have the same layout order.
|
|
179
|
+
*
|
|
180
|
+
* - The function assumes that the input and output ndarrays have the same shape. Hence, loop interchange order should only be determined **after** broadcasting.
|
|
181
|
+
*
|
|
182
|
+
* @param sh - array dimensions
|
|
183
|
+
* @param sx - first input array stride lengths
|
|
184
|
+
* @param sy - second input array stride lengths
|
|
185
|
+
* @param sz - output array stride lengths
|
|
186
|
+
* @returns loop interchange data
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* var sh = [ 2, 3, 4 ];
|
|
190
|
+
*
|
|
191
|
+
* var sx = [ 12, 4, 1 ]; // row-major
|
|
192
|
+
* var sy = [ 24, 8, 1 ]; // row-major
|
|
193
|
+
* var sz = [ 1, -2, 6 ]; // column-major
|
|
194
|
+
*
|
|
195
|
+
* var o = loopOrder( sh, sx, sy, sz );
|
|
196
|
+
* // returns {...}
|
|
197
|
+
*
|
|
198
|
+
* var ssh = o.sh;
|
|
199
|
+
* // returns [ 4, 3, 2 ]
|
|
200
|
+
*
|
|
201
|
+
* var ssx = o.sx;
|
|
202
|
+
* // returns [ 1, 4, 12 ]
|
|
203
|
+
*
|
|
204
|
+
* var ssy = o.sy;
|
|
205
|
+
* // returns [ 1, 8, 24 ]
|
|
206
|
+
*
|
|
207
|
+
* var ssz = o.sz;
|
|
208
|
+
* // returns [ 6, -2, 1 ]
|
|
209
|
+
*/
|
|
210
|
+
binaryLoopOrder: typeof binaryLoopOrder;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Returns a loop block size for multi-dimensional array tiled loops.
|
|
214
|
+
*
|
|
215
|
+
* @param dtypeX - first input array data type
|
|
216
|
+
* @param dtypeY - second input array data type
|
|
217
|
+
* @param dtypeZ - output array data type
|
|
218
|
+
* @returns block size (in units of elements)
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* var bsize = ns.binaryBlockSize( 'float64', 'float64', 'float64' );
|
|
222
|
+
* // returns <number>
|
|
223
|
+
*/
|
|
224
|
+
binaryBlockSize: typeof binaryBlockSize;
|
|
225
|
+
|
|
72
226
|
/**
|
|
73
227
|
* Converts a linear index in an underlying data buffer to a linear index in an array view.
|
|
74
228
|
*
|
|
@@ -110,7 +264,7 @@ interface Namespace {
|
|
|
110
264
|
* @returns broadcasted array
|
|
111
265
|
*
|
|
112
266
|
* @example
|
|
113
|
-
* var array = require(
|
|
267
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
114
268
|
*
|
|
115
269
|
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
116
270
|
* // returns <ndarray>
|
|
@@ -144,6 +298,107 @@ interface Namespace {
|
|
|
144
298
|
*/
|
|
145
299
|
broadcastArray: typeof broadcastArray;
|
|
146
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Broadcasts ndarrays to a common shape.
|
|
303
|
+
*
|
|
304
|
+
* ## Notes
|
|
305
|
+
*
|
|
306
|
+
* - The function throws an error if provided broadcast-incompatible ndarrays.
|
|
307
|
+
* - The returned arrays are views on their respective underlying array data buffers. The views are typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to a returned array, copy the array before performing operations which may mutate elements.
|
|
308
|
+
* - The returned arrays are "base" ndarrays, and, thus, returned arrays do not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast ndarray-like objects within internal implementations and to do so with minimal overhead.
|
|
309
|
+
* - The function always returns new ndarray instances even if an input ndarray shape and the broadcasted shape are the same.
|
|
310
|
+
*
|
|
311
|
+
* @param arrays - input arrays
|
|
312
|
+
* @throws input arrays must be broadcast compatible
|
|
313
|
+
* @returns list of broadcasted arrays
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
317
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
318
|
+
*
|
|
319
|
+
* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
320
|
+
* // returns <ndarray>
|
|
321
|
+
*
|
|
322
|
+
* var shx = x1.shape;
|
|
323
|
+
* // returns [ 2, 2 ]
|
|
324
|
+
*
|
|
325
|
+
* var y1 = zeros( [ 3, 2, 2 ] );
|
|
326
|
+
* // returns <ndarray>
|
|
327
|
+
*
|
|
328
|
+
* var shy = y1.shape;
|
|
329
|
+
* // returns [ 3, 2, 2 ]
|
|
330
|
+
*
|
|
331
|
+
* var out = ns.broadcastArrays( [ x1, y1 ] );
|
|
332
|
+
* // returns <ndarray>
|
|
333
|
+
*
|
|
334
|
+
* var x2 = out[ 0 ];
|
|
335
|
+
* // returns <ndarray>
|
|
336
|
+
*
|
|
337
|
+
* var y2 = out[ 1 ];
|
|
338
|
+
* // returns <ndarray>
|
|
339
|
+
*
|
|
340
|
+
* shx = x2.shape;
|
|
341
|
+
* // returns [ 3, 2, 2 ]
|
|
342
|
+
*
|
|
343
|
+
* shy = y2.shape;
|
|
344
|
+
* // returns [ 3, 2, 2 ]
|
|
345
|
+
*
|
|
346
|
+
* var v = x2.get( 0, 0, 0 );
|
|
347
|
+
* // returns 1
|
|
348
|
+
*
|
|
349
|
+
* v = x2.get( 0, 0, 1 );
|
|
350
|
+
* // returns 2
|
|
351
|
+
*
|
|
352
|
+
* v = x2.get( 1, 0, 0 );
|
|
353
|
+
* // returns 1
|
|
354
|
+
*
|
|
355
|
+
* v = x2.get( 1, 1, 0 );
|
|
356
|
+
* // returns 3
|
|
357
|
+
*
|
|
358
|
+
* v = x2.get( 2, 0, 0 );
|
|
359
|
+
* // returns 1
|
|
360
|
+
*
|
|
361
|
+
* v = x2.get( 2, 1, 1 );
|
|
362
|
+
* // returns 4
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
366
|
+
*
|
|
367
|
+
* var x = zeros( [ 2, 2 ] );
|
|
368
|
+
* // returns <ndarray>
|
|
369
|
+
*
|
|
370
|
+
* var y = zeros( [ 4, 2 ] );
|
|
371
|
+
* // returns <ndarray>
|
|
372
|
+
*
|
|
373
|
+
* var out = ns.broadcastArrays( [ x, y ] );
|
|
374
|
+
* // throws <Error>
|
|
375
|
+
*/
|
|
376
|
+
broadcastArrays: typeof broadcastArrays;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Broadcasts a scalar value to an ndarray having a specified shape.
|
|
380
|
+
*
|
|
381
|
+
* @param value - scalar value
|
|
382
|
+
* @param dtype - array data type
|
|
383
|
+
* @param shape - array shape
|
|
384
|
+
* @param order - array order
|
|
385
|
+
* @returns ndarray
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* var x = ns.broadcastScalar( 1.0, 'generic', [ 2, 2 ], 'row-major' );
|
|
389
|
+
* // returns <ndarray>
|
|
390
|
+
*
|
|
391
|
+
* var sh = x.shape;
|
|
392
|
+
* // returns [ 2, 2 ]
|
|
393
|
+
*
|
|
394
|
+
* var dt = x.dtype;
|
|
395
|
+
* // returns 'generic'
|
|
396
|
+
*
|
|
397
|
+
* var v = x.get( 0, 1 );
|
|
398
|
+
* // returns 1.0
|
|
399
|
+
*/
|
|
400
|
+
broadcastScalar: typeof broadcastScalar;
|
|
401
|
+
|
|
147
402
|
/**
|
|
148
403
|
* Broadcasts array shapes to a single shape.
|
|
149
404
|
*
|
|
@@ -344,7 +599,7 @@ interface Namespace {
|
|
|
344
599
|
* @returns data type enumeration constant or null
|
|
345
600
|
*
|
|
346
601
|
* @example
|
|
347
|
-
* var Float64Array = require(
|
|
602
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
348
603
|
*
|
|
349
604
|
* var x = new Float64Array( 10 );
|
|
350
605
|
*
|
|
@@ -432,6 +687,42 @@ interface Namespace {
|
|
|
432
687
|
*/
|
|
433
688
|
ndarray: typeof ndarray;
|
|
434
689
|
|
|
690
|
+
/**
|
|
691
|
+
* Returns the underlying data buffer of a provided ndarray.
|
|
692
|
+
*
|
|
693
|
+
* @param x - input ndarray
|
|
694
|
+
* @returns underlying data buffer
|
|
695
|
+
*
|
|
696
|
+
* @example
|
|
697
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
698
|
+
*
|
|
699
|
+
* var x = zeros( [ 3, 3, 3 ], {
|
|
700
|
+
* 'dtype': 'float64'
|
|
701
|
+
* });
|
|
702
|
+
*
|
|
703
|
+
* var out = ns.data( x );
|
|
704
|
+
* // returns <Float64Array>
|
|
705
|
+
*/
|
|
706
|
+
data: typeof data;
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Returns the data type of a provided ndarray.
|
|
710
|
+
*
|
|
711
|
+
* @param x - input ndarray
|
|
712
|
+
* @returns data type
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
716
|
+
*
|
|
717
|
+
* var x = zeros( [ 3, 3, 3 ], {
|
|
718
|
+
* 'ns.dtype': 'float64'
|
|
719
|
+
* });
|
|
720
|
+
*
|
|
721
|
+
* var dt = ns.dtype( x );
|
|
722
|
+
* // returns 'float64'
|
|
723
|
+
*/
|
|
724
|
+
dtype: typeof dtype;
|
|
725
|
+
|
|
435
726
|
/**
|
|
436
727
|
* Returns an object mapping data type strings to single letter character abbreviations.
|
|
437
728
|
*
|
|
@@ -461,7 +752,7 @@ interface Namespace {
|
|
|
461
752
|
* @returns data type string
|
|
462
753
|
*
|
|
463
754
|
* @example
|
|
464
|
-
* var str2enum = require(
|
|
755
|
+
* var str2enum = require( '@stdlib/ndarray-base-dtype-str2enum' );
|
|
465
756
|
*
|
|
466
757
|
* var v = str2enum( 'float64' );
|
|
467
758
|
* // returns <number>
|
|
@@ -494,7 +785,7 @@ interface Namespace {
|
|
|
494
785
|
* @returns data type string
|
|
495
786
|
*
|
|
496
787
|
* @example
|
|
497
|
-
* var str2enum = require(
|
|
788
|
+
* var str2enum = require( '@stdlib/ndarray-base-dtype-str2enum' );
|
|
498
789
|
*
|
|
499
790
|
* var v = ns.dtypeResolveStr( str2enum( 'float64' ) );
|
|
500
791
|
* // returns 'float64'
|
|
@@ -518,9 +809,9 @@ interface Namespace {
|
|
|
518
809
|
dtypeStr2Enum: typeof dtypeStr2Enum;
|
|
519
810
|
|
|
520
811
|
/**
|
|
521
|
-
* Returns the C data type associated with a provided data type
|
|
812
|
+
* Returns the C data type associated with a provided data type value.
|
|
522
813
|
*
|
|
523
|
-
* @param dtype - data type
|
|
814
|
+
* @param dtype - data type value
|
|
524
815
|
* @returns C data type (or null)
|
|
525
816
|
*
|
|
526
817
|
* @example
|
|
@@ -557,136 +848,378 @@ interface Namespace {
|
|
|
557
848
|
dtypes2signatures: typeof dtypes2signatures;
|
|
558
849
|
|
|
559
850
|
/**
|
|
560
|
-
*
|
|
851
|
+
* Creates an uninitialized array having a specified shape and data type.
|
|
561
852
|
*
|
|
562
|
-
* @param
|
|
563
|
-
* @param
|
|
564
|
-
* @param
|
|
565
|
-
* @
|
|
566
|
-
* @returns index
|
|
853
|
+
* @param dtype - underlying data type
|
|
854
|
+
* @param shape - array shape
|
|
855
|
+
* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)
|
|
856
|
+
* @returns output array
|
|
567
857
|
*
|
|
568
858
|
* @example
|
|
569
|
-
* var
|
|
570
|
-
* // returns
|
|
859
|
+
* var arr = ns.empty( 'float32', [ 2, 2 ], 'row-major' );
|
|
860
|
+
* // returns <ndarray>
|
|
571
861
|
*
|
|
572
|
-
*
|
|
573
|
-
* // returns
|
|
862
|
+
* var sh = arr.shape;
|
|
863
|
+
* // returns [ 2, 2 ]
|
|
574
864
|
*
|
|
575
|
-
*
|
|
576
|
-
* // returns
|
|
865
|
+
* var dt = arr.dtype;
|
|
866
|
+
* // returns 'float32'
|
|
867
|
+
*/
|
|
868
|
+
empty: typeof empty;
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Creates an uninitialized array having the same shape and data type as a provided input ndarray.
|
|
872
|
+
*
|
|
873
|
+
* @param x - input array
|
|
874
|
+
* @returns output array
|
|
577
875
|
*
|
|
578
876
|
* @example
|
|
579
|
-
* var
|
|
580
|
-
* // returns 2
|
|
877
|
+
* var zeros = require( '@stdlib/ndarray-base-zeros' );
|
|
581
878
|
*
|
|
582
|
-
*
|
|
583
|
-
* // returns
|
|
879
|
+
* var x = zeros( 'generic', [ 2, 2 ], 'row-major' );
|
|
880
|
+
* // returns <ndarray>
|
|
584
881
|
*
|
|
585
|
-
*
|
|
586
|
-
* // returns
|
|
882
|
+
* var sh = x.shape;
|
|
883
|
+
* // returns [ 2, 2 ]
|
|
587
884
|
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
* // returns 2
|
|
885
|
+
* var dt = x.dtype;
|
|
886
|
+
* // returns 'generic'
|
|
591
887
|
*
|
|
592
|
-
*
|
|
593
|
-
* //
|
|
888
|
+
* var y = ns.emptyLike( x );
|
|
889
|
+
* // returns <ndarray>
|
|
594
890
|
*
|
|
595
|
-
*
|
|
596
|
-
* //
|
|
891
|
+
* sh = y.shape;
|
|
892
|
+
* // returns [ 2, 2 ]
|
|
893
|
+
*
|
|
894
|
+
* dt = y.dtype;
|
|
895
|
+
* // returns 'generic'
|
|
597
896
|
*/
|
|
598
|
-
|
|
897
|
+
emptyLike: typeof emptyLike;
|
|
599
898
|
|
|
600
899
|
/**
|
|
601
|
-
*
|
|
900
|
+
* Expands the shape of an array by inserting a new dimension of size one at a specified axis.
|
|
602
901
|
*
|
|
603
902
|
* ## Notes
|
|
604
903
|
*
|
|
605
|
-
* -
|
|
904
|
+
* - A provided axis must reside on the interval `[-N-1, N]`, where `N` is the rank (i.e., number of dimensions) of the provided input array. If provided a negative `axis`, the axis position at which to insert a singleton dimension is computed as `N + axis + 1`. Hence, if provided `-1`, the resolved axis position is `N` (i.e., a singleton dimension is appended to the input array).
|
|
606
905
|
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
906
|
+
* @param x - input array
|
|
907
|
+
* @param axis - axis at which to insert a singleton dimension
|
|
908
|
+
* @returns output array
|
|
610
909
|
*
|
|
611
|
-
*
|
|
910
|
+
* @example
|
|
911
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
612
912
|
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
* Buffer: [ 1, 2, 3, 4 ]
|
|
913
|
+
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
914
|
+
* // returns <ndarray>
|
|
616
915
|
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
916
|
+
* var shx = x.shape;
|
|
917
|
+
* // returns [ 2, 2 ]
|
|
619
918
|
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
919
|
+
* var y = ns.expandDimensions( x, 1 );
|
|
920
|
+
* // returns <ndarray>
|
|
622
921
|
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
922
|
+
* var shy = y.shape;
|
|
923
|
+
* // returns [ 2, 1, 2 ]
|
|
625
924
|
*
|
|
626
|
-
*
|
|
627
|
-
*
|
|
925
|
+
* var v = y.get( 0, 0, 0 );
|
|
926
|
+
* // returns 1
|
|
628
927
|
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
928
|
+
* v = y.get( 0, 0, 1 );
|
|
929
|
+
* // returns 2
|
|
631
930
|
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
931
|
+
* v = y.get( 1, 0, 0 );
|
|
932
|
+
* // returns 3
|
|
634
933
|
*
|
|
635
|
-
*
|
|
636
|
-
*
|
|
934
|
+
* v = y.get( 1, 0, 1 );
|
|
935
|
+
* // returns 4
|
|
936
|
+
*/
|
|
937
|
+
expandDimensions: typeof expandDimensions;
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Returns a specified flag for a provided ndarray.
|
|
637
941
|
*
|
|
638
|
-
*
|
|
639
|
-
*
|
|
942
|
+
* @param x - input ndarray
|
|
943
|
+
* @param name - flag name
|
|
944
|
+
* @returns flag value
|
|
640
945
|
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
* ```
|
|
946
|
+
* @example
|
|
947
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
644
948
|
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
949
|
+
* var o = ns.flag( zeros( [ 3, 3, 3 ] ), 'READONLY' );
|
|
950
|
+
* // returns <boolean>
|
|
951
|
+
*/
|
|
952
|
+
flag: typeof flag;
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* Returns the flags of a provided ndarray.
|
|
651
956
|
*
|
|
652
|
-
*
|
|
653
|
-
* var s = ind2sub( shape, strides, 0, order, 0, mode );
|
|
654
|
-
* // returns [ 0, 0 ]
|
|
957
|
+
* ## Notes
|
|
655
958
|
*
|
|
656
|
-
*
|
|
657
|
-
* // returns [ 0, 1 ]
|
|
959
|
+
* - When `copy` is `false`, changes to the returned object may mutate the input ndarray flags. If there is a chance that the returned object will be mutated (either directly or by downstream consumers), set `copy` to `true` to prevent unintended side effects.
|
|
658
960
|
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
961
|
+
* @param x - input ndarray
|
|
962
|
+
* @param copy - boolean indicating whether to explicitly copy the value assigned to the input ndarray's `flags` property
|
|
963
|
+
* @returns flags
|
|
661
964
|
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
965
|
+
* @example
|
|
966
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
664
967
|
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
|
|
968
|
+
* var o = ns.flags( zeros( [ 3, 3, 3 ] ), false );
|
|
969
|
+
* // returns {...}
|
|
970
|
+
*/
|
|
971
|
+
flags: typeof flags;
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Returns a view of an input ndarray in which the order of elements along the last dimension is reversed.
|
|
668
975
|
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
976
|
+
* @param x - input array
|
|
977
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
978
|
+
* @returns output array
|
|
671
979
|
*
|
|
672
|
-
*
|
|
673
|
-
*
|
|
980
|
+
* @example
|
|
981
|
+
* var typedarray = require( '@stdlib/array-typed' );
|
|
982
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
983
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
674
984
|
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
985
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
986
|
+
* var shape = [ 3, 2 ];
|
|
987
|
+
* var strides = [ 2, 1 ];
|
|
988
|
+
* var offset = 0;
|
|
678
989
|
*
|
|
679
|
-
*
|
|
990
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
991
|
+
* // returns <ndarray>
|
|
680
992
|
*
|
|
993
|
+
* var sh = x.shape;
|
|
994
|
+
* // returns [ 3, 2 ]
|
|
681
995
|
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
996
|
+
* var arr = ndarray2array( x );
|
|
997
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
998
|
+
*
|
|
999
|
+
* var y = ns.fliplr( x, false );
|
|
1000
|
+
* // returns <ndarray>
|
|
1001
|
+
*
|
|
1002
|
+
* sh = y.shape;
|
|
1003
|
+
* // returns [ 3, 2 ]
|
|
1004
|
+
*
|
|
1005
|
+
* arr = ndarray2array( y );
|
|
1006
|
+
* // returns [ [ 2, 1 ], [ 4, 3 ], [ 6, 5 ] ]
|
|
1007
|
+
*/
|
|
1008
|
+
fliplr: typeof fliplr;
|
|
1009
|
+
|
|
1010
|
+
/**
|
|
1011
|
+
* Returns a view of an input ndarray in which the order of elements along the second-to-last dimension is reversed.
|
|
1012
|
+
*
|
|
1013
|
+
* @param x - input array
|
|
1014
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
1015
|
+
* @returns output array
|
|
1016
|
+
*
|
|
1017
|
+
* @example
|
|
1018
|
+
* var typedarray = require( '@stdlib/array-typed' );
|
|
1019
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
1020
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
1021
|
+
*
|
|
1022
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
1023
|
+
* var shape = [ 3, 2 ];
|
|
1024
|
+
* var strides = [ 2, 1 ];
|
|
1025
|
+
* var offset = 0;
|
|
1026
|
+
*
|
|
1027
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
1028
|
+
* // returns <ndarray>
|
|
1029
|
+
*
|
|
1030
|
+
* var sh = x.shape;
|
|
1031
|
+
* // returns [ 3, 2 ]
|
|
1032
|
+
*
|
|
1033
|
+
* var arr = ndarray2array( x );
|
|
1034
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
1035
|
+
*
|
|
1036
|
+
* var y = ns.flipud( x, false );
|
|
1037
|
+
* // returns <ndarray>
|
|
1038
|
+
*
|
|
1039
|
+
* sh = y.shape;
|
|
1040
|
+
* // returns [ 3, 2 ]
|
|
1041
|
+
*
|
|
1042
|
+
* arr = ndarray2array( y );
|
|
1043
|
+
* // returns [ [ 5, 6 ], [ 3, 4 ], [ 1, 2 ] ]
|
|
1044
|
+
*/
|
|
1045
|
+
flipud: typeof flipud;
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Returns a zero-dimensional ndarray containing a provided scalar value.
|
|
1049
|
+
*
|
|
1050
|
+
* @param value - scalar value
|
|
1051
|
+
* @param dtype - array data type
|
|
1052
|
+
* @param order - memory layout (row-major or column-major)
|
|
1053
|
+
* @returns zero-dimensional ndarray
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* var x = ns.scalar2ndarray( 1.0, 'generic', 'row-major' );
|
|
1057
|
+
* // returns <ndarray>
|
|
1058
|
+
*
|
|
1059
|
+
* var sh = x.shape;
|
|
1060
|
+
* // returns []
|
|
1061
|
+
*
|
|
1062
|
+
* var dt = x.dtype;
|
|
1063
|
+
* // returns 'generic'
|
|
1064
|
+
*
|
|
1065
|
+
* var v = x.get();
|
|
1066
|
+
* // returns 1.0
|
|
1067
|
+
*/
|
|
1068
|
+
scalar2ndarray: typeof scalar2ndarray;
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* Returns an index given an index mode.
|
|
1072
|
+
*
|
|
1073
|
+
* @param idx - index
|
|
1074
|
+
* @param max - maximum index
|
|
1075
|
+
* @param mode - specifies how to handle an index outside the interval `[0,max]`
|
|
1076
|
+
* @returns index
|
|
1077
|
+
*
|
|
1078
|
+
* @example
|
|
1079
|
+
* var idx = ns.ind( 2, 9, 'clamp' );
|
|
1080
|
+
* // returns 2
|
|
1081
|
+
*
|
|
1082
|
+
* idx = ns.ind( 10, 9, 'clamp' );
|
|
1083
|
+
* // returns 9
|
|
1084
|
+
*
|
|
1085
|
+
* idx = ns.ind( -1, 9, 'clamp' );
|
|
1086
|
+
* // returns 0
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* var idx = ns.ind( 2, 9, 'wrap' );
|
|
1090
|
+
* // returns 2
|
|
1091
|
+
*
|
|
1092
|
+
* idx = ns.ind( 10, 9, 'wrap' );
|
|
1093
|
+
* // returns 0
|
|
1094
|
+
*
|
|
1095
|
+
* idx = ns.ind( -1, 9, 'wrap' );
|
|
1096
|
+
* // returns 9
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* var idx = ns.ind( 2, 9, 'throw' );
|
|
1100
|
+
* // returns 2
|
|
1101
|
+
*
|
|
1102
|
+
* idx = ns.ind( 10, 9, 'throw' );
|
|
1103
|
+
* // throws <RangeError>
|
|
1104
|
+
*
|
|
1105
|
+
* idx = ns.ind( -1, 9, 'throw' );
|
|
1106
|
+
* // throws <RangeError>
|
|
1107
|
+
*
|
|
1108
|
+
* @example
|
|
1109
|
+
* var idx = ns.ind( 2, 9, 'normalize' );
|
|
1110
|
+
* // returns 2
|
|
1111
|
+
*
|
|
1112
|
+
* idx = ns.ind( -5, 9, 'normalize' );
|
|
1113
|
+
* // returns 5
|
|
1114
|
+
*
|
|
1115
|
+
* idx = ns.ind( -20, 9, 'normalize' );
|
|
1116
|
+
* // throws <RangeError>
|
|
1117
|
+
*
|
|
1118
|
+
* @example
|
|
1119
|
+
* var fcn = ns.ind.factory( 'clamp' );
|
|
1120
|
+
*
|
|
1121
|
+
* var idx = fcn( 2, 9 );
|
|
1122
|
+
* // returns 2
|
|
1123
|
+
*
|
|
1124
|
+
* idx = fcn( 10, 9 );
|
|
1125
|
+
* // returns 9
|
|
1126
|
+
*
|
|
1127
|
+
* idx = fcn( -1, 9 );
|
|
1128
|
+
* // returns 0
|
|
1129
|
+
*/
|
|
1130
|
+
ind: typeof ind;
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Converts a linear index to an array of subscripts.
|
|
1134
|
+
*
|
|
1135
|
+
* ## Notes
|
|
1136
|
+
*
|
|
1137
|
+
* - The function accepts the following "modes":
|
|
1138
|
+
*
|
|
1139
|
+
* - **throw**: throw an error when a linear index exceeds array dimensions.
|
|
1140
|
+
* - **normalize**: normalize negative indices and throw an error when a linear index exceeds array dimensions.
|
|
1141
|
+
* - **wrap**: wrap around a linear index exceeding array dimensions using modulo arithmetic.
|
|
1142
|
+
* - **clamp**: set a linear index exceeding array dimensions to either `0` (minimum linear index) or the maximum linear index.
|
|
1143
|
+
*
|
|
1144
|
+
* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function interprets the linear index as an index into the underlying data buffer for the array, thus returning subscripts from the perspective of that buffer. If an `offset` is equal to `0`, the function treats the linear index as an index into an array view, thus returning subscripts from the perspective of that view.
|
|
1145
|
+
*
|
|
1146
|
+
* ```text
|
|
1147
|
+
* Dims: 2x2
|
|
1148
|
+
* Buffer: [ 1, 2, 3, 4 ]
|
|
1149
|
+
*
|
|
1150
|
+
* View = [ a00, a01,
|
|
1151
|
+
* a10, a11 ]
|
|
1152
|
+
*
|
|
1153
|
+
* Strides: 2,1
|
|
1154
|
+
* Offset: 0
|
|
1155
|
+
*
|
|
1156
|
+
* View = [ 1, 2,
|
|
1157
|
+
* 3, 4 ]
|
|
1158
|
+
*
|
|
1159
|
+
* Strides: 2,-1
|
|
1160
|
+
* Offset: 1
|
|
1161
|
+
*
|
|
1162
|
+
* View = [ 2, 1,
|
|
1163
|
+
* 4, 3 ]
|
|
1164
|
+
*
|
|
1165
|
+
* Strides: -2,1
|
|
1166
|
+
* Offset: 2
|
|
1167
|
+
*
|
|
1168
|
+
* View = [ 3, 4,
|
|
1169
|
+
* 1, 2 ]
|
|
1170
|
+
*
|
|
1171
|
+
* Strides: -2,-1
|
|
1172
|
+
* Offset: 3
|
|
1173
|
+
*
|
|
1174
|
+
* View = [ 4, 3,
|
|
1175
|
+
* 2, 1 ]
|
|
1176
|
+
* ```
|
|
1177
|
+
*
|
|
1178
|
+
* ```javascript
|
|
1179
|
+
* var shape = [ 2, 2 ];
|
|
1180
|
+
* var order = 'row-major';
|
|
1181
|
+
* var strides = [ -2, 1 ];
|
|
1182
|
+
* var offset = 2;
|
|
1183
|
+
* var mode = 'throw';
|
|
1184
|
+
*
|
|
1185
|
+
* // From the perspective of a view...
|
|
1186
|
+
* var s = ind2sub( shape, strides, 0, order, 0, mode );
|
|
1187
|
+
* // returns [ 0, 0 ]
|
|
1188
|
+
*
|
|
1189
|
+
* s = ind2sub( shape, strides, 0, order, 1, mode );
|
|
1190
|
+
* // returns [ 0, 1 ]
|
|
1191
|
+
*
|
|
1192
|
+
* s = ind2sub( shape, strides, 0, order, 2, mode );
|
|
1193
|
+
* // returns [ 1, 0 ]
|
|
1194
|
+
*
|
|
1195
|
+
* s = ind2sub( shape, strides, 0, order, 3, mode );
|
|
1196
|
+
* // returns [ 1, 1 ]
|
|
1197
|
+
*
|
|
1198
|
+
* // From the perspective of an underlying buffer...
|
|
1199
|
+
* s = ind2sub( shape, strides, offset, order, 0, mode );
|
|
1200
|
+
* // returns [ 1, 0 ]
|
|
1201
|
+
*
|
|
1202
|
+
* s = ind2sub( shape, strides, offset, order, 1, mode );
|
|
1203
|
+
* // returns [ 1, 1 ]
|
|
1204
|
+
*
|
|
1205
|
+
* s = ind2sub( shape, strides, offset, order, 2, mode );
|
|
1206
|
+
* // returns [ 0, 0 ]
|
|
1207
|
+
*
|
|
1208
|
+
* s = ind2sub( shape, strides, offset, order, 3, mode );
|
|
1209
|
+
* // returns [ 0, 1 ]
|
|
1210
|
+
* ```
|
|
1211
|
+
*
|
|
1212
|
+
* In short, from the perspective of a view, view data is always ordered.
|
|
1213
|
+
*
|
|
1214
|
+
*
|
|
1215
|
+
* @param shape - array shape
|
|
1216
|
+
* @param strides - stride array
|
|
1217
|
+
* @param offset - location of the first indexed value **based** on the stride array
|
|
1218
|
+
* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)
|
|
1219
|
+
* @param idx - linear index
|
|
1220
|
+
* @param mode - specifies how to handle a linear index which exceeds array dimensions
|
|
1221
|
+
* @throws linear index must not exceed array dimensions
|
|
1222
|
+
* @returns subscripts
|
|
690
1223
|
*
|
|
691
1224
|
* @example
|
|
692
1225
|
* var shape = [ 3, 3, 3 ];
|
|
@@ -768,62 +1301,179 @@ interface Namespace {
|
|
|
768
1301
|
maxViewBufferIndex: typeof maxViewBufferIndex;
|
|
769
1302
|
|
|
770
1303
|
/**
|
|
771
|
-
*
|
|
1304
|
+
* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.
|
|
772
1305
|
*
|
|
773
|
-
*
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
1306
|
+
* ## Notes
|
|
1307
|
+
*
|
|
1308
|
+
* - The function throws an error if a provided ndarray is incompatible with a provided shape.
|
|
1309
|
+
* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray.
|
|
1310
|
+
* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements.
|
|
1311
|
+
* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead.
|
|
1312
|
+
*
|
|
1313
|
+
* @param arr - input array
|
|
1314
|
+
* @param shape - desired shape
|
|
1315
|
+
* @throws input array cannot have more dimensions than the desired shape
|
|
1316
|
+
* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape
|
|
1317
|
+
* @throws input array and desired shape must be broadcast compatible
|
|
1318
|
+
* @returns broadcasted array
|
|
780
1319
|
*
|
|
781
1320
|
* @example
|
|
782
|
-
*
|
|
783
|
-
* var meta = {
|
|
784
|
-
* 'nargs': 2,
|
|
785
|
-
* 'nin': 1,
|
|
786
|
-
* 'nout': 1
|
|
787
|
-
* };
|
|
1321
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
788
1322
|
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
* 'float64', 'float64',
|
|
792
|
-
* 'float32', 'float32',
|
|
793
|
-
* 'generic', 'generic'
|
|
794
|
-
* ];
|
|
1323
|
+
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
1324
|
+
* // returns <ndarray>
|
|
795
1325
|
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
1326
|
+
* var shx = x.shape;
|
|
1327
|
+
* // returns [ 2, 2 ]
|
|
798
1328
|
*
|
|
799
|
-
*
|
|
800
|
-
*
|
|
1329
|
+
* var y = ns.maybeBroadcastArray( x, [ 3, 2, 2 ] );
|
|
1330
|
+
* // returns <ndarray>
|
|
1331
|
+
*
|
|
1332
|
+
* var shy = y.shape;
|
|
1333
|
+
* // returns [ 3, 2, 2 ]
|
|
1334
|
+
*
|
|
1335
|
+
* var v = y.get( 0, 0, 0 );
|
|
1336
|
+
* // returns 1
|
|
1337
|
+
*
|
|
1338
|
+
* v = y.get( 0, 0, 1 );
|
|
1339
|
+
* // returns 2
|
|
1340
|
+
*
|
|
1341
|
+
* v = y.get( 1, 0, 0 );
|
|
1342
|
+
* // returns 1
|
|
1343
|
+
*
|
|
1344
|
+
* v = y.get( 1, 1, 0 );
|
|
1345
|
+
* // returns 3
|
|
1346
|
+
*
|
|
1347
|
+
* v = y.get( 2, 0, 0 );
|
|
1348
|
+
* // returns 1
|
|
1349
|
+
*
|
|
1350
|
+
* v = y.get( 2, 1, 1 );
|
|
1351
|
+
* // returns 4
|
|
801
1352
|
*/
|
|
802
|
-
|
|
1353
|
+
maybeBroadcastArray: typeof maybeBroadcastArray;
|
|
803
1354
|
|
|
804
1355
|
/**
|
|
805
|
-
*
|
|
1356
|
+
* Broadcasts ndarrays to a common shape.
|
|
806
1357
|
*
|
|
807
|
-
*
|
|
808
|
-
* @param strides - stride array
|
|
809
|
-
* @param offset - index offset
|
|
810
|
-
* @returns linear index
|
|
1358
|
+
* ## Notes
|
|
811
1359
|
*
|
|
812
|
-
*
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
*
|
|
1360
|
+
* - The function throws an error if a provided broadcast-incompatible ndarrays.
|
|
1361
|
+
* - If a provided ndarray has a shape matching the common shape, the function returns the provided ndarray.
|
|
1362
|
+
* - If a provided ndarray has a different (broadcast compatible) shape than the common shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to a returned array, copy the array before performing operations which may mutate elements.
|
|
1363
|
+
* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast ndarray-like objects within internal implementations and to do so with minimal overhead.
|
|
816
1364
|
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
1365
|
+
* @param arrays - input arrays
|
|
1366
|
+
* @throws input arrays must be broadcast compatible
|
|
1367
|
+
* @returns list of broadcasted arrays
|
|
819
1368
|
*
|
|
820
1369
|
* @example
|
|
821
|
-
* var
|
|
822
|
-
* var
|
|
823
|
-
* var offset = 109;
|
|
1370
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1371
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
824
1372
|
*
|
|
825
|
-
* var
|
|
826
|
-
* // returns
|
|
1373
|
+
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
1374
|
+
* // returns <ndarray>
|
|
1375
|
+
*
|
|
1376
|
+
* var shx = x.shape;
|
|
1377
|
+
* // returns [ 2, 2 ]
|
|
1378
|
+
*
|
|
1379
|
+
* var y1 = zeros( [ 3, 2, 2 ] );
|
|
1380
|
+
* // returns <ndarray>
|
|
1381
|
+
*
|
|
1382
|
+
* var shy = y1.shape;
|
|
1383
|
+
* // returns [ 3, 2, 2 ]
|
|
1384
|
+
*
|
|
1385
|
+
* var out = ns.maybeBroadcastArrays( [ x, y ] );
|
|
1386
|
+
* // returns <ndarray>
|
|
1387
|
+
*
|
|
1388
|
+
* var x2 = out[ 0 ];
|
|
1389
|
+
* // returns <ndarray>
|
|
1390
|
+
*
|
|
1391
|
+
* var y2 = out[ 1 ];
|
|
1392
|
+
* // returns <ndarray>
|
|
1393
|
+
*
|
|
1394
|
+
* shx = x2.shape;
|
|
1395
|
+
* // returns [ 3, 2, 2 ]
|
|
1396
|
+
*
|
|
1397
|
+
* shy = y2.shape;
|
|
1398
|
+
* // returns [ 3, 2, 2 ]
|
|
1399
|
+
*
|
|
1400
|
+
* var v = x2.get( 0, 0, 0 );
|
|
1401
|
+
* // returns 1
|
|
1402
|
+
*
|
|
1403
|
+
* v = x2.get( 0, 0, 1 );
|
|
1404
|
+
* // returns 2
|
|
1405
|
+
*
|
|
1406
|
+
* v = x2.get( 1, 0, 0 );
|
|
1407
|
+
* // returns 1
|
|
1408
|
+
*
|
|
1409
|
+
* v = x2.get( 1, 1, 0 );
|
|
1410
|
+
* // returns 3
|
|
1411
|
+
*
|
|
1412
|
+
* v = x2.get( 2, 0, 0 );
|
|
1413
|
+
* // returns 1
|
|
1414
|
+
*
|
|
1415
|
+
* v = x2.get( 2, 1, 1 );
|
|
1416
|
+
* // returns 4
|
|
1417
|
+
*/
|
|
1418
|
+
maybeBroadcastArrays: typeof maybeBroadcastArrays;
|
|
1419
|
+
|
|
1420
|
+
/**
|
|
1421
|
+
* Defines non-enumerable read-only properties which expose ndarray function meta data.
|
|
1422
|
+
*
|
|
1423
|
+
* @param meta - function meta data
|
|
1424
|
+
* @param meta.nargs - total number of arguments
|
|
1425
|
+
* @param meta.nin - total number of input arrays
|
|
1426
|
+
* @param meta.nout - total number of output arrays
|
|
1427
|
+
* @param dtypes - list of ndarray data types
|
|
1428
|
+
* @param obj - object on which to define properties
|
|
1429
|
+
* @returns object on which properties were defined
|
|
1430
|
+
*
|
|
1431
|
+
* @example
|
|
1432
|
+
* // Define ndarray function meta data:
|
|
1433
|
+
* var meta = {
|
|
1434
|
+
* 'nargs': 2,
|
|
1435
|
+
* 'nin': 1,
|
|
1436
|
+
* 'nout': 1
|
|
1437
|
+
* };
|
|
1438
|
+
*
|
|
1439
|
+
* // Define the list of ndarray data types:
|
|
1440
|
+
* var dtypes = [
|
|
1441
|
+
* 'float64', 'float64',
|
|
1442
|
+
* 'float32', 'float32',
|
|
1443
|
+
* 'generic', 'generic'
|
|
1444
|
+
* ];
|
|
1445
|
+
*
|
|
1446
|
+
* // Define an object/function on which to set the properties:
|
|
1447
|
+
* var obj = {};
|
|
1448
|
+
*
|
|
1449
|
+
* // Set the properties:
|
|
1450
|
+
* ns.metaDataProps( meta, dtypes, obj );
|
|
1451
|
+
*/
|
|
1452
|
+
metaDataProps: typeof metaDataProps;
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* Computes the minimum linear index in an underlying data buffer accessible to an array view.
|
|
1456
|
+
*
|
|
1457
|
+
* @param shape - array shape
|
|
1458
|
+
* @param strides - stride array
|
|
1459
|
+
* @param offset - index offset
|
|
1460
|
+
* @returns linear index
|
|
1461
|
+
*
|
|
1462
|
+
* @example
|
|
1463
|
+
* var shape = [ 10, 10 ];
|
|
1464
|
+
* var strides = [ 10, 1 ];
|
|
1465
|
+
* var offset = 10;
|
|
1466
|
+
*
|
|
1467
|
+
* var idx = ns.minViewBufferIndex( shape, strides, offset );
|
|
1468
|
+
* // returns 10
|
|
1469
|
+
*
|
|
1470
|
+
* @example
|
|
1471
|
+
* var shape = [ 10, 10 ];
|
|
1472
|
+
* var strides = [ -10, -1 ];
|
|
1473
|
+
* var offset = 109;
|
|
1474
|
+
*
|
|
1475
|
+
* var idx = ns.minViewBufferIndex( shape, strides, offset );
|
|
1476
|
+
* // returns 10
|
|
827
1477
|
*
|
|
828
1478
|
* @example
|
|
829
1479
|
* var shape = [ 10, 10 ];
|
|
@@ -867,163 +1517,990 @@ interface Namespace {
|
|
|
867
1517
|
* var idx = ns.minmaxViewBufferIndex( shape, strides, offset );
|
|
868
1518
|
* // returns [ 0, 99 ]
|
|
869
1519
|
*
|
|
870
|
-
* @example
|
|
871
|
-
* var shape = [ 10, 10 ];
|
|
872
|
-
* var strides = [ 1, 10 ];
|
|
873
|
-
* var offset = 10;
|
|
1520
|
+
* @example
|
|
1521
|
+
* var shape = [ 10, 10 ];
|
|
1522
|
+
* var strides = [ 1, 10 ];
|
|
1523
|
+
* var offset = 10;
|
|
1524
|
+
*
|
|
1525
|
+
* var idx = ns.minmaxViewBufferIndex( shape, strides, offset );
|
|
1526
|
+
* // returns [ 10, 109 ]
|
|
1527
|
+
*
|
|
1528
|
+
* @example
|
|
1529
|
+
* var shape = [ 10, 10 ];
|
|
1530
|
+
* var strides = [ -1, -10 ];
|
|
1531
|
+
* var offset = 99;
|
|
1532
|
+
*
|
|
1533
|
+
* var idx = ns.minmaxViewBufferIndex( shape, strides, offset );
|
|
1534
|
+
* // returns [ 0, 99 ]
|
|
1535
|
+
*/
|
|
1536
|
+
minmaxViewBufferIndex: typeof minmaxViewBufferIndex;
|
|
1537
|
+
|
|
1538
|
+
/**
|
|
1539
|
+
* Converts an ndarray-like to an object likely to have the same "shape".
|
|
1540
|
+
*
|
|
1541
|
+
* ## Notes
|
|
1542
|
+
*
|
|
1543
|
+
* - This function is intended as a potential performance optimization. In V8, for example, even if two objects share common properties, if those properties were added in different orders or if one object has additional properties not shared by the other object, then those objects will have different "hidden" classes. If a function is provided many objects having different "shapes", some JavaScript VMs (e.g., V8) will consider the function "megamorphic" and fail to perform various runtime optimizations. Accordingly, the intent of this function is to standardize the "shape" of the object holding ndarray meta data to ensure that internal functions operating on ndarrays are provided consistent argument "shapes".
|
|
1544
|
+
*
|
|
1545
|
+
* @param x - input ndarray
|
|
1546
|
+
* @returns object containing ndarray data
|
|
1547
|
+
*
|
|
1548
|
+
* @example
|
|
1549
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1550
|
+
*
|
|
1551
|
+
* var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
|
|
1552
|
+
*
|
|
1553
|
+
* var obj = ns.ndarraylike2object( x );
|
|
1554
|
+
* // returns {...}
|
|
1555
|
+
*/
|
|
1556
|
+
ndarraylike2object: typeof ndarraylike2object;
|
|
1557
|
+
|
|
1558
|
+
/**
|
|
1559
|
+
* Returns the number of ndarray dimensions.
|
|
1560
|
+
*
|
|
1561
|
+
* @param x - input ndarray
|
|
1562
|
+
* @returns number of dimensions
|
|
1563
|
+
*
|
|
1564
|
+
* @example
|
|
1565
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
1566
|
+
*
|
|
1567
|
+
* var n = ns.ndims( zeros( [ 3, 3, 3 ] ) );
|
|
1568
|
+
* // returns 3
|
|
1569
|
+
*/
|
|
1570
|
+
ndims: typeof ndims;
|
|
1571
|
+
|
|
1572
|
+
/**
|
|
1573
|
+
* Returns the next Cartesian index (i.e., set of subscripts/dimension indices).
|
|
1574
|
+
*
|
|
1575
|
+
* ## Notes
|
|
1576
|
+
*
|
|
1577
|
+
* - The function does not check whether the current index is the "last" index. Instead, if the function is provided dimension indices corresponding to the last element, the function will cycle back to the "first" index.
|
|
1578
|
+
* - If provided an empty shape (i.e., a shape corresponding to a zero-dimensional ndarray) or a dimension index `dim` which is out-of-bounds, the function returns `null`.
|
|
1579
|
+
*
|
|
1580
|
+
* @param shape - array shape
|
|
1581
|
+
* @param order - iteration order
|
|
1582
|
+
* @param idx - current dimension indices
|
|
1583
|
+
* @param dim - index of the dimension from which to start incrementing (inclusive)
|
|
1584
|
+
* @returns updated dimension indices
|
|
1585
|
+
*
|
|
1586
|
+
* @example
|
|
1587
|
+
* var shape = [ 12 ];
|
|
1588
|
+
* var idx = ns.nextCartesianIndex( shape, 'row-major', [ 2 ], 0 );
|
|
1589
|
+
* // returns [ 3 ]
|
|
1590
|
+
*
|
|
1591
|
+
* @example
|
|
1592
|
+
* var shape = [ 2, 2, 2 ];
|
|
1593
|
+
*
|
|
1594
|
+
* var idx = ns.nextCartesianIndex( shape, 'row-major', [ 0, 0, 1 ], -1 );
|
|
1595
|
+
* // returns [ 0, 1, 0 ]
|
|
1596
|
+
*
|
|
1597
|
+
* idx = ns.nextCartesianIndex( shape, 'row-major', idx, -1 );
|
|
1598
|
+
* // returns [ 0, 1, 1 ]
|
|
1599
|
+
*
|
|
1600
|
+
* idx = ns.nextCartesianIndex( shape, 'row-major', idx, -1 );
|
|
1601
|
+
* // returns [ 1, 0, 0 ]
|
|
1602
|
+
*
|
|
1603
|
+
* idx = ns.nextCartesianIndex( shape, 'row-major', idx, -1 );
|
|
1604
|
+
* // returns [ 1, 0, 1 ]
|
|
1605
|
+
*
|
|
1606
|
+
* idx = ns.nextCartesianIndex( shape, 'row-major', idx, -1 );
|
|
1607
|
+
* // returns [ 1, 1, 0 ]
|
|
1608
|
+
*
|
|
1609
|
+
* idx = ns.nextCartesianIndex( shape, 'row-major', idx, -1 );
|
|
1610
|
+
* // returns [ 1, 1, 1 ]
|
|
1611
|
+
*
|
|
1612
|
+
* @example
|
|
1613
|
+
* var shape = [];
|
|
1614
|
+
* var idx = ns.nextCartesianIndex( shape, 'row-major', [], 0 );
|
|
1615
|
+
* // returns null
|
|
1616
|
+
*
|
|
1617
|
+
* @example
|
|
1618
|
+
* var shape = [ 12 ];
|
|
1619
|
+
* var idx = ns.nextCartesianIndex( shape, 'row-major', [ 2 ], -10 );
|
|
1620
|
+
* // returns null
|
|
1621
|
+
*
|
|
1622
|
+
* @example
|
|
1623
|
+
* var shape = [ 12 ];
|
|
1624
|
+
* var idx = ns.nextCartesianIndex( shape, 'column-major', [ 2 ], 10 );
|
|
1625
|
+
* // returns null
|
|
1626
|
+
*/
|
|
1627
|
+
nextCartesianIndex: typeof nextCartesianIndex;
|
|
1628
|
+
|
|
1629
|
+
/**
|
|
1630
|
+
* Returns the number of non-singleton dimensions.
|
|
1631
|
+
*
|
|
1632
|
+
* ## Notes
|
|
1633
|
+
*
|
|
1634
|
+
* - A singleton dimension is a dimension whose size is equal to `1`.
|
|
1635
|
+
*
|
|
1636
|
+
* @param shape - array shape
|
|
1637
|
+
* @returns number of non-singleton dimensions
|
|
1638
|
+
*
|
|
1639
|
+
* @example
|
|
1640
|
+
* var n = ns.nonsingletonDimensions( [ 3, 3, 1, 2 ] );
|
|
1641
|
+
* // returns 3
|
|
1642
|
+
*
|
|
1643
|
+
* @example
|
|
1644
|
+
* var n = ns.nonsingletonDimensions( [ 1, 1 ] );
|
|
1645
|
+
* // returns 0
|
|
1646
|
+
*/
|
|
1647
|
+
nonsingletonDimensions: typeof nonsingletonDimensions;
|
|
1648
|
+
|
|
1649
|
+
/**
|
|
1650
|
+
* Normalizes an index to the interval `[0,max]`.
|
|
1651
|
+
*
|
|
1652
|
+
* ## Notes
|
|
1653
|
+
*
|
|
1654
|
+
* - If provided an out-of-bounds index, the function returns `-1`.
|
|
1655
|
+
*
|
|
1656
|
+
* @param idx - index
|
|
1657
|
+
* @param max - maximum index
|
|
1658
|
+
* @returns index
|
|
1659
|
+
*
|
|
1660
|
+
* @example
|
|
1661
|
+
* var idx = ns.normalizeIndex( -2, 10 );
|
|
1662
|
+
* // returns 9
|
|
1663
|
+
*
|
|
1664
|
+
* idx = ns.normalizeIndex( 15, 10 );
|
|
1665
|
+
* // returns -1
|
|
1666
|
+
*
|
|
1667
|
+
* idx = ns.normalizeIndex( 5, 10 );
|
|
1668
|
+
* // returns 5
|
|
1669
|
+
*/
|
|
1670
|
+
normalizeIndex: typeof normalizeIndex;
|
|
1671
|
+
|
|
1672
|
+
/**
|
|
1673
|
+
* Applies a nullary callback and assigns results to elements in an output ndarray.
|
|
1674
|
+
*
|
|
1675
|
+
* @param arrays - array-like object containing an output ndarray
|
|
1676
|
+
* @param fcn - nullary callback
|
|
1677
|
+
*
|
|
1678
|
+
* @example
|
|
1679
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
1680
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
1681
|
+
*
|
|
1682
|
+
* function fcn() {
|
|
1683
|
+
* return 10.0;
|
|
1684
|
+
* }
|
|
1685
|
+
*
|
|
1686
|
+
* // Create data buffers:
|
|
1687
|
+
* var xbuf = new Float64Array( 12 );
|
|
1688
|
+
*
|
|
1689
|
+
* // Define the shape of the output array:
|
|
1690
|
+
* var shape = [ 3, 1, 2 ];
|
|
1691
|
+
*
|
|
1692
|
+
* // Define the array strides:
|
|
1693
|
+
* var sx = [ 4, 4, 1 ];
|
|
1694
|
+
*
|
|
1695
|
+
* // Define the index offset:
|
|
1696
|
+
* var ox = 1;
|
|
1697
|
+
*
|
|
1698
|
+
* // Create the output ndarray:
|
|
1699
|
+
* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );
|
|
1700
|
+
*
|
|
1701
|
+
* // Apply the ns.nullary function:
|
|
1702
|
+
* ns.nullary( [ x ], fcn );
|
|
1703
|
+
*
|
|
1704
|
+
* console.log( x.data );
|
|
1705
|
+
* // => <Float64Array>[ 0.0, 10.0, 10.0, 0.0, 0.0, 10.0, 10.0, 0.0, 0.0, 10.0, 10.0, 0.0 ]
|
|
1706
|
+
*/
|
|
1707
|
+
nullary: typeof nullary;
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* Reorders ndarray dimensions and associated strides for loop interchange.
|
|
1711
|
+
*
|
|
1712
|
+
* ## Notes
|
|
1713
|
+
*
|
|
1714
|
+
* - The returned object has the following properties:
|
|
1715
|
+
*
|
|
1716
|
+
* - **sh**: dimensions sorted in loop order.
|
|
1717
|
+
* - **sx**: ndarray strides sorted in loop order.
|
|
1718
|
+
* - **idx**: dimension indices sorted in loop order.
|
|
1719
|
+
*
|
|
1720
|
+
* - When iterating over the elements of a multi-dimensional array, accessing elements which are closer in memory can improve performance. To this end, loop interchange is a technique used in loop nest optimization to improve locality of reference and take advantage of CPU cache.
|
|
1721
|
+
*
|
|
1722
|
+
* The purpose of this function is to order ndarray dimensions according to the magnitude of array strides. By using the ordered dimensions and associated strides, one can construct nested loops (one for each dimension) such that the innermost loop iterates over the dimension in which array elements are closest in memory and the outermost loop iterates over the dimension in which array elements are farthest apart in memory. As a consequence, element iteration is optimized to minimize cache misses and ensure locality of reference.
|
|
1723
|
+
*
|
|
1724
|
+
* @param sh - array dimensions
|
|
1725
|
+
* @param sx - array stride lengths
|
|
1726
|
+
* @returns loop interchange data
|
|
1727
|
+
*
|
|
1728
|
+
* @example
|
|
1729
|
+
* var sh = [ 2, 3, 4 ];
|
|
1730
|
+
*
|
|
1731
|
+
* var sx = [ 12, 4, 1 ]; // row-major
|
|
1732
|
+
*
|
|
1733
|
+
* var o = ns.nullaryLoopOrder( sh, sx );
|
|
1734
|
+
* // returns {...}
|
|
1735
|
+
*
|
|
1736
|
+
* var ssh = o.sh;
|
|
1737
|
+
* // returns [ 4, 3, 2 ]
|
|
1738
|
+
*
|
|
1739
|
+
* var ssx = o.sx;
|
|
1740
|
+
* // returns [ 1, 4, 12 ]
|
|
1741
|
+
*
|
|
1742
|
+
* var idx = o.idx;
|
|
1743
|
+
* // returns [ 2, 1, 0 ]
|
|
1744
|
+
*/
|
|
1745
|
+
nullaryLoopOrder: typeof nullaryLoopOrder;
|
|
1746
|
+
|
|
1747
|
+
/**
|
|
1748
|
+
* Returns a loop block size for multi-dimensional array tiled loops.
|
|
1749
|
+
*
|
|
1750
|
+
* @param dtypeX - array data type
|
|
1751
|
+
* @returns block size (in units of elements)
|
|
1752
|
+
*
|
|
1753
|
+
* @example
|
|
1754
|
+
* var bsize = ns.nullaryBlockSize( 'float64' );
|
|
1755
|
+
* // returns <number>
|
|
1756
|
+
*/
|
|
1757
|
+
nullaryBlockSize: typeof nullaryBlockSize;
|
|
1758
|
+
|
|
1759
|
+
/**
|
|
1760
|
+
* Returns the number of elements in an array.
|
|
1761
|
+
*
|
|
1762
|
+
* @param shape - array shape
|
|
1763
|
+
* @returns number of elements
|
|
1764
|
+
*
|
|
1765
|
+
* @example
|
|
1766
|
+
* var n = ns.numel( [ 3, 3, 3 ] );
|
|
1767
|
+
* // returns 27
|
|
1768
|
+
*/
|
|
1769
|
+
numel: typeof numel;
|
|
1770
|
+
|
|
1771
|
+
/**
|
|
1772
|
+
* Returns the size (i.e., number of elements) of a specified dimension for a provided ndarray.
|
|
1773
|
+
*
|
|
1774
|
+
* @param x - input ndarray
|
|
1775
|
+
* @param dim - dimension index
|
|
1776
|
+
* @returns dimension size
|
|
1777
|
+
*
|
|
1778
|
+
* @example
|
|
1779
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
1780
|
+
*
|
|
1781
|
+
* var d = ns.numelDimension( zeros( [ 4, 2, 3 ] ), 0 );
|
|
1782
|
+
* // returns 4
|
|
1783
|
+
*/
|
|
1784
|
+
numelDimension: typeof numelDimension;
|
|
1785
|
+
|
|
1786
|
+
/**
|
|
1787
|
+
* Returns the index offset specifying the underlying buffer index of the first iterated ndarray element.
|
|
1788
|
+
*
|
|
1789
|
+
* @param x - input ndarray
|
|
1790
|
+
* @returns index offset
|
|
1791
|
+
*
|
|
1792
|
+
* @example
|
|
1793
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
1794
|
+
*
|
|
1795
|
+
* var n = ns.offset( zeros( [ 3, 3, 3 ] ) );
|
|
1796
|
+
* // returns 0
|
|
1797
|
+
*/
|
|
1798
|
+
offset: typeof offset;
|
|
1799
|
+
|
|
1800
|
+
/**
|
|
1801
|
+
* Returns the layout order of a provided ndarray.
|
|
1802
|
+
*
|
|
1803
|
+
* ## Notes
|
|
1804
|
+
*
|
|
1805
|
+
* - If unable to resolve a layout order, the function returns `null`.
|
|
1806
|
+
*
|
|
1807
|
+
* @param x - input ndarray
|
|
1808
|
+
* @returns layout order (or null)
|
|
1809
|
+
*
|
|
1810
|
+
* @example
|
|
1811
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
1812
|
+
*
|
|
1813
|
+
* var x = zeros( [ 3, 3, 3 ], {
|
|
1814
|
+
* 'ns.order': 'row-major'
|
|
1815
|
+
* });
|
|
1816
|
+
*
|
|
1817
|
+
* var o = ns.order( x );
|
|
1818
|
+
* // returns 'row-major'
|
|
1819
|
+
*/
|
|
1820
|
+
order: typeof order;
|
|
1821
|
+
|
|
1822
|
+
/**
|
|
1823
|
+
* Returns the policy string associated with an output ndarray data type policy enumeration constant.
|
|
1824
|
+
*
|
|
1825
|
+
* @param policy - policy enumeration constant
|
|
1826
|
+
* @returns policy string
|
|
1827
|
+
*
|
|
1828
|
+
* @example
|
|
1829
|
+
* var str2enum = require( '@stdlib/ndarray-base-output-policy-str2enum' );
|
|
1830
|
+
*
|
|
1831
|
+
* var v = str2enum( 'same' );
|
|
1832
|
+
* // returns <number>
|
|
1833
|
+
*
|
|
1834
|
+
* var policy = ns.outputPolicyEnum2Str( v );
|
|
1835
|
+
* // returns 'same'
|
|
1836
|
+
*/
|
|
1837
|
+
outputPolicyEnum2Str: typeof outputPolicyEnum2Str;
|
|
1838
|
+
|
|
1839
|
+
/**
|
|
1840
|
+
* Returns the enumeration constant associated with an ndarray data type policy value.
|
|
1841
|
+
*
|
|
1842
|
+
* ## Notes
|
|
1843
|
+
*
|
|
1844
|
+
* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `SAME == 0`). Instead, the function should be used in an opaque manner.
|
|
1845
|
+
*
|
|
1846
|
+
* @param policy - policy value
|
|
1847
|
+
* @returns enumeration constant
|
|
1848
|
+
*
|
|
1849
|
+
* @example
|
|
1850
|
+
* var v = ns.outputPolicyResolveEnum( 'same' );
|
|
1851
|
+
* // returns <number>
|
|
1852
|
+
*/
|
|
1853
|
+
outputPolicyResolveEnum: typeof outputPolicyResolveEnum;
|
|
1854
|
+
|
|
1855
|
+
/**
|
|
1856
|
+
* Returns the policy string associated with an output ndarray data type policy value.
|
|
1857
|
+
*
|
|
1858
|
+
* @param policy - policy value
|
|
1859
|
+
* @returns policy string
|
|
1860
|
+
*
|
|
1861
|
+
* @example
|
|
1862
|
+
* var str2enum = require( '@stdlib/ndarray-base-output-policy-str2enum' );
|
|
1863
|
+
*
|
|
1864
|
+
* var v = ns.outputPolicyResolveStr( str2enum( 'same' ) );
|
|
1865
|
+
* // returns 'same'
|
|
1866
|
+
*/
|
|
1867
|
+
outputPolicyResolveStr: typeof outputPolicyResolveStr;
|
|
1868
|
+
|
|
1869
|
+
/**
|
|
1870
|
+
* Returns the enumeration constant associated with an output ndarray data type policy string.
|
|
1871
|
+
*
|
|
1872
|
+
* ## Notes
|
|
1873
|
+
*
|
|
1874
|
+
* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `SAME == 0`). Instead, the function should be used in an opaque manner.
|
|
1875
|
+
*
|
|
1876
|
+
* @param policy - policy string
|
|
1877
|
+
* @returns enumeration constant
|
|
1878
|
+
*
|
|
1879
|
+
* @example
|
|
1880
|
+
* var v = ns.outputPolicyStr2Enum( 'same' );
|
|
1881
|
+
* // returns <number>
|
|
1882
|
+
*/
|
|
1883
|
+
outputPolicyStr2Enum: typeof outputPolicyStr2Enum;
|
|
1884
|
+
|
|
1885
|
+
/**
|
|
1886
|
+
* Returns an array with a specified number of prepended singleton dimensions.
|
|
1887
|
+
*
|
|
1888
|
+
* @param x - input array
|
|
1889
|
+
* @param n - number of singleton dimensions to prepend
|
|
1890
|
+
* @returns output array
|
|
1891
|
+
*
|
|
1892
|
+
* @example
|
|
1893
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1894
|
+
*
|
|
1895
|
+
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
1896
|
+
* // returns <ndarray>
|
|
1897
|
+
*
|
|
1898
|
+
* var shx = x.shape;
|
|
1899
|
+
* // returns [ 2, 2 ]
|
|
1900
|
+
*
|
|
1901
|
+
* var y = ns.prependSingletonDimensions( x, 3 );
|
|
1902
|
+
* // returns <ndarray>
|
|
1903
|
+
*
|
|
1904
|
+
* var shy = y.shape;
|
|
1905
|
+
* // returns [ 1, 1, 1, 2, 2 ]
|
|
1906
|
+
*
|
|
1907
|
+
* var v = y.get( 0, 0, 0, 0, 0 );
|
|
1908
|
+
* // returns 1
|
|
1909
|
+
*
|
|
1910
|
+
* v = y.get( 0, 0, 0, 0, 1 );
|
|
1911
|
+
* // returns 2
|
|
1912
|
+
*
|
|
1913
|
+
* v = y.get( 0, 0, 0, 1, 0 );
|
|
1914
|
+
* // returns 3
|
|
1915
|
+
*
|
|
1916
|
+
* v = y.get( 0, 0, 0, 1, 1 );
|
|
1917
|
+
* // returns 4
|
|
1918
|
+
*/
|
|
1919
|
+
prependSingletonDimensions: typeof prependSingletonDimensions;
|
|
1920
|
+
|
|
1921
|
+
/**
|
|
1922
|
+
* Returns an array without singleton dimensions.
|
|
1923
|
+
*
|
|
1924
|
+
* ## Notes
|
|
1925
|
+
*
|
|
1926
|
+
* - If a provided ndarray does not have any singleton dimensions, the function returns the provided ndarray unchanged.
|
|
1927
|
+
* - If a provided ndarray does have singleton dimensions, the function returns a new ndarray view.
|
|
1928
|
+
*
|
|
1929
|
+
* @param x - input array
|
|
1930
|
+
* @returns squeezed array
|
|
1931
|
+
*
|
|
1932
|
+
* @example
|
|
1933
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1934
|
+
*
|
|
1935
|
+
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ], {
|
|
1936
|
+
* 'ndmin': 5
|
|
1937
|
+
* });
|
|
1938
|
+
* // returns <ndarray>
|
|
1939
|
+
*
|
|
1940
|
+
* var shx = x.shape;
|
|
1941
|
+
* // returns [ 1, 1, 1, 2, 2 ]
|
|
1942
|
+
*
|
|
1943
|
+
* var y = ns.removeSingletonDimensions( x );
|
|
1944
|
+
* // returns <ndarray>
|
|
1945
|
+
*
|
|
1946
|
+
* var shy = y.shape;
|
|
1947
|
+
* // returns [ 2, 2 ]
|
|
1948
|
+
*
|
|
1949
|
+
* var v = y.get( 0, 0 );
|
|
1950
|
+
* // returns 1
|
|
1951
|
+
*
|
|
1952
|
+
* v = y.get( 0, 1 );
|
|
1953
|
+
* // returns 2
|
|
1954
|
+
*
|
|
1955
|
+
* v = y.get( 1, 0 );
|
|
1956
|
+
* // returns 3
|
|
1957
|
+
*
|
|
1958
|
+
* v = y.get( 1, 1 );
|
|
1959
|
+
* // returns 4
|
|
1960
|
+
*/
|
|
1961
|
+
removeSingletonDimensions: typeof removeSingletonDimensions;
|
|
1962
|
+
|
|
1963
|
+
/**
|
|
1964
|
+
* Returns a view of an input ndarray in which the order of elements along each dimension is reversed.
|
|
1965
|
+
*
|
|
1966
|
+
* @param x - input array
|
|
1967
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
1968
|
+
* @returns output array
|
|
1969
|
+
*
|
|
1970
|
+
* @example
|
|
1971
|
+
* var typedarray = require( '@stdlib/array-typed' );
|
|
1972
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
1973
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
1974
|
+
*
|
|
1975
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
1976
|
+
* var shape = [ 3, 2 ];
|
|
1977
|
+
* var strides = [ 2, 1 ];
|
|
1978
|
+
* var offset = 0;
|
|
1979
|
+
*
|
|
1980
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
1981
|
+
* // returns <ndarray>
|
|
1982
|
+
*
|
|
1983
|
+
* var sh = x.shape;
|
|
1984
|
+
* // returns [ 3, 2 ]
|
|
1985
|
+
*
|
|
1986
|
+
* var arr = ndarray2array( x );
|
|
1987
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
1988
|
+
*
|
|
1989
|
+
* var y = ns.reverse( x, false );
|
|
1990
|
+
* // returns <ndarray>
|
|
1991
|
+
*
|
|
1992
|
+
* sh = y.shape;
|
|
1993
|
+
* // returns [ 3, 2 ]
|
|
1994
|
+
*
|
|
1995
|
+
* arr = ndarray2array( y );
|
|
1996
|
+
* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ]
|
|
1997
|
+
*/
|
|
1998
|
+
reverse: typeof reverse;
|
|
1999
|
+
|
|
2000
|
+
/**
|
|
2001
|
+
* Returns a view of an input ndarray in which the order of elements along a specified dimension is reversed.
|
|
2002
|
+
*
|
|
2003
|
+
* @param x - input array
|
|
2004
|
+
* @param dim - index of dimension to reverse
|
|
2005
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
2006
|
+
* @returns output array
|
|
2007
|
+
*
|
|
2008
|
+
* @example
|
|
2009
|
+
* var typedarray = require( '@stdlib/array-typed' );
|
|
2010
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2011
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
2012
|
+
*
|
|
2013
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2014
|
+
* var shape = [ 3, 2 ];
|
|
2015
|
+
* var strides = [ 2, 1 ];
|
|
2016
|
+
* var offset = 0;
|
|
2017
|
+
*
|
|
2018
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2019
|
+
* // returns <ndarray>
|
|
2020
|
+
*
|
|
2021
|
+
* var sh = x.shape;
|
|
2022
|
+
* // returns [ 3, 2 ]
|
|
2023
|
+
*
|
|
2024
|
+
* var arr = ndarray2array( x );
|
|
2025
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
2026
|
+
*
|
|
2027
|
+
* var y = ns.reverseDimension( x, 0, false );
|
|
2028
|
+
* // returns <ndarray>
|
|
2029
|
+
*
|
|
2030
|
+
* sh = y.shape;
|
|
2031
|
+
* // returns [ 3, 2 ]
|
|
2032
|
+
*
|
|
2033
|
+
* arr = ndarray2array( y );
|
|
2034
|
+
* // returns [ [ 5, 6 ], [ 3, 4 ], [ 1, 2 ] ]
|
|
2035
|
+
*/
|
|
2036
|
+
reverseDimension: typeof reverseDimension;
|
|
2037
|
+
|
|
2038
|
+
/**
|
|
2039
|
+
* Serializes ndarray meta data.
|
|
2040
|
+
*
|
|
2041
|
+
* ## Notes
|
|
2042
|
+
*
|
|
2043
|
+
* - Serialization is performed according to host byte order (endianness).
|
|
2044
|
+
*
|
|
2045
|
+
* - Meta data format:
|
|
2046
|
+
*
|
|
2047
|
+
* ```text
|
|
2048
|
+
* | <endianness> (1 byte) | <dtype> (2 bytes) | <ndims> (8 bytes) | <shape> (ndims*8 bytes) | <strides> (ndims*8 bytes) | <offset> (8 bytes) | <order> (1 byte) | <mode> (1 byte) | <nsubmodes> (8 bytes) | <submodes> (nsubmodes*1 bytes) | <flags> (4 bytes) |
|
|
2049
|
+
* ```
|
|
2050
|
+
*
|
|
2051
|
+
* which translates to the following `ArrayBuffer` layout:
|
|
2052
|
+
*
|
|
2053
|
+
* ```text
|
|
2054
|
+
* ArrayBuffer[
|
|
2055
|
+
* <endianness>[int8],
|
|
2056
|
+
* <dtype>[int16],
|
|
2057
|
+
* <ndims>[int64],
|
|
2058
|
+
* <shape>[ndims*int64],
|
|
2059
|
+
* <strides>[ndims*int64],
|
|
2060
|
+
* <offset>[int64],
|
|
2061
|
+
* <order>[int8],
|
|
2062
|
+
* <mode>[int8],
|
|
2063
|
+
* <nsubmodes>[int64],
|
|
2064
|
+
* <submodes>[nsubmodes*int8]
|
|
2065
|
+
* <flags>[int32]
|
|
2066
|
+
* ]
|
|
2067
|
+
* ```
|
|
2068
|
+
*
|
|
2069
|
+
* where `strides` and `offset` are in units of bytes.
|
|
2070
|
+
*
|
|
2071
|
+
* - If the endianness is `1`, the byte order is little endian. If the endianness is `0`, the byte order is big endian.
|
|
2072
|
+
*
|
|
2073
|
+
* - Buffer length:
|
|
2074
|
+
*
|
|
2075
|
+
* ```text
|
|
2076
|
+
* 1 + 2 + 8 + (ndims*8) + (ndims*8) + 8 + 1 + 1 + 8 + (nsubmodes*1) + 4 = 33 + (ndims*16) + nsubmodes
|
|
2077
|
+
* ```
|
|
2078
|
+
*
|
|
2079
|
+
* For example, consider a three-dimensional ndarray with one subscript index mode (submode):
|
|
2080
|
+
*
|
|
2081
|
+
* ```text
|
|
2082
|
+
* 33 + (3*16) + 1 = 82 bytes
|
|
2083
|
+
* ```
|
|
2084
|
+
*
|
|
2085
|
+
* - Views:
|
|
2086
|
+
*
|
|
2087
|
+
* - endianness: `Int8Array( buf, 0, 1 )`
|
|
2088
|
+
* - dtype: `Int16Array( buf, 1, 1 )`
|
|
2089
|
+
* - ndims: `Int64Array( buf, 3, 1 )`
|
|
2090
|
+
* - shape: `Int64Array( buf, 11, ndims )`
|
|
2091
|
+
* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`
|
|
2092
|
+
* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`
|
|
2093
|
+
* - order: `Int8Array( buf, 19+(ndims*16), 1 )`
|
|
2094
|
+
* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`
|
|
2095
|
+
* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`
|
|
2096
|
+
* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`
|
|
2097
|
+
* - flags: `Int32Array( buf, 29+(ndims*16)+nsubmodes, 1)`
|
|
2098
|
+
*
|
|
2099
|
+
* @param x - input ndarray
|
|
2100
|
+
* @returns serialized meta data
|
|
2101
|
+
*
|
|
2102
|
+
* @example
|
|
2103
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
2104
|
+
*
|
|
2105
|
+
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
2106
|
+
*
|
|
2107
|
+
* var dv = ns.serializeMetaData( x );
|
|
2108
|
+
* // returns <DataView>
|
|
2109
|
+
*/
|
|
2110
|
+
serializeMetaData: typeof serializeMetaData;
|
|
2111
|
+
|
|
2112
|
+
/**
|
|
2113
|
+
* Returns the shape of a provided ndarray.
|
|
2114
|
+
*
|
|
2115
|
+
* ## Notes
|
|
2116
|
+
*
|
|
2117
|
+
* - When `copy` is `false`, changes to the returned shape array may mutate the input ndarray shape. If there is a chance that the returned shape will be mutated (either directly or by downstream consumers), set `copy` to `true` to prevent unintended side effects.
|
|
2118
|
+
*
|
|
2119
|
+
* @param x - input ndarray
|
|
2120
|
+
* @param copy - boolean indicating whether to explicitly copy the value assigned to the input ndarray's `shape` property
|
|
2121
|
+
* @returns shape
|
|
2122
|
+
*
|
|
2123
|
+
* @example
|
|
2124
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
2125
|
+
*
|
|
2126
|
+
* var sh = ns.shape( zeros( [ 3, 3, 3 ] ), false );
|
|
2127
|
+
* // returns [ 3, 3, 3 ]
|
|
2128
|
+
*/
|
|
2129
|
+
shape: typeof shape;
|
|
2130
|
+
|
|
2131
|
+
/**
|
|
2132
|
+
* Generates a stride array from an array shape.
|
|
2133
|
+
*
|
|
2134
|
+
* @param shape - array shape
|
|
2135
|
+
* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)
|
|
2136
|
+
* @returns array strides
|
|
2137
|
+
*
|
|
2138
|
+
* @example
|
|
2139
|
+
* var s = ns.shape2strides( [ 3, 2 ], 'row-major' );
|
|
2140
|
+
* // returns [ 2, 1 ]
|
|
2141
|
+
*
|
|
2142
|
+
* s = ns.shape2strides( [ 3, 2 ], 'column-major' );
|
|
2143
|
+
* // returns [ 1, 3 ]
|
|
2144
|
+
*/
|
|
2145
|
+
shape2strides: typeof shape2strides;
|
|
2146
|
+
|
|
2147
|
+
/**
|
|
2148
|
+
* Returns the number of singleton dimensions.
|
|
2149
|
+
*
|
|
2150
|
+
* ## Notes
|
|
2151
|
+
*
|
|
2152
|
+
* - A singleton dimension is a dimension whose size is equal to `1`.
|
|
2153
|
+
*
|
|
2154
|
+
* @param shape - array shape
|
|
2155
|
+
* @returns number of singleton dimensions
|
|
2156
|
+
*
|
|
2157
|
+
* @example
|
|
2158
|
+
* var n = ns.singletonDimensions( [ 3, 3, 1, 2 ] );
|
|
2159
|
+
* // returns 1
|
|
2160
|
+
*
|
|
2161
|
+
* @example
|
|
2162
|
+
* var n = ns.singletonDimensions( [ 2, 2 ] );
|
|
2163
|
+
* // returns 0
|
|
2164
|
+
*/
|
|
2165
|
+
singletonDimensions: typeof singletonDimensions;
|
|
2166
|
+
|
|
2167
|
+
/**
|
|
2168
|
+
* Returns a view of an input ndarray.
|
|
2169
|
+
*
|
|
2170
|
+
* @param x - input array
|
|
2171
|
+
* @param s - multi-slice object
|
|
2172
|
+
* @param strict - boolean indicating whether to enforce strict bounds checking
|
|
2173
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
2174
|
+
* @returns output array
|
|
2175
|
+
*
|
|
2176
|
+
* @example
|
|
2177
|
+
* var Slice = require( '@stdlib/ns.slice-ctor' );
|
|
2178
|
+
* var MultiSlice = require( '@stdlib/ns.slice-multi' );
|
|
2179
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2180
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
2181
|
+
*
|
|
2182
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2183
|
+
* var shape = [ 3, 2 ];
|
|
2184
|
+
* var strides = [ 2, 1 ];
|
|
2185
|
+
* var offset = 0;
|
|
2186
|
+
*
|
|
2187
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2188
|
+
* // returns <ndarray>
|
|
2189
|
+
*
|
|
2190
|
+
* var sh = x.shape;
|
|
2191
|
+
* // returns [ 3, 2 ]
|
|
2192
|
+
*
|
|
2193
|
+
* var arr = ndarray2array( x );
|
|
2194
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
2195
|
+
*
|
|
2196
|
+
* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );
|
|
2197
|
+
* // returns <MultiSlice>
|
|
2198
|
+
*
|
|
2199
|
+
* var y = ns.slice( x, s, false, false );
|
|
2200
|
+
* // returns <ndarray>
|
|
2201
|
+
*
|
|
2202
|
+
* sh = y.shape;
|
|
2203
|
+
* // returns [ 2, 2 ]
|
|
2204
|
+
*
|
|
2205
|
+
* arr = ndarray2array( y );
|
|
2206
|
+
* // returns [ [ 6, 5 ], [ 2, 1 ] ]
|
|
2207
|
+
*/
|
|
2208
|
+
slice: typeof slice;
|
|
2209
|
+
|
|
2210
|
+
/**
|
|
2211
|
+
* Assigns element values from a broadcasted input ndarray to corresponding elements in an output ndarray view.
|
|
2212
|
+
*
|
|
2213
|
+
* ## Notes
|
|
2214
|
+
*
|
|
2215
|
+
* - The input array must be broadcast compatible with the output array view to which elements will be assigned.
|
|
2216
|
+
* - The input array must have a data type which can be safely cast to the output array data type. Floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., element values from a `'float64'` input array can be assigned to corresponding elements in a `'float32'` output array).
|
|
2217
|
+
*
|
|
2218
|
+
* @param x - input array
|
|
2219
|
+
* @param y - output array
|
|
2220
|
+
* @param s - multi-slice object for the output array
|
|
2221
|
+
* @param strict - boolean indicating whether to enforce strict bounds checking
|
|
2222
|
+
* @returns output array
|
|
2223
|
+
*
|
|
2224
|
+
* @example
|
|
2225
|
+
* var Slice = require( '@stdlib/slice-ctor' );
|
|
2226
|
+
* var MultiSlice = require( '@stdlib/slice-multi' );
|
|
2227
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2228
|
+
* var ndzeros = require( '@stdlib/ndarray-zeros' );
|
|
2229
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
2230
|
+
*
|
|
2231
|
+
* // Define an input array:
|
|
2232
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2233
|
+
* var shape = [ 3, 2 ];
|
|
2234
|
+
* var strides = [ 2, 1 ];
|
|
2235
|
+
* var offset = 0;
|
|
2236
|
+
*
|
|
2237
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2238
|
+
* // returns <ndarray>
|
|
2239
|
+
*
|
|
2240
|
+
* var sh = x.shape;
|
|
2241
|
+
* // returns [ 3, 2 ]
|
|
2242
|
+
*
|
|
2243
|
+
* var arr = ndarray2array( x );
|
|
2244
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
2245
|
+
*
|
|
2246
|
+
* // Define an output array:
|
|
2247
|
+
* var y = ndzeros( [ 2, 3, 2 ], {
|
|
2248
|
+
* 'dtype': x.dtype
|
|
2249
|
+
* });
|
|
2250
|
+
*
|
|
2251
|
+
* // Create a slice:
|
|
2252
|
+
* var s0 = null;
|
|
2253
|
+
* var s1 = new Slice( null, null, -1 );
|
|
2254
|
+
* var s2 = new Slice( null, null, -1 );
|
|
2255
|
+
* var s = new MultiSlice( s0, s1, s2 );
|
|
2256
|
+
* // returns <MultiSlice>
|
|
2257
|
+
*
|
|
2258
|
+
* // Perform assignment:
|
|
2259
|
+
* var out = ns.sliceAssign( x, y, s, false );
|
|
2260
|
+
* // returns <ndarray>
|
|
2261
|
+
*
|
|
2262
|
+
* var bool = ( out === y );
|
|
2263
|
+
* // returns true
|
|
2264
|
+
*
|
|
2265
|
+
* arr = ndarray2array( y );
|
|
2266
|
+
* // returns [ [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ], [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] ]
|
|
2267
|
+
*/
|
|
2268
|
+
sliceAssign: typeof sliceAssign;
|
|
2269
|
+
|
|
2270
|
+
/**
|
|
2271
|
+
* Returns a view of an input ndarray when sliced along a specified dimension.
|
|
2272
|
+
*
|
|
2273
|
+
* @param x - input array
|
|
2274
|
+
* @param dim - index of dimension to slice
|
|
2275
|
+
* @param s - slice object or an integer
|
|
2276
|
+
* @param strict - boolean indicating whether to enforce strict bounds checking
|
|
2277
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
2278
|
+
* @returns output array
|
|
2279
|
+
*
|
|
2280
|
+
* @example
|
|
2281
|
+
* var Slice = require( '@stdlib/slice-ctor' );
|
|
2282
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2283
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
2284
|
+
*
|
|
2285
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2286
|
+
* var shape = [ 3, 2 ];
|
|
2287
|
+
* var strides = [ 2, 1 ];
|
|
2288
|
+
* var offset = 0;
|
|
2289
|
+
*
|
|
2290
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2291
|
+
* // returns <ndarray>
|
|
2292
|
+
*
|
|
2293
|
+
* var sh = x.shape;
|
|
2294
|
+
* // returns [ 3, 2 ]
|
|
2295
|
+
*
|
|
2296
|
+
* var arr = ndarray2array( x );
|
|
2297
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
2298
|
+
*
|
|
2299
|
+
* var s = new Slice( null, null, -1 );
|
|
2300
|
+
* // returns <Slice>
|
|
874
2301
|
*
|
|
875
|
-
* var
|
|
876
|
-
* // returns
|
|
2302
|
+
* var y = ns.sliceDimension( x, 0, s, false, false );
|
|
2303
|
+
* // returns <ndarray>
|
|
877
2304
|
*
|
|
878
|
-
*
|
|
879
|
-
*
|
|
880
|
-
* var strides = [ -1, -10 ];
|
|
881
|
-
* var offset = 99;
|
|
2305
|
+
* sh = y.shape;
|
|
2306
|
+
* // returns [ 3, 2 ]
|
|
882
2307
|
*
|
|
883
|
-
*
|
|
884
|
-
* // returns [
|
|
2308
|
+
* arr = ndarray2array( y );
|
|
2309
|
+
* // returns [ [ 5, 6 ], [ 3, 4 ], [ 1, 2 ] ]
|
|
885
2310
|
*/
|
|
886
|
-
|
|
2311
|
+
sliceDimension: typeof sliceDimension;
|
|
887
2312
|
|
|
888
2313
|
/**
|
|
889
|
-
* Returns
|
|
2314
|
+
* Returns a shifted view of an input ndarray along a specified dimension.
|
|
890
2315
|
*
|
|
891
|
-
*
|
|
2316
|
+
* @param x - input array
|
|
2317
|
+
* @param start - starting index (inclusive)
|
|
2318
|
+
* @param strict - boolean indicating whether to enforce strict bounds checking
|
|
2319
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
2320
|
+
* @returns output array
|
|
892
2321
|
*
|
|
893
|
-
*
|
|
2322
|
+
* @example
|
|
2323
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2324
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
894
2325
|
*
|
|
895
|
-
*
|
|
896
|
-
*
|
|
2326
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2327
|
+
* var shape = [ 3, 2 ];
|
|
2328
|
+
* var strides = [ 2, 1 ];
|
|
2329
|
+
* var offset = 0;
|
|
897
2330
|
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
* // returns 3
|
|
2331
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2332
|
+
* // returns <ndarray>
|
|
901
2333
|
*
|
|
902
|
-
*
|
|
903
|
-
*
|
|
904
|
-
*
|
|
2334
|
+
* var sh = x.shape;
|
|
2335
|
+
* // returns [ 3, 2 ]
|
|
2336
|
+
*
|
|
2337
|
+
* var arr = ndarray2array( x );
|
|
2338
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
2339
|
+
*
|
|
2340
|
+
* var y = ns.sliceDimensionFrom( x, 0, 1, false, false );
|
|
2341
|
+
* // returns <ndarray>
|
|
2342
|
+
*
|
|
2343
|
+
* sh = y.shape;
|
|
2344
|
+
* // returns [ 2, 2 ]
|
|
2345
|
+
*
|
|
2346
|
+
* arr = ndarray2array( y );
|
|
2347
|
+
* // returns [ [ 3, 4 ], [ 5, 6 ] ]
|
|
905
2348
|
*/
|
|
906
|
-
|
|
2349
|
+
sliceDimensionFrom: typeof sliceDimensionFrom;
|
|
907
2350
|
|
|
908
2351
|
/**
|
|
909
|
-
* Returns
|
|
2352
|
+
* Returns a truncated view of an input ndarray along a specified dimension.
|
|
910
2353
|
*
|
|
911
|
-
* @param
|
|
912
|
-
* @
|
|
2354
|
+
* @param x - input array
|
|
2355
|
+
* @param stop - ending index (exclusive)
|
|
2356
|
+
* @param strict - boolean indicating whether to enforce strict bounds checking
|
|
2357
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
2358
|
+
* @returns output array
|
|
913
2359
|
*
|
|
914
2360
|
* @example
|
|
915
|
-
* var
|
|
916
|
-
*
|
|
2361
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2362
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
2363
|
+
*
|
|
2364
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2365
|
+
* var shape = [ 3, 2 ];
|
|
2366
|
+
* var strides = [ 2, 1 ];
|
|
2367
|
+
* var offset = 0;
|
|
2368
|
+
*
|
|
2369
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2370
|
+
* // returns <ndarray>
|
|
2371
|
+
*
|
|
2372
|
+
* var sh = x.shape;
|
|
2373
|
+
* // returns [ 3, 2 ]
|
|
2374
|
+
*
|
|
2375
|
+
* var arr = ndarray2array( x );
|
|
2376
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
2377
|
+
*
|
|
2378
|
+
* var y = ns.sliceDimensionTo( x, 0, 2, false, false );
|
|
2379
|
+
* // returns <ndarray>
|
|
2380
|
+
*
|
|
2381
|
+
* sh = y.shape;
|
|
2382
|
+
* // returns [ 2, 2 ]
|
|
2383
|
+
*
|
|
2384
|
+
* arr = ndarray2array( y );
|
|
2385
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ] ]
|
|
917
2386
|
*/
|
|
918
|
-
|
|
2387
|
+
sliceDimensionTo: typeof sliceDimensionTo;
|
|
919
2388
|
|
|
920
2389
|
/**
|
|
921
|
-
*
|
|
2390
|
+
* Returns a shifted view of an input ndarray.
|
|
922
2391
|
*
|
|
923
|
-
*
|
|
2392
|
+
* @param x - input array
|
|
2393
|
+
* @param start - starting indices (inclusive)
|
|
2394
|
+
* @param strict - boolean indicating whether to enforce strict bounds checking
|
|
2395
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
2396
|
+
* @returns output array
|
|
924
2397
|
*
|
|
925
|
-
*
|
|
2398
|
+
* @example
|
|
2399
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2400
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
926
2401
|
*
|
|
927
|
-
*
|
|
2402
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2403
|
+
* var shape = [ 3, 2 ];
|
|
2404
|
+
* var strides = [ 2, 1 ];
|
|
2405
|
+
* var offset = 0;
|
|
928
2406
|
*
|
|
929
|
-
*
|
|
930
|
-
*
|
|
931
|
-
* ```
|
|
2407
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2408
|
+
* // returns <ndarray>
|
|
932
2409
|
*
|
|
933
|
-
*
|
|
2410
|
+
* var sh = x.shape;
|
|
2411
|
+
* // returns [ 3, 2 ]
|
|
934
2412
|
*
|
|
935
|
-
*
|
|
936
|
-
*
|
|
937
|
-
* <endianness>[int8],
|
|
938
|
-
* <dtype>[int16],
|
|
939
|
-
* <ndims>[int64],
|
|
940
|
-
* <shape>[ndims*int64],
|
|
941
|
-
* <strides>[ndims*int64],
|
|
942
|
-
* <offset>[int64],
|
|
943
|
-
* <order>[int8],
|
|
944
|
-
* <mode>[int8],
|
|
945
|
-
* <nsubmodes>[int64],
|
|
946
|
-
* <submodes>[nsubmodes*int8]
|
|
947
|
-
* ]
|
|
948
|
-
* ```
|
|
2413
|
+
* var arr = ndarray2array( x );
|
|
2414
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
949
2415
|
*
|
|
950
|
-
*
|
|
2416
|
+
* var s = [ 1, null ];
|
|
2417
|
+
* var y = ns.sliceFrom( x, s, false, false );
|
|
2418
|
+
* // returns <ndarray>
|
|
951
2419
|
*
|
|
952
|
-
*
|
|
2420
|
+
* sh = y.shape;
|
|
2421
|
+
* // returns [ 2, 2 ]
|
|
953
2422
|
*
|
|
954
|
-
*
|
|
2423
|
+
* arr = ndarray2array( y );
|
|
2424
|
+
* // returns [ [ 3, 4 ], [ 5, 6 ] ]
|
|
2425
|
+
*/
|
|
2426
|
+
sliceFrom: typeof sliceFrom;
|
|
2427
|
+
|
|
2428
|
+
/**
|
|
2429
|
+
* Returns a truncated view of an input ndarray.
|
|
955
2430
|
*
|
|
956
|
-
*
|
|
957
|
-
*
|
|
958
|
-
*
|
|
2431
|
+
* @param x - input array
|
|
2432
|
+
* @param stop - ending indices (exclusive)
|
|
2433
|
+
* @param strict - boolean indicating whether to enforce strict bounds checking
|
|
2434
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
2435
|
+
* @returns output array
|
|
959
2436
|
*
|
|
960
|
-
*
|
|
2437
|
+
* @example
|
|
2438
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2439
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
961
2440
|
*
|
|
962
|
-
*
|
|
963
|
-
*
|
|
964
|
-
*
|
|
2441
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2442
|
+
* var shape = [ 3, 2 ];
|
|
2443
|
+
* var strides = [ 2, 1 ];
|
|
2444
|
+
* var offset = 0;
|
|
965
2445
|
*
|
|
966
|
-
* -
|
|
2446
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2447
|
+
* // returns <ndarray>
|
|
967
2448
|
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
* - ndims: `Int64Array( buf, 3, 1 )`
|
|
971
|
-
* - shape: `Int64Array( buf, 11, ndims )`
|
|
972
|
-
* - strides: `Int64Array( buf, 11+(ndims*8), ndims )`
|
|
973
|
-
* - offset: `Int64Array( buf, 11+(ndims*16), 1 )`
|
|
974
|
-
* - order: `Int8Array( buf, 19+(ndims*16), 1 )`
|
|
975
|
-
* - mode: `Int8Array( buf, 20+(ndims*16), 1 )`
|
|
976
|
-
* - nsubmodes: `Int64Array( buf, 21+(ndims*16), 1 )`
|
|
977
|
-
* - submodes: `Int8Array( buf, 29+(ndims*16), nsubmodes )`
|
|
2449
|
+
* var sh = x.shape;
|
|
2450
|
+
* // returns [ 3, 2 ]
|
|
978
2451
|
*
|
|
979
|
-
*
|
|
980
|
-
*
|
|
2452
|
+
* var arr = ndarray2array( x );
|
|
2453
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
981
2454
|
*
|
|
982
|
-
*
|
|
983
|
-
* var
|
|
2455
|
+
* var s = [ 2, null ];
|
|
2456
|
+
* var y = ns.sliceTo( x, s, false, false );
|
|
2457
|
+
* // returns <ndarray>
|
|
984
2458
|
*
|
|
985
|
-
*
|
|
2459
|
+
* sh = y.shape;
|
|
2460
|
+
* // returns [ 2, 2 ]
|
|
986
2461
|
*
|
|
987
|
-
*
|
|
988
|
-
* // returns
|
|
2462
|
+
* arr = ndarray2array( y );
|
|
2463
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ] ]
|
|
989
2464
|
*/
|
|
990
|
-
|
|
2465
|
+
sliceTo: typeof sliceTo;
|
|
991
2466
|
|
|
992
2467
|
/**
|
|
993
|
-
*
|
|
2468
|
+
* Returns the stride along a specified dimension for a provided ndarray.
|
|
994
2469
|
*
|
|
995
|
-
*
|
|
996
|
-
*
|
|
997
|
-
*
|
|
2470
|
+
* ## Notes
|
|
2471
|
+
*
|
|
2472
|
+
* - A "stride" is the linear distance (i.e., number of elements) between adjacent elements along a specified dimension.
|
|
2473
|
+
*
|
|
2474
|
+
* @param x - input ndarray
|
|
2475
|
+
* @param dim - dimension index
|
|
2476
|
+
* @returns stride
|
|
998
2477
|
*
|
|
999
2478
|
* @example
|
|
1000
|
-
* var
|
|
1001
|
-
* // returns [ 2, 1 ]
|
|
2479
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
1002
2480
|
*
|
|
1003
|
-
*
|
|
1004
|
-
* // returns
|
|
2481
|
+
* var st = ns.stride( zeros( [ 3, 3, 3 ] ), 0 );
|
|
2482
|
+
* // returns 9
|
|
1005
2483
|
*/
|
|
1006
|
-
|
|
2484
|
+
stride: typeof stride;
|
|
1007
2485
|
|
|
1008
2486
|
/**
|
|
1009
|
-
* Returns the
|
|
2487
|
+
* Returns the strides of a provided ndarray.
|
|
1010
2488
|
*
|
|
1011
2489
|
* ## Notes
|
|
1012
2490
|
*
|
|
1013
|
-
* -
|
|
2491
|
+
* - When `copy` is `false`, changes to the returned strides array may mutate the input ndarray strides. If there is a chance that the returned strides will be mutated (either directly or by downstream consumers), set `copy` to `true` to prevent unintended side effects.
|
|
1014
2492
|
*
|
|
1015
|
-
* @param
|
|
1016
|
-
* @
|
|
2493
|
+
* @param x - input ndarray
|
|
2494
|
+
* @param copy - boolean indicating whether to explicitly copy the value assigned to the input ndarray's `strides` property
|
|
2495
|
+
* @returns strides
|
|
1017
2496
|
*
|
|
1018
2497
|
* @example
|
|
1019
|
-
* var
|
|
1020
|
-
* // returns 1
|
|
2498
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
1021
2499
|
*
|
|
1022
|
-
*
|
|
1023
|
-
*
|
|
1024
|
-
* // returns 0
|
|
2500
|
+
* var st = ns.strides( zeros( [ 3, 3, 3 ] ), false );
|
|
2501
|
+
* // returns [ 9, 3, 1 ]
|
|
1025
2502
|
*/
|
|
1026
|
-
|
|
2503
|
+
strides: typeof strides;
|
|
1027
2504
|
|
|
1028
2505
|
/**
|
|
1029
2506
|
* Returns the index offset which specifies the location of the first indexed value in a multidimensional array based on a stride array.
|
|
@@ -1072,9 +2549,10 @@ interface Namespace {
|
|
|
1072
2549
|
*
|
|
1073
2550
|
* - The function accepts the following "modes":
|
|
1074
2551
|
*
|
|
1075
|
-
* -
|
|
1076
|
-
* -
|
|
1077
|
-
* -
|
|
2552
|
+
* - **throw**: throw an error when a subscript exceeds array dimensions.
|
|
2553
|
+
* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.
|
|
2554
|
+
* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.
|
|
2555
|
+
* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.
|
|
1078
2556
|
*
|
|
1079
2557
|
* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.
|
|
1080
2558
|
*
|
|
@@ -1189,6 +2667,196 @@ interface Namespace {
|
|
|
1189
2667
|
*/
|
|
1190
2668
|
ndarray2array: typeof ndarray2array;
|
|
1191
2669
|
|
|
2670
|
+
/**
|
|
2671
|
+
* Transposes a matrix (or a stack of matrices).
|
|
2672
|
+
*
|
|
2673
|
+
* @param x - input array
|
|
2674
|
+
* @returns ndarray view
|
|
2675
|
+
*
|
|
2676
|
+
* @example
|
|
2677
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
2678
|
+
*
|
|
2679
|
+
* var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], {
|
|
2680
|
+
* 'dtype': 'generic'
|
|
2681
|
+
* });
|
|
2682
|
+
* // returns <ndarray>
|
|
2683
|
+
*
|
|
2684
|
+
* var sh = x.shape;
|
|
2685
|
+
* // returns [ 2, 3 ]
|
|
2686
|
+
*
|
|
2687
|
+
* var y = ns.transpose( x );
|
|
2688
|
+
* // returns <ndarray>
|
|
2689
|
+
*
|
|
2690
|
+
* sh = y.shape;
|
|
2691
|
+
* // returns [ 3, 2 ]
|
|
2692
|
+
*
|
|
2693
|
+
* var bool = ( x.get( 0, 1 ) === y.get( 1, 0 ) );
|
|
2694
|
+
* // returns true
|
|
2695
|
+
*
|
|
2696
|
+
* bool = ( x.data === y.data );
|
|
2697
|
+
* // returns true
|
|
2698
|
+
*/
|
|
2699
|
+
transpose: typeof transpose;
|
|
2700
|
+
|
|
2701
|
+
/**
|
|
2702
|
+
* Applies a unary callback to elements in an ndarray and assigns results to elements in an ndarray.
|
|
2703
|
+
*
|
|
2704
|
+
* @param arrays - array-like object containing one input ndarray and one output ndarray
|
|
2705
|
+
* @param fcn - unary callback
|
|
2706
|
+
* @throws arrays must have the same number of dimensions
|
|
2707
|
+
* @throws arrays must have the same shape
|
|
2708
|
+
*
|
|
2709
|
+
* @example
|
|
2710
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
2711
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2712
|
+
*
|
|
2713
|
+
* function scale( x ) {
|
|
2714
|
+
* return x * 10.0;
|
|
2715
|
+
* }
|
|
2716
|
+
*
|
|
2717
|
+
* // Create data buffers:
|
|
2718
|
+
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
|
|
2719
|
+
* var ybuf = new Float64Array( 6 );
|
|
2720
|
+
*
|
|
2721
|
+
* // Define the shape of the input and output arrays:
|
|
2722
|
+
* var shape = [ 3, 1, 2 ];
|
|
2723
|
+
*
|
|
2724
|
+
* // Define the array strides:
|
|
2725
|
+
* var sx = [ 4, 4, 1 ];
|
|
2726
|
+
* var sy = [ 2, 2, 1 ];
|
|
2727
|
+
*
|
|
2728
|
+
* // Define the index offsets:
|
|
2729
|
+
* var ox = 1;
|
|
2730
|
+
* var oy = 0;
|
|
2731
|
+
*
|
|
2732
|
+
* // Create the input and output ndarrays:
|
|
2733
|
+
* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );
|
|
2734
|
+
* var y = ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' );
|
|
2735
|
+
*
|
|
2736
|
+
* // Apply the ns.unary function:
|
|
2737
|
+
* ns.unary( [ x, y ], scale );
|
|
2738
|
+
*
|
|
2739
|
+
* console.log( y.data );
|
|
2740
|
+
* // => <Float64Array>[ 20.0, 30.0, 60.0, 70.0, 100.0, 110.0 ]
|
|
2741
|
+
*/
|
|
2742
|
+
unary: typeof unary;
|
|
2743
|
+
|
|
2744
|
+
/**
|
|
2745
|
+
* Applies a unary function to elements in an ndarray and assigns results to elements in an ndarray.
|
|
2746
|
+
*
|
|
2747
|
+
* @param arrays - array-like object containing one input ndarray and one output ndarray
|
|
2748
|
+
* @param fcn - unary function to apply to callback return values
|
|
2749
|
+
* @param clbk - callback function
|
|
2750
|
+
* @param thisArg - callback execution context
|
|
2751
|
+
* @throws arrays must have the same number of dimensions
|
|
2752
|
+
* @throws arrays must have the same shape
|
|
2753
|
+
*
|
|
2754
|
+
* @example
|
|
2755
|
+
* var identity = require( '@stdlib/math-base-special-identity' );
|
|
2756
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
2757
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2758
|
+
*
|
|
2759
|
+
* function scale( x ) {
|
|
2760
|
+
* return x * 10.0;
|
|
2761
|
+
* }
|
|
2762
|
+
*
|
|
2763
|
+
* // Create data buffers:
|
|
2764
|
+
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
|
|
2765
|
+
* var ybuf = new Float64Array( 6 );
|
|
2766
|
+
*
|
|
2767
|
+
* // Define the shape of the input and output arrays:
|
|
2768
|
+
* var shape = [ 3, 1, 2 ];
|
|
2769
|
+
*
|
|
2770
|
+
* // Define the array strides:
|
|
2771
|
+
* var sx = [ 4, 4, 1 ];
|
|
2772
|
+
* var sy = [ 2, 2, 1 ];
|
|
2773
|
+
*
|
|
2774
|
+
* // Define the index offsets:
|
|
2775
|
+
* var ox = 1;
|
|
2776
|
+
* var oy = 0;
|
|
2777
|
+
*
|
|
2778
|
+
* // Create the input and output ndarrays:
|
|
2779
|
+
* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );
|
|
2780
|
+
* var y = ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' );
|
|
2781
|
+
*
|
|
2782
|
+
* // Apply the unary function:
|
|
2783
|
+
* ns.unaryBy( [ x, y ], scale, identity );
|
|
2784
|
+
*
|
|
2785
|
+
* console.log( y.data );
|
|
2786
|
+
* // => <Float64Array>[ 20.0, 30.0, 60.0, 70.0, 100.0, 110.0 ]
|
|
2787
|
+
*/
|
|
2788
|
+
unaryBy: typeof unaryBy;
|
|
2789
|
+
|
|
2790
|
+
/**
|
|
2791
|
+
* Reorders ndarray dimensions and associated strides for loop interchange.
|
|
2792
|
+
*
|
|
2793
|
+
* ## Notes
|
|
2794
|
+
*
|
|
2795
|
+
* - The returned object has the following properties:
|
|
2796
|
+
*
|
|
2797
|
+
* - **sh**: dimensions sorted in loop order.
|
|
2798
|
+
* - **sx**: input ndarray strides sorted in loop order.
|
|
2799
|
+
* - **sy**: output ndarray strides sorted in loop order.
|
|
2800
|
+
*
|
|
2801
|
+
* - When iterating over the elements of a multi-dimensional array, accessing elements which are closer in memory can improve performance. To this end, loop interchange is a technique used in loop nest optimization to improve locality of reference and take advantage of CPU cache.
|
|
2802
|
+
*
|
|
2803
|
+
* The purpose of this function is to order ndarray dimensions according to the magnitude of **input array** strides. By using the ordered dimensions and associated strides, one can construct nested loops (one for each dimension) such that the innermost loop iterates over the dimension in which array elements are closest in memory and the outermost loop iterates over the dimension in which array elements are farthest apart in memory. As a consequence, element iteration is optimized to minimize cache misses and ensure locality of reference.
|
|
2804
|
+
*
|
|
2805
|
+
* - Cache performance may be degraded if the layout order (i.e., row-major or column-major) differs for the input and output ndarrays. This function is intended to optimize cache performance for the input ndarray. If the output ndarray has a different layout order (e.g., if the input ndarray is row-major and the output ndarray is column-major), cache misses are likely for the output ndarray. In general, to ensure best performance, input and output ndarrays should have the same layout order.
|
|
2806
|
+
*
|
|
2807
|
+
* - The function assumes that the input and output ndarrays have the same shape. Hence, loop interchange order should only be determined **after** broadcasting.
|
|
2808
|
+
*
|
|
2809
|
+
* @param sh - array dimensions
|
|
2810
|
+
* @param sx - input array stride lengths
|
|
2811
|
+
* @param sy - output array stride lengths
|
|
2812
|
+
* @returns loop interchange data
|
|
2813
|
+
*
|
|
2814
|
+
* @example
|
|
2815
|
+
* var sh = [ 2, 3, 4 ];
|
|
2816
|
+
*
|
|
2817
|
+
* var sx = [ 12, 4, 1 ]; // row-major
|
|
2818
|
+
* var sy = [ 1, -2, 6 ]; // column-major
|
|
2819
|
+
*
|
|
2820
|
+
* var o = ns.unaryLoopOrder( sh, sx, sy );
|
|
2821
|
+
* // returns {...}
|
|
2822
|
+
*
|
|
2823
|
+
* var ssh = o.sh;
|
|
2824
|
+
* // returns [ 4, 3, 2 ]
|
|
2825
|
+
*
|
|
2826
|
+
* var ssx = o.sx;
|
|
2827
|
+
* // returns [ 1, 4, 12 ]
|
|
2828
|
+
*
|
|
2829
|
+
* var ssy = o.sy;
|
|
2830
|
+
* // returns [ 6, -2, 1 ]
|
|
2831
|
+
*/
|
|
2832
|
+
unaryLoopOrder: typeof unaryLoopOrder;
|
|
2833
|
+
|
|
2834
|
+
/**
|
|
2835
|
+
* Resolves the output ndarray data type for a unary function.
|
|
2836
|
+
*
|
|
2837
|
+
* @param dtype - input ndarray data type
|
|
2838
|
+
* @param policy - output ndarray data type policy
|
|
2839
|
+
* @returns output ndarray data type
|
|
2840
|
+
*
|
|
2841
|
+
* @example
|
|
2842
|
+
* var dt = ns.unaryOutputDataType( 'float64', 'complex_floating_point' );
|
|
2843
|
+
* // returns <string>
|
|
2844
|
+
*/
|
|
2845
|
+
unaryOutputDataType: typeof unaryOutputDataType;
|
|
2846
|
+
|
|
2847
|
+
/**
|
|
2848
|
+
* Returns a loop block size for multi-dimensional array tiled loops.
|
|
2849
|
+
*
|
|
2850
|
+
* @param dtypeX - input array data type
|
|
2851
|
+
* @param dtypeY - output array data type
|
|
2852
|
+
* @returns block size (in units of elements)
|
|
2853
|
+
*
|
|
2854
|
+
* @example
|
|
2855
|
+
* var bsize = ns.unaryBlockSize( 'float64', 'float64' );
|
|
2856
|
+
* // returns <number>
|
|
2857
|
+
*/
|
|
2858
|
+
unaryBlockSize: typeof unaryBlockSize;
|
|
2859
|
+
|
|
1192
2860
|
/**
|
|
1193
2861
|
* Converts a linear index in an array view to a linear index in an underlying data buffer.
|
|
1194
2862
|
*
|
|
@@ -1231,6 +2899,55 @@ interface Namespace {
|
|
|
1231
2899
|
* // returns 6
|
|
1232
2900
|
*/
|
|
1233
2901
|
wrapIndex: typeof wrapIndex;
|
|
2902
|
+
|
|
2903
|
+
/**
|
|
2904
|
+
* Creates a zero-filled array having a specified shape and data type.
|
|
2905
|
+
*
|
|
2906
|
+
* @param dtype - underlying data type
|
|
2907
|
+
* @param shape - array shape
|
|
2908
|
+
* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style)
|
|
2909
|
+
* @returns zero-filled array
|
|
2910
|
+
*
|
|
2911
|
+
* @example
|
|
2912
|
+
* var arr = ns.zeros( 'float32', [ 2, 2 ], 'row-major' );
|
|
2913
|
+
* // returns <ndarray>
|
|
2914
|
+
*
|
|
2915
|
+
* var sh = arr.shape;
|
|
2916
|
+
* // returns [ 2, 2 ]
|
|
2917
|
+
*
|
|
2918
|
+
* var dt = arr.dtype;
|
|
2919
|
+
* // returns 'float32'
|
|
2920
|
+
*/
|
|
2921
|
+
zeros: typeof zeros;
|
|
2922
|
+
|
|
2923
|
+
/**
|
|
2924
|
+
* Creates a zero-filled array having the same shape and data type as a provided input ndarray.
|
|
2925
|
+
*
|
|
2926
|
+
* @param x - input array
|
|
2927
|
+
* @returns zero-filled array
|
|
2928
|
+
*
|
|
2929
|
+
* @example
|
|
2930
|
+
* var zeros = require( '@stdlib/ndarray-base-zeros' );
|
|
2931
|
+
*
|
|
2932
|
+
* var x = zeros( 'generic', [ 2, 2 ], 'row-major' );
|
|
2933
|
+
* // returns <ndarray>
|
|
2934
|
+
*
|
|
2935
|
+
* var sh = x.shape;
|
|
2936
|
+
* // returns [ 2, 2 ]
|
|
2937
|
+
*
|
|
2938
|
+
* var dt = x.dtype;
|
|
2939
|
+
* // returns 'generic'
|
|
2940
|
+
*
|
|
2941
|
+
* var y = ns.zerosLike( x );
|
|
2942
|
+
* // returns <ndarray>
|
|
2943
|
+
*
|
|
2944
|
+
* sh = y.shape;
|
|
2945
|
+
* // returns [ 2, 2 ]
|
|
2946
|
+
*
|
|
2947
|
+
* dt = y.dtype;
|
|
2948
|
+
* // returns 'generic'
|
|
2949
|
+
*/
|
|
2950
|
+
zerosLike: typeof zerosLike;
|
|
1234
2951
|
}
|
|
1235
2952
|
|
|
1236
2953
|
/**
|