Skip to content

Commit 397958c

Browse files
committed
Auto-generated commit
1 parent 74f687e commit 397958c

File tree

67 files changed

+6963
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6963
-35
lines changed

Diff for: CHANGELOG.md

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

7-
## Unreleased (2025-03-21)
7+
## Unreleased (2025-03-22)
88

99
<section class="packages">
1010

@@ -91,6 +91,7 @@
9191

9292
##### Features
9393

94+
- [`282d01f`](https://github.com/stdlib-js/stdlib/commit/282d01f86247ea1b4c8a3345493b6dc8ec034517) - add `fillBy` to namespace
9495
- [`e661213`](https://github.com/stdlib-js/stdlib/commit/e66121352ef767cdb87d19e938b1eccf7970fa3a) - update namespace TypeScript declarations [(#4706)](https://github.com/stdlib-js/stdlib/pull/4706)
9596
- [`741b6f1`](https://github.com/stdlib-js/stdlib/commit/741b6f1df8ce11e77fb22c279cee6bbae3323176) - add `spreadDimensions` to namespace
9697
- [`908239e`](https://github.com/stdlib-js/stdlib/commit/908239e7cc6b4b3e260d0cc1f5aebb9af35d83c6) - add `toUniqueNormalizedIndices` to namespace
@@ -391,6 +392,28 @@ This release closes the following issue:
391392

392393
<!-- /.package -->
393394

395+
<section class="package" id="ndarray-base-fill-by-unreleased">
396+
397+
#### [@stdlib/ndarray/base/fill-by](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/fill-by)
398+
399+
<details>
400+
401+
<section class="features">
402+
403+
##### Features
404+
405+
- [`d29b55f`](https://github.com/stdlib-js/stdlib/commit/d29b55fd2f01608cf9cbff68eb5b6dad4ca1722b) - add `ndarray/base/fill-by`
406+
407+
</section>
408+
409+
<!-- /.features -->
410+
411+
</details>
412+
413+
</section>
414+
415+
<!-- /.package -->
416+
394417
<section class="package" id="ndarray-base-from-scalar-like-unreleased">
395418

396419
#### [@stdlib/ndarray/base/from-scalar-like](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/from-scalar-like)
@@ -1087,6 +1110,10 @@ A total of 7 people contributed to this release. Thank you to the following cont
10871110

10881111
<details>
10891112

1113+
- [`282d01f`](https://github.com/stdlib-js/stdlib/commit/282d01f86247ea1b4c8a3345493b6dc8ec034517) - **feat:** add `fillBy` to namespace _(by Athan Reines)_
1114+
- [`d29b55f`](https://github.com/stdlib-js/stdlib/commit/d29b55fd2f01608cf9cbff68eb5b6dad4ca1722b) - **feat:** add `ndarray/base/fill-by` _(by Athan Reines)_
1115+
- [`266a064`](https://github.com/stdlib-js/stdlib/commit/266a064a8cc55b100a00d2ad98c84820d8f17653) - **style:** fix spacing _(by Athan Reines)_
1116+
- [`04f7752`](https://github.com/stdlib-js/stdlib/commit/04f77520acf685e9325bf4413be6da7543ed3cb5) - **refactor:** accommodate known array types for increased performance _(by Athan Reines)_
10901117
- [`70d0be2`](https://github.com/stdlib-js/stdlib/commit/70d0be235297eecc69d8e7ec4aad484ac7d5aedc) - **test:** add 0d tests _(by Athan Reines)_
10911118
- [`d761114`](https://github.com/stdlib-js/stdlib/commit/d761114ce6f6f74f0befb8c445e4632c0265c150) - **docs:** update descriptions _(by Athan Reines)_
10921119
- [`59ab26d`](https://github.com/stdlib-js/stdlib/commit/59ab26d220e5950d2a4e1fa087602e73ce3e3b5b) - **docs:** add `c_x_as_z_x` example _(by Athan Reines)_

Diff for: base/assign/lib/main.js

+65-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@
2222

2323
var isComplexDataType = require( './../../../base/assert/is-complex-floating-point-data-type' );
2424
var isRealDataType = require( './../../../base/assert/is-real-data-type' );
25+
var isComplexArray = require( '@stdlib/array/base/assert/is-complex-typed-array' );
26+
var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' );
2527
var iterationOrder = require( './../../../base/iteration-order' );
2628
var castReturn = require( '@stdlib/complex/base/cast-return' );
2729
var complexCtors = require( '@stdlib/complex/ctors' );
2830
var minmaxViewBufferIndex = require( './../../../base/minmax-view-buffer-index' );
2931
var ndarray2object = require( './../../../base/ndarraylike2object' );
32+
var reinterpretComplex = require( '@stdlib/strided/base/reinterpret-complex' );
33+
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
34+
var gscal = require( '@stdlib/blas/base/gscal' );
3035
var blockedaccessorassign2d = require( './2d_blocked_accessors.js' );
3136
var blockedaccessorassign3d = require( './3d_blocked_accessors.js' );
3237
var blockedaccessorassign4d = require( './4d_blocked_accessors.js' );
@@ -123,6 +128,57 @@ var BLOCKED_ACCESSOR_ASSIGN = [
123128
];
124129
var MAX_DIMS = ASSIGN.length - 1;
125130

131+
// TODO: consider adding a package utility for mapping a complex dtype to its complementary real-valued counterpart
132+
var COMPLEX_TO_REAL = { // WARNING: this table needs to be manually updated if we add support for additional complex number dtypes
133+
'complex128': 'float64',
134+
'complex64': 'float32'
135+
};
136+
137+
138+
// FUNCTIONS //
139+
140+
/**
141+
* Converts a boolean ndarray to an 8-bit unsigned integer ndarray.
142+
*
143+
* ## Notes
144+
*
145+
* - The function mutates the input ndarray object.
146+
*
147+
* @private
148+
* @param {Object} x - input ndarray object
149+
* @returns {Object} output ndarray object
150+
*/
151+
function boolean2uint8( x ) {
152+
x.data = reinterpretBoolean( x.data, 0 );
153+
x.accessorProtocol = false;
154+
return x;
155+
}
156+
157+
/**
158+
* Converts a complex-valued floating-point ndarray to a real-valued floating-point ndarray.
159+
*
160+
* ## Notes
161+
*
162+
* - The function mutates the input ndarray object.
163+
*
164+
* @private
165+
* @param {Object} x - input ndarray object
166+
* @returns {Object} output ndarray object
167+
*/
168+
function complex2real( x ) {
169+
x.data = reinterpretComplex( x.data, 0 );
170+
x.accessorProtocol = false;
171+
x.dtype = COMPLEX_TO_REAL[ x.dtype ];
172+
x.strides = gscal( x.shape.length, 2, x.strides, 1 );
173+
x.offset *= 2;
174+
175+
// Append a trailing dimension where each element is the real and imaginary component for a corresponding element in the original input ndarray (note: this means that a two-dimensional complex-valued ndarray becomes a three-dimensional real-valued ndarray; while this does entail additional loop overhead, it is still significantly faster than sending complex-valued ndarrays down the accessor path):
176+
x.shape.push( 2 ); // real and imaginary components
177+
x.strides.push( 1 ); // real and imaginary components are assumed to be adjacent in memory
178+
179+
return x;
180+
}
181+
126182

127183
// MAIN //
128184

@@ -210,8 +266,16 @@ function assign( arrays ) {
210266
x = ndarray2object( arrays[ 0 ] );
211267
y = ndarray2object( arrays[ 1 ] );
212268

269+
// Check for known array types which can be reinterpreted for better iteration performance...
270+
if ( isBooleanArray( x.data ) && isBooleanArray( y.data ) ) {
271+
x = boolean2uint8( x );
272+
y = boolean2uint8( y );
273+
} else if ( isComplexArray( x.data ) && isComplexArray( y.data ) ) {
274+
x = complex2real( x );
275+
y = complex2real( y );
276+
}
213277
// Determine whether we are casting a real data type to a complex data type and we need to use a specialized accessor (note: we don't support the other way, complex-to-real, as this is not an allowed (mostly) safe cast)...
214-
if ( isRealDataType( x.dtype ) && isComplexDataType( y.dtype ) ) {
278+
else if ( isRealDataType( x.dtype ) && isComplexDataType( y.dtype ) ) {
215279
x.accessorProtocol = true;
216280
x.accessors[ 0 ] = castReturn( x.accessors[ 0 ], 2, complexCtors( y.dtype ) ); // eslint-disable-line max-len
217281
}

Diff for: base/fill-by/README.md

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# fillBy
22+
23+
> Fill an input ndarray according to a callback function.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var fillBy = require( '@stdlib/ndarray/base/fill-by' );
37+
```
38+
39+
#### fillBy( x, fcn\[, thisArg] )
40+
41+
Fills an input ndarray according to a callback function.
42+
43+
```javascript
44+
var Float64Array = require( '@stdlib/array/float64' );
45+
46+
function fcn( value ) {
47+
return value * 10.0;
48+
}
49+
50+
// Create a data buffer:
51+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
52+
53+
// Define the shape of the input array:
54+
var shape = [ 3, 1, 2 ];
55+
56+
// Define the array strides:
57+
var sx = [ 2, 2, 1 ];
58+
59+
// Define the index offset:
60+
var ox = 0;
61+
62+
// Create the input ndarray-like object:
63+
var x = {
64+
'dtype': 'float64',
65+
'data': xbuf,
66+
'shape': shape,
67+
'strides': sx,
68+
'offset': ox,
69+
'order': 'row-major'
70+
};
71+
72+
fillBy( x, fcn );
73+
74+
console.log( x.data );
75+
// => <Float64Array>[ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0 ]
76+
```
77+
78+
The function accepts the following arguments:
79+
80+
- **x**: array-like object containing an input ndarray.
81+
- **fcn**: callback function.
82+
- **thisArg**: callback function execution context (_optional_).
83+
84+
To set the callback function execution context, provide a `thisArg`.
85+
86+
<!-- eslint-disable no-invalid-this -->
87+
88+
```javascript
89+
var Float64Array = require( '@stdlib/array/float64' );
90+
91+
function fcn( value ) {
92+
return value * this.factor;
93+
}
94+
95+
// Create a data buffer:
96+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
97+
98+
// Define the shape of the input array:
99+
var shape = [ 3, 1, 2 ];
100+
101+
// Define the array strides:
102+
var sx = [ 2, 2, 1 ];
103+
104+
// Define the index offset:
105+
var ox = 0;
106+
107+
// Create the input ndarray-like object:
108+
var x = {
109+
'dtype': 'float64',
110+
'data': xbuf,
111+
'shape': shape,
112+
'strides': sx,
113+
'offset': ox,
114+
'order': 'row-major'
115+
};
116+
117+
var ctx = {
118+
'factor': 10.0
119+
};
120+
fillBy( x, fcn, ctx );
121+
122+
console.log( x.data );
123+
// => <Float64Array>[ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0 ]
124+
```
125+
126+
A provided ndarray should be an object with the following properties:
127+
128+
- **dtype**: data type.
129+
- **data**: data buffer.
130+
- **shape**: dimensions.
131+
- **strides**: stride lengths.
132+
- **offset**: index offset.
133+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
134+
135+
</section>
136+
137+
<!-- /.usage -->
138+
139+
<section class="notes">
140+
141+
## Notes
142+
143+
- The function **mutates** the input ndarray.
144+
145+
</section>
146+
147+
<!-- /.notes -->
148+
149+
<section class="examples">
150+
151+
## Examples
152+
153+
<!-- eslint no-undef: "error" -->
154+
155+
```javascript
156+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
157+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
158+
var zeros = require( '@stdlib/ndarray/zeros' );
159+
var fillBy = require( '@stdlib/ndarray/base/fill-by' );
160+
161+
// Create a zero-filled ndarray:
162+
var x = zeros( [ 5, 2 ], {
163+
'dtype': 'generic'
164+
});
165+
console.log( ndarray2array( x ) );
166+
167+
// Fill the ndarray with random values:
168+
fillBy( x, discreteUniform( -100, 100 ) );
169+
console.log( ndarray2array( x ) );
170+
```
171+
172+
</section>
173+
174+
<!-- /.examples -->
175+
176+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
177+
178+
<section class="related">
179+
180+
</section>
181+
182+
<!-- /.related -->
183+
184+
<section class="links">
185+
186+
<!-- <related-links> -->
187+
188+
<!-- </related-links> -->
189+
190+
</section>
191+
192+
<!-- /.links -->

0 commit comments

Comments
 (0)