Skip to content

Commit 67ab428

Browse files
committed
Auto-generated commit
1 parent 3450217 commit 67ab428

File tree

12 files changed

+2319
-1
lines changed

12 files changed

+2319
-1
lines changed

CHANGELOG.md

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

7-
## Unreleased (2025-05-13)
7+
## Unreleased (2025-05-15)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`916b907`](https://github.com/stdlib-js/stdlib/commit/916b9073d6cf82262233e835f9bbbaca26d685f0) - add `ndarray/vector/ctor`
1314
- [`9b0d852`](https://github.com/stdlib-js/stdlib/commit/9b0d8520418c2788d20d446b6a39471b6393a787) - add `loopOrder` to namespace
1415
- [`bdc9110`](https://github.com/stdlib-js/stdlib/commit/bdc91105259200e3ebb60aea16e918718301ce4b) - add `ndarray/base/loop-interchange-order`
1516
- [`e5ddc80`](https://github.com/stdlib-js/stdlib/commit/e5ddc80ad0e60653c61dfc8847ecc65dff6c69f2) - add `outputDataType` to namespace
@@ -388,6 +389,7 @@ A total of 15 issues were closed in this release:
388389

389390
<details>
390391

392+
- [`916b907`](https://github.com/stdlib-js/stdlib/commit/916b9073d6cf82262233e835f9bbbaca26d685f0) - **feat:** add `ndarray/vector/ctor` _(by Athan Reines)_
391393
- [`9b8f3a8`](https://github.com/stdlib-js/stdlib/commit/9b8f3a8e51b449803b683c7bf394d498de479a5f) - **docs:** update namespace table of contents [(#6996)](https://github.com/stdlib-js/stdlib/pull/6996) _(by stdlib-bot)_
392394
- [`603ba97`](https://github.com/stdlib-js/stdlib/commit/603ba974c88f33cb73ba53c69435183ca535ded9) - **docs:** fix parameter names _(by Athan Reines)_
393395
- [`dcfb648`](https://github.com/stdlib-js/stdlib/commit/dcfb6488ac9624b23ec546f7c54a2da0156c6695) - **refactor:** use generalized utility for resolving loop data _(by Athan Reines)_

vector/ctor/README.md

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
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+
# Vector
22+
23+
> Create a vector (i.e., a one-dimensional [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 vector = require( '@stdlib/ndarray/vector/ctor' );
41+
```
42+
43+
#### vector( \[dtype]\[, options] )
44+
45+
Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] having a specified [data type][@stdlib/ndarray/dtypes].
46+
47+
```javascript
48+
var getDType = require( '@stdlib/ndarray/dtype' );
49+
var numel = require( '@stdlib/ndarray/numel' );
50+
51+
var arr = vector();
52+
// returns <ndarray>
53+
54+
var len = numel( arr );
55+
// returns 0
56+
57+
var dt = getDType( arr );
58+
// returns 'float64'
59+
```
60+
61+
By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [`float64`][@stdlib/ndarray/dtypes] data type. To specify an alternative [data type][@stdlib/ndarray/dtypes], provide a `dtype` argument.
62+
63+
```javascript
64+
var getDType = require( '@stdlib/ndarray/dtype' );
65+
var numel = require( '@stdlib/ndarray/numel' );
66+
67+
var arr = vector( 'int32' );
68+
// returns <ndarray>
69+
70+
var len = numel( arr );
71+
// returns 0
72+
73+
var dt = getDType( arr );
74+
// returns 'int32'
75+
```
76+
77+
The function accepts the following options:
78+
79+
- **order**: specifies whether an [ndarray][@stdlib/ndarray/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). Default: `'row-major'`.
80+
- **mode**: specifies how to handle indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`.
81+
- **readonly**: boolean indicating whether an array should be **read-only**. Default: `false`.
82+
83+
#### vector( length\[, dtype]\[, options] )
84+
85+
Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] having a specified `length`.
86+
87+
```javascript
88+
var numel = require( '@stdlib/ndarray/numel' );
89+
90+
var arr1 = vector( 5 );
91+
// returns <ndarray>
92+
93+
var len1 = numel( arr1 );
94+
// returns 5
95+
96+
var arr2 = vector( 5, 'uint8' );
97+
// returns <ndarray>
98+
99+
var len2 = numel( arr2 );
100+
// returns 5
101+
```
102+
103+
#### vector( obj\[, dtype]\[, options] )
104+
105+
Creates a one-dimensional [ndarray][@stdlib/ndarray/ctor] from an array-like object or iterable.
106+
107+
```javascript
108+
var numel = require( '@stdlib/ndarray/numel' );
109+
110+
var arr1 = vector( [ 0.5, 0.5, 0.5 ] );
111+
// returns <ndarray>
112+
113+
var len1 = numel( arr1 );
114+
// returns 3
115+
116+
var arr2 = vector( [ 0.5, 0.5, 0.5 ], 'float32' );
117+
// returns <ndarray>
118+
119+
var len2 = numel( arr2 );
120+
// returns 3
121+
```
122+
123+
#### vector( buffer\[, byteOffset\[, length]]\[, dtype]\[, options] )
124+
125+
Returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] view of an [`ArrayBuffer`][@stdlib/array/buffer].
126+
127+
```javascript
128+
var ArrayBuffer = require( '@stdlib/array/buffer' );
129+
var getDType = require( '@stdlib/ndarray/dtype' );
130+
var numel = require( '@stdlib/ndarray/numel' );
131+
132+
var buf = new ArrayBuffer( 32 );
133+
134+
var arr1 = vector( buf );
135+
// returns <ndarray>
136+
137+
var len1 = numel( arr1 );
138+
// returns 4
139+
140+
var dt1 = getDType( arr1 );
141+
// returns 'float64'
142+
143+
var arr2 = vector( buf, 'float32' );
144+
// returns <ndarray>
145+
146+
var len2 = numel( arr2 );
147+
// returns 8
148+
149+
var dt2 = getDType( arr2 );
150+
// returns 'float32'
151+
152+
var arr3 = vector( buf, 16 );
153+
// returns <ndarray>
154+
155+
var len3 = numel( arr3 );
156+
// returns 2
157+
158+
var dt3 = getDType( arr3 );
159+
// returns 'float64'
160+
161+
var arr4 = vector( buf, 16, 'float32' );
162+
// returns <ndarray>
163+
164+
var len4 = numel( arr4 );
165+
// returns 4
166+
167+
var dt4 = getDType( arr4 );
168+
// returns 'float32'
169+
170+
var arr5 = vector( buf, 16, 1 );
171+
// returns <ndarray>
172+
173+
var len5 = numel( arr5 );
174+
// returns 1
175+
176+
var dt5 = getDType( arr5 );
177+
// returns 'float64'
178+
179+
var arr6 = vector( buf, 10, 4, 'int16' );
180+
// returns <ndarray>
181+
182+
var len6 = numel( arr6 );
183+
// returns 4
184+
185+
var dt6 = getDType( arr6 );
186+
// returns 'int16'
187+
```
188+
189+
</section>
190+
191+
<!-- /.usage -->
192+
193+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
194+
195+
<section class="notes">
196+
197+
</section>
198+
199+
<!-- /.notes -->
200+
201+
<!-- Package usage examples. -->
202+
203+
<section class="examples">
204+
205+
## Examples
206+
207+
<!-- eslint no-undef: "error" -->
208+
209+
```javascript
210+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
211+
var cartesianProduct = require( '@stdlib/array/cartesian-product' );
212+
var unzip = require( '@stdlib/utils/unzip' );
213+
var dtypes = require( '@stdlib/ndarray/dtypes' );
214+
var getShape = require( '@stdlib/ndarray/shape' );
215+
var logEachMap = require( '@stdlib/console/log-each-map' );
216+
var vector = require( '@stdlib/ndarray/vector/ctor' );
217+
218+
// Create an array of random array lengths:
219+
var lens = discreteUniform( 10, 5, 15, {
220+
'dtype': 'int32'
221+
});
222+
223+
// Resolve a list of supported ndarray date types:
224+
var dts = dtypes();
225+
226+
// Create length-dtype pairs:
227+
var pairs = cartesianProduct( lens, dts );
228+
229+
// Split the pairs into individual arguments:
230+
var args = unzip( pairs );
231+
232+
// Define a callback to create a vector and return the vector shape:
233+
function clbk( len, dtype ) {
234+
var x = vector( len, dtype );
235+
return getShape( x );
236+
}
237+
238+
// Apply the callback and print the results:
239+
logEachMap( 'len: %2d. dtype: %10s. shape: [%d].', args[ 0 ], args[ 1 ], clbk );
240+
```
241+
242+
</section>
243+
244+
<!-- /.examples -->
245+
246+
<!-- 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. -->
247+
248+
<section class="references">
249+
250+
</section>
251+
252+
<!-- /.references -->
253+
254+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
255+
256+
<section class="related">
257+
258+
</section>
259+
260+
<!-- /.related -->
261+
262+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
263+
264+
<section class="links">
265+
266+
[@stdlib/array/buffer]: https://github.com/stdlib-js/array-buffer
267+
268+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
269+
270+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
271+
272+
</section>
273+
274+
<!-- /.links -->

0 commit comments

Comments
 (0)