Skip to content

Commit e2c9645

Browse files
committed
Auto-generated commit
1 parent 67d19bc commit e2c9645

File tree

13 files changed

+1837
-492
lines changed

13 files changed

+1837
-492
lines changed

CHANGELOG.md

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

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

99
<section class="features">
1010

1111
### Features
1212

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

390391
<details>
391392

393+
- [`848f226`](https://github.com/stdlib-js/stdlib/commit/848f226d45aad2d627453c8306ae192c75338ac3) - **feat:** add `factory` method _(by Athan Reines)_
392394
- [`d30fed0`](https://github.com/stdlib-js/stdlib/commit/d30fed0b3516e362f957aa15d1521b3b3fe6cefd) - **docs:** update examples _(by Athan Reines)_
393395
- [`916b907`](https://github.com/stdlib-js/stdlib/commit/916b9073d6cf82262233e835f9bbbaca26d685f0) - **feat:** add `ndarray/vector/ctor` _(by Athan Reines)_
394396
- [`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)_

vector/ctor/README.md

+42-7
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,41 @@ var dt6 = getDType( arr6 );
186186
// returns 'int16'
187187
```
188188

189+
#### vector.factory( dtype\[, options] )
190+
191+
Returns a function for creating a one-dimensional [ndarray][@stdlib/ndarray/ctor].
192+
193+
```javascript
194+
var getDType = require( '@stdlib/ndarray/dtype' );
195+
var numel = require( '@stdlib/ndarray/numel' );
196+
197+
var Float32Vector = vector.factory( 'float32' );
198+
199+
var arr = new Float32Vector( [ 1, 2, 3 ] );
200+
// returns <ndarray>
201+
202+
var dt = getDType( arr );
203+
// returns 'float32'
204+
205+
var len = numel( arr );
206+
// returns 3
207+
```
208+
209+
The function supports the following parameters:
210+
211+
- **dtype**: [data type][@stdlib/ndarray/dtypes].
212+
- **options**: function options (_optional_).
213+
214+
The function accepts the following options:
215+
216+
- **order**: specifies whether the default memory layout for a returned [ndarray][@stdlib/ndarray/ctor] should be `'row-major'` (C-style) or `'column-major'` (Fortran-style). Default: `'row-major'`.
217+
- **mode**: specifies the default behavior when handling indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`.
218+
- **readonly**: boolean indicating whether to return a **read-only** [ndarray][@stdlib/ndarray/ctor] by default. Default: `false`.
219+
220+
The function returned by the `factory` method supports the same arguments and options as `vector` above, except for the `dtype` argument, as the returned function always returns a one-dimensional [ndarray][@stdlib/ndarray/ctor] having the same [data type][@stdlib/ndarray/dtypes].
221+
222+
When providing options to the returned function, the provided option values override the defaults established during function creation.
223+
189224
</section>
190225

191226
<!-- /.usage -->
@@ -211,7 +246,7 @@ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
211246
var cartesianProduct = require( '@stdlib/array/cartesian-product' );
212247
var unzip = require( '@stdlib/utils/unzip' );
213248
var dtypes = require( '@stdlib/ndarray/dtypes' );
214-
var getShape = require( '@stdlib/ndarray/shape' );
249+
var sum = require( '@stdlib/blas/ext/sum' );
215250
var logEachMap = require( '@stdlib/console/log-each-map' );
216251
var vector = require( '@stdlib/ndarray/vector/ctor' );
217252

@@ -220,23 +255,23 @@ var lens = discreteUniform( 10, 5, 15, {
220255
'dtype': 'int32'
221256
});
222257

223-
// Resolve a list of supported ndarray date types:
224-
var dts = dtypes();
258+
// Resolve a list of supported ndarray real-valued data types:
259+
var dts = dtypes( 'real_and_generic' );
225260

226261
// Create length-dtype pairs:
227262
var pairs = cartesianProduct( lens, dts );
228263

229264
// Split the pairs into individual arguments:
230265
var args = unzip( pairs );
231266

232-
// Define a callback to create a vector and return the vector shape:
267+
// Define a callback to create a random vector and return the sum of all vector elements:
233268
function clbk( len, dtype ) {
234-
var x = vector( len, dtype );
235-
return getShape( x );
269+
var x = vector( discreteUniform( len, 0, 100 ), dtype );
270+
return sum( x ).get();
236271
}
237272

238273
// Apply the callback and print the results:
239-
logEachMap( 'len: %2d. dtype: %10s. shape: [%d].', args[ 0 ], args[ 1 ], clbk );
274+
logEachMap( 'len: %2d. dtype: %7s. sum: %d.', args[ 0 ], args[ 1 ], clbk );
240275
```
241276

242277
</section>

0 commit comments

Comments
 (0)