@stdlib/ndarray-base 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +87 -3
- package/SECURITY.md +5 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/docs/types/index.d.ts +1007 -53
- package/lib/index.js +243 -0
- package/package.json +96 -233
- package/CITATION.cff +0 -30
package/docs/types/index.d.ts
CHANGED
|
@@ -18,14 +18,15 @@
|
|
|
18
18
|
|
|
19
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
25
|
import binaryLoopOrder = require( '@stdlib/ndarray-base-binary-loop-interchange-order' );
|
|
26
26
|
import binaryBlockSize = require( '@stdlib/ndarray-base-binary-tiling-block-size' );
|
|
27
27
|
import bind2vind = require( '@stdlib/ndarray-base-bind2vind' );
|
|
28
28
|
import broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' );
|
|
29
|
+
import broadcastArrays = require( '@stdlib/ndarray-base-broadcast-arrays' );
|
|
29
30
|
import broadcastScalar = require( '@stdlib/ndarray-base-broadcast-scalar' );
|
|
30
31
|
import broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );
|
|
31
32
|
import buffer = require( '@stdlib/ndarray-base-buffer' );
|
|
@@ -36,6 +37,8 @@ import bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );
|
|
|
36
37
|
import char2dtype = require( '@stdlib/ndarray-base-char2dtype' );
|
|
37
38
|
import clampIndex = require( '@stdlib/ndarray-base-clamp-index' );
|
|
38
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' );
|
|
39
42
|
import dtypeChar = require( '@stdlib/ndarray-base-dtype-char' );
|
|
40
43
|
import dtypeDesc = require( '@stdlib/ndarray-base-dtype-desc' );
|
|
41
44
|
import dtypeEnum2Str = require( '@stdlib/ndarray-base-dtype-enum2str' );
|
|
@@ -47,30 +50,53 @@ import dtypes2signatures = require( '@stdlib/ndarray-base-dtypes2signatures' );
|
|
|
47
50
|
import empty = require( '@stdlib/ndarray-base-empty' );
|
|
48
51
|
import emptyLike = require( '@stdlib/ndarray-base-empty-like' );
|
|
49
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' );
|
|
50
57
|
import scalar2ndarray = require( '@stdlib/ndarray-base-from-scalar' );
|
|
51
58
|
import ind = require( '@stdlib/ndarray-base-ind' );
|
|
52
59
|
import ind2sub = require( '@stdlib/ndarray-base-ind2sub' );
|
|
53
60
|
import iterationOrder = require( '@stdlib/ndarray-base-iteration-order' );
|
|
54
61
|
import maxViewBufferIndex = require( '@stdlib/ndarray-base-max-view-buffer-index' );
|
|
55
62
|
import maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );
|
|
63
|
+
import maybeBroadcastArrays = require( '@stdlib/ndarray-base-maybe-broadcast-arrays' );
|
|
56
64
|
import metaDataProps = require( '@stdlib/ndarray-base-meta-data-props' );
|
|
57
65
|
import minViewBufferIndex = require( '@stdlib/ndarray-base-min-view-buffer-index' );
|
|
58
66
|
import minmaxViewBufferIndex = require( '@stdlib/ndarray-base-minmax-view-buffer-index' );
|
|
59
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' );
|
|
60
70
|
import nonsingletonDimensions = require( '@stdlib/ndarray-base-nonsingleton-dimensions' );
|
|
71
|
+
import normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );
|
|
61
72
|
import nullary = require( '@stdlib/ndarray-base-nullary' );
|
|
62
73
|
import nullaryLoopOrder = require( '@stdlib/ndarray-base-nullary-loop-interchange-order' );
|
|
63
74
|
import nullaryBlockSize = require( '@stdlib/ndarray-base-nullary-tiling-block-size' );
|
|
64
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' );
|
|
65
79
|
import outputPolicyEnum2Str = require( '@stdlib/ndarray-base-output-policy-enum2str' );
|
|
66
80
|
import outputPolicyResolveEnum = require( '@stdlib/ndarray-base-output-policy-resolve-enum' );
|
|
67
81
|
import outputPolicyResolveStr = require( '@stdlib/ndarray-base-output-policy-resolve-str' );
|
|
68
82
|
import outputPolicyStr2Enum = require( '@stdlib/ndarray-base-output-policy-str2enum' );
|
|
69
83
|
import prependSingletonDimensions = require( '@stdlib/ndarray-base-prepend-singleton-dimensions' );
|
|
70
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' );
|
|
71
87
|
import serializeMetaData = require( '@stdlib/ndarray-base-serialize-meta-data' );
|
|
88
|
+
import shape = require( '@stdlib/ndarray-base-shape' );
|
|
72
89
|
import shape2strides = require( '@stdlib/ndarray-base-shape2strides' );
|
|
73
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' );
|
|
74
100
|
import strides2offset = require( '@stdlib/ndarray-base-strides2offset' );
|
|
75
101
|
import strides2order = require( '@stdlib/ndarray-base-strides2order' );
|
|
76
102
|
import sub2ind = require( '@stdlib/ndarray-base-sub2ind' );
|
|
@@ -95,6 +121,44 @@ interface Namespace {
|
|
|
95
121
|
*/
|
|
96
122
|
assert: typeof assert;
|
|
97
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
|
+
|
|
98
162
|
/**
|
|
99
163
|
* Reorders ndarray dimensions and associated strides for loop interchange.
|
|
100
164
|
*
|
|
@@ -200,7 +264,7 @@ interface Namespace {
|
|
|
200
264
|
* @returns broadcasted array
|
|
201
265
|
*
|
|
202
266
|
* @example
|
|
203
|
-
* var array = require(
|
|
267
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
204
268
|
*
|
|
205
269
|
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
206
270
|
* // returns <ndarray>
|
|
@@ -234,6 +298,83 @@ interface Namespace {
|
|
|
234
298
|
*/
|
|
235
299
|
broadcastArray: typeof broadcastArray;
|
|
236
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
|
+
|
|
237
378
|
/**
|
|
238
379
|
* Broadcasts a scalar value to an ndarray having a specified shape.
|
|
239
380
|
*
|
|
@@ -458,7 +599,7 @@ interface Namespace {
|
|
|
458
599
|
* @returns data type enumeration constant or null
|
|
459
600
|
*
|
|
460
601
|
* @example
|
|
461
|
-
* var Float64Array = require(
|
|
602
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
462
603
|
*
|
|
463
604
|
* var x = new Float64Array( 10 );
|
|
464
605
|
*
|
|
@@ -546,6 +687,42 @@ interface Namespace {
|
|
|
546
687
|
*/
|
|
547
688
|
ndarray: typeof ndarray;
|
|
548
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
|
+
|
|
549
726
|
/**
|
|
550
727
|
* Returns an object mapping data type strings to single letter character abbreviations.
|
|
551
728
|
*
|
|
@@ -575,7 +752,7 @@ interface Namespace {
|
|
|
575
752
|
* @returns data type string
|
|
576
753
|
*
|
|
577
754
|
* @example
|
|
578
|
-
* var str2enum = require(
|
|
755
|
+
* var str2enum = require( '@stdlib/ndarray-base-dtype-str2enum' );
|
|
579
756
|
*
|
|
580
757
|
* var v = str2enum( 'float64' );
|
|
581
758
|
* // returns <number>
|
|
@@ -608,7 +785,7 @@ interface Namespace {
|
|
|
608
785
|
* @returns data type string
|
|
609
786
|
*
|
|
610
787
|
* @example
|
|
611
|
-
* var str2enum = require(
|
|
788
|
+
* var str2enum = require( '@stdlib/ndarray-base-dtype-str2enum' );
|
|
612
789
|
*
|
|
613
790
|
* var v = ns.dtypeResolveStr( str2enum( 'float64' ) );
|
|
614
791
|
* // returns 'float64'
|
|
@@ -697,7 +874,7 @@ interface Namespace {
|
|
|
697
874
|
* @returns output array
|
|
698
875
|
*
|
|
699
876
|
* @example
|
|
700
|
-
* var zeros = require(
|
|
877
|
+
* var zeros = require( '@stdlib/ndarray-base-zeros' );
|
|
701
878
|
*
|
|
702
879
|
* var x = zeros( 'generic', [ 2, 2 ], 'row-major' );
|
|
703
880
|
* // returns <ndarray>
|
|
@@ -731,7 +908,7 @@ interface Namespace {
|
|
|
731
908
|
* @returns output array
|
|
732
909
|
*
|
|
733
910
|
* @example
|
|
734
|
-
* var array = require(
|
|
911
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
735
912
|
*
|
|
736
913
|
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
737
914
|
* // returns <ndarray>
|
|
@@ -759,6 +936,114 @@ interface Namespace {
|
|
|
759
936
|
*/
|
|
760
937
|
expandDimensions: typeof expandDimensions;
|
|
761
938
|
|
|
939
|
+
/**
|
|
940
|
+
* Returns a specified flag for a provided ndarray.
|
|
941
|
+
*
|
|
942
|
+
* @param x - input ndarray
|
|
943
|
+
* @param name - flag name
|
|
944
|
+
* @returns flag value
|
|
945
|
+
*
|
|
946
|
+
* @example
|
|
947
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
948
|
+
*
|
|
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.
|
|
956
|
+
*
|
|
957
|
+
* ## Notes
|
|
958
|
+
*
|
|
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.
|
|
960
|
+
*
|
|
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
|
|
964
|
+
*
|
|
965
|
+
* @example
|
|
966
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
967
|
+
*
|
|
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.
|
|
975
|
+
*
|
|
976
|
+
* @param x - input array
|
|
977
|
+
* @param writable - boolean indicating whether a returned array should be writable
|
|
978
|
+
* @returns output array
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* var typedarray = require( '@stdlib/array-typed' );
|
|
982
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
983
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
984
|
+
*
|
|
985
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
986
|
+
* var shape = [ 3, 2 ];
|
|
987
|
+
* var strides = [ 2, 1 ];
|
|
988
|
+
* var offset = 0;
|
|
989
|
+
*
|
|
990
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
991
|
+
* // returns <ndarray>
|
|
992
|
+
*
|
|
993
|
+
* var sh = x.shape;
|
|
994
|
+
* // returns [ 3, 2 ]
|
|
995
|
+
*
|
|
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
|
+
|
|
762
1047
|
/**
|
|
763
1048
|
* Returns a zero-dimensional ndarray containing a provided scalar value.
|
|
764
1049
|
*
|
|
@@ -788,7 +1073,6 @@ interface Namespace {
|
|
|
788
1073
|
* @param idx - index
|
|
789
1074
|
* @param max - maximum index
|
|
790
1075
|
* @param mode - specifies how to handle an index outside the interval `[0,max]`
|
|
791
|
-
* @throws index out-of-bounds
|
|
792
1076
|
* @returns index
|
|
793
1077
|
*
|
|
794
1078
|
* @example
|
|
@@ -820,6 +1104,28 @@ interface Namespace {
|
|
|
820
1104
|
*
|
|
821
1105
|
* idx = ns.ind( -1, 9, 'throw' );
|
|
822
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
|
|
823
1129
|
*/
|
|
824
1130
|
ind: typeof ind;
|
|
825
1131
|
|
|
@@ -830,9 +1136,10 @@ interface Namespace {
|
|
|
830
1136
|
*
|
|
831
1137
|
* - The function accepts the following "modes":
|
|
832
1138
|
*
|
|
833
|
-
* -
|
|
834
|
-
* -
|
|
835
|
-
* -
|
|
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.
|
|
836
1143
|
*
|
|
837
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.
|
|
838
1145
|
*
|
|
@@ -1011,7 +1318,7 @@ interface Namespace {
|
|
|
1011
1318
|
* @returns broadcasted array
|
|
1012
1319
|
*
|
|
1013
1320
|
* @example
|
|
1014
|
-
* var array = require(
|
|
1321
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1015
1322
|
*
|
|
1016
1323
|
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
1017
1324
|
* // returns <ndarray>
|
|
@@ -1045,6 +1352,71 @@ interface Namespace {
|
|
|
1045
1352
|
*/
|
|
1046
1353
|
maybeBroadcastArray: typeof maybeBroadcastArray;
|
|
1047
1354
|
|
|
1355
|
+
/**
|
|
1356
|
+
* Broadcasts ndarrays to a common shape.
|
|
1357
|
+
*
|
|
1358
|
+
* ## Notes
|
|
1359
|
+
*
|
|
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.
|
|
1364
|
+
*
|
|
1365
|
+
* @param arrays - input arrays
|
|
1366
|
+
* @throws input arrays must be broadcast compatible
|
|
1367
|
+
* @returns list of broadcasted arrays
|
|
1368
|
+
*
|
|
1369
|
+
* @example
|
|
1370
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1371
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
1372
|
+
*
|
|
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
|
+
|
|
1048
1420
|
/**
|
|
1049
1421
|
* Defines non-enumerable read-only properties which expose ndarray function meta data.
|
|
1050
1422
|
*
|
|
@@ -1174,7 +1546,7 @@ interface Namespace {
|
|
|
1174
1546
|
* @returns object containing ndarray data
|
|
1175
1547
|
*
|
|
1176
1548
|
* @example
|
|
1177
|
-
* var array = require(
|
|
1549
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1178
1550
|
*
|
|
1179
1551
|
* var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
|
|
1180
1552
|
*
|
|
@@ -1184,44 +1556,138 @@ interface Namespace {
|
|
|
1184
1556
|
ndarraylike2object: typeof ndarraylike2object;
|
|
1185
1557
|
|
|
1186
1558
|
/**
|
|
1187
|
-
* Returns the number of
|
|
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).
|
|
1188
1574
|
*
|
|
1189
1575
|
* ## Notes
|
|
1190
1576
|
*
|
|
1191
|
-
* -
|
|
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`.
|
|
1192
1579
|
*
|
|
1193
1580
|
* @param shape - array shape
|
|
1194
|
-
* @
|
|
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
|
|
1195
1585
|
*
|
|
1196
1586
|
* @example
|
|
1197
|
-
* var
|
|
1198
|
-
*
|
|
1587
|
+
* var shape = [ 12 ];
|
|
1588
|
+
* var idx = ns.nextCartesianIndex( shape, 'row-major', [ 2 ], 0 );
|
|
1589
|
+
* // returns [ 3 ]
|
|
1199
1590
|
*
|
|
1200
1591
|
* @example
|
|
1201
|
-
* var
|
|
1202
|
-
* // returns 0
|
|
1203
|
-
*/
|
|
1204
|
-
nonsingletonDimensions: typeof nonsingletonDimensions;
|
|
1205
|
-
|
|
1206
|
-
/**
|
|
1207
|
-
* Applies a nullary callback and assigns results to elements in an output ndarray.
|
|
1592
|
+
* var shape = [ 2, 2, 2 ];
|
|
1208
1593
|
*
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1594
|
+
* var idx = ns.nextCartesianIndex( shape, 'row-major', [ 0, 0, 1 ], -1 );
|
|
1595
|
+
* // returns [ 0, 1, 0 ]
|
|
1211
1596
|
*
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
* var ndarray = require( `@stdlib/ndarray/ctor` );
|
|
1597
|
+
* idx = ns.nextCartesianIndex( shape, 'row-major', idx, -1 );
|
|
1598
|
+
* // returns [ 0, 1, 1 ]
|
|
1215
1599
|
*
|
|
1216
|
-
*
|
|
1217
|
-
*
|
|
1218
|
-
* }
|
|
1600
|
+
* idx = ns.nextCartesianIndex( shape, 'row-major', idx, -1 );
|
|
1601
|
+
* // returns [ 1, 0, 0 ]
|
|
1219
1602
|
*
|
|
1220
|
-
*
|
|
1221
|
-
*
|
|
1603
|
+
* idx = ns.nextCartesianIndex( shape, 'row-major', idx, -1 );
|
|
1604
|
+
* // returns [ 1, 0, 1 ]
|
|
1222
1605
|
*
|
|
1223
|
-
*
|
|
1224
|
-
*
|
|
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 ];
|
|
1225
1691
|
*
|
|
1226
1692
|
* // Define the array strides:
|
|
1227
1693
|
* var sx = [ 4, 4, 1 ];
|
|
@@ -1249,6 +1715,7 @@ interface Namespace {
|
|
|
1249
1715
|
*
|
|
1250
1716
|
* - **sh**: dimensions sorted in loop order.
|
|
1251
1717
|
* - **sx**: ndarray strides sorted in loop order.
|
|
1718
|
+
* - **idx**: dimension indices sorted in loop order.
|
|
1252
1719
|
*
|
|
1253
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.
|
|
1254
1721
|
*
|
|
@@ -1271,6 +1738,9 @@ interface Namespace {
|
|
|
1271
1738
|
*
|
|
1272
1739
|
* var ssx = o.sx;
|
|
1273
1740
|
* // returns [ 1, 4, 12 ]
|
|
1741
|
+
*
|
|
1742
|
+
* var idx = o.idx;
|
|
1743
|
+
* // returns [ 2, 1, 0 ]
|
|
1274
1744
|
*/
|
|
1275
1745
|
nullaryLoopOrder: typeof nullaryLoopOrder;
|
|
1276
1746
|
|
|
@@ -1298,6 +1768,57 @@ interface Namespace {
|
|
|
1298
1768
|
*/
|
|
1299
1769
|
numel: typeof numel;
|
|
1300
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
|
+
|
|
1301
1822
|
/**
|
|
1302
1823
|
* Returns the policy string associated with an output ndarray data type policy enumeration constant.
|
|
1303
1824
|
*
|
|
@@ -1305,7 +1826,7 @@ interface Namespace {
|
|
|
1305
1826
|
* @returns policy string
|
|
1306
1827
|
*
|
|
1307
1828
|
* @example
|
|
1308
|
-
* var str2enum = require(
|
|
1829
|
+
* var str2enum = require( '@stdlib/ndarray-base-output-policy-str2enum' );
|
|
1309
1830
|
*
|
|
1310
1831
|
* var v = str2enum( 'same' );
|
|
1311
1832
|
* // returns <number>
|
|
@@ -1338,7 +1859,7 @@ interface Namespace {
|
|
|
1338
1859
|
* @returns policy string
|
|
1339
1860
|
*
|
|
1340
1861
|
* @example
|
|
1341
|
-
* var str2enum = require(
|
|
1862
|
+
* var str2enum = require( '@stdlib/ndarray-base-output-policy-str2enum' );
|
|
1342
1863
|
*
|
|
1343
1864
|
* var v = ns.outputPolicyResolveStr( str2enum( 'same' ) );
|
|
1344
1865
|
* // returns 'same'
|
|
@@ -1369,7 +1890,7 @@ interface Namespace {
|
|
|
1369
1890
|
* @returns output array
|
|
1370
1891
|
*
|
|
1371
1892
|
* @example
|
|
1372
|
-
* var array = require(
|
|
1893
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1373
1894
|
*
|
|
1374
1895
|
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
1375
1896
|
* // returns <ndarray>
|
|
@@ -1409,7 +1930,7 @@ interface Namespace {
|
|
|
1409
1930
|
* @returns squeezed array
|
|
1410
1931
|
*
|
|
1411
1932
|
* @example
|
|
1412
|
-
* var array = require(
|
|
1933
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1413
1934
|
*
|
|
1414
1935
|
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ], {
|
|
1415
1936
|
* 'ndmin': 5
|
|
@@ -1439,6 +1960,81 @@ interface Namespace {
|
|
|
1439
1960
|
*/
|
|
1440
1961
|
removeSingletonDimensions: typeof removeSingletonDimensions;
|
|
1441
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
|
+
|
|
1442
2038
|
/**
|
|
1443
2039
|
* Serializes ndarray meta data.
|
|
1444
2040
|
*
|
|
@@ -1504,7 +2100,7 @@ interface Namespace {
|
|
|
1504
2100
|
* @returns serialized meta data
|
|
1505
2101
|
*
|
|
1506
2102
|
* @example
|
|
1507
|
-
* var array = require(
|
|
2103
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1508
2104
|
*
|
|
1509
2105
|
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
|
|
1510
2106
|
*
|
|
@@ -1513,6 +2109,25 @@ interface Namespace {
|
|
|
1513
2109
|
*/
|
|
1514
2110
|
serializeMetaData: typeof serializeMetaData;
|
|
1515
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
|
+
|
|
1516
2131
|
/**
|
|
1517
2132
|
* Generates a stride array from an array shape.
|
|
1518
2133
|
*
|
|
@@ -1549,6 +2164,344 @@ interface Namespace {
|
|
|
1549
2164
|
*/
|
|
1550
2165
|
singletonDimensions: typeof singletonDimensions;
|
|
1551
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>
|
|
2301
|
+
*
|
|
2302
|
+
* var y = ns.sliceDimension( x, 0, s, false, false );
|
|
2303
|
+
* // returns <ndarray>
|
|
2304
|
+
*
|
|
2305
|
+
* sh = y.shape;
|
|
2306
|
+
* // returns [ 3, 2 ]
|
|
2307
|
+
*
|
|
2308
|
+
* arr = ndarray2array( y );
|
|
2309
|
+
* // returns [ [ 5, 6 ], [ 3, 4 ], [ 1, 2 ] ]
|
|
2310
|
+
*/
|
|
2311
|
+
sliceDimension: typeof sliceDimension;
|
|
2312
|
+
|
|
2313
|
+
/**
|
|
2314
|
+
* Returns a shifted view of an input ndarray along a specified dimension.
|
|
2315
|
+
*
|
|
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
|
|
2321
|
+
*
|
|
2322
|
+
* @example
|
|
2323
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2324
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
2325
|
+
*
|
|
2326
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2327
|
+
* var shape = [ 3, 2 ];
|
|
2328
|
+
* var strides = [ 2, 1 ];
|
|
2329
|
+
* var offset = 0;
|
|
2330
|
+
*
|
|
2331
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2332
|
+
* // returns <ndarray>
|
|
2333
|
+
*
|
|
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 ] ]
|
|
2348
|
+
*/
|
|
2349
|
+
sliceDimensionFrom: typeof sliceDimensionFrom;
|
|
2350
|
+
|
|
2351
|
+
/**
|
|
2352
|
+
* Returns a truncated view of an input ndarray along a specified dimension.
|
|
2353
|
+
*
|
|
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
|
|
2359
|
+
*
|
|
2360
|
+
* @example
|
|
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 ] ]
|
|
2386
|
+
*/
|
|
2387
|
+
sliceDimensionTo: typeof sliceDimensionTo;
|
|
2388
|
+
|
|
2389
|
+
/**
|
|
2390
|
+
* Returns a shifted view of an input ndarray.
|
|
2391
|
+
*
|
|
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
|
|
2397
|
+
*
|
|
2398
|
+
* @example
|
|
2399
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2400
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
2401
|
+
*
|
|
2402
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2403
|
+
* var shape = [ 3, 2 ];
|
|
2404
|
+
* var strides = [ 2, 1 ];
|
|
2405
|
+
* var offset = 0;
|
|
2406
|
+
*
|
|
2407
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2408
|
+
* // returns <ndarray>
|
|
2409
|
+
*
|
|
2410
|
+
* var sh = x.shape;
|
|
2411
|
+
* // returns [ 3, 2 ]
|
|
2412
|
+
*
|
|
2413
|
+
* var arr = ndarray2array( x );
|
|
2414
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
2415
|
+
*
|
|
2416
|
+
* var s = [ 1, null ];
|
|
2417
|
+
* var y = ns.sliceFrom( x, s, false, false );
|
|
2418
|
+
* // returns <ndarray>
|
|
2419
|
+
*
|
|
2420
|
+
* sh = y.shape;
|
|
2421
|
+
* // returns [ 2, 2 ]
|
|
2422
|
+
*
|
|
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.
|
|
2430
|
+
*
|
|
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
|
|
2436
|
+
*
|
|
2437
|
+
* @example
|
|
2438
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
2439
|
+
* var ndarray2array = require( '@stdlib/ndarray-to-array' );
|
|
2440
|
+
*
|
|
2441
|
+
* var buffer = [ 1, 2, 3, 4, 5, 6 ];
|
|
2442
|
+
* var shape = [ 3, 2 ];
|
|
2443
|
+
* var strides = [ 2, 1 ];
|
|
2444
|
+
* var offset = 0;
|
|
2445
|
+
*
|
|
2446
|
+
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
|
|
2447
|
+
* // returns <ndarray>
|
|
2448
|
+
*
|
|
2449
|
+
* var sh = x.shape;
|
|
2450
|
+
* // returns [ 3, 2 ]
|
|
2451
|
+
*
|
|
2452
|
+
* var arr = ndarray2array( x );
|
|
2453
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
|
|
2454
|
+
*
|
|
2455
|
+
* var s = [ 2, null ];
|
|
2456
|
+
* var y = ns.sliceTo( x, s, false, false );
|
|
2457
|
+
* // returns <ndarray>
|
|
2458
|
+
*
|
|
2459
|
+
* sh = y.shape;
|
|
2460
|
+
* // returns [ 2, 2 ]
|
|
2461
|
+
*
|
|
2462
|
+
* arr = ndarray2array( y );
|
|
2463
|
+
* // returns [ [ 1, 2 ], [ 3, 4 ] ]
|
|
2464
|
+
*/
|
|
2465
|
+
sliceTo: typeof sliceTo;
|
|
2466
|
+
|
|
2467
|
+
/**
|
|
2468
|
+
* Returns the stride along a specified dimension for a provided ndarray.
|
|
2469
|
+
*
|
|
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
|
|
2477
|
+
*
|
|
2478
|
+
* @example
|
|
2479
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
2480
|
+
*
|
|
2481
|
+
* var st = ns.stride( zeros( [ 3, 3, 3 ] ), 0 );
|
|
2482
|
+
* // returns 9
|
|
2483
|
+
*/
|
|
2484
|
+
stride: typeof stride;
|
|
2485
|
+
|
|
2486
|
+
/**
|
|
2487
|
+
* Returns the strides of a provided ndarray.
|
|
2488
|
+
*
|
|
2489
|
+
* ## Notes
|
|
2490
|
+
*
|
|
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.
|
|
2492
|
+
*
|
|
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
|
|
2496
|
+
*
|
|
2497
|
+
* @example
|
|
2498
|
+
* var zeros = require( '@stdlib/ndarray-zeros' );
|
|
2499
|
+
*
|
|
2500
|
+
* var st = ns.strides( zeros( [ 3, 3, 3 ] ), false );
|
|
2501
|
+
* // returns [ 9, 3, 1 ]
|
|
2502
|
+
*/
|
|
2503
|
+
strides: typeof strides;
|
|
2504
|
+
|
|
1552
2505
|
/**
|
|
1553
2506
|
* Returns the index offset which specifies the location of the first indexed value in a multidimensional array based on a stride array.
|
|
1554
2507
|
*
|
|
@@ -1596,9 +2549,10 @@ interface Namespace {
|
|
|
1596
2549
|
*
|
|
1597
2550
|
* - The function accepts the following "modes":
|
|
1598
2551
|
*
|
|
1599
|
-
* -
|
|
1600
|
-
* -
|
|
1601
|
-
* -
|
|
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.
|
|
1602
2556
|
*
|
|
1603
2557
|
* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.
|
|
1604
2558
|
*
|
|
@@ -1720,7 +2674,7 @@ interface Namespace {
|
|
|
1720
2674
|
* @returns ndarray view
|
|
1721
2675
|
*
|
|
1722
2676
|
* @example
|
|
1723
|
-
* var array = require(
|
|
2677
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
1724
2678
|
*
|
|
1725
2679
|
* var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], {
|
|
1726
2680
|
* 'dtype': 'generic'
|
|
@@ -1753,8 +2707,8 @@ interface Namespace {
|
|
|
1753
2707
|
* @throws arrays must have the same shape
|
|
1754
2708
|
*
|
|
1755
2709
|
* @example
|
|
1756
|
-
* var Float64Array = require(
|
|
1757
|
-
* var ndarray = require(
|
|
2710
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
2711
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
1758
2712
|
*
|
|
1759
2713
|
* function scale( x ) {
|
|
1760
2714
|
* return x * 10.0;
|
|
@@ -1798,9 +2752,9 @@ interface Namespace {
|
|
|
1798
2752
|
* @throws arrays must have the same shape
|
|
1799
2753
|
*
|
|
1800
2754
|
* @example
|
|
1801
|
-
* var identity = require(
|
|
1802
|
-
* var Float64Array = require(
|
|
1803
|
-
* var ndarray = require(
|
|
2755
|
+
* var identity = require( '@stdlib/math-base-special-identity' );
|
|
2756
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
2757
|
+
* var ndarray = require( '@stdlib/ndarray-ctor' );
|
|
1804
2758
|
*
|
|
1805
2759
|
* function scale( x ) {
|
|
1806
2760
|
* return x * 10.0;
|
|
@@ -1973,7 +2927,7 @@ interface Namespace {
|
|
|
1973
2927
|
* @returns zero-filled array
|
|
1974
2928
|
*
|
|
1975
2929
|
* @example
|
|
1976
|
-
* var zeros = require(
|
|
2930
|
+
* var zeros = require( '@stdlib/ndarray-base-zeros' );
|
|
1977
2931
|
*
|
|
1978
2932
|
* var x = zeros( 'generic', [ 2, 2 ], 'row-major' );
|
|
1979
2933
|
* // returns <ndarray>
|