From c38d37151751b6ad1f3e7b2b91d6701e948f831c Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 30 Sep 2024 01:24:38 +0000 Subject: [PATCH] Update artifacts --- blas/ext/base/dsort2ins/coverage.ndjson | 1 + blas/ext/base/dsort2ins/dsort2ins.js.html | 652 ++++++++++++++++++ .../base/dsort2ins/dsort2ins.native.js.html | 268 +++++++ blas/ext/base/dsort2ins/index.html | 206 ++++++ blas/ext/base/dsort2ins/index.js.html | 325 +++++++++ blas/ext/base/dsort2ins/main.js.html | 190 +++++ blas/ext/base/dsort2ins/native.js.html | 190 +++++ blas/ext/base/dsort2ins/ndarray.js.html | 643 +++++++++++++++++ .../ext/base/dsort2ins/ndarray.native.js.html | 325 +++++++++ 9 files changed, 2800 insertions(+) create mode 100644 blas/ext/base/dsort2ins/coverage.ndjson create mode 100644 blas/ext/base/dsort2ins/dsort2ins.js.html create mode 100644 blas/ext/base/dsort2ins/dsort2ins.native.js.html create mode 100644 blas/ext/base/dsort2ins/index.html create mode 100644 blas/ext/base/dsort2ins/index.js.html create mode 100644 blas/ext/base/dsort2ins/main.js.html create mode 100644 blas/ext/base/dsort2ins/native.js.html create mode 100644 blas/ext/base/dsort2ins/ndarray.js.html create mode 100644 blas/ext/base/dsort2ins/ndarray.native.js.html diff --git a/blas/ext/base/dsort2ins/coverage.ndjson b/blas/ext/base/dsort2ins/coverage.ndjson new file mode 100644 index 000000000..2694a15de --- /dev/null +++ b/blas/ext/base/dsort2ins/coverage.ndjson @@ -0,0 +1 @@ +[666,666,100,74,74,100,4,4,100,666,666,100,"cf62100c3ef0fe8318291d861f7db73ff3acec33","2024-09-29 21:22:14 -0400"] diff --git a/blas/ext/base/dsort2ins/dsort2ins.js.html b/blas/ext/base/dsort2ins/dsort2ins.js.html new file mode 100644 index 000000000..0622d0074 --- /dev/null +++ b/blas/ext/base/dsort2ins/dsort2ins.js.html @@ -0,0 +1,652 @@ + + + + +
++ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 | 2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +22x +22x +22x +22x +22x +22x +22x +22x +22x +22x +22x +22x +22x +22x +22x +22x +3x +3x +19x +22x +9x +9x +9x +22x +9x +9x +22x +10x +10x +10x +19x +19x +22x +9x +9x +9x +9x +9x +9x +9x +38x +38x +38x +38x +38x +4x +4x +4x +4x +4x +12x +12x +12x +12x +12x +4x +4x +38x +34x +34x +34x +34x +34x +34x +75x +75x +25x +25x +25x +50x +50x +50x +50x +50x +34x +34x +34x +34x +34x +38x +9x +9x +10x +10x +10x +10x +10x +10x +22x +42x +42x +42x +42x +42x +4x +4x +4x +4x +4x +8x +8x +8x +8x +8x +4x +4x +42x +38x +38x +38x +38x +38x +38x +71x +71x +22x +22x +22x +49x +49x +49x +49x +49x +38x +38x +38x +38x +38x +42x +10x +22x +2x +2x +2x +2x +2x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} order - sort order +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` index increment +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` index increment +* @returns {Float64Array} `x` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); +* var y = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); +* +* dsort2ins( x.length, 1.0, x, 1, y, 1 ); +* +* console.log( x ); +* // => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ] +* +* console.log( y ); +* // => <Float64Array>[ 3.0, 1.0, 0.0, 2.0 ] +*/ +function dsort2ins( N, order, x, strideX, y, strideY ) { + var flg; + var ix; + var jx; + var fx; + var lx; + var iy; + var jy; + var fy; + var ly; + var vx; + var vy; + var ux; + var i; + + if ( N <= 0 || order === 0.0 ) { + return x; + } + // For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order... + if ( order < 0.0 ) { + strideX *= -1; + strideY *= -1; + } + if ( strideY < 0 ) { + fy = (1-N) * strideY; + ly = 0; + } else { + fy = 0; + ly = (N-1) * strideY; + } + iy = fy + strideY; + + if ( strideX < 0 ) { + // Traverse the strided array from right-to-left... + fx = (1-N) * strideX; // first index + lx = 0; // last index + ix = fx + strideX; + + // Sort in increasing order... + for ( i = 1; i < N; i++ ) { + vx = x[ ix ]; + vy = y[ iy ]; + + // Sort `NaN` values to the end (i.e., the left)... + if ( isnan( vx ) ) { + jx = ix; + jy = iy; + + // Shift all values (including NaNs) to the left of the current element to the right... + while ( jx > lx ) { + x[ jx ] = x[ jx+strideX ]; + y[ jy ] = y[ jy+strideY ]; + jx += strideX; + jy += strideY; + } + x[ lx ] = vx; + y[ ly ] = vy; + } else { + flg = isNegativeZero( vx ); + jx = ix - strideX; + jy = iy - strideY; + + // Shift all larger values to the right of the current element to the left... + while ( jx <= fx ) { + ux = x[ jx ]; + if ( ux <= vx && !(flg && ux === vx && isNegativeZero( ux ) === false) ) { // eslint-disable-line max-len + // Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left + break; + } + x[ jx+strideX ] = ux; + y[ jy+strideY ] = y[ jy ]; + jx -= strideX; + jy -= strideY; + } + x[ jx+strideX ] = vx; + y[ jy+strideY ] = vy; + ix += strideX; + iy += strideY; + } + } + return x; + } + // Traverse the strided array from left-to-right... + fx = 0; // first index + lx = (N-1) * strideX; // last index + ix = fx + strideX; + + // Sort in increasing order... + for ( i = 1; i < N; i++ ) { + vx = x[ ix ]; + vy = y[ iy ]; + + // Sort `NaN` values to the end... + if ( isnan( vx ) ) { + jx = ix; + jy = iy; + + // Shift all values (including NaNs) to the right of the current element to the left... + while ( jx < lx ) { + x[ jx ] = x[ jx+strideX ]; + y[ jy ] = y[ jy+strideY ]; + jx += strideX; + jy += strideY; + } + x[ lx ] = vx; + y[ ly ] = vy; + } else { + flg = isNegativeZero( vx ); + jx = ix - strideX; + jy = iy - strideY; + + // Shift all larger values to the left of the current element to the right... + while ( jx >= fx ) { + ux = x[ jx ]; + if ( ux <= vx && !(flg && ux === vx && isNegativeZero( ux ) === false) ) { // eslint-disable-line max-len + // Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right + break; + } + x[ jx+strideX ] = ux; + y[ jy+strideY ] = y[ jy ]; + jx -= strideX; + jy -= strideY; + } + x[ jx+strideX ] = vx; + y[ jy+strideY ] = vy; + ix += strideX; + iy += strideY; + } + } + return x; +} + + +// EXPORTS // + +module.exports = dsort2ins; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 | 3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +46x +46x +46x +46x +3x +3x +3x +3x +3x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} order - sort order +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` index increment +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` index increment +* @returns {Float64Array} `x` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); +* var y = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); +* +* dsort2ins( x.length, 1.0, x, 1, y, 1 ); +* +* console.log( x ); +* // => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ] +* +* console.log( y ); +* // => <Float64Array>[ 3.0, 1.0, 0.0, 2.0 ] +*/ +function dsort2ins( N, order, x, strideX, y, strideY ) { + addon( N, order, x, strideX, y, strideY ); + return x; +} + + +// EXPORTS // + +module.exports = dsort2ins; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
---|---|---|---|---|---|---|---|---|---|
dsort2ins.js | +
+
+ |
+ 100% | +189/189 | +100% | +33/33 | +100% | +1/1 | +100% | +189/189 | +
dsort2ins.native.js | +
+
+ |
+ 100% | +61/61 | +100% | +2/2 | +100% | +1/1 | +100% | +61/61 | +
index.js | +
+
+ |
+ 100% | +80/80 | +100% | +3/3 | +100% | +0/0 | +100% | +80/80 | +
main.js | +
+
+ |
+ 100% | +35/35 | +100% | +1/1 | +100% | +0/0 | +100% | +35/35 | +
native.js | +
+
+ |
+ 100% | +35/35 | +100% | +1/1 | +100% | +0/0 | +100% | +35/35 | +
ndarray.js | +
+
+ |
+ 100% | +186/186 | +100% | +30/30 | +100% | +1/1 | +100% | +186/186 | +
ndarray.native.js | +
+
+ |
+ 100% | +80/80 | +100% | +4/4 | +100% | +1/1 | +100% | +80/80 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 | 3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +1x +3x +2x +2x +3x +3x +3x +3x +3x +3x +3x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2020 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'; + +/** +* Simultaneously sort two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort. +* +* @module @stdlib/blas/ext/base/dsort2ins +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dsort2ins = require( '@stdlib/blas/ext/base/dsort2ins' ); +* +* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); +* var y = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); +* +* dsort2ins( x.length, 1.0, x, 1, y, 1 ); +* +* console.log( x ); +* // => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ] +* +* console.log( y ); +* // => <Float64Array>[ 3.0, 1.0, 0.0, 2.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dsort2ins = require( '@stdlib/blas/ext/base/dsort2ins' ); +* +* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); +* var y = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); +* +* dsort2ins( x.length, 1.0, x, 1, 0, y, 1, 0 ); +* +* console.log( x ); +* // => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ] +* +* console.log( y ); +* // => <Float64Array>[ 3.0, 1.0, 0.0, 2.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var dsort2ins; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dsort2ins = main; +} else { + dsort2ins = tmp; +} + + +// EXPORTS // + +module.exports = dsort2ins; + +// exports: { "ndarray": "dsort2ins.ndarray" } + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 | 1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dsort2ins = require( './dsort2ins.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dsort2ins, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dsort2ins; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 | 1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dsort2ins = require( './dsort2ins.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( dsort2ins, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dsort2ins; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 | 2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +24x +24x +24x +24x +24x +24x +24x +24x +24x +24x +24x +24x +24x +24x +24x +24x +3x +3x +21x +24x +10x +10x +10x +10x +10x +21x +21x +21x +21x +21x +21x +21x +21x +24x +10x +10x +10x +10x +40x +40x +40x +40x +40x +4x +4x +4x +4x +4x +12x +12x +12x +12x +12x +4x +4x +40x +36x +36x +36x +36x +36x +36x +78x +78x +27x +27x +27x +51x +51x +51x +51x +51x +36x +36x +36x +36x +36x +40x +10x +10x +11x +11x +11x +24x +44x +44x +44x +44x +44x +4x +4x +4x +4x +4x +8x +8x +8x +8x +8x +4x +4x +44x +40x +40x +40x +40x +40x +40x +74x +74x +22x +22x +22x +52x +52x +52x +52x +52x +40x +40x +40x +40x +40x +44x +11x +24x +2x +2x +2x +2x +2x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} order - sort order +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` index increment +* @param {NonNegativeInteger} offsetX - `x` starting index +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` index increment +* @param {NonNegativeInteger} offsetY - `y` starting index +* @returns {Float64Array} `x` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); +* var y = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); +* +* dsort2ins( x.length, 1.0, x, 1, 0, y, 1, 0 ); +* +* console.log( x ); +* // => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ] +* +* console.log( y ); +* // => <Float64Array>[ 3.0, 1.0, 0.0, 2.0 ] +*/ +function dsort2ins( N, order, x, strideX, offsetX, y, strideY, offsetY ) { + var flg; + var ix; + var jx; + var fx; + var lx; + var iy; + var jy; + var fy; + var ly; + var vx; + var vy; + var ux; + var i; + + if ( N <= 0 || order === 0.0 ) { + return x; + } + // For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order... + if ( order < 0.0 ) { + strideX *= -1; + strideY *= -1; + offsetX -= (N-1) * strideX; + offsetY -= (N-1) * strideY; + } + fx = offsetX; // first index + lx = fx + ((N-1)*strideX); // last index + ix = fx + strideX; + + fy = offsetY; // first index + ly = fy + ((N-1)*strideY); // last index + iy = fy + strideY; + + if ( strideX < 0 ) { + // Traverse the strided array from right-to-left... + + // Sort in increasing order... + for ( i = 1; i < N; i++ ) { + vx = x[ ix ]; + vy = y[ iy ]; + + // Sort `NaN` values to the end (i.e., the left)... + if ( isnan( vx ) ) { + jx = ix; + jy = iy; + + // Shift all values (including NaNs) to the left of the current element to the right... + while ( jx > lx ) { + x[ jx ] = x[ jx+strideX ]; + y[ jy ] = y[ jy+strideY ]; + jx += strideX; + jy += strideY; + } + x[ lx ] = vx; + y[ ly ] = vy; + } else { + flg = isNegativeZero( vx ); + jx = ix - strideX; + jy = iy - strideY; + + // Shift all larger values to the right of the current element to the left... + while ( jx <= fx ) { + ux = x[ jx ]; + if ( ux <= vx && !(flg && ux === vx && isNegativeZero( ux ) === false) ) { // eslint-disable-line max-len + // Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left + break; + } + x[ jx+strideX ] = ux; + y[ jy+strideY ] = y[ jy ]; + jx -= strideX; + jy -= strideY; + } + x[ jx+strideX ] = vx; + y[ jy+strideY ] = vy; + ix += strideX; + iy += strideY; + } + } + return x; + } + // Traverse the strided array from left-to-right... + + // Sort in increasing order... + for ( i = 1; i < N; i++ ) { + vx = x[ ix ]; + vy = y[ iy ]; + + // Sort `NaN` values to the end... + if ( isnan( vx ) ) { + jx = ix; + jy = iy; + + // Shift all values (including NaNs) to the right of the current element to the left... + while ( jx < lx ) { + x[ jx ] = x[ jx+strideX ]; + y[ jy ] = y[ jy+strideY ]; + jx += strideX; + jy += strideY; + } + x[ lx ] = vx; + y[ ly ] = vy; + } else { + flg = isNegativeZero( vx ); + jx = ix - strideX; + jy = iy - strideY; + + // Shift all larger values to the left of the current element to the right... + while ( jx >= fx ) { + ux = x[ jx ]; + if ( ux <= vx && !(flg && ux === vx && isNegativeZero( ux ) === false) ) { // eslint-disable-line max-len + // Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right + break; + } + x[ jx+strideX ] = ux; + y[ jy+strideY ] = y[ jy ]; + jx -= strideX; + jy -= strideY; + } + x[ jx+strideX ] = vx; + y[ jy+strideY ] = vy; + ix += strideX; + iy += strideY; + } + } + return x; +} + + +// EXPORTS // + +module.exports = dsort2ins; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 | 2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +24x +24x +24x +24x +24x +24x +24x +4x +4x +4x +4x +4x +24x +2x +2x +24x +24x +24x +24x +24x +2x +2x +2x +2x +2x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 Float64Array = require( '@stdlib/array/float64' ); +var addon = require( './dsort2ins.native.js' ); + + +// MAIN // + +/** +* Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} order - sort order +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` index increment +* @param {NonNegativeInteger} offsetX - `x` starting index +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` index increment +* @param {NonNegativeInteger} offsetY - `y` starting index +* @returns {Float64Array} `x` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); +* var y = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); +* +* dsort2ins( x.length, 1.0, x, 1, 0, y, 1, 0 ); +* +* console.log( x ); +* // => <Float64Array>[ -4.0, -2.0, 1.0, 3.0 ] +* +* console.log( y ); +* // => <Float64Array>[ 3.0, 1.0, 0.0, 2.0 ] +*/ +function dsort2ins( N, order, x, strideX, offsetX, y, strideY, offsetY ) { + var viewX; + var viewY; + var flg; + + flg = 1.0; + if ( strideX < 0 ) { + flg *= -1.0; // reversing order + order *= -1.0; + strideX *= -1; + offsetX -= (N-1) * strideX; + } + if ( strideY < 0 ) { + offsetY += (N-1) * strideY; + } + viewX = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len + viewY = new Float64Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len + addon( N, order, viewX, strideX, viewY, flg*strideY ); + return x; +} + + +// EXPORTS // + +module.exports = dsort2ins; + |