From 1c707c574bcd7584270729d1b81a99b1cc71f6f5 Mon Sep 17 00:00:00 2001 From: Nathan Jang Date: Sun, 1 Dec 2024 12:28:55 +0800 Subject: [PATCH 01/19] fix: resolve merge conflicts --- .../array/fixed-endian-factory/lib/main.js | 50 +++++++++++++++++++ 1 file changed, 50 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 079902a6c333..76bb37669ae8 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 @@ -963,6 +963,56 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli return acc; }); + /** + * Returns a new typed array containing the elements in reversed order. + * + * @name toReversed + * @memberof TypedArray.prototype + * @type {Function} + * @throws {TypeError} `this` is not a typed array + * @returns {TypedArray} reversed array + * + * @example + * var Float64ArrayFE = factory( 'float64' ); + * + * var arr = new Float64ArrayFE( 'little-endian', [1.0, 2.0, 3.0] ); + * + * var out = arr.toReversed(); + * // returns + * + * var v = out.get( 0 ); + * // returns 1.0 + * + * v = out.get( 1 ); + * // returns 2.0 + * + * v = out.get( 2 ); + * // returns 3.0 + */ + setReadOnly( TypedArray.prototype, 'toReversed', function toReversed() { + var obuf; + var out; + var len; + var buf; + var i; + var v; + + if ( !isTypedArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a typed array.' ); + } + + len = this._length; + out = new this.constructor( flag2byteOrder( this._isLE ), len ); + buf = this._buffer; + obuf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + v = buf[ GETTER ]( ( ( len - 1 ) * BYTES_PER_ELEMENT ) - ( i * BYTES_PER_ELEMENT ), this._isLE ); + obuf[ SETTER ]( i * BYTES_PER_ELEMENT, v, this._isLE ); + } + + return out; + }); + /** * Sets an array element. * From 9be5f9eb402a136311330e7a2d8cfbb089550f4c Mon Sep 17 00:00:00 2001 From: Nathan Jang Date: Fri, 29 Nov 2024 22:31:22 +0800 Subject: [PATCH 02/19] test: add tests for toReverse method in array/fixed-endian-factory --- .../test/test.to_reversed.js | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js new file mode 100644 index 000000000000..82e3fdd604de --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js @@ -0,0 +1,120 @@ +/** +* @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 instanceOf = require( '@stdlib/assert/instance-of' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +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( 'attached to the prototype of the main export is a `toReversed` method', function test( t ) { + var ctor = factory( 'float64' ); + t.strictEqual( hasOwnProp( ctor.prototype, 'toReversed' ), true, 'returns expected value' ); + t.strictEqual( isFunction( ctor.prototype.toReversed ), 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] ); + } + + function badValue( value ) { + return function badValue() { + return arr.toReversed.call( value ); + }; + } + t.end(); +}); + +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.toReversed(); + + t.strictEqual(out.length, 0, 'returns expected value'); + t.end(); +}); + +tape( 'the method returns a new typed array containing elements in reverse order', 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 ] ); + expected = new Uint8Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + out = arr.toReversed(); + + t.strictEqual( instanceOf( out, ctor ), true, 'returns expected value' ); + t.notEqual( out, arr, 'returns a new instance' ); + t.strictEqual( out.length, expected.length, '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', 10 ); + out = arr.toReversed(); + + t.strictEqual( out.length, 10, 'returns expected value' ); + t.end(); +}); From f5b6712fa018cc2bb9edbc8da50f21ff9a7546e2 Mon Sep 17 00:00:00 2001 From: Nathan Jang Date: Fri, 29 Nov 2024 22:37:05 +0800 Subject: [PATCH 03/19] bench: add benchmarks for toReverse method in array/fixed-endian-factory --- .../benchmark/benchmark.to_reversed.js | 55 ++++++++++ .../benchmark/benchmark.to_reversed.length.js | 101 ++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js create mode 100644 lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js new file mode 100644 index 000000000000..be982f0d5718 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js @@ -0,0 +1,55 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// VARIABLES // + +var Float64ArrayFE = factory( 'float64' ); + + +// MAIN // + +bench( pkg+':toReversed', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 2.0, 1.0 ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toReversed(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !( out instanceof Float64ArrayFE) ) { + 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.to_reversed.length.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js new file mode 100644 index 000000000000..caf0b0681a66 --- /dev/null +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js @@ -0,0 +1,101 @@ +/** +* @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 zeroTo = require( '@stdlib/array/zero-to' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// 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; + + 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.toReversed(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !( out instanceof Float64ArrayFE ) ) { + b.fail( 'should return a Complex64Array' ); + } + 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+':toReversed:len='+len, f ); + } +} + +main(); From 04f6f815b98b5b43e497ba2e51da5c51b150683c Mon Sep 17 00:00:00 2001 From: Nathan Jang Date: Fri, 29 Nov 2024 22:57:29 +0800 Subject: [PATCH 04/19] docs: add documentation for toReverse method in array/fixed-endian-factory --- .../array/fixed-endian-factory/README.md | 25 +++++++++++++++++++ 1 file changed, 25 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 ab659bbc55ba..b30f6a96a1c0 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/README.md @@ -887,6 +887,31 @@ var count = context.count; // returns 3 ``` + + +#### TypedArray.prototype.toReversed() + +Returns a new typed array containing the elements in reversed order. + +```javascript +var Float64ArrayFE = fixedEndianFactory( 'float64' ); + +var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 3.0 ] ); +// returns + +var out = arr.toReversed(); +// returns + +var v = out.get( 0 ); +// returns 3.0 + +v = out.get( 1 ); +// returns 2.0 + +v = out.get( 2 ); +// returns 1.0 +``` + #### TypedArrayFE.prototype.toString() From b4eeca27a207ded5a65e25d7246f7dd249fcd00a Mon Sep 17 00:00:00 2001 From: Nathan Jang Date: Sun, 1 Dec 2024 11:43:50 +0800 Subject: [PATCH 05/19] fix: add missing test to toReverse method in array/fixed-endian-factory --- .../array/fixed-endian-factory/test/test.to_reversed.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js index 82e3fdd604de..2fa1f38bc098 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js @@ -24,7 +24,6 @@ var tape = require( 'tape' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isFunction = require( '@stdlib/assert/is-function' ); var instanceOf = require( '@stdlib/assert/instance-of' ); -var Uint8Array = require( '@stdlib/array/uint8' ); var factory = require( './../lib' ); @@ -97,11 +96,12 @@ tape( 'the method returns a new typed array containing elements in reverse order ctor = factory( 'float64' ); arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0 ] ); - expected = new Uint8Array( [ 4.0, 3.0, 2.0, 1.0 ] ); + expected = new ctor( 'little-endian', [ 4.0, 3.0, 2.0, 1.0 ] ); out = arr.toReversed(); t.strictEqual( instanceOf( out, ctor ), true, 'returns expected value' ); t.notEqual( out, arr, 'returns a new instance' ); + t.deepEqual( out, expected, 'returns expected value' ); t.strictEqual( out.length, expected.length, 'returns expected value' ); t.end(); }); From 459d8f4f949f0139ecf1373e8d24ef956d55cfa8 Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:06:27 +0800 Subject: [PATCH 06/19] style: add missing space to array/fixed-endian-factory/benchmark Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> --- .../fixed-endian-factory/benchmark/benchmark.to_reversed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js index be982f0d5718..ea337e87e977 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js @@ -47,7 +47,7 @@ bench( pkg+':toReversed', function benchmark( b ) { } } b.toc(); - if ( !( out instanceof Float64ArrayFE) ) { + if ( !( out instanceof Float64ArrayFE ) ) { b.fail( 'should return a Typed Array' ); } b.pass( 'benchmark finished' ); From 361340c997ae2ecab38e4af7f3dfe96db200a549 Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:11:02 +0800 Subject: [PATCH 07/19] fix: capitalise fail message in array/fixed-endian-factory/benchmark Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> --- .../fixed-endian-factory/benchmark/benchmark.to_reversed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js index ea337e87e977..5140086a7dde 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.js @@ -48,7 +48,7 @@ bench( pkg+':toReversed', function benchmark( b ) { } b.toc(); if ( !( out instanceof Float64ArrayFE ) ) { - b.fail( 'should return a Typed Array' ); + b.fail( 'should return a typed array' ); } b.pass( 'benchmark finished' ); b.end(); From a43f6488b4c121d7617cff4d4c38e3c200a10d93 Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:15:33 +0800 Subject: [PATCH 08/19] refactor: edit arr variable declaration in array/fixed-endian-factory/benchmark Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> --- .../benchmark/benchmark.to_reversed.length.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js index caf0b0681a66..d5e568dcf9bf 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js @@ -42,9 +42,7 @@ var Float64ArrayFE = factory( 'float64' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var arr; - - arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) ); + var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) ); return benchmark; /** From 4d1c5ce36711bf4ce0f37f0265ad43243aec2a14 Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:17:23 +0800 Subject: [PATCH 09/19] fix: edit fail message in array/fixed-endian-factory/benchmark Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> --- .../benchmark/benchmark.to_reversed.length.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js index d5e568dcf9bf..bf806c0265c6 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/benchmark/benchmark.to_reversed.length.js @@ -64,7 +64,7 @@ function createBenchmark( len ) { } b.toc(); if ( !( out instanceof Float64ArrayFE ) ) { - b.fail( 'should return a Complex64Array' ); + b.fail( 'should return a typed array' ); } b.pass( 'benchmark finished' ); b.end(); From f770a9c019f1f92ca0dd0f4620a2958a69bbff2c Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:19:15 +0800 Subject: [PATCH 10/19] docs: update JSDoc comment toReversed method in array/fixed-endian-factory Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> --- lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js | 1 + 1 file changed, 1 insertion(+) 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 76bb37669ae8..6b7da595abaf 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 @@ -966,6 +966,7 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli /** * Returns a new typed array containing the elements in reversed order. * + * @private * @name toReversed * @memberof TypedArray.prototype * @type {Function} From 6d03899c5c2ef13b564664c9cd6ca53a98790b29 Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:25:36 +0800 Subject: [PATCH 11/19] docs: edit JSDoc comment to toReversed method in array/fixed-endian-factory Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> --- lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js | 1 + 1 file changed, 1 insertion(+) 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 6b7da595abaf..0d87ab3b7bf2 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 @@ -967,6 +967,7 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli * Returns a new typed array containing the elements in reversed order. * * @private + * @private * @name toReversed * @memberof TypedArray.prototype * @type {Function} From c701482532d21cd11794e4a23327261de6bb85d3 Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:26:56 +0800 Subject: [PATCH 12/19] docs: edit JSDoc comment to toReversed method in array/fixed-endian-factory Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> --- .../array/fixed-endian-factory/lib/main.js | 17 ----------------- 1 file changed, 17 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 0d87ab3b7bf2..10e90e30d1d4 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 @@ -973,23 +973,6 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli * @type {Function} * @throws {TypeError} `this` is not a typed array * @returns {TypedArray} reversed array - * - * @example - * var Float64ArrayFE = factory( 'float64' ); - * - * var arr = new Float64ArrayFE( 'little-endian', [1.0, 2.0, 3.0] ); - * - * var out = arr.toReversed(); - * // returns - * - * var v = out.get( 0 ); - * // returns 1.0 - * - * v = out.get( 1 ); - * // returns 2.0 - * - * v = out.get( 2 ); - * // returns 3.0 */ setReadOnly( TypedArray.prototype, 'toReversed', function toReversed() { var obuf; From fe317dda7a8a9679dd2522e00f44de65de6f485a Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:28:33 +0800 Subject: [PATCH 13/19] perf: minimize arithmetic in array/fixed-endian-factory Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@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 10e90e30d1d4..8ad8287f178e 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 @@ -991,7 +991,7 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli buf = this._buffer; obuf = out._buffer; // eslint-disable-line no-underscore-dangle for ( i = 0; i < len; i++ ) { - v = buf[ GETTER ]( ( ( len - 1 ) * BYTES_PER_ELEMENT ) - ( i * BYTES_PER_ELEMENT ), this._isLE ); + v = buf[ GETTER ]( ( len - i - 1 ) * BYTES_PER_ELEMENT, this._isLE ); obuf[ SETTER ]( i * BYTES_PER_ELEMENT, v, this._isLE ); } From 661d0bc2ae3045ebfb9061680de24603d1719cb5 Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:35:10 +0800 Subject: [PATCH 14/19] style: add missing space to array/fixed-endian-factory/test Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> style: add missing space to array/fixed-endian-factory/test style: add missing space to test for toReversed method --- .../@stdlib/array/fixed-endian-factory/test/test.to_reversed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js index 2fa1f38bc098..be945c234718 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js @@ -84,7 +84,7 @@ tape( 'the method returns an empty array if operating on an empty typed array', arr = new ctor( 'little-endian' ); out = arr.toReversed(); - t.strictEqual(out.length, 0, 'returns expected value'); + t.strictEqual(out.length, 0, 'returns expected value' ); t.end(); }); From 7f4f8beaec01f458c1f24080b6c9bf9705e128a0 Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Sat, 7 Dec 2024 10:43:40 +0800 Subject: [PATCH 15/19] style: remove blank line for toReversed method in array/fixed-endian-factory Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> style: remove blank line for toReversed method in array/fixed-endian-factory style: remove blank line for toReversed method in array/fixed-endian-factory style: remove blank line in toReversed method --- lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js | 1 - 1 file changed, 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 8ad8287f178e..ddf0d620acf4 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 @@ -985,7 +985,6 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli if ( !isTypedArray( this ) ) { throw new TypeError( 'invalid invocation. `this` is not a typed array.' ); } - len = this._length; out = new this.constructor( flag2byteOrder( this._isLE ), len ); buf = this._buffer; From b595cc294dc8864693f13d57107c673aa6cc14ba Mon Sep 17 00:00:00 2001 From: Nate <155411729+nate10j@users.noreply.github.com> Date: Sat, 7 Dec 2024 10:44:24 +0800 Subject: [PATCH 16/19] style: remove blank line for toReversed method in array/fixed-endian-factory Co-authored-by: Athan Signed-off-by: Nate <155411729+nate10j@users.noreply.github.com> style: remove blank line for toReversed method in array/fixed-endian-factory style: remove blank line in toReversed method in array/fixed-endian-factory style: remove blank line for toReversed method --- lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js | 1 - 1 file changed, 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 ddf0d620acf4..4ba1cd169210 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 @@ -993,7 +993,6 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli v = buf[ GETTER ]( ( len - i - 1 ) * BYTES_PER_ELEMENT, this._isLE ); obuf[ SETTER ]( i * BYTES_PER_ELEMENT, v, this._isLE ); } - return out; }); From da970816ad0355b212ab3282b2589cc593d7ed46 Mon Sep 17 00:00:00 2001 From: Nathan Jang Date: Sat, 7 Dec 2024 11:48:30 +0800 Subject: [PATCH 17/19] docs: remove duplicate JSDoc comment in array/fixed-endian-factory --- lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js | 1 - 1 file changed, 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 4ba1cd169210..4953cd471346 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 @@ -967,7 +967,6 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli * Returns a new typed array containing the elements in reversed order. * * @private - * @private * @name toReversed * @memberof TypedArray.prototype * @type {Function} From 328ba9d0ac95b23990dfdc5ad6ee795f3ff21bd1 Mon Sep 17 00:00:00 2001 From: Nathan Jang Date: Sat, 7 Dec 2024 12:02:32 +0800 Subject: [PATCH 18/19] test: use hasSameValues method to test in array/fixed-endian-factory --- .../array/fixed-endian-factory/test/test.to_reversed.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js index be945c234718..a473f84242a0 100644 --- a/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js +++ b/lib/node_modules/@stdlib/array/fixed-endian-factory/test/test.to_reversed.js @@ -24,6 +24,7 @@ var tape = require( 'tape' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isFunction = require( '@stdlib/assert/is-function' ); var instanceOf = require( '@stdlib/assert/instance-of' ); +var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' ); var factory = require( './../lib' ); @@ -101,7 +102,7 @@ tape( 'the method returns a new typed array containing elements in reverse order t.strictEqual( instanceOf( out, ctor ), true, 'returns expected value' ); t.notEqual( out, arr, 'returns a new instance' ); - t.deepEqual( out, expected, 'returns expected value' ); + t.strictEqual( hasSameValues( out, expected ), true, 'returns expected value' ); t.strictEqual( out.length, expected.length, 'returns expected value' ); t.end(); }); From 0e0154c292408c8b033d871da0248a90e35f5492 Mon Sep 17 00:00:00 2001 From: Nathan Jang Date: Sat, 7 Dec 2024 12:15:48 +0800 Subject: [PATCH 19/19] style: insert toReversed in alphabetic order in array/fixed-endian-factory --- .../array/fixed-endian-factory/lib/main.js | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 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 4953cd471346..473cfe6eef8e 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 @@ -963,38 +963,6 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli return acc; }); - /** - * Returns a new typed array containing the elements in reversed order. - * - * @private - * @name toReversed - * @memberof TypedArray.prototype - * @type {Function} - * @throws {TypeError} `this` is not a typed array - * @returns {TypedArray} reversed array - */ - setReadOnly( TypedArray.prototype, 'toReversed', function toReversed() { - var obuf; - var out; - var len; - var buf; - var i; - var v; - - if ( !isTypedArray( this ) ) { - throw new TypeError( 'invalid invocation. `this` is not a typed array.' ); - } - len = this._length; - out = new this.constructor( flag2byteOrder( this._isLE ), len ); - buf = this._buffer; - obuf = out._buffer; // eslint-disable-line no-underscore-dangle - for ( i = 0; i < len; i++ ) { - v = buf[ GETTER ]( ( len - i - 1 ) * BYTES_PER_ELEMENT, this._isLE ); - obuf[ SETTER ]( i * BYTES_PER_ELEMENT, v, this._isLE ); - } - return out; - }); - /** * Sets an array element. * @@ -1121,6 +1089,38 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli return false; }); + /** + * Returns a new typed array containing the elements in reversed order. + * + * @private + * @name toReversed + * @memberof TypedArray.prototype + * @type {Function} + * @throws {TypeError} `this` is not a typed array + * @returns {TypedArray} reversed array + */ + setReadOnly( TypedArray.prototype, 'toReversed', function toReversed() { + var obuf; + var out; + var len; + var buf; + var i; + var v; + + if ( !isTypedArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a typed array.' ); + } + len = this._length; + out = new this.constructor( flag2byteOrder( this._isLE ), len ); + buf = this._buffer; + obuf = out._buffer; // eslint-disable-line no-underscore-dangle + for ( i = 0; i < len; i++ ) { + v = buf[ GETTER ]( ( len - i - 1 ) * BYTES_PER_ELEMENT, this._isLE ); + obuf[ SETTER ]( i * BYTES_PER_ELEMENT, v, this._isLE ); + } + return out; + }); + /** * Serializes an array as a string. *