Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Aug 16, 2024
1 parent 1c3faa4 commit 75c5741
Show file tree
Hide file tree
Showing 15 changed files with 791 additions and 3 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

##### Features

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

<!-- /.package -->

<section class="package" id="ndarray-base-ndarraylike2ndarray-unreleased">

#### [@stdlib/ndarray/base/ndarraylike2ndarray](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ndarraylike2ndarray)

<details>

<section class="features">

##### Features

- [`5d01561`](https://github.com/stdlib-js/stdlib/commit/5d015616e9731e40d20f7d4dca6b136ae47cc9bc) - add `ndarray/base/ndarraylike2ndarray`

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="ndarray-base-nullary-unreleased">

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

<details>

- [`dd48932`](https://github.com/stdlib-js/stdlib/commit/dd489326b8dcee32f41f2ef7c2bafcaa4eb6ce46) - **docs:** fix descriptions _(by Athan Reines)_
- [`54262c8`](https://github.com/stdlib-js/stdlib/commit/54262c89e70eae566591c6e87ece69b68ca09488) - **feat:** add `ndarraylike2ndarray` to namespace _(by Athan Reines)_
- [`5d01561`](https://github.com/stdlib-js/stdlib/commit/5d015616e9731e40d20f7d4dca6b136ae47cc9bc) - **feat:** add `ndarray/base/ndarraylike2ndarray` _(by Athan Reines)_
- [`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)_
- [`96c7ddf`](https://github.com/stdlib-js/stdlib/commit/96c7ddfdbcecc6ff60fcb56681db16463d19020e) - **fix:** use computed order and fix strides in examples _(by Athan Reines)_
- [`e2b7fb5`](https://github.com/stdlib-js/stdlib/commit/e2b7fb5df61f15ae7dbf148ec0c0412ff434b123) - **fix:** use computed order and fix strides in examples _(by Athan Reines)_
Expand Down
9 changes: 9 additions & 0 deletions base/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ setReadOnly( ns, 'minViewBufferIndex', require( './../../base/min-view-buffer-in
*/
setReadOnly( ns, 'minmaxViewBufferIndex', require( './../../base/minmax-view-buffer-index' ) );

/**
* @name ndarraylike2ndarray
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/ndarray/base/ndarraylike2ndarray}
*/
setReadOnly( ns, 'ndarraylike2ndarray', require( './../../base/ndarraylike2ndarray' ) );

/**
* @name ndarraylike2object
* @memberof ns
Expand Down
124 changes: 124 additions & 0 deletions base/ndarraylike2ndarray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!--
@license Apache-2.0
Copyright (c) 2024 The Stdlib Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# ndarraylike2ndarray

> Convert an ndarray-like object to an [`ndarray`][@stdlib/ndarray/base/ctor].
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' );
```

#### ndarraylike2ndarray( x )

Converts an ndarray-like object to an [`ndarray`][@stdlib/ndarray/base/ctor].

```javascript
var array = require( '@stdlib/ndarray/array' );

var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );
var out = ndarraylike2ndarray( arr );
// returns <ndarray>
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var array = require( '@stdlib/ndarray/array' );
var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' );

// Create an ndarray:
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );

// Convert to a "base" ndarray:
var out = ndarraylike2ndarray( x );
// returns <ndarray>

// Print various properties:
console.log( 'dtype: %s', out.dtype );
console.log( 'ndims: %d', out.shape.length );
console.log( 'length: %d', out.length );
console.log( 'shape: [ %s ]', out.shape.join( ', ' ) );
console.log( 'strides: [ %s ]', out.strides.join( ', ' ) );
console.log( 'offset: %d', out.offset );
console.log( 'order: %s', out.order );
```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray/tree/main/base/ctor

</section>

<!-- /.links -->
161 changes: 161 additions & 0 deletions base/ndarraylike2ndarray/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var ndarrayBase = require( './../../../base/ctor' );
var ndarray = require( './../../../ctor' );
var isCollection = require( '@stdlib/assert/is-collection' );
var pkg = require( './../package.json' ).name;
var ndarraylike2ndarray = require( './../lib' );


// MAIN //

bench( pkg+'::base_ndarray', function benchmark( b ) {
var strides;
var values;
var buffer;
var offset;
var dtype;
var shape;
var order;
var out;
var i;

dtype = 'float64';
buffer = new Float64Array( 4 );
shape = [ 2, 2 ];
strides = [ 2, 1 ];
offset = 0;
order = 'row-major';

values = [
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
ndarrayBase( dtype, buffer, shape, strides, offset, order )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = ndarraylike2ndarray( values[ i%values.length ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isCollection( out.data ) ) {
b.fail( 'should return a collection' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::ndarray', function benchmark( b ) {
var strides;
var values;
var buffer;
var offset;
var dtype;
var shape;
var order;
var out;
var i;

dtype = 'float64';
buffer = new Float64Array( 4 );
shape = [ 2, 2 ];
strides = [ 2, 1 ];
offset = 0;
order = 'row-major';

values = [
ndarray( dtype, buffer, shape, strides, offset, order ),
ndarray( dtype, buffer, shape, strides, offset, order ),
ndarray( dtype, buffer, shape, strides, offset, order ),
ndarray( dtype, buffer, shape, strides, offset, order ),
ndarray( dtype, buffer, shape, strides, offset, order )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = ndarraylike2ndarray( values[ i%values.length ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isCollection( out.data ) ) {
b.fail( 'should return a collection' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::ndarray_like', function benchmark( b ) {
var strides;
var values;
var buffer;
var offset;
var dtype;
var shape;
var order;
var out;
var obj;
var i;

dtype = 'float64';
buffer = new Float64Array( 4 );
shape = [ 2, 2 ];
strides = [ 2, 1 ];
offset = 0;
order = 'row-major';

values = [];
for ( i = 0; i < 5; i++ ) {
obj = {
'dtype': dtype,
'data': buffer,
'shape': shape,
'strides': strides,
'offset': offset,
'order': order
};
values.push( obj );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = ndarraylike2ndarray( values[ i%values.length ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isCollection( out.data ) ) {
b.fail( 'should return a collection' );
}
b.pass( 'benchmark finished' );
b.end();
});
23 changes: 23 additions & 0 deletions base/ndarraylike2ndarray/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

{{alias}}( x )
Converts an ndarray-like object to an ndarray.

Parameters
----------
x: ndarrayLike
Input ndarray-like object.

Returns
-------
out: ndarray
Output array.

Examples
--------
> var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] );
> var out = {{alias}}( arr )
<ndarray>

See Also
--------

Loading

0 comments on commit 75c5741

Please sign in to comment.