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 17, 2024
1 parent 75c5741 commit 8e6d651
Show file tree
Hide file tree
Showing 14 changed files with 1,090 additions and 6 deletions.
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<section class="release" id="unreleased">

## Unreleased (2024-08-16)
## Unreleased (2024-08-17)

<section class="packages">

Expand All @@ -20,6 +20,7 @@

##### Features

- [`ba0c5d0`](https://github.com/stdlib-js/stdlib/commit/ba0c5d0a00c8f2b5eff6321b14dd62398be26be8) - add `ndarraylike2ndarray` to namespace
- [`de17de3`](https://github.com/stdlib-js/stdlib/commit/de17de32867461079aae166d5cecbecb1da7f922) - update namespace TypeScript declarations [(#2593)](https://github.com/stdlib-js/stdlib/pull/2593)
- [`b8bd516`](https://github.com/stdlib-js/stdlib/commit/b8bd51687cabdda74299cb37b9a5527fddd35aaa) - update namespace TypeScript declarations [(#2351)](https://github.com/stdlib-js/stdlib/pull/2351)
- [`0adcae5`](https://github.com/stdlib-js/stdlib/commit/0adcae51386086e2ef5fb5d78402389cff776deb) - update namespace TypeScript declarations [(#1340)](https://github.com/stdlib-js/stdlib/pull/1340)
Expand Down Expand Up @@ -809,6 +810,28 @@ This release closes the following issue:

<!-- /.package -->

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

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

<details>

<section class="features">

##### Features

- [`e7b56b1`](https://github.com/stdlib-js/stdlib/commit/e7b56b133fffc0bf83638ab267242c25eb8a359a) - add `ndarray/ndarraylike2ndarray`

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="ndarray-next-dtype-unreleased">

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

<details>

- [`ba0c5d0`](https://github.com/stdlib-js/stdlib/commit/ba0c5d0a00c8f2b5eff6321b14dd62398be26be8) - **feat:** add `ndarraylike2ndarray` to namespace _(by Athan Reines)_
- [`e7b56b1`](https://github.com/stdlib-js/stdlib/commit/e7b56b133fffc0bf83638ab267242c25eb8a359a) - **feat:** add `ndarray/ndarraylike2ndarray` _(by Athan Reines)_
- [`453c7f9`](https://github.com/stdlib-js/stdlib/commit/453c7f9f7c8ac5b8817b1d81f98af42570f1d0a5) - **refactor:** allow array-like objects containing submodes _(by Athan Reines)_
- [`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)_
Expand Down
4 changes: 2 additions & 2 deletions ctor/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/// <reference types="@stdlib/types"/>

import { Collection } from '@stdlib/types/array';
import { Collection, ArrayLike } from '@stdlib/types/array';
import { ndarray, DataType, Mode, Order, Shape, Strides } from '@stdlib/types/ndarray';
import { Buffer } from 'buffer';

Expand All @@ -36,7 +36,7 @@ interface Options {
/**
* Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']).
*/
submode?: Array<Mode>;
submode?: ArrayLike<Mode>;

/**
* Boolean indicating whether an array should be read-only (default: false).
Expand Down
6 changes: 3 additions & 3 deletions ctor/lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var isObject = require( '@stdlib/assert/is-plain-object' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var isArray = require( '@stdlib/assert/is-array' );
var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
var isIndexMode = require( './../../base/assert/is-index-mode' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var format = require( '@stdlib/string/format' );
Expand All @@ -37,7 +37,7 @@ var format = require( '@stdlib/string/format' );
* @param {Object} opts - destination object
* @param {Options} options - function options
* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions
* @param {string} [options.submode] - specifies how to handle subscripts which exceed array dimensions
* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions
* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only
* @returns {(Error|null)} null or an error object
*
Expand Down Expand Up @@ -65,7 +65,7 @@ function validate( opts, options ) {
}
if ( hasOwnProp( options, 'submode' ) ) {
opts.submode = options.submode;
if ( !isArray( opts.submode ) ) {
if ( !isArrayLikeObject( opts.submode ) ) {
return new TypeError( format( 'invalid option. `%s` option must be an array containing recognized modes. Option: `%s`.', 'submode', opts.submode ) );
}
if ( opts.submode.length === 0 ) {
Expand Down
9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ setReadOnly( ns, 'minDataType', require( './../min-dtype' ) );
*/
setReadOnly( ns, 'mostlySafeCasts', require( './../mostly-safe-casts' ) );

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

/**
* @name ndims
* @memberof ns
Expand Down
130 changes: 130 additions & 0 deletions ndarraylike2ndarray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<!--
@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/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/ndarraylike2ndarray' );
```

#### ndarraylike2ndarray( x\[, options] )

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

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

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

The function supports the same `options` as [`ndarray`][@stdlib/ndarray/ctor].

</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">

## Notes

- If provided a **read-only** [`ndarray`][@stdlib/ndarray/ctor], the function returns a **read-only** [`ndarray`][@stdlib/ndarray/ctor].

</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/ndarraylike2ndarray' );

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

// Create another ndarray sharing the same data:
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/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor

</section>

<!-- /.links -->
Loading

0 comments on commit 8e6d651

Please sign in to comment.