Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add indexOf method to array/complex64 #1191

Merged
merged 14 commits into from
Dec 19, 2023
61 changes: 61 additions & 0 deletions lib/node_modules/@stdlib/array/complex64/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
* @param {*} value - value to test
* @returns {boolean} boolean indicating if a value is a `Complex64Array`
*/
function isComplex64Array( value ) { // TODO: move to array/base/assert/is-complex64-array

Check warning on line 109 in lib/node_modules/@stdlib/array/complex64/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: move to...'
return (
typeof value === 'object' &&
value !== null &&
Expand All @@ -122,7 +122,7 @@
* @param {*} value - value to test
* @returns {boolean} boolean indicating if a value is a `Complex128Array`
*/
function isComplex128Array( value ) { // TODO: move to array/base/assert/is-complex128-array

Check warning on line 125 in lib/node_modules/@stdlib/array/complex64/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: move to...'
return (
typeof value === 'object' &&
value !== null &&
Expand Down Expand Up @@ -281,7 +281,7 @@
}
buf = buf[ ITERATOR_SYMBOL ]();
if ( !isFunction( buf.next ) ) {
throw new TypeError( format( 'invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.', buf ) ); // FIXME: `buf` is what is returned from above, NOT the original value

Check warning on line 284 in lib/node_modules/@stdlib/array/complex64/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: `buf` is what is returned from...'
}
buf = fromIterator( buf );
if ( buf instanceof Error ) {
Expand Down Expand Up @@ -746,7 +746,7 @@
if ( !isComplexArray( this ) ) {
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
}
// FIXME: prefer a functional `copyWithin` implementation which addresses lack of universal browser support (e.g., IE11 and Safari) or ensure that typed arrays are polyfilled

Check warning on line 749 in lib/node_modules/@stdlib/array/complex64/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: prefer a functional `copyWithin`...'
if ( arguments.length === 2 ) {
this._buffer.copyWithin( target*2, start*2 );
} else {
Expand Down Expand Up @@ -971,6 +971,67 @@
return getComplex64( this._buffer, idx );
});

/**

Check failure on line 974 in lib/node_modules/@stdlib/array/complex64/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Encountered an error while running code: `searchFrom is not defined`.Did you mean to include a `// throws <ReferenceError>` annotation instead of `// returns 2`?
* Returns the first index at which a given element can be found.
*
* @name indexOf
* @memberof Complex64Array.prototype
* @type {Function}
* @param {Complex64} searchElement - element to find
* @param {integer} [fromIndex=0] - starting index (inclusive)
* @throws {TypeError} `this` must be a complex number array
* @throws {TypeError} first argument must be a complex number
* @throws {TypeError} second argument must be an nonnegative integer
* @returns {integer} index or -1
*
* @example
* var Complex64 = require( '@stdlib/complex/float32' );
*
* var arr = new Complex64Array( 10 );
*
* arr.set( [ 1.0, -1.0 ], 0 );
* arr.set( [ 2.0, -2.0 ], 1 );
* arr.set( [ 3.0, -3.0 ], 2 );
* arr.set( [ 4.0, -4.0 ], 3 );
* arr.set( [ 5.0, -5.0 ], 4 );
*
* var idx = arr.indexOf( new Complex64( 3.0, -3.0 ) );
* // returns 2
*
* idx = arr.indexOf( new Complex64( 3.0, -3.0 ), 3 );
* // returns -1
*/
setReadOnly( Complex64Array.prototype, 'indexOf', function indexOf( searchElement, fromIndex ) {
var buf;
var idx;
var re;
var im;
var i;
if ( !isComplexArray( this ) ) {
throw new TypeError( 'invalid invocation. `this` is not a complex number array.' );
}
if ( !isComplexLike( searchElement ) ) {
throw new TypeError( format( 'invalid argument. First argument must be a complex number. Value: `%s`.', searchElement ) );
}
if ( arguments.length > 1 ) {
if ( !isNonNegativeInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', fromIndex ) );
}
} else {
searchFrom = 0;

Check failure on line 1021 in lib/node_modules/@stdlib/array/complex64/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'searchFrom' is not defined
kgryte marked this conversation as resolved.
Show resolved Hide resolved
}
re = realf( searchElement );
im = imagf( searchElement );
buf = this._buffer;
for ( i = fromIndex; i < this._length; i++ ) {
idx = 2 * i;
if ( re === buf[ idx ] && im === buf[ idx+1 ] ) {
return i;
}
}
return -1;
});

/**
* Number of array elements.
*
Expand Down Expand Up @@ -1147,7 +1208,7 @@
// We need to copy source values...
tmp = new Float32Array( N );
for ( i = 0; i < N; i++ ) {
tmp[ i ] = sbuf[ i ]; // TODO: handle accessor arrays

Check warning on line 1211 in lib/node_modules/@stdlib/array/complex64/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: handle accessor arrays'
}
sbuf = tmp;
}
Expand Down
Loading