diff --git a/lib/node_modules/@stdlib/array/uint64/README.md b/lib/node_modules/@stdlib/array/uint64/README.md index 02da19409141..3f36af04b09f 100644 --- a/lib/node_modules/@stdlib/array/uint64/README.md +++ b/lib/node_modules/@stdlib/array/uint64/README.md @@ -309,6 +309,42 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the - **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. - **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + + +#### Uint64Array.prototype.fill( value\[, start\[, end]] ) + +Returns a modified typed array filled with a fill value. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( 3 ); + +// Set all elements to the same value: +arr.fill( new Uint64( 1 ) ); +// arr => [ 1n, 1n, 1n ] + +// Fill all elements starting from the second element: +arr.fill( new Uint64( 2 ), 1 ); +// arr => [ 1n, 2n, 2n ] + +// Fill all elements from first element until the second-to-last element: +arr.fill( new Uint64( 3 ), 0, 2 ); +// arr => [ 3n, 3n, 2n ] +``` + +When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var arr = new Uint64Array( 3 ); + +// Set all array elements, except the last element, to the same value: +arr.fill( new Uint64( 1 ), 0, -1 ); +// arr => [ 1n, 1n, 0n ] +``` + #### Uint64Array.prototype.get( i ) diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.js new file mode 100644 index 000000000000..57906323120c --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var format = require( '@stdlib/string/format' ); +var isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:fill', pkg ), function benchmark( b ) { + var values; + var arr; + var out; + var i; + + values = [ + new Uint64( 1 ), + new Uint64( 2 ), + new Uint64( 3 ) + ]; + arr = new Uint64Array( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.fill( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.length.js new file mode 100644 index 000000000000..ca8e0eefc600 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.fill.length.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var format = require( '@stdlib/string/format' ); +var isUint64Array = require( '@stdlib/assert/is-uint64array' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var values; + var out; + var i; + + values = [ + new Uint64( 1 ), + new Uint64( 2 ), + new Uint64( 3 ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.fill( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64Array( out ) ) { + b.fail( 'should return a Uint64Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:fill:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index c737fc5bf588..00ee2dfd0f91 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -275,6 +275,34 @@ true +{{alias}}.prototype.fill( value[, start[, end]] ) + Returns a modified typed array filled with a fill value. + + Parameters + ---------- + value: Uint64 + Fill value. + + start: integer (optional) + Start index. If less than zero, the start index is resolved relative to + the last array element. Default: 0. + + end: integer (optional) + End index (non-inclusive). If less than zero, the end index is resolved + relative to the last array element. Default: out.length. + + Returns + ------- + out: Uint64Array + Modified array. + + Examples + -------- + > var arr = new {{alias}}( 3 ); + > arr.fill( 1 ) + [ 1n, 1n, 1n ] + + {{alias}}.prototype.get( i ) Returns an array element located at integer position (index) `i`. diff --git a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts index 78b11c503625..2f95fc802ff5 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts @@ -454,6 +454,23 @@ declare class Uint64Array implements Uint64ArrayInterface { */ entries(): TypedIterator<[number, Uint64]>; + /** + * Returns a modified typed array filled with a fill value. + * + * @param value - fill value + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @returns modified typed array + * + * @example + * var arr = new Uint64Array( 3 ); + * // returns [ 0n , 0n, 0n ] + * + * arr = arr.fill( 1, 1 ); + * // returns [ 0n, 1n, 1n ] + */ + fill( value: Uint, start?: number, end?: number ): Uint64Array; + /** * Returns an array element. * diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 684cb8e4b9bd..ffa4563fb675 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -702,6 +702,86 @@ setReadOnly( Uint64Array.prototype, 'entries', function entries() { } }); +/** +* Returns a modified typed array filled with a fill value. +* +* @name fill +* @memberof Uint64Array.prototype +* @type {Function} +* @param {(Uint64|bigint|number)} value - fill value +* @param {integer} [start=0] - starting index (inclusive) +* @param {integer} [end] - ending index (exclusive) +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer +* @throws {TypeError} second argument must be an integer +* @throws {TypeError} third argument must be an integer +* @returns {Uint64Array} modified array +* +* @example +* var arr = new Uint64Array( 3 ); +* // returns [ 0n , 0n, 0n ] +* +* arr = arr.fill( 1, 1 ); +* // returns [ 0n, 1n, 1n ] +*/ +setReadOnly( Uint64Array.prototype, 'fill', function fill( value, start, end ) { + var words; + var buf; + var len; + var idx; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isUint64( value ) ) { + try { + value = new Uint64( value ); + } catch ( err ) { // eslint-disable-line no-unused-vars + throw new TypeError( format( 'invalid argument. First argument must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', value ) ); + } + } + buf = this._buffer; + len = this._length; + if ( arguments.length > 1 ) { + if ( !isInteger( start ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', start ) ); + } + if ( start < 0 ) { + start += len; + if ( start < 0 ) { + start = 0; + } + } + if ( arguments.length > 2 ) { + if ( !isInteger( end ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', end ) ); + } + if ( end < 0 ) { + end += len; + if ( end < 0 ) { + end = 0; + } + } + if ( end > len ) { + end = len; + } + } else { + end = len; + } + } else { + start = 0; + end = len; + } + words = [ 0, 0 ]; + toWords( value, words, 1, 0 ); + for ( i = start; i < end; i++ ) { + idx = 2*i; + buf[ idx+indices.HIGH ] = words[ 0 ]; + buf[ idx+indices.LOW ] = words[ 1 ]; + } + return this; +}); + /** * Returns an array element. * diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.fill.js b/lib/node_modules/@stdlib/array/uint64/test/test.fill.js new file mode 100644 index 000000000000..7f8701cc2d63 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.fill.js @@ -0,0 +1,282 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `fill` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'fill' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.fill ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.fill.call( value, new Uint64( 1 ) ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a nonnegative integer, nonnegative bigint, 64-bit unsigned integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + -5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.fill( value ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.fill( new Uint64( 1 ), value ); + }; + } +}); + +tape( 'the method throws an error if provided a third argument which is not an integer', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.fill( new Uint64( 1 ), 0, value ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + var out; + + arr = new Uint64Array(); + out = arr.fill( new Uint64( 1 ) ); + + t.strictEqual( out instanceof Uint64Array, true, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var arr; + var out; + + arr = new Uint64Array( 10 ); + out = arr.fill( new Uint64( 1 ) ); + + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + t.end(); +}); + +tape( 'if called with one argument, the method sets each array element to the provided value', function test( t ) { + var expected; + var arr; + + arr = new Uint64Array( 3 ); + expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + arr.fill( new Uint64( 1 ) ); + + t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); + t.end(); +}); + +// tape( 'if called with two arguments, the method sets each array element to the provided value starting from a start index (inclusive)', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), 1 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'if called with three arguments, the method sets each array element to the provided value starting from a start index (inclusive) until a specified end index (exclusive)', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), 0, 2 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'the method supports negative indices', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), -3, -1 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'if a provided start index resolves to a negative index, the method fills an array starting from the first element', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), -10 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'if a provided end index resolves to an index exceeding the last array element index, the method fills an array until the last element (inclusive)', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), 1, 10 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// }); + +// tape( 'if a provided start index resolves to an index which is greater than or equal to a resolved end index, the method does not fill an array', function test( t ) { +// var expected; +// var arr; + +// arr = new Uint64Array( 3 ); +// expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// arr.fill( new Uint64( 1.0, 1.0 ), 2, 1 ); + +// t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); +// t.end(); +// });