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 Jun 21, 2024
1 parent 61ddff2 commit c7b656a
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 54 deletions.
13 changes: 12 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-06-20)
## Unreleased (2024-06-21)

<section class="features">

Expand All @@ -18,12 +18,23 @@

<!-- /.features -->

<section class="bug-fixes">

### Bug Fixes

- [`d301be9`](https://github.com/stdlib-js/stdlib/commit/d301be9e2cabe07efe219c00d10aebd15e0673e7) - ensure support for real-to-complex casting in boolean and mask array indexing

</section>

<!-- /.bug-fixes -->

<section class="commits">

### Commits

<details>

- [`d301be9`](https://github.com/stdlib-js/stdlib/commit/d301be9e2cabe07efe219c00d10aebd15e0673e7) - **fix:** ensure support for real-to-complex casting in boolean and mask array indexing _(by Athan Reines)_
- [`e57ccb2`](https://github.com/stdlib-js/stdlib/commit/e57ccb234687de4087aa12348d266ea448f3f241) - **refactor:** update boolean array indexing implementation and add tests _(by Athan Reines)_
- [`b981bc3`](https://github.com/stdlib-js/stdlib/commit/b981bc30e83a7f88cdc2c0efca082fb31f9e1ac0) - **refactor:** avoid repeated property access _(by Athan Reines)_
- [`550285b`](https://github.com/stdlib-js/stdlib/commit/550285bf4a57dd3dabc8ed3998e7b612515fe082) - **feat:** add support for boolean and mask array assignment _(by Athan Reines)_
Expand Down
80 changes: 40 additions & 40 deletions dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/index.js.map

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions lib/set_elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
// MODULES //

var isMostlySafeCast = require( '@stdlib/array-base-assert-is-mostly-safe-data-type-cast' );
var isRealDataType = require( '@stdlib/array-base-assert-is-real-data-type' );
var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );
var isCollection = require( '@stdlib/assert-is-collection' );
var scalar2array = require( '@stdlib/array-from-scalar' );
var dtype = require( '@stdlib/array-dtype' );
var put = require( '@stdlib/array-put' );
var place = require( '@stdlib/array-place' );
var convert = require( '@stdlib/array-convert' );
var where = require( '@stdlib/array-base-where' ).assign;
var place = require( '@stdlib/array-base-place' );
var format = require( '@stdlib/string-format' );
var prop2array = require( './prop2array.js' );
var errMessage = require( './error_message.js' );
Expand Down Expand Up @@ -88,24 +91,31 @@ function setElements( target, property, value, ctx ) {
}
return true;
}
if ( idx.type === 'bool' ) {
try {
place( target, idx.data, v, {
'mode': 'strict_broadcast'
});
} catch ( err ) {
throw new err.constructor( errMessage( err.message ) );
}
return true;
}
if ( vdt === void 0 ) {
vdt = dtype( value ) || 'generic';
}
// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the target array data type is floating-point...
if ( !isMostlySafeCast( vdt, tdt ) ) {
throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, tdt ) );
}
if ( idx.type === 'bool' ) {
try {
place( target, idx.data, v, 'strict_broadcast' );
} catch ( err ) {
throw new err.constructor( errMessage( err.message ) );
}
return true;
// When performing a real-to-complex assignment, interpret the real-valued array as containing real components with implied imaginary components equal to zero and explicitly convert to a complex-valued array...
if ( isComplexDataType( tdt ) && isRealDataType( vdt ) ) {
v = convert( v, tdt );
}
if ( idx.type === 'mask' ) {
// NOTE: we intentionally deviate from boolean array indexing here and interpret the mask as applying to both the target and values array, thus requiring that the assigned value array be broadcast compatible with the target array and NOT just the selected elements as in boolean array indexing
try {
where( idx.data, target, v, target, 1, 0 ); // note: intentionally deviate from boolean array indexing here and interpret the mask as applying to both the target and values array, thus requiring that the assigned value array be broadcast compatible with the target array and NOT just the selected elements as in boolean array indexing
where( idx.data, target, v, target, 1, 0 );
} catch ( err ) {
throw new err.constructor( errMessage( err.message ) );
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@
"@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1",
"@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1",
"@stdlib/array-base-assert-is-mostly-safe-data-type-cast": "^0.2.1",
"@stdlib/array-base-assert-is-real-data-type": "^0.2.1",
"@stdlib/array-base-assert-is-real-floating-point-data-type": "^0.2.1",
"@stdlib/array-base-assert-is-safe-data-type-cast": "^0.3.1",
"@stdlib/array-base-assert-is-signed-integer-data-type": "^0.2.1",
"@stdlib/array-base-assert-is-unsigned-integer-data-type": "^0.2.1",
"@stdlib/array-base-fancy-slice": "^0.3.1",
"@stdlib/array-base-fancy-slice-assign": "^0.2.1",
"@stdlib/array-base-min-signed-integer-dtype": "^0.2.1",
"@stdlib/array-base-place": "github:stdlib-js/array-base-place#main",
"@stdlib/array-base-where": "^0.0.1",
"@stdlib/array-convert": "^0.2.1",
"@stdlib/array-dtype": "^0.2.1",
"@stdlib/array-from-scalar": "^0.2.1",
"@stdlib/array-index": "^0.2.1",
"@stdlib/array-min-dtype": "^0.2.1",
"@stdlib/array-mskfilter": "^0.1.1",
"@stdlib/array-mskreject": "^0.1.1",
"@stdlib/array-place": "github:stdlib-js/array-place#main",
"@stdlib/array-put": "^0.0.1",
"@stdlib/array-take": "^0.1.1",
"@stdlib/assert-has-own-property": "^0.2.1",
Expand Down
45 changes: 45 additions & 0 deletions test/test.set.boolean_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,51 @@ tape( 'the function returns an array-like object supporting casting (complex128,
t.end();
});

tape( 'the function returns an array-like object supporting casting (complex128, float64)', opts, function test( t ) {
var expected;
var idx;
var x;
var y;

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( [ true, true, true, true ] );
expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] );
y[ idx ] = new Float64Array( [ 9, 10, 11, 12 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( new BooleanArray( [ true, true, false, false ] ) );
expected = new Complex128Array( [ 17, 0, 18, 0, 5, 6, 7, 8 ] );
y[ idx ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( [ false, true, true, false ] );
expected = new Complex128Array( [ 1, 2, 17, 0, 18, 0, 7, 8 ] );
y[ idx ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( new BooleanArray( [ true, false, true, false ] ) );
expected = new Complex128Array( [ 17, 0, 3, 4, 18, 0, 7, 8 ] );
y[ idx ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

t.end();
});

tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (float32, float64)', opts, function test( t ) {
var expected;
var idx;
Expand Down
54 changes: 54 additions & 0 deletions test/test.set.integer_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,60 @@ tape( 'the function returns an array-like object supporting casting (complex128,
t.end();
});

tape( 'the function returns an array-like object supporting casting (complex128, float64)', opts, function test( t ) {
var expected;
var idx;
var x;
var y;

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( [ 0, 1, 2, 3 ] );
expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] );
y[ idx ] = new Float64Array( [ 9, 10, 11, 12 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( [ 0, 1 ] );
expected = new Complex128Array( [ 17, 0, 18, 0, 5, 6, 7, 8 ] );
y[ idx ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( [ 1, 2 ] );
expected = new Complex128Array( [ 1, 2, 17, 0, 18, 0, 7, 8 ] );
y[ idx ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( [ 0, 2 ] );
expected = new Complex128Array( [ 17, 0, 3, 4, 18, 0, 7, 8 ] );
y[ idx ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( [ -1, -3 ] );
expected = new Complex128Array( [ 1, 2, 18, 0, 5, 6, 17, 0 ] );
y[ idx ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

t.end();
});

tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (float32, float64)', opts, function test( t ) {
var expected;
var idx;
Expand Down
45 changes: 45 additions & 0 deletions test/test.set.mask_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,51 @@ tape( 'the function returns an array-like object supporting casting (complex128,
t.end();
});

tape( 'the function returns an array-like object supporting casting (complex128, float64)', opts, function test( t ) {
var expected;
var idx;
var x;
var y;

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( new Uint8Array( [ 0, 0, 0, 0 ] ) );
expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] );
y[ idx ] = new Float64Array( [ 9, 10, 11, 12 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( new Uint8Array( [ 0, 0, 1, 1 ] ) );
expected = new Complex128Array( [ 17, 0, 18, 0, 5, 6, 7, 8 ] );
y[ idx ] = new Float64Array( [ 17, 18, 0, 0 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( new Uint8Array( [ 1, 0, 0, 1 ] ) );
expected = new Complex128Array( [ 1, 2, 17, 0, 18, 0, 7, 8 ] );
y[ idx ] = new Float64Array( [ 0, 17, 18, 0 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

idx = array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) );
expected = new Complex128Array( [ 17, 0, 3, 4, 18, 0, 7, 8 ] );
y[ idx ] = new Float64Array( [ 17, 0, 18, 0 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

t.end();
});

tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (float32, float64)', opts, function test( t ) {
var expected;
var idx;
Expand Down
48 changes: 48 additions & 0 deletions test/test.set.subsequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,54 @@ tape( 'the function returns an array-like object supporting casting (complex128,
t.end();
});

tape( 'the function returns an array-like object supporting casting (complex128, float64)', opts, function test( t ) {
var expected;
var x;
var y;

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

expected = new Complex128Array( [ 9, 0, 10, 0, 11, 0, 12, 0 ] );
y[ ':' ] = new Float64Array( [ 9, 10, 11, 12 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

expected = new Complex128Array( [ 17, 0, 18, 0, 5, 6, 7, 8 ] );
y[ ':2' ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

expected = new Complex128Array( [ 1, 2, 17, 0, 18, 0, 7, 8 ] );
y[ '1:3' ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

expected = new Complex128Array( [ 17, 0, 3, 4, 18, 0, 7, 8 ] );
y[ '::2' ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

x = new Complex128Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
y = array2fancy( x );

expected = new Complex128Array( [ 1, 2, 18, 0, 5, 6, 17, 0 ] );
y[ '-1::-2' ] = new Float64Array( [ 17, 18 ] );

t.strictEqual( isSameComplex128Array( y, expected ), true, 'returns expected value' );

t.end();
});

tape( 'the function returns an array-like object supporting downcasting of floating-point arrays (float32, float64)', opts, function test( t ) {
var expected;
var x;
Expand Down

0 comments on commit c7b656a

Please sign in to comment.