@stdlib/ndarray-base-to-array 0.0.6 → 0.0.7
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 +23 -4
- package/lib/main.js +2 -1
- package/lib/recurse.js +6 -4
- package/package.json +5 -1
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2022 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ limitations under the License.
|
|
|
20
20
|
|
|
21
21
|
# ndarray2array
|
|
22
22
|
|
|
23
|
-
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] [![dependencies][dependencies-image]][dependencies-url]
|
|
23
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
24
24
|
|
|
25
25
|
> Convert an ndarray buffer to a generic array.
|
|
26
26
|
|
|
@@ -116,7 +116,7 @@ var arr = ndarray2array( buffer, shape, strides, offset, order );
|
|
|
116
116
|
```javascript
|
|
117
117
|
var shape2strides = require( '@stdlib/ndarray-base-shape2strides' );
|
|
118
118
|
var strides2offset = require( '@stdlib/ndarray-base-strides2offset' );
|
|
119
|
-
var
|
|
119
|
+
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
|
|
120
120
|
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
|
|
121
121
|
|
|
122
122
|
// Create a data buffer:
|
|
@@ -143,7 +143,7 @@ console.log( 'Dims: %s', shape.join( 'x' ) );
|
|
|
143
143
|
var arr;
|
|
144
144
|
var j;
|
|
145
145
|
for ( i = 0; i < 20; i++ ) {
|
|
146
|
-
j =
|
|
146
|
+
j = discreteUniform( 0, ndims-1 );
|
|
147
147
|
strides[ j ] *= -1;
|
|
148
148
|
offset = strides2offset( shape, strides );
|
|
149
149
|
|
|
@@ -168,6 +168,14 @@ for ( i = 0; i < 20; i++ ) {
|
|
|
168
168
|
|
|
169
169
|
<!-- /.references -->
|
|
170
170
|
|
|
171
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
172
|
+
|
|
173
|
+
<section class="related">
|
|
174
|
+
|
|
175
|
+
</section>
|
|
176
|
+
|
|
177
|
+
<!-- /.related -->
|
|
178
|
+
|
|
171
179
|
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
172
180
|
|
|
173
181
|
|
|
@@ -194,7 +202,7 @@ See [LICENSE][stdlib-license].
|
|
|
194
202
|
|
|
195
203
|
## Copyright
|
|
196
204
|
|
|
197
|
-
Copyright © 2016-
|
|
205
|
+
Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
198
206
|
|
|
199
207
|
</section>
|
|
200
208
|
|
|
@@ -213,9 +221,20 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
213
221
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-to-array/main.svg
|
|
214
222
|
[coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-to-array?branch=main
|
|
215
223
|
|
|
224
|
+
<!--
|
|
225
|
+
|
|
216
226
|
[dependencies-image]: https://img.shields.io/david/stdlib-js/ndarray-base-to-array.svg
|
|
217
227
|
[dependencies-url]: https://david-dm.org/stdlib-js/ndarray-base-to-array/main
|
|
218
228
|
|
|
229
|
+
-->
|
|
230
|
+
|
|
231
|
+
[umd]: https://github.com/umdjs/umd
|
|
232
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
233
|
+
|
|
234
|
+
[deno-url]: https://github.com/stdlib-js/ndarray-base-to-array/tree/deno
|
|
235
|
+
[umd-url]: https://github.com/stdlib-js/ndarray-base-to-array/tree/umd
|
|
236
|
+
[esm-url]: https://github.com/stdlib-js/ndarray-base-to-array/tree/esm
|
|
237
|
+
|
|
219
238
|
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
220
239
|
[chat-url]: https://gitter.im/stdlib-js/stdlib/
|
|
221
240
|
|
package/lib/main.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
+
var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
23
24
|
var recurse = require( './recurse.js' );
|
|
24
25
|
|
|
25
26
|
|
|
@@ -55,7 +56,7 @@ function ndarray2array( buffer, shape, strides, offset, order ) {
|
|
|
55
56
|
return [];
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
|
-
return recurse( buffer, shape, strides, offset, order, 0 );
|
|
59
|
+
return recurse( arraylike2object( buffer ), shape, strides, offset, order, 0 ); // eslint-disable-line max-len
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
|
package/lib/recurse.js
CHANGED
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
* Recursively converts an ndarray to a generic array.
|
|
25
25
|
*
|
|
26
26
|
* @private
|
|
27
|
-
* @param {
|
|
27
|
+
* @param {Object} obj - array object
|
|
28
|
+
* @param {(ArrayLikeObject|TypedArray|Buffer)} obj.data - data buffer
|
|
29
|
+
* @param {Function} obj.getter - element accessor
|
|
28
30
|
* @param {NonNegativeIntegerArray} shape - array shape
|
|
29
31
|
* @param {IntegerArray} strides - array strides
|
|
30
32
|
* @param {NonNegativeInteger} offset - index offset
|
|
@@ -32,7 +34,7 @@
|
|
|
32
34
|
* @param {NonNegativeInteger} dim - dimension
|
|
33
35
|
* @returns {(Array|Array<Array>)} output array
|
|
34
36
|
*/
|
|
35
|
-
function recurse(
|
|
37
|
+
function recurse( obj, shape, strides, offset, order, dim ) {
|
|
36
38
|
var stride;
|
|
37
39
|
var item;
|
|
38
40
|
var out;
|
|
@@ -40,7 +42,7 @@ function recurse( buffer, shape, strides, offset, order, dim ) {
|
|
|
40
42
|
var i;
|
|
41
43
|
|
|
42
44
|
if ( dim >= shape.length ) {
|
|
43
|
-
return
|
|
45
|
+
return obj.getter( obj.data, offset );
|
|
44
46
|
}
|
|
45
47
|
out = [];
|
|
46
48
|
|
|
@@ -48,7 +50,7 @@ function recurse( buffer, shape, strides, offset, order, dim ) {
|
|
|
48
50
|
stride = strides[ dim ];
|
|
49
51
|
|
|
50
52
|
for ( i = 0; i < n; i++ ) {
|
|
51
|
-
item = recurse(
|
|
53
|
+
item = recurse( obj, shape, strides, offset, order, dim+1 );
|
|
52
54
|
out.push( item );
|
|
53
55
|
offset += stride;
|
|
54
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/ndarray-base-to-array",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Convert an ndarray buffer to a generic array.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,12 +37,16 @@
|
|
|
37
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@stdlib/array-base-arraylike2object": "^0.0.x",
|
|
40
41
|
"@stdlib/types": "^0.0.x"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
44
|
+
"@stdlib/array-complex64": "^0.0.x",
|
|
43
45
|
"@stdlib/assert-is-array": "^0.0.x",
|
|
44
46
|
"@stdlib/assert-is-array-array": "^0.0.x",
|
|
45
47
|
"@stdlib/bench": "^0.0.x",
|
|
48
|
+
"@stdlib/complex-imagf": "^0.0.x",
|
|
49
|
+
"@stdlib/complex-realf": "^0.0.x",
|
|
46
50
|
"@stdlib/ndarray-base-numel": "^0.0.x",
|
|
47
51
|
"@stdlib/ndarray-base-shape2strides": "^0.0.x",
|
|
48
52
|
"@stdlib/ndarray-base-strides2offset": "^0.0.x",
|