diff --git a/blas/ext/base/sapx/coverage.ndjson b/blas/ext/base/sapx/coverage.ndjson new file mode 100644 index 000000000..92b346fca --- /dev/null +++ b/blas/ext/base/sapx/coverage.ndjson @@ -0,0 +1 @@ +[432,432,100,42,42,100,4,4,100,432,432,100,"e4f0dcd53e364d25d1a598e20ed25dd73cf547e7","2024-03-20 21:53:43 -0700"] diff --git a/blas/ext/base/sapx/index.html b/blas/ext/base/sapx/index.html new file mode 100644 index 000000000..578bb9c60 --- /dev/null +++ b/blas/ext/base/sapx/index.html @@ -0,0 +1,206 @@ + + + + +
++ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
---|---|---|---|---|---|---|---|---|---|
index.js | +
+
+ |
+ 100% | +68/68 | +100% | +3/3 | +100% | +0/0 | +100% | +68/68 | +
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% | +91/91 | +100% | +15/15 | +100% | +1/1 | +100% | +91/91 | +
ndarray.native.js | +
+
+ |
+ 100% | +60/60 | +100% | +2/2 | +100% | +1/1 | +100% | +60/60 | +
sapx.js | +
+
+ |
+ 100% | +90/90 | +100% | +18/18 | +100% | +1/1 | +100% | +90/90 | +
sapx.native.js | +
+
+ |
+ 100% | +53/53 | +100% | +2/2 | +100% | +1/1 | +100% | +53/53 | +
+ 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 | 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'; + +/** +* Add a constant to each element in a single-precision floating-point strided array. +* +* @module @stdlib/blas/ext/base/sapx +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var sapx = require( '@stdlib/blas/ext/base/sapx' ); +* +* var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* sapx( x.length, 5.0, x, 1 ); +* // x => <Float32Array>[ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.0, 2.0 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var sapx = require( '@stdlib/blas/ext/base/sapx' ); +* +* var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* sapx.ndarray( x.length, 5.0, x, 1, 0 ); +* // x => <Float32Array>[ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.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 sapx; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + sapx = main; +} else { + sapx = tmp; +} + + +// EXPORTS // + +module.exports = sapx; + +// exports: { "ndarray": "sapx.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 sapx = require( './sapx.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( sapx, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = sapx; + |
+ 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 sapx = require( './sapx.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( sapx, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = sapx; + |
+ 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 | 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 +11x +11x +11x +11x +11x +11x +3x +3x +8x +8x +8x +11x +5x +5x +5x +5x +2x +5x +5x +5x +2x +5x +1x +1x +5x +70x +70x +70x +70x +70x +70x +70x +4x +4x +11x +9x +9x +9x +3x +11x +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'; + +// VARIABLES // + +var M = 5; + + +// MAIN // + +/** +* Adds a constant to each element in a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - scalar +* @param {Float32Array} x - input array +* @param {integer} stride - index increment +* @param {NonNegativeInteger} offset - starting index +* @returns {Float32Array} input array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); +* var alpha = 5.0; +* +* sapx( 3, alpha, x, 1, x.length-3 ); +* // x => <Float32Array>[ 1.0, -2.0, 3.0, 1.0, 10.0, -1.0 ] +*/ +function sapx( N, alpha, x, stride, offset ) { + var ix; + var m; + var i; + + if ( N <= 0 || alpha === 0.0 ) { + return x; + } + ix = offset; + + // Use loop unrolling if the stride is equal to `1`... + if ( stride === 1 ) { + m = N % M; + + // If we have a remainder, run a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + x[ ix ] += alpha; + ix += stride; + } + } + if ( N < M ) { + return x; + } + for ( i = m; i < N; i += M ) { + x[ ix ] += alpha; + x[ ix+1 ] += alpha; + x[ ix+2 ] += alpha; + x[ ix+3 ] += alpha; + x[ ix+4 ] += alpha; + ix += M; + } + return x; + } + for ( i = 0; i < N; i++ ) { + x[ ix ] += alpha; + ix += stride; + } + return x; +} + + +// EXPORTS // + +module.exports = sapx; + |
+ 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 | 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 +11x +11x +11x +11x +11x +11x +11x +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 minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); +var offsetView = require( '@stdlib/strided/base/offset-view' ); +var addon = require( './sapx.native.js' ); + + +// MAIN // + +/** +* Adds a constant to each element in a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - scalar +* @param {Float32Array} x - input array +* @param {integer} stride - index increment +* @param {NonNegativeInteger} offset - starting index +* @returns {Float32Array} input array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); +* var alpha = 5.0; +* +* sapx( 3, alpha, x, 1, x.length-3 ); +* // x => <Float32Array>[ 1.0, -2.0, 3.0, 1.0, 10.0, -1.0 ] +*/ +function sapx( N, alpha, x, stride, offset ) { + var view; + offset = minViewBufferIndex( N, stride, offset ); + view = offsetView( x, offset ); + addon( N, alpha, view, stride ); + return x; +} + + +// EXPORTS // + +module.exports = sapx; + |
+ 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 | 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 +11x +11x +11x +11x +11x +11x +3x +3x +8x +11x +5x +5x +5x +5x +2x +5x +5x +2x +5x +1x +1x +5x +70x +70x +70x +70x +70x +70x +4x +4x +11x +1x +11x +2x +2x +11x +9x +9x +9x +3x +11x +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'; + +// VARIABLES // + +var M = 5; + + +// MAIN // + +/** +* Adds a constant to each element in a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - scalar +* @param {Float32Array} x - input array +* @param {integer} stride - index increment +* @returns {Float32Array} input array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* sapx( x.length, 5.0, x, 1 ); +* // x => <Float32Array>[ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.0, 2.0 ] +*/ +function sapx( N, alpha, x, stride ) { + var ix; + var i; + var m; + + if ( N <= 0 || alpha === 0.0 ) { + return x; + } + // Use loop unrolling if the stride is equal to `1`... + if ( stride === 1 ) { + m = N % M; + + // If we have a remainder, run a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + x[ i ] += alpha; + } + } + if ( N < M ) { + return x; + } + for ( i = m; i < N; i += M ) { + x[ i ] += alpha; + x[ i+1 ] += alpha; + x[ i+2 ] += alpha; + x[ i+3 ] += alpha; + x[ i+4 ] += alpha; + } + return x; + } + if ( stride < 0 ) { + ix = (1-N) * stride; + } else { + ix = 0; + } + for ( i = 0; i < N; i++ ) { + x[ ix ] += alpha; + ix += stride; + } + return x; +} + + +// EXPORTS // + +module.exports = sapx; + |
+ 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 | 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 +22x +22x +22x +22x +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 // + +/** +* Adds a constant to each element in a single-precision floating-point strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - scalar +* @param {Float32Array} x - input array +* @param {integer} stride - index increment +* @returns {Float32Array} input array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* sapx( x.length, 5.0, x, 1 ); +* // x => <Float32Array>[ 3.0, 6.0, 8.0, 0.0, 9.0, 5.0, 4.0, 2.0 ] +*/ +function sapx( N, alpha, x, stride ) { + addon( N, alpha, x, stride ); + return x; +} + + +// EXPORTS // + +module.exports = sapx; + |