Skip to content

Commit 75c5741

Browse files
committed
Auto-generated commit
1 parent 1c3faa4 commit 75c5741

File tree

15 files changed

+791
-3
lines changed

15 files changed

+791
-3
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
##### Features
6666

67+
- [`54262c8`](https://github.com/stdlib-js/stdlib/commit/54262c89e70eae566591c6e87ece69b68ca09488) - add `ndarraylike2ndarray` to namespace
6768
- [`6e4b9eb`](https://github.com/stdlib-js/stdlib/commit/6e4b9ebc31d9629446019e37e31bfe9b180b675c) - update namespace TypeScript declarations [(#2681)](https://github.com/stdlib-js/stdlib/pull/2681)
6869
- [`d31e751`](https://github.com/stdlib-js/stdlib/commit/d31e7515b71dc5b76751173c7724d73d943b1473) - add `forEach` to namespace
6970
- [`de17de3`](https://github.com/stdlib-js/stdlib/commit/de17de32867461079aae166d5cecbecb1da7f922) - update namespace TypeScript declarations [(#2593)](https://github.com/stdlib-js/stdlib/pull/2593)
@@ -298,6 +299,28 @@
298299

299300
<!-- /.package -->
300301

302+
<section class="package" id="ndarray-base-ndarraylike2ndarray-unreleased">
303+
304+
#### [@stdlib/ndarray/base/ndarraylike2ndarray](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ndarraylike2ndarray)
305+
306+
<details>
307+
308+
<section class="features">
309+
310+
##### Features
311+
312+
- [`5d01561`](https://github.com/stdlib-js/stdlib/commit/5d015616e9731e40d20f7d4dca6b136ae47cc9bc) - add `ndarray/base/ndarraylike2ndarray`
313+
314+
</section>
315+
316+
<!-- /.features -->
317+
318+
</details>
319+
320+
</section>
321+
322+
<!-- /.package -->
323+
301324
<section class="package" id="ndarray-base-nullary-unreleased">
302325

303326
#### [@stdlib/ndarray/base/nullary](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/nullary)
@@ -989,6 +1012,9 @@ A total of 4 people contributed to this release. Thank you to the following cont
9891012

9901013
<details>
9911014

1015+
- [`dd48932`](https://github.com/stdlib-js/stdlib/commit/dd489326b8dcee32f41f2ef7c2bafcaa4eb6ce46) - **docs:** fix descriptions _(by Athan Reines)_
1016+
- [`54262c8`](https://github.com/stdlib-js/stdlib/commit/54262c89e70eae566591c6e87ece69b68ca09488) - **feat:** add `ndarraylike2ndarray` to namespace _(by Athan Reines)_
1017+
- [`5d01561`](https://github.com/stdlib-js/stdlib/commit/5d015616e9731e40d20f7d4dca6b136ae47cc9bc) - **feat:** add `ndarray/base/ndarraylike2ndarray` _(by Athan Reines)_
9921018
- [`72ed2e1`](https://github.com/stdlib-js/stdlib/commit/72ed2e1e6331858c078564e22b6dca041f5daaca) - **feat:** add `ndarray/base/map` [(#2715)](https://github.com/stdlib-js/stdlib/pull/2715) _(by Muhammad Haris, Athan Reines)_
9931019
- [`96c7ddf`](https://github.com/stdlib-js/stdlib/commit/96c7ddfdbcecc6ff60fcb56681db16463d19020e) - **fix:** use computed order and fix strides in examples _(by Athan Reines)_
9941020
- [`e2b7fb5`](https://github.com/stdlib-js/stdlib/commit/e2b7fb5df61f15ae7dbf148ec0c0412ff434b123) - **fix:** use computed order and fix strides in examples _(by Athan Reines)_

base/lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,15 @@ setReadOnly( ns, 'minViewBufferIndex', require( './../../base/min-view-buffer-in
445445
*/
446446
setReadOnly( ns, 'minmaxViewBufferIndex', require( './../../base/minmax-view-buffer-index' ) );
447447

448+
/**
449+
* @name ndarraylike2ndarray
450+
* @memberof ns
451+
* @readonly
452+
* @type {Function}
453+
* @see {@link module:@stdlib/ndarray/base/ndarraylike2ndarray}
454+
*/
455+
setReadOnly( ns, 'ndarraylike2ndarray', require( './../../base/ndarraylike2ndarray' ) );
456+
448457
/**
449458
* @name ndarraylike2object
450459
* @memberof ns

base/ndarraylike2ndarray/README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# ndarraylike2ndarray
22+
23+
> Convert an ndarray-like object to an [`ndarray`][@stdlib/ndarray/base/ctor].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' );
41+
```
42+
43+
#### ndarraylike2ndarray( x )
44+
45+
Converts an ndarray-like object to an [`ndarray`][@stdlib/ndarray/base/ctor].
46+
47+
```javascript
48+
var array = require( '@stdlib/ndarray/array' );
49+
50+
var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );
51+
var out = ndarraylike2ndarray( arr );
52+
// returns <ndarray>
53+
```
54+
55+
</section>
56+
57+
<!-- /.usage -->
58+
59+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
60+
61+
<section class="notes">
62+
63+
</section>
64+
65+
<!-- /.notes -->
66+
67+
<!-- Package usage examples. -->
68+
69+
<section class="examples">
70+
71+
## Examples
72+
73+
<!-- eslint no-undef: "error" -->
74+
75+
```javascript
76+
var array = require( '@stdlib/ndarray/array' );
77+
var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' );
78+
79+
// Create an ndarray:
80+
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
81+
82+
// Convert to a "base" ndarray:
83+
var out = ndarraylike2ndarray( x );
84+
// returns <ndarray>
85+
86+
// Print various properties:
87+
console.log( 'dtype: %s', out.dtype );
88+
console.log( 'ndims: %d', out.shape.length );
89+
console.log( 'length: %d', out.length );
90+
console.log( 'shape: [ %s ]', out.shape.join( ', ' ) );
91+
console.log( 'strides: [ %s ]', out.strides.join( ', ' ) );
92+
console.log( 'offset: %d', out.offset );
93+
console.log( 'order: %s', out.order );
94+
```
95+
96+
</section>
97+
98+
<!-- /.examples -->
99+
100+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
101+
102+
<section class="references">
103+
104+
</section>
105+
106+
<!-- /.references -->
107+
108+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
109+
110+
<section class="related">
111+
112+
</section>
113+
114+
<!-- /.related -->
115+
116+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
117+
118+
<section class="links">
119+
120+
[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray/tree/main/base/ctor
121+
122+
</section>
123+
124+
<!-- /.links -->
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var ndarrayBase = require( './../../../base/ctor' );
26+
var ndarray = require( './../../../ctor' );
27+
var isCollection = require( '@stdlib/assert/is-collection' );
28+
var pkg = require( './../package.json' ).name;
29+
var ndarraylike2ndarray = require( './../lib' );
30+
31+
32+
// MAIN //
33+
34+
bench( pkg+'::base_ndarray', function benchmark( b ) {
35+
var strides;
36+
var values;
37+
var buffer;
38+
var offset;
39+
var dtype;
40+
var shape;
41+
var order;
42+
var out;
43+
var i;
44+
45+
dtype = 'float64';
46+
buffer = new Float64Array( 4 );
47+
shape = [ 2, 2 ];
48+
strides = [ 2, 1 ];
49+
offset = 0;
50+
order = 'row-major';
51+
52+
values = [
53+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
54+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
55+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
56+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
57+
ndarrayBase( dtype, buffer, shape, strides, offset, order )
58+
];
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
out = ndarraylike2ndarray( values[ i%values.length ] );
63+
if ( typeof out !== 'object' ) {
64+
b.fail( 'should return an object' );
65+
}
66+
}
67+
b.toc();
68+
if ( !isCollection( out.data ) ) {
69+
b.fail( 'should return a collection' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
});
74+
75+
bench( pkg+'::ndarray', function benchmark( b ) {
76+
var strides;
77+
var values;
78+
var buffer;
79+
var offset;
80+
var dtype;
81+
var shape;
82+
var order;
83+
var out;
84+
var i;
85+
86+
dtype = 'float64';
87+
buffer = new Float64Array( 4 );
88+
shape = [ 2, 2 ];
89+
strides = [ 2, 1 ];
90+
offset = 0;
91+
order = 'row-major';
92+
93+
values = [
94+
ndarray( dtype, buffer, shape, strides, offset, order ),
95+
ndarray( dtype, buffer, shape, strides, offset, order ),
96+
ndarray( dtype, buffer, shape, strides, offset, order ),
97+
ndarray( dtype, buffer, shape, strides, offset, order ),
98+
ndarray( dtype, buffer, shape, strides, offset, order )
99+
];
100+
101+
b.tic();
102+
for ( i = 0; i < b.iterations; i++ ) {
103+
out = ndarraylike2ndarray( values[ i%values.length ] );
104+
if ( typeof out !== 'object' ) {
105+
b.fail( 'should return an object' );
106+
}
107+
}
108+
b.toc();
109+
if ( !isCollection( out.data ) ) {
110+
b.fail( 'should return a collection' );
111+
}
112+
b.pass( 'benchmark finished' );
113+
b.end();
114+
});
115+
116+
bench( pkg+'::ndarray_like', function benchmark( b ) {
117+
var strides;
118+
var values;
119+
var buffer;
120+
var offset;
121+
var dtype;
122+
var shape;
123+
var order;
124+
var out;
125+
var obj;
126+
var i;
127+
128+
dtype = 'float64';
129+
buffer = new Float64Array( 4 );
130+
shape = [ 2, 2 ];
131+
strides = [ 2, 1 ];
132+
offset = 0;
133+
order = 'row-major';
134+
135+
values = [];
136+
for ( i = 0; i < 5; i++ ) {
137+
obj = {
138+
'dtype': dtype,
139+
'data': buffer,
140+
'shape': shape,
141+
'strides': strides,
142+
'offset': offset,
143+
'order': order
144+
};
145+
values.push( obj );
146+
}
147+
148+
b.tic();
149+
for ( i = 0; i < b.iterations; i++ ) {
150+
out = ndarraylike2ndarray( values[ i%values.length ] );
151+
if ( typeof out !== 'object' ) {
152+
b.fail( 'should return an object' );
153+
}
154+
}
155+
b.toc();
156+
if ( !isCollection( out.data ) ) {
157+
b.fail( 'should return a collection' );
158+
}
159+
b.pass( 'benchmark finished' );
160+
b.end();
161+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
{{alias}}( x )
3+
Converts an ndarray-like object to an ndarray.
4+
5+
Parameters
6+
----------
7+
x: ndarrayLike
8+
Input ndarray-like object.
9+
10+
Returns
11+
-------
12+
out: ndarray
13+
Output array.
14+
15+
Examples
16+
--------
17+
> var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] );
18+
> var out = {{alias}}( arr )
19+
<ndarray>
20+
21+
See Also
22+
--------
23+

0 commit comments

Comments
 (0)