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 20, 2024
1 parent 68e112f commit 61ddff2
Show file tree
Hide file tree
Showing 9 changed files with 3,175 additions and 124 deletions.
3 changes: 2 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-19)
## Unreleased (2024-06-20)

<section class="features">

Expand All @@ -24,6 +24,7 @@

<details>

- [`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)_
- [`074cbef`](https://github.com/stdlib-js/stdlib/commit/074cbef3f9d616c37c2be856a949e257481ff2fc) - **docs:** add note concerning broadcasting of nested array elements _(by Athan Reines)_
Expand Down
114 changes: 57 additions & 57 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.

31 changes: 22 additions & 9 deletions lib/set_elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var scalar2array = require( '@stdlib/array-from-scalar' );
var dtype = require( '@stdlib/array-dtype' );
var put = require( '@stdlib/array-put' );
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 @@ -53,20 +54,20 @@ var errMessage = require( './error_message.js' );
* @returns {boolean} boolean indicating whether assignment succeeded
*/
function setElements( target, property, value, ctx ) {
var tdt;
var vdt;
var idx;
var err;
var dt;
var v;

idx = prop2array( property, ctx.cache );
tdt = ctx.dtype || 'generic';
if ( isCollection( value ) ) {
// When handling collections, we delegate to implementation APIs (see below) to perform argument validation (e.g., ensuring a (mostly) safe cast, broadcast compatibility, etc), so we just reassign the value here:
v = value;
dt = dtype( value ) || 'generic';
} else {
// When provided a "scalar", we need to check whether the value can be safely cast to the target array data type:
dt = ctx.dtype;
err = ctx.validator( value, dt );
err = ctx.validator( value, tdt );
if ( err ) {
throw err;
}
Expand All @@ -76,7 +77,8 @@ function setElements( target, property, value, ctx ) {
v = value;
}
// As the scalar can be safely cast, convert the scalar to an array having the same data type as the target array to allow for broadcasting during assignment:
v = scalar2array( v, dt );
v = scalar2array( v, tdt );
vdt = tdt;
}
if ( idx.type === 'int' ) {
try {
Expand All @@ -86,16 +88,27 @@ function setElements( target, property, value, ctx ) {
}
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( dt, ctx.dtype ) ) {
throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', dt, ctx.dtype ) );
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' ) {
where( idx.data, v, target, target, 1, 0 );
try {
place( target, idx.data, v, 'strict_broadcast' );
} catch ( err ) {
throw new err.constructor( errMessage( err.message ) );
}
return true;
}
if ( idx.type === 'mask' ) {
where( idx.data, target, v, target, 1, 0 );
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
} catch ( err ) {
throw new err.constructor( errMessage( err.message ) );
}
return true;
}
throw new Error( format( 'invalid operation. Unrecognized array index type. Value: `%s`.', idx.type ) );
Expand Down
2 changes: 1 addition & 1 deletion lib/set_slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function setSlice( target, property, value, receiver, ctx ) {
throw err;
}
// As the scalar can be safely cast, convert the scalar to an array having the same data type as the target array to allow for broadcasting during slice assignment:
v = scalar2array( value, ctx.dtype );
v = scalar2array( value, ctx.dtype || 'generic' );
}
try {
sliceAssign( v, receiver, s, ctx.strict );
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@stdlib/array-base-arraylike2object": "^0.2.1",
"@stdlib/array-base-assert-is-boolean-data-type": "github:stdlib-js/array-base-assert-is-boolean-data-type#main",
"@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-floating-point-data-type": "^0.2.1",
Expand All @@ -48,14 +48,15 @@
"@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-where": "github:stdlib-js/array-base-where#main",
"@stdlib/array-base-place": "github:stdlib-js/array-base-place#main",
"@stdlib/array-base-where": "^0.0.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-put": "github:stdlib-js/array-put#main",
"@stdlib/array-put": "^0.0.1",
"@stdlib/array-take": "^0.1.1",
"@stdlib/assert-has-own-property": "^0.2.1",
"@stdlib/assert-has-property": "^0.2.1",
Expand Down Expand Up @@ -85,7 +86,7 @@
},
"devDependencies": {
"@stdlib/array-base-to-accessor-array": "^0.2.1",
"@stdlib/array-bool": "github:stdlib-js/array-bool#main",
"@stdlib/array-bool": "^0.0.1",
"@stdlib/array-complex128": "^0.2.1",
"@stdlib/array-complex64": "^0.2.1",
"@stdlib/array-filled": "^0.2.1",
Expand All @@ -106,7 +107,7 @@
"@stdlib/assert-is-same-complex64array": "^0.2.1",
"@stdlib/assert-is-syntax-error": "^0.2.1",
"@stdlib/assert-is-type-error": "^0.2.1",
"@stdlib/complex-float64-ctor": "github:stdlib-js/complex-float64-ctor#main",
"@stdlib/complex-float64-ctor": "^0.0.1",
"@stdlib/slice-ctor": "^0.2.1",
"@stdlib/symbol-ctor": "^0.2.1",
"@stdlib/utils-properties-in": "^0.2.1",
Expand Down
Loading

0 comments on commit 61ddff2

Please sign in to comment.