From 08b4b49a6fbd847b2d0c2e2878fa6531723295e7 Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Thu, 28 Nov 2024 13:56:10 +0200 Subject: [PATCH 01/16] feat: add reverse method logic --- .../array/fixed-endian-factory/lib/main.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js index 3cb7a82e6997..2ea8066f4bcd 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js @@ -676,6 +676,41 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli return -1; }); + /** + * Reverse an array in-place. + * + * @private + * @name reverse + * @memberof TypedArray.prototype + * @type {Function} + * @throws {TypeError} `this` must be a typed array + * @returns {TypedArray} reversed array + */ + setReadOnly( TypedArray.prototype, 'reverse', function reverse( ) { + var buf; + var tmp; + var len; + var N; + var i; + var j; + + if ( !isTypedArray( this ) ) { + throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) ); + } + buf = this._buffer; + len = this._length; + + // Compute floor of len / 2 + N = ( ( len + 1 ) / 2 * 2 ) - ( len % 2 ); + for ( i = 0; i < N; i++ ) { + j=len-i-1; + tmp=buf[i]; + buf[i]=buf[j]; + buf[j]=tmp; + } + return this; + }); + /** * Number of array elements. * From 853dff1b77ba9c636aff0a51bca99307fec2bc01 Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Thu, 28 Nov 2024 14:21:51 +0200 Subject: [PATCH 02/16] feat: add benchmark for reverse method --- .../benchmark/benchmark.reverse.js | 56 ++++++++++ .../benchmark/benchmark.reverse.length.js | 100 ++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.js create mode 100644 lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.length.js diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.js new file mode 100644 index 000000000000..b5d51aa386b8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isTypedArray= require( '@stdlib/assert/is-typed-array' ); +var factory = require( './../lib' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+':reverse', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reverse( ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isTypedArray( out ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.length.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.length.js new file mode 100644 index 000000000000..3210f5f700f0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.length.js @@ -0,0 +1,100 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 pow = require( '@stdlib/math/base/special/pow' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var factory = require( './../lib' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reverse( ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isTypedArray( out ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':reverse:len='+len, f ); + } +} + +main(); From f1bb538e08b7c724492263607ca1124b333fc2c5 Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Thu, 28 Nov 2024 15:48:46 +0200 Subject: [PATCH 03/16] test: add tests for reverse method --- .../fixed-endian-factory/test/test.reverse.js | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js new file mode 100644 index 000000000000..dfd21c34a5ad --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 factory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a function', function test( t ) { + var ctor = factory( 'float64' ); + t.strictEqual( isFunction( ctor ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the prototype of the returned function is a `reverse` method', function test( t ) { + var ctor = factory( 'float64' ); + t.strictEqual( hasOwnProp( ctor.prototype, 'reverse' ), true, 'returns expected value' ); + t.strictEqual( isFunction( ctor.prototype.reverse ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance', function test( t ) { + var values; + var ctor; + var arr; + var i; + + ctor = factory( 'float64' ); + arr = new ctor( 'little-endian', 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.reverse.call( value, 0 ); + }; + } +}); + +tape( 'the method returns an empty array if operating on an empty typed array', function test( t ) { + var ctor; + var arr; + var out; + + ctor = factory( 'float64' ); + arr = new ctor('little-endian'); + out = arr.reverse(); + t.strictEqual( out.buffer, arr.buffer, 'returns expected value' ); + t.strictEqual( out.length, 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the method reverses elements of a typed array in-place', function test( t ) { + var expected; + var ctor; + var arr; + var out; + + ctor = factory( 'float64' ); + arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + expected = new ctor('little-endian', [ 5.0, 4.0, 3.0, 2.0, 1.0 ] ); + out = arr.reverse(); + + t.strictEqual( out instanceof ctor, true, 'returns expected value' ); + t.strictEqual( out, arr, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method does not change the array length', function test( t ) { + var ctor; + var arr; + var out; + + ctor = factory( 'float64' ); + arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + out = arr.reverse(); + + t.strictEqual( out.length, 5, 'returns expected value' ); + t.end(); +}); From 3e47bf5fe8be93d5bf32adb81f547c3805957140 Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Thu, 28 Nov 2024 16:38:41 +0200 Subject: [PATCH 04/16] docs: add documentation for reverse method --- .../array/fixed-endian-factory/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md b/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md index 46e322fe4eed..8319129c09e8 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md @@ -515,6 +515,24 @@ var idx = arr.indexOf( 5.0 ); // returns -1 ``` + + +#### TypedArrayFE.prototype.reverse() + +Reverses an array in-place. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); + +var out=arr.reverse(); +// returns + +var v=out.get(1); +// returns 2.0 +``` + #### TypedArray.prototype.map( callbackFn\[, thisArg] ) From e7bdce93b2741abfa7c404aaa93ae2dcd3ecd719 Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Thu, 28 Nov 2024 18:57:46 +0200 Subject: [PATCH 05/16] docs: add documentation for reverse method --- .../@stdlib/array/fixed-endian-factory/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md b/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md index 8319129c09e8..52f069486b87 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md @@ -525,12 +525,20 @@ Reverses an array in-place. var Float64ArrayFE = fixedEndianFactory( 'float64' ); var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); +// returns var out=arr.reverse(); // returns -var v=out.get(1); +var v=out.get(0); +// returns 3.0 + +v=out.get(1); // returns 2.0 + +v=out.get(2); +// returns 1.0 + ``` From 55d746b65d0e59b80ad70beb3fc92884c1a5fcf8 Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Thu, 28 Nov 2024 19:14:11 +0200 Subject: [PATCH 06/16] fix: fix reverse logic --- .../@stdlib/array/fixed-endian-factory/lib/main.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js index 2ea8066f4bcd..ba75267b0c8d 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js @@ -44,6 +44,7 @@ var contains = require( '@stdlib/array/base/assert/contains' ).factory; var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); var capitalize = require( '@stdlib/string/base/capitalize' ); var format = require( '@stdlib/string/format' ); +var floor = require( '@stdlib/math/base/special/floor' ); var fromIterator = require( './from_iterator.js' ); var fromIteratorMap = require( './from_iterator_map.js' ); @@ -699,14 +700,12 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli } buf = this._buffer; len = this._length; - - // Compute floor of len / 2 - N = ( ( len + 1 ) / 2 * 2 ) - ( len % 2 ); + N = floor(len / 2); for ( i = 0; i < N; i++ ) { j=len-i-1; - tmp=buf[i]; - buf[i]=buf[j]; - buf[j]=tmp; + tmp=buf[ GETTER ]( i*BYTES_PER_ELEMENT, this._isLE ); + buf[ SETTER ]( i*BYTES_PER_ELEMENT, buf[ GETTER ]( j*BYTES_PER_ELEMENT, this._isLE ), this._isLE ); + buf[ SETTER ]( j*BYTES_PER_ELEMENT, tmp, this._isLE ); } return this; }); From 1196a8910073ed17ae9ee3dd30f05f171164e363 Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Thu, 28 Nov 2024 19:15:47 +0200 Subject: [PATCH 07/16] test: fix tests for reverse method --- .../fixed-endian-factory/test/test.reverse.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js index dfd21c34a5ad..e282d861b84e 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js @@ -95,19 +95,28 @@ tape( 'the method returns an empty array if operating on an empty typed array', tape( 'the method reverses elements of a typed array in-place', function test( t ) { var expected; + var values; var ctor; var arr; var out; + var i; ctor = factory( 'float64' ); arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - expected = new ctor('little-endian', [ 5.0, 4.0, 3.0, 2.0, 1.0 ] ); + expected = [ 5.0, 4.0, 3.0, 2.0, 1.0 ]; out = arr.reverse(); - + values = []; + fcn(); t.strictEqual( out instanceof ctor, true, 'returns expected value' ); t.strictEqual( out, arr, 'returns expected value' ); t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); + t.deepEqual( values, expected, 'returns expected value' ); + + function fcn() { + for ( i = 0; i < 5; i++) { + values.push(arr.at(i)); + } + } t.end(); }); From 7cd3e9c85519498bfde4ea4af65b8cb99c648314 Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Thu, 28 Nov 2024 19:24:01 +0200 Subject: [PATCH 08/16] test: update test for reverse method --- .../@stdlib/array/fixed-endian-factory/test/test.reverse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js index e282d861b84e..c91c3577fb52 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js @@ -113,7 +113,7 @@ tape( 'the method reverses elements of a typed array in-place', function test( t t.deepEqual( values, expected, 'returns expected value' ); function fcn() { - for ( i = 0; i < 5; i++) { + for ( i = 0; i < arr.length; i++) { values.push(arr.at(i)); } } From d84bfe5eaa2c4d1785fc80843a3d1f51e9e4005f Mon Sep 17 00:00:00 2001 From: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:21:21 +0200 Subject: [PATCH 09/16] Update lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js Co-authored-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Signed-off-by: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> --- lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js index ba75267b0c8d..ce599c4fd1a9 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js @@ -700,7 +700,7 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli } buf = this._buffer; len = this._length; - N = floor(len / 2); + N = floor( len / 2 ); for ( i = 0; i < N; i++ ) { j=len-i-1; tmp=buf[ GETTER ]( i*BYTES_PER_ELEMENT, this._isLE ); From 58de63175d87e678b62f845be7f3643a72527113 Mon Sep 17 00:00:00 2001 From: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:27:22 +0200 Subject: [PATCH 10/16] Update lib/node_modules/@stdlib/array/fixed-endian-factory/README.md Co-authored-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Signed-off-by: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> --- .../@stdlib/array/fixed-endian-factory/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md b/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md index 52f069486b87..9c8acd43bdc0 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md @@ -527,16 +527,16 @@ var Float64ArrayFE = fixedEndianFactory( 'float64' ); var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); // returns -var out=arr.reverse(); +var out = arr.reverse(); // returns -var v=out.get(0); +var v = out.get( 0 ); // returns 3.0 -v=out.get(1); +v = out.get( 1 ); // returns 2.0 -v=out.get(2); +v = out.get( 2 ); // returns 1.0 ``` From ae68d95efb106018305b56481173cb6f3b48ac0b Mon Sep 17 00:00:00 2001 From: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:27:33 +0200 Subject: [PATCH 11/16] Update lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js Co-authored-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Signed-off-by: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> --- lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js index ce599c4fd1a9..c621bc1e84d5 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js @@ -702,7 +702,7 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli len = this._length; N = floor( len / 2 ); for ( i = 0; i < N; i++ ) { - j=len-i-1; + j = len-i-1; tmp=buf[ GETTER ]( i*BYTES_PER_ELEMENT, this._isLE ); buf[ SETTER ]( i*BYTES_PER_ELEMENT, buf[ GETTER ]( j*BYTES_PER_ELEMENT, this._isLE ), this._isLE ); buf[ SETTER ]( j*BYTES_PER_ELEMENT, tmp, this._isLE ); From eab6e02dfac1511b9dd86f44f2cf856ffcb159d7 Mon Sep 17 00:00:00 2001 From: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:27:42 +0200 Subject: [PATCH 12/16] Update lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js Co-authored-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Signed-off-by: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> --- lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js index c621bc1e84d5..99c03dd90e73 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js @@ -703,7 +703,7 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli N = floor( len / 2 ); for ( i = 0; i < N; i++ ) { j = len-i-1; - tmp=buf[ GETTER ]( i*BYTES_PER_ELEMENT, this._isLE ); + tmp = buf[ GETTER ]( i*BYTES_PER_ELEMENT, this._isLE ); buf[ SETTER ]( i*BYTES_PER_ELEMENT, buf[ GETTER ]( j*BYTES_PER_ELEMENT, this._isLE ), this._isLE ); buf[ SETTER ]( j*BYTES_PER_ELEMENT, tmp, this._isLE ); } From 4ddca670d246478acafe9bccc62e0bbe3548b49a Mon Sep 17 00:00:00 2001 From: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:27:52 +0200 Subject: [PATCH 13/16] Update lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js Co-authored-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Signed-off-by: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> --- .../@stdlib/array/fixed-endian-factory/test/test.reverse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js index c91c3577fb52..7697810efe57 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js @@ -114,7 +114,7 @@ tape( 'the method reverses elements of a typed array in-place', function test( t function fcn() { for ( i = 0; i < arr.length; i++) { - values.push(arr.at(i)); + values.push( arr.at( i ) ); } } t.end(); From 44c7097ea4fb9aa7dd78d4c934144dce2d92a064 Mon Sep 17 00:00:00 2001 From: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:28:01 +0200 Subject: [PATCH 14/16] Update lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js Co-authored-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Signed-off-by: Ahmed_Kashkoush <89735230+ahmad-kashkoush@users.noreply.github.com> --- .../@stdlib/array/fixed-endian-factory/test/test.reverse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js index 7697810efe57..17ac5bebd6bf 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js @@ -113,7 +113,7 @@ tape( 'the method reverses elements of a typed array in-place', function test( t t.deepEqual( values, expected, 'returns expected value' ); function fcn() { - for ( i = 0; i < arr.length; i++) { + for ( i = 0; i < arr.length; i++ ) { values.push( arr.at( i ) ); } } From bf43f4c62b20fbcb6bbd53063748cf30fa32b5af Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Wed, 4 Dec 2024 18:57:39 +0200 Subject: [PATCH 15/16] refactor: update type checking in benchmark --- .../fixed-endian-factory/benchmark/benchmark.reverse.js | 3 +-- .../benchmark/benchmark.reverse.length.js | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.js index b5d51aa386b8..31d797d79560 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.js @@ -21,7 +21,6 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var isTypedArray= require( '@stdlib/assert/is-typed-array' ); var factory = require( './../lib' ); var pkg = require( './../package.json' ).name; @@ -48,7 +47,7 @@ bench( pkg+':reverse', function benchmark( b ) { } } b.toc(); - if ( !isTypedArray( out ) ) { + if ( !( out instanceof Float64ArrayFE ) ) { b.fail( 'should return a typed array' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.length.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.length.js index 3210f5f700f0..bdbc03292792 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.length.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.reverse.length.js @@ -23,7 +23,6 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var zeroTo = require( '@stdlib/array/zero-to' ); -var isTypedArray = require( '@stdlib/assert/is-typed-array' ); var factory = require( './../lib' ); var pkg = require( './../package.json' ).name; @@ -58,13 +57,13 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = arr.reverse( ); + out = arr.reverse(); if ( typeof out !== 'object' ) { b.fail( 'should return an object' ); } } b.toc(); - if ( !isTypedArray( out ) ) { + if ( !( out instanceof Float64ArrayFE ) ) { b.fail( 'should return a typed array' ); } b.pass( 'benchmark finished' ); From 3687f8cf03913f703a0cb18cafbfe6c50cf2fdbc Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Wed, 4 Dec 2024 18:58:18 +0200 Subject: [PATCH 16/16] refactor: replace fcn with hasSameValues --- .../array/fixed-endian-factory/lib/main.js | 6 +++--- .../fixed-endian-factory/test/test.reverse.js | 16 ++++------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js index 696c4061e49d..8d76dcc65df7 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js @@ -947,9 +947,9 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli len = this._length; N = floor( len / 2 ); for ( i = 0; i < N; i++ ) { - j = len-i-1; - tmp = buf[ GETTER ]( i*BYTES_PER_ELEMENT, this._isLE ); - buf[ SETTER ]( i*BYTES_PER_ELEMENT, buf[ GETTER ]( j*BYTES_PER_ELEMENT, this._isLE ), this._isLE ); + j = len - i - 1; + tmp = buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ); + buf[ SETTER ]( i * BYTES_PER_ELEMENT, buf[ GETTER ]( j*BYTES_PER_ELEMENT, this._isLE ), this._isLE ); buf[ SETTER ]( j*BYTES_PER_ELEMENT, tmp, this._isLE ); } return this; diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js index 17ac5bebd6bf..ad23a2a4ae89 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.reverse.js @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' ); var isFunction = require( '@stdlib/assert/is-function' ); var factory = require( './../lib' ); @@ -95,28 +96,19 @@ tape( 'the method returns an empty array if operating on an empty typed array', tape( 'the method reverses elements of a typed array in-place', function test( t ) { var expected; - var values; var ctor; var arr; var out; - var i; ctor = factory( 'float64' ); arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - expected = [ 5.0, 4.0, 3.0, 2.0, 1.0 ]; + expected = new ctor( 'little-endian', [ 5.0, 4.0, 3.0, 2.0, 1.0 ] ); out = arr.reverse(); - values = []; - fcn(); + t.strictEqual( out instanceof ctor, true, 'returns expected value' ); t.strictEqual( out, arr, 'returns expected value' ); t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( values, expected, 'returns expected value' ); - - function fcn() { - for ( i = 0; i < arr.length; i++ ) { - values.push( arr.at( i ) ); - } - } + t.strictEqual( hasSameValues(out, expected), true, 'returns expected value' ); t.end(); });