Skip to content

Commit 8e6d651

Browse files
committed
Auto-generated commit
1 parent 75c5741 commit 8e6d651

File tree

14 files changed

+1090
-6
lines changed

14 files changed

+1090
-6
lines changed

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-08-16)
7+
## Unreleased (2024-08-17)
88

99
<section class="packages">
1010

@@ -20,6 +20,7 @@
2020

2121
##### Features
2222

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

810811
<!-- /.package -->
811812

813+
<section class="package" id="ndarray-ndarraylike2ndarray-unreleased">
814+
815+
#### [@stdlib/ndarray/ndarraylike2ndarray](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ndarraylike2ndarray)
816+
817+
<details>
818+
819+
<section class="features">
820+
821+
##### Features
822+
823+
- [`e7b56b1`](https://github.com/stdlib-js/stdlib/commit/e7b56b133fffc0bf83638ab267242c25eb8a359a) - add `ndarray/ndarraylike2ndarray`
824+
825+
</section>
826+
827+
<!-- /.features -->
828+
829+
</details>
830+
831+
</section>
832+
833+
<!-- /.package -->
834+
812835
<section class="package" id="ndarray-next-dtype-unreleased">
813836

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

10131036
<details>
10141037

1038+
- [`ba0c5d0`](https://github.com/stdlib-js/stdlib/commit/ba0c5d0a00c8f2b5eff6321b14dd62398be26be8) - **feat:** add `ndarraylike2ndarray` to namespace _(by Athan Reines)_
1039+
- [`e7b56b1`](https://github.com/stdlib-js/stdlib/commit/e7b56b133fffc0bf83638ab267242c25eb8a359a) - **feat:** add `ndarray/ndarraylike2ndarray` _(by Athan Reines)_
1040+
- [`453c7f9`](https://github.com/stdlib-js/stdlib/commit/453c7f9f7c8ac5b8817b1d81f98af42570f1d0a5) - **refactor:** allow array-like objects containing submodes _(by Athan Reines)_
10151041
- [`dd48932`](https://github.com/stdlib-js/stdlib/commit/dd489326b8dcee32f41f2ef7c2bafcaa4eb6ce46) - **docs:** fix descriptions _(by Athan Reines)_
10161042
- [`54262c8`](https://github.com/stdlib-js/stdlib/commit/54262c89e70eae566591c6e87ece69b68ca09488) - **feat:** add `ndarraylike2ndarray` to namespace _(by Athan Reines)_
10171043
- [`5d01561`](https://github.com/stdlib-js/stdlib/commit/5d015616e9731e40d20f7d4dca6b136ae47cc9bc) - **feat:** add `ndarray/base/ndarraylike2ndarray` _(by Athan Reines)_

ctor/docs/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

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

23-
import { Collection } from '@stdlib/types/array';
23+
import { Collection, ArrayLike } from '@stdlib/types/array';
2424
import { ndarray, DataType, Mode, Order, Shape, Strides } from '@stdlib/types/ndarray';
2525
import { Buffer } from 'buffer';
2626

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

4141
/**
4242
* Boolean indicating whether an array should be read-only (default: false).

ctor/lib/validate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var isObject = require( '@stdlib/assert/is-plain-object' );
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25-
var isArray = require( '@stdlib/assert/is-array' );
25+
var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
2626
var isIndexMode = require( './../../base/assert/is-index-mode' );
2727
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2828
var format = require( '@stdlib/string/format' );
@@ -37,7 +37,7 @@ var format = require( '@stdlib/string/format' );
3737
* @param {Object} opts - destination object
3838
* @param {Options} options - function options
3939
* @param {string} [options.mode] - specifies how to handle indices which exceed array dimensions
40-
* @param {string} [options.submode] - specifies how to handle subscripts which exceed array dimensions
40+
* @param {StringArray} [options.submode] - specifies how to handle subscripts which exceed array dimensions
4141
* @param {boolean} [options.readonly] - boolean indicating whether an array should be read-only
4242
* @returns {(Error|null)} null or an error object
4343
*
@@ -65,7 +65,7 @@ function validate( opts, options ) {
6565
}
6666
if ( hasOwnProp( options, 'submode' ) ) {
6767
opts.submode = options.submode;
68-
if ( !isArray( opts.submode ) ) {
68+
if ( !isArrayLikeObject( opts.submode ) ) {
6969
return new TypeError( format( 'invalid option. `%s` option must be an array containing recognized modes. Option: `%s`.', 'submode', opts.submode ) );
7070
}
7171
if ( opts.submode.length === 0 ) {

lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ setReadOnly( ns, 'minDataType', require( './../min-dtype' ) );
261261
*/
262262
setReadOnly( ns, 'mostlySafeCasts', require( './../mostly-safe-casts' ) );
263263

264+
/**
265+
* @name ndarraylike2ndarray
266+
* @memberof ns
267+
* @readonly
268+
* @type {Function}
269+
* @see {@link module:@stdlib/ndarray/ndarraylike2ndarray}
270+
*/
271+
setReadOnly( ns, 'ndarraylike2ndarray', require( './../ndarraylike2ndarray' ) );
272+
264273
/**
265274
* @name ndims
266275
* @memberof ns

ndarraylike2ndarray/README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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/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/ndarraylike2ndarray' );
41+
```
42+
43+
#### ndarraylike2ndarray( x\[, options] )
44+
45+
Converts an ndarray-like object to an [`ndarray`][@stdlib/ndarray/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+
The function supports the same `options` as [`ndarray`][@stdlib/ndarray/ctor].
56+
57+
</section>
58+
59+
<!-- /.usage -->
60+
61+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
62+
63+
<section class="notes">
64+
65+
## Notes
66+
67+
- If provided a **read-only** [`ndarray`][@stdlib/ndarray/ctor], the function returns a **read-only** [`ndarray`][@stdlib/ndarray/ctor].
68+
69+
</section>
70+
71+
<!-- /.notes -->
72+
73+
<!-- Package usage examples. -->
74+
75+
<section class="examples">
76+
77+
## Examples
78+
79+
<!-- eslint no-undef: "error" -->
80+
81+
```javascript
82+
var array = require( '@stdlib/ndarray/array' );
83+
var ndarraylike2ndarray = require( '@stdlib/ndarray/ndarraylike2ndarray' );
84+
85+
// Create an ndarray:
86+
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
87+
88+
// Create another ndarray sharing the same data:
89+
var out = ndarraylike2ndarray( x );
90+
// returns <ndarray>
91+
92+
// Print various properties:
93+
console.log( 'dtype: %s', out.dtype );
94+
console.log( 'ndims: %d', out.shape.length );
95+
console.log( 'length: %d', out.length );
96+
console.log( 'shape: [ %s ]', out.shape.join( ', ' ) );
97+
console.log( 'strides: [ %s ]', out.strides.join( ', ' ) );
98+
console.log( 'offset: %d', out.offset );
99+
console.log( 'order: %s', out.order );
100+
```
101+
102+
</section>
103+
104+
<!-- /.examples -->
105+
106+
<!-- 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. -->
107+
108+
<section class="references">
109+
110+
</section>
111+
112+
<!-- /.references -->
113+
114+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
115+
116+
<section class="related">
117+
118+
</section>
119+
120+
<!-- /.related -->
121+
122+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
123+
124+
<section class="links">
125+
126+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
127+
128+
</section>
129+
130+
<!-- /.links -->

0 commit comments

Comments
 (0)