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 18, 2024
1 parent 7e0795d commit 29a04c0
Show file tree
Hide file tree
Showing 18 changed files with 2,325 additions and 179 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
<section class="release" id="unreleased">

## Unreleased (2024-06-05)
## Unreleased (2024-06-18)

<section class="features">

### Features

- [`b079d65`](https://github.com/stdlib-js/stdlib/commit/b079d653226019925581555fdaf9aa927ec69c0e) - add support for integer array indexing assignment
- [`96e896a`](https://github.com/stdlib-js/stdlib/commit/96e896a39be08912b2e06dfb6b671ec13d042412) - add support for boolean array indices

</section>
Expand All @@ -22,6 +23,7 @@

<details>

- [`b079d65`](https://github.com/stdlib-js/stdlib/commit/b079d653226019925581555fdaf9aa927ec69c0e) - **feat:** add support for integer array indexing assignment _(by Athan Reines)_
- [`96e896a`](https://github.com/stdlib-js/stdlib/commit/96e896a39be08912b2e06dfb6b671ec13d042412) - **feat:** add support for boolean array indices _(by Athan Reines)_
- [`75d4f83`](https://github.com/stdlib-js/stdlib/commit/75d4f83cb85610d23a04dc21a03f8075f6d3665f) - **refactor:** update require and include paths _(by Athan Reines)_

Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Pushpendra Chandravanshi <[email protected]>
Raunak Kumar Gupta <[email protected]>
Rejoan Sardar <[email protected]>
Ricky Reusser <[email protected]>
Ridam Garg <[email protected]>
Robert Gislason <[email protected]>
Roman Stetsyk <[email protected]>
Rutam <[email protected]>
Expand All @@ -75,7 +76,7 @@ Shraddheya Shendre <[email protected]>
Shubh Mehta <[email protected]>
Shubham Mishra <[email protected]>
Sivam Das <[email protected]>
Snehil Shah <[email protected].com>
Snehil Shah <snehilshah.989@gmail.com>
Soumajit Chatterjee <[email protected]>
Spandan Barve <[email protected]>
Stephannie Jiménez Gacha <[email protected]>
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ im = imag( v );
```javascript
var Uint8Array = require( '@stdlib/array-uint8' );
var Int32Array = require( '@stdlib/array-int32' );
var BooleanArray = require( '@stdlib/array-bool' );
var array2fancy = require( '@stdlib/array-to-fancy' );

var x = [ 1, 2, 3, 4, 5, 6 ];
Expand Down Expand Up @@ -525,6 +526,10 @@ i = idx( [ true, false, false, true, true, true ] ); // boolean array
z = y[ i ];
// returns [ 1, -9, -8, 6 ]

i = idx( new BooleanArray( [ true, false, false, true, true, true ] ) ); // boolean array
z = y[ i ];
// returns [ 1, -9, -8, 6 ]

i = idx( new Uint8Array( [ 0, 0, 1, 0, 0, 1 ] ) ); // mask array
z = y[ i ];
// returns [ 1, 2, -9, -8 ]
Expand Down
38 changes: 38 additions & 0 deletions benchmark/benchmark.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,41 @@ bench( pkg+'::set,subsequence:len=1', opts, function benchmark( b ) {
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::set,integer_array:len=1', opts, function benchmark( b ) {
var values;
var base;
var opts;
var idx;
var x;
var v;
var i;

base = zeroTo( 100, 'generic' );
x = array2fancy( base );

opts = {
'persist': true
};
values = [
array2fancy.idx( [ 0 ], opts ),
array2fancy.idx( [ 1 ], opts ),
array2fancy.idx( [ 2 ], opts )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
idx = values[ i%values.length ];
x[ idx ] = i * 2;
v = base[ i%3 ];
if ( v !== v ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( v ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
112 changes: 57 additions & 55 deletions dist/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/index.js.map

Large diffs are not rendered by default.

114 changes: 2 additions & 112 deletions docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/// <reference types="@stdlib/types"/>

import { Collection, ArrayLike, AccessorArrayLike, Complex128Array, Complex64Array, ArrayIndexObject } from '@stdlib/types/array';
import { Collection, ArrayLike, AccessorArrayLike, ComplexTypedArray, TypedArray, BooleanTypedArray, ArrayIndexObject } from '@stdlib/types/array';
import ArrayIndex = require( '@stdlib/array-index' );

/**
Expand Down Expand Up @@ -74,17 +74,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
*/
( x: Float64Array, options?: Options ): Float64Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Float32Array = require( '@stdlib/array-float32' );
Expand All @@ -96,17 +85,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Float32Array>[ 1.0, 2.0, 3.0, 4.0 ]
*/
( x: Float32Array, options?: Options ): Float32Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Complex128Array = require( '@stdlib/array-complex128' );
Expand All @@ -118,17 +96,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Complex128Array>[ 1.0, 2.0, 3.0, 4.0 ]
*/
( x: Complex128Array, options?: Options ): Complex128Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Complex64Array = require( '@stdlib/array-complex64' );
Expand All @@ -140,17 +107,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Complex64Array>[ 1.0, 2.0, 3.0, 4.0 ]
*/
( x: Complex64Array, options?: Options ): Complex64Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Int32Array = require( '@stdlib/array-int32' );
Expand All @@ -162,17 +118,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Int32Array>[ 1, 2, 3, 4 ]
*/
( x: Int32Array, options?: Options ): Int32Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Int16Array = require( '@stdlib/array-int16' );
Expand All @@ -184,17 +129,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Int16Array>[ 1, 2, 3, 4 ]
*/
( x: Int16Array, options?: Options ): Int16Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Int8Array = require( '@stdlib/array-int8' );
Expand All @@ -206,17 +140,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Int8Array>[ 1, 2, 3, 4 ]
*/
( x: Int8Array, options?: Options ): Int8Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Uint32Array = require( '@stdlib/array-uint32' );
Expand All @@ -228,17 +151,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Uint32Array>[ 1, 2, 3, 4 ]
*/
( x: Uint32Array, options?: Options ): Uint32Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Uint16Array = require( '@stdlib/array-uint16' );
Expand All @@ -250,17 +162,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Uint16Array>[ 1, 2, 3, 4 ]
*/
( x: Uint16Array, options?: Options ): Uint16Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Uint8Array = require( '@stdlib/array-uint8' );
Expand All @@ -272,17 +173,6 @@ interface Array2Fancy {
*
* var v = y[ ':' ];
* // returns <Uint8Array>[ 1, 2, 3, 4 ]
*/
( x: Uint8Array, options?: Options ): Uint8Array;

/**
* Converts an array to an object supporting fancy indexing.
*
* @param x - input array
* @param options - function options
* @param options.strict - boolean indicating whether to enforce strict bounds checking
* @param options.cache - cache for resolving array index objects
* @returns fancy array
*
* @example
* var Uint8ClampedArray = require( '@stdlib/array-uint8c' );
Expand All @@ -295,7 +185,7 @@ interface Array2Fancy {
* var v = y[ ':' ];
* // returns <Uint8ClampedArray>[ 1, 2, 3, 4 ]
*/
( x: Uint8ClampedArray, options?: Options ): Uint8ClampedArray;
<T extends TypedArray | ComplexTypedArray | BooleanTypedArray>( x: T, options?: Options ): T;

/**
* Converts an array to an object supporting fancy indexing.
Expand Down
2 changes: 2 additions & 0 deletions docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import array2fancy = require( './index' );
array2fancy( new Uint8ClampedArray( [ 1, 2, 3 ] ) ); // $ExpectType Uint8ClampedArray
array2fancy( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ) ); // $ExpectType Complex128Array
array2fancy( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ) ); // $ExpectType Complex64Array
array2fancy( new BooleanArray( [ true, false, true ] ) ); // $ExpectType BooleanArray

const opts = {
'strict': true
Expand All @@ -54,6 +55,7 @@ import array2fancy = require( './index' );
array2fancy( new Uint8ClampedArray( [ 1, 2, 3 ] ), opts ); // $ExpectType Uint8ClampedArray
array2fancy( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), opts ); // $ExpectType Complex128Array
array2fancy( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), opts ); // $ExpectType Complex64Array
array2fancy( new BooleanArray( [ true, false, true ] ), opts ); // $ExpectType BooleanArray
}

// The compiler throws an error if the function is provided a first argument which is not an array-like value...
Expand Down
6 changes: 6 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

var Uint8Array = require( '@stdlib/array-uint8' );
var Int32Array = require( '@stdlib/array-int32' );
var BooleanArray = require( '@stdlib/array-bool' );
var array2fancy = require( './../lib' );

var x = [ 1, 2, 3, 4, 5, 6 ];
Expand Down Expand Up @@ -63,6 +64,11 @@ z = y[ i ];
console.log( z );
// => [ 1, -9, -8, 6 ]

i = idx( new BooleanArray( [ true, false, false, true, true, true ] ) ); // boolean array
z = y[ i ];
console.log( z );
// => [ 1, -9, -8, 6 ]

i = idx( new Uint8Array( [ 0, 0, 1, 0, 0, 1 ] ) ); // mask array
z = y[ i ];
console.log( z );
Expand Down
1 change: 0 additions & 1 deletion lib/get_elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var prop2array = require( './prop2array.js' );
* @param {Object} target - target object
* @param {string} property - index string
* @param {Object} ctx - context object
* @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking
* @param {Object} ctx.cache - cache for resolving array index objects
* @param {Function} ctx.postGetArray - function to process a retrieved array
* @throws {Error} invalid array index
Expand Down
5 changes: 5 additions & 0 deletions lib/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
var hasProperty = require( '@stdlib/assert-has-property' );
var isIntegerString = require( './is_integer_string.js' );
var isArrayIndexString = require( './is_array_index_string.js' );
var setElements = require( './set_elements.js' );
var setElement = require( './set_element.js' );
var setValue = require( './set_value.js' );
var setSlice = require( './set_slice.js' );
Expand Down Expand Up @@ -71,6 +73,9 @@ function factory( ctx ) {
if ( hasProperty( property ) || !isString( property ) ) {
return setValue( target, property, value, ctx );
}
if ( isArrayIndexString( property ) ) {
return setElements( target, property, value, ctx );
}
out = setSlice( target, property, value, receiver, ctx );
if ( out ) {
return out;
Expand Down
Loading

0 comments on commit 29a04c0

Please sign in to comment.