diff --git a/lib/node_modules/@stdlib/blas/base/scasum/README.md b/lib/node_modules/@stdlib/blas/base/scasum/README.md new file mode 100644 index 00000000000..9066bf4c5a7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/README.md @@ -0,0 +1,267 @@ + + +# scasum + +> Compute the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. + +
+ +## Usage + +```javascript +var scasum = require( '@stdlib/blas/base/scasum' ); +``` + +#### scasum( N, cx, strideX ) + +Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] ); + +var out = scasum( 4, cx, 1 ); +// returns ~1.6 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **cx**: input [`Complex64Array`][@stdlib/array/complex64]. +- **strideX**: index increment for `cx`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to traverse every other value, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var cx = new Complex64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var out = scasum( 2, cx, 2 ); +// returns 7.0 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +// Initial array: +var cx0 = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +// Create an offset view: +var cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Compute the L2-out: +var out = scasum( 2, cx1, 1 ); +// returns 18.0 +``` + +#### scasum.ndarray( N, cx, strideX, offset ) + +Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector using alternative indexing semantics. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] ); + +var out = scasum.ndarray( 4, cx, 1, 0 ); +// returns ~1.6 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to start from the second index, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var cx = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +var out = scasum.ndarray( 2, cx, 1, 1 ); +// returns 18.0 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `0.0`. +- `scasum()` corresponds to the [BLAS][blas] level 1 function [`scasum`][scasum]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scasum = require( '@stdlib/blas/base/scasum' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +console.log( cx.toString() ); + +// Compute the sum of the absolute values of real and imaginary components: +var out = scasum( cx.length, cx, 1 ); +console.log( out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/scasum.h" +``` + +#### c_scasum( N, \*CX, strideX ) + +Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. + +```c +const float cx[] = { 0.3f, 0.1f, 0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.2f }; + +float out = c_scasum( 4, (void *)cx, 1 ); +// returns 1.6f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **CX**: `[in] void*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `CX`. + +```c +float c_scasum( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/scasum.h" +#include + +int main( void ) { + // Create a strided array of interleaved real and imaginary components: + const float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify stride length: + const int strideX = 1; + + // Compute the sum of the absolute values of real and imaginary components: + float out = c_scasum( N, (void *)cx, strideX ); + + // Print the result: + printf( "out: %f\n", out ); +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.js new file mode 100644 index 00000000000..f46cbdab9e4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.js @@ -0,0 +1,92 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var pkg = require( './../package.json' ).name; +var scasum = require( './../lib/scasum.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var cx = new Complex64Array( uniform( len*2, -10.0, 10.0, options ) ); + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = scasum( cx.length, cx, 1 ); + if ( isnanf( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.native.js new file mode 100644 index 00000000000..7c30f90fe00 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.native.js @@ -0,0 +1,97 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var scasum = tryRequire( resolve( __dirname, './../lib/scasum.native.js' ) ); +var opts = { + 'skip': ( scasum instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var cx = new Complex64Array( uniform( len*2, -10.0, 10.0, options ) ); + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = scasum( cx.length, cx, 1 ); + if ( isnanf( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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+'::native:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.ndarray.js new file mode 100644 index 00000000000..020d7242d13 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.ndarray.js @@ -0,0 +1,92 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var pkg = require( './../package.json' ).name; +var scasum = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var cx = new Complex64Array( uniform( len*2, -10.0, 10.0, options ) ); + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = scasum( cx.length, cx, 1, 0 ); + if ( isnanf( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.ndarray.native.js new file mode 100644 index 00000000000..8602518dd40 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,97 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var scasum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( scasum instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var cx = new Complex64Array( uniform( len*2, -10.0, 10.0, options ) ); + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = scasum( cx.length, cx, 1, 0 ); + if ( isnanf( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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+'::native:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/scasum/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/c/Makefile new file mode 100644 index 00000000000..9f97140e7cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/scasum/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/c/benchmark.length.c new file mode 100644 index 00000000000..273d83386b4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/c/benchmark.length.c @@ -0,0 +1,155 @@ +/** +* @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. +*/ + +/** +* Benchmark `scasum`. +*/ +#include "stdlib/blas/base/scasum.h" +#include +#include +#include +#include +#include + +#define NAME "scasum" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1]. +* +* @return random number +*/ +float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +double benchmark( int iterations, int len ) { + float cx[ len*2 ]; + double elapsed; + float out; + double t; + int i; + + for ( i = 0; i < len*2; i += 2 ) { + cx[ i ] = ( rand_float()*10000.0f ) - 5000.0f; + cx[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; + } + out = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + out = c_scasum( len, (void *)cx, 1 ); + if ( out != out ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( out != out ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/base/scasum/benchmark/fortran/Makefile b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/fortran/Makefile new file mode 100644 index 00000000000..db161f7e6c8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/fortran/Makefile @@ -0,0 +1,141 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][]2). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling Fortran source files: +ifdef FORTRAN_COMPILER + FC := $(FORTRAN_COMPILER) +else + FC := gfortran +endif + +# Define the command-line options when compiling Fortran files: +FFLAGS ?= \ + -std=f95 \ + -ffree-form \ + -O3 \ + -Wall \ + -Wextra \ + -Wno-compare-reals \ + -Wimplicit-interface \ + -fno-underscoring \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop`): +INCLUDE ?= + +# List of Fortran source files: +SOURCE_FILES ?= ../../src/scasum.f + +# List of Fortran targets: +f_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles Fortran source files. +# +# @param {string} SOURCE_FILES - list of Fortran source files +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {string} [FORTRAN_COMPILER] - Fortran compiler +# @param {string} [FFLAGS] - Fortran compiler flags +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code +# +# @example +# make +# +# @example +# make all +#/ +all: $(f_targets) + +.PHONY: all + +#/ +# Compiles Fortran source files. +# +# @private +# @param {string} SOURCE_FILES - list of Fortran source files +# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {string} FC - Fortran compiler +# @param {string} FFLAGS - Fortran compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(f_targets): %.out: %.f + $(QUIET) $(FC) $(FFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(f_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/scasum/benchmark/fortran/benchmark.length.f b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/fortran/benchmark.length.f new file mode 100644 index 00000000000..564981914ca --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/benchmark/fortran/benchmark.length.f @@ -0,0 +1,220 @@ +!> +! @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. +!< + +!> Benchmark `scasum`. +! +! ## Notes +! +! - Written in "free form" Fortran 95. +! +!< +program bench + implicit none + ! .. + ! Local constants: + character(6), parameter :: name = 'scasum' ! if changed, be sure to adjust length + integer, parameter :: iterations = 10000000 + integer, parameter :: repeats = 3 + integer, parameter :: min = 1 + integer, parameter :: max = 6 + ! .. + ! Run the benchmarks: + call main() + ! .. + ! Functions: +contains + ! .. + ! Prints the TAP version. + ! .. + subroutine print_version() + print '(A)', 'TAP version 13' + end subroutine print_version + ! .. + ! Prints the TAP summary. + ! + ! @param {integer} total - total number of tests + ! @param {integer} passing - total number of passing tests + ! .. + subroutine print_summary( total, passing ) + ! .. + ! Scalar arguments: + integer, intent(in) :: total, passing + ! .. + ! Local variables: + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic adjustl, trim + ! .. + print '(A)', '#' + ! .. + write (str, '(I15)') total ! TAP plan + tmp = adjustl( str ) + print '(A,A)', '1..', trim( tmp ) + ! .. + print '(A,A)', '# total ', trim( tmp ) + ! .. + write (str, '(I15)') passing + tmp = adjustl( str ) + print '(A,A)', '# pass ', trim( tmp ) + ! .. + print '(A)', '#' + print '(A)', '# ok' + end subroutine print_summary + ! .. + ! Prints benchmarks results. + ! + ! @param {integer} iterations - number of iterations + ! @param {double} elapsed - elapsed time in seconds + ! .. + subroutine print_results( iterations, elapsed ) + ! .. + ! Scalar arguments: + double precision, intent(in) :: elapsed + integer, intent(in) :: iterations + ! .. + ! Local variables: + double precision :: rate + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic dble, adjustl, trim + ! .. + rate = dble( iterations ) / elapsed + ! .. + print '(A)', ' ---' + ! .. + write (str, '(I15)') iterations + tmp = adjustl( str ) + print '(A,A)', ' iterations: ', trim( tmp ) + ! .. + write (str, '(f0.9)') elapsed + tmp = adjustl( str ) + print '(A,A)', ' elapsed: ', trim( tmp ) + ! .. + write( str, '(f0.9)') rate + tmp = adjustl( str ) + print '(A,A)', ' rate: ', trim( tmp ) + ! .. + print '(A)', ' ...' + end subroutine print_results + ! .. + ! Runs a benchmark. + ! + ! @param {integer} iterations - number of iterations + ! @param {integer} len - array length + ! @return {double} elapsed time in seconds + ! .. + double precision function benchmark( iterations, len ) + ! .. + ! External functions: + interface + real function scasum( N, cx, strideX ) + complex :: cx(*) + integer :: strideX, N + end function scasum + end interface + ! .. + ! Scalar arguments: + integer, intent(in) :: iterations, len + ! .. + ! Local scalars: + double precision :: elapsed, r1, r2 + real :: t1, t2, y + integer :: i + ! .. + ! Local arrays: + complex, allocatable :: x(:) + ! .. + ! Intrinsic functions: + intrinsic random_number, cpu_time, cmplx + ! .. + ! Allocate arrays: + allocate( x(len) ) + ! .. + call random_number( r1 ) + call random_number( r2 ) + do i = 1, len + call random_number( r1 ) + call random_number( r2 ) + x( i ) = cmplx( (real(r1)*10000.0)-5000.0, (real(r2)*10000.0)-5000.0 ) + end do + ! .. + y = 0.0e0 + ! .. + call cpu_time( t1 ) + ! .. + do i = 1, iterations + y = scasum( len, x, 1 ); + if ( y /= y ) then + print '(A)', 'should not return NaN' + exit + end if + end do + ! .. + call cpu_time( t2 ) + ! .. + elapsed = t2 - t1 + ! .. + if ( y /= y ) then + print '(A)', 'should not return NaN' + end if + ! .. + ! Deallocate arrays: + deallocate( x ) + ! .. + benchmark = elapsed + return + end function benchmark + ! .. + ! Main execution sequence. + ! .. + subroutine main() + ! .. + ! Local variables: + integer :: count, iter, len, i, j + double precision :: elapsed + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic adjustl, trim + ! .. + call print_version() + count = 0 + do i = min, max + len = 10**i + iter = iterations / 10**(i-1) + do j = 1, repeats + count = count + 1 + ! .. + write (str, '(I15)') len + tmp = adjustl( str ) + print '(A,A,A,A)', '# fortran::native::', name, ':len=', trim( tmp ) + ! .. + elapsed = benchmark( iter, len ) + ! .. + call print_results( iter, elapsed ) + ! .. + write (str, '(I15)') count + tmp = adjustl( str ) + print '(A,A,A)', 'ok ', trim( tmp ), ' benchmark finished' + end do + end do + call print_summary( count, count ) + end subroutine main +end program bench \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/scasum/binding.gyp b/lib/node_modules/@stdlib/blas/base/scasum/binding.gyp new file mode 100644 index 00000000000..02a2799da09 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/binding.gyp @@ -0,0 +1,265 @@ +# @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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/base/scasum/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/scasum/docs/repl.txt new file mode 100644 index 00000000000..610defe96a7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/docs/repl.txt @@ -0,0 +1,91 @@ + +{{alias}}( N, cx, strideX ) + Computes the sum of the absolute values of the real and imaginary components + of a single-precision complex floating-point vector. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0` or `strideX <= 0`, the function returns `0.0`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + cx: Complex64Array + Input array. + + strideX: integer + Index increment for `cx`. + + Returns + ------- + out: number + Result. + + Examples + -------- + // Standard Usage: + > var cx = new {{alias:@stdlib/array/complex64}}( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 ] ); + > var out = {{alias}}( 4, cx, 1 ) + ~1.6 + + // Using `N` and stride parameters: + > cx = new {{alias:@stdlib/array/complex64}}( [ 3.0, -4.0, 0.0, 0.0, 5.0, -6.0 ] ); + > out = {{alias}}( 2, cx, 2 ) + 18.0 + + // Using view offsets: + > var cx0 = new {{alias:@stdlib/array/complex64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > var cx1 = new {{alias:@stdlib/array/complex64}}( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); + > out = {{alias}}( 2, cx1, 1 ) + 18.0 + + +{{alias}}.ndarray( N, cx, strideX, offsetX ) + Computes the sum of the absolute values of the real and imaginary components + of a single-precision complex floating-point vector using alternative + indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + cx: Complex64Array + Input array. + + strideX: integer + Index increment for `cx`. + + offsetX: integer + Starting index of `cx`. + + Returns + ------- + out: number + Result. + + Examples + -------- + // Standard Usage: + > var cx = new {{alias:@stdlib/array/complex64}}( [ 3.0, -4.0, 0.0, 0.0, 5.0, -6.0 ] ); + > var out = {{alias}}.ndarray( 2, cx, 2, 0 ) + 18.0 + + // Using an index offset: + > cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > out = {{alias}}.ndarray( 2, cx, 1, 1 ) + 18.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/scasum/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/scasum/docs/types/index.d.ts new file mode 100644 index 00000000000..72e73524703 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Complex64Array } from '@stdlib/types/array'; + +/** +* Interface describing `scasum`. +*/ +interface Routine { + /** + * Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. + * + * @param N - number of indexed elements + * @param cx - input array + * @param strideX - `cx` stride length + * @returns out + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2, 2.0, 3.0 ] ); + * + * var out = scasum( 5, cx, 1 ); + * // returns ~6.9 + */ + ( N: number, cx: Complex64Array, strideX: number ): number; + + /** + * Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param cx - input array + * @param strideX - `cx` stride length + * @param offsetX - starting index for `cx` + * @returns out + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * var cx = new Complex64Array( [ 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2, 2.0, 3.0 ] ); + * + * var out = scasum.ndarray( 5, cx, 1, 0 ); + * // returns ~6.9 + */ + ndarray( N: number, cx: Complex64Array, strideX: number, offsetX: number ): number; +} + +/** +* Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. +* +* @param N - number of indexed elements +* @param cx - input array +* @param strideX - `cx` stride length +* @returns out +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var cx = new Complex64Array( [ 0.3, 0.1, 5.0, 8.0, 0.5, 0.0, 6.0, 9.0, 0.0, 0.5, 8.0, 3.0, 0.0, 0.2, 9.0, 4.0 ] ); +* +* var out = scasum( 4, cx, 2 ); +* // returns ~1.6 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var cx = new Complex64Array( [ 0.3, 0.1, 5.0, 8.0, 0.5, 0.0, 6.0, 9.0, 0.0, 0.5, 8.0, 3.0, 0.0, 0.2, 9.0, 4.0 ] ); +* +* var out = scasum.ndarray( 4, cx, 2, 0 ); +* // returns ~1.6 +*/ +declare var scasum: Routine; + + +// EXPORTS // + +export = scasum; diff --git a/lib/node_modules/@stdlib/blas/base/scasum/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/scasum/docs/types/test.ts new file mode 100644 index 00000000000..0d420429207 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/docs/types/test.ts @@ -0,0 +1,158 @@ +/* +* @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. +*/ + +import Complex64Array = require( '@stdlib/array/complex64' ); +import scasum = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const cx = new Complex64Array( 10 ); + + scasum( cx.length, cx, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + + scasum( '10', cx, 1 ); // $ExpectError + scasum( true, cx, 1 ); // $ExpectError + scasum( false, cx, 1 ); // $ExpectError + scasum( null, cx, 1 ); // $ExpectError + scasum( undefined, cx, 1 ); // $ExpectError + scasum( [], cx, 1 ); // $ExpectError + scasum( {}, cx, 1 ); // $ExpectError + scasum( ( cx: number ): number => cx, cx, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + + scasum( cx.length, 10, 1 ); // $ExpectError + scasum( cx.length, '10', 1 ); // $ExpectError + scasum( cx.length, true, 1 ); // $ExpectError + scasum( cx.length, false, 1 ); // $ExpectError + scasum( cx.length, null, 1 ); // $ExpectError + scasum( cx.length, undefined, 1 ); // $ExpectError + scasum( cx.length, [], 1 ); // $ExpectError + scasum( cx.length, {}, 1 ); // $ExpectError + scasum( cx.length, ( cx: number ): number => cx, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + + scasum( cx.length, cx, '10' ); // $ExpectError + scasum( cx.length, cx, true ); // $ExpectError + scasum( cx.length, cx, false ); // $ExpectError + scasum( cx.length, cx, null ); // $ExpectError + scasum( cx.length, cx, undefined ); // $ExpectError + scasum( cx.length, cx, [] ); // $ExpectError + scasum( cx.length, cx, {} ); // $ExpectError + scasum( cx.length, cx, ( cx: number ): number => cx ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const cx = new Complex64Array( 10 ); + + scasum(); // $ExpectError + scasum( cx.length ); // $ExpectError + scasum( cx.length, cx ); // $ExpectError + scasum( cx.length, cx, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const cx = new Complex64Array( 10 ); + + scasum.ndarray( cx.length, cx, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + + scasum.ndarray( '10', cx, 1, 0 ); // $ExpectError + scasum.ndarray( true, cx, 1, 0 ); // $ExpectError + scasum.ndarray( false, cx, 1, 0 ); // $ExpectError + scasum.ndarray( null, cx, 1, 0 ); // $ExpectError + scasum.ndarray( undefined, cx, 1, 0 ); // $ExpectError + scasum.ndarray( [], cx, 1, 0 ); // $ExpectError + scasum.ndarray( {}, cx, 1, 0 ); // $ExpectError + scasum.ndarray( ( cx: number ): number => cx, cx, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + + scasum.ndarray( cx.length, 10, 1, 0 ); // $ExpectError + scasum.ndarray( cx.length, '10', 1, 0 ); // $ExpectError + scasum.ndarray( cx.length, true, 1, 0 ); // $ExpectError + scasum.ndarray( cx.length, false, 1, 0 ); // $ExpectError + scasum.ndarray( cx.length, null, 1, 0 ); // $ExpectError + scasum.ndarray( cx.length, undefined, 1, 0 ); // $ExpectError + scasum.ndarray( cx.length, [], 1, 0 ); // $ExpectError + scasum.ndarray( cx.length, {}, 1, 0 ); // $ExpectError + scasum.ndarray( cx.length, ( cx: number ): number => cx, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + + scasum.ndarray( cx.length, cx, '10', 0 ); // $ExpectError + scasum.ndarray( cx.length, cx, true, 0 ); // $ExpectError + scasum.ndarray( cx.length, cx, false, 0 ); // $ExpectError + scasum.ndarray( cx.length, cx, null, 0 ); // $ExpectError + scasum.ndarray( cx.length, cx, undefined, 0 ); // $ExpectError + scasum.ndarray( cx.length, cx, [], 0 ); // $ExpectError + scasum.ndarray( cx.length, cx, {}, 0 ); // $ExpectError + scasum.ndarray( cx.length, cx, ( cx: number ): number => cx, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + + scasum.ndarray( cx.length, cx, 1, '10' ); // $ExpectError + scasum.ndarray( cx.length, cx, 1, true ); // $ExpectError + scasum.ndarray( cx.length, cx, 1, false ); // $ExpectError + scasum.ndarray( cx.length, cx, 1, null ); // $ExpectError + scasum.ndarray( cx.length, cx, 1, undefined ); // $ExpectError + scasum.ndarray( cx.length, cx, 1, [] ); // $ExpectError + scasum.ndarray( cx.length, cx, 1, {} ); // $ExpectError + scasum.ndarray( cx.length, cx, 1, ( cx: number ): number => cx ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const cx = new Complex64Array( 10 ); + + scasum.ndarray(); // $ExpectError + scasum.ndarray( cx.length ); // $ExpectError + scasum.ndarray( cx.length, cx ); // $ExpectError + scasum.ndarray( cx.length, cx, 1 ); // $ExpectError + scasum.ndarray( cx.length, cx, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/scasum/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/scasum/examples/c/Makefile new file mode 100644 index 00000000000..6aed70daf16 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/scasum/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/scasum/examples/c/example.c new file mode 100644 index 00000000000..46f2e0717b4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/examples/c/example.c @@ -0,0 +1,37 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/scasum.h" +#include + +int main( void ) { + // Create a strided array of interleaved real and imaginary components: + const float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify stride length: + const int strideX = 1; + + // Compute the sum of the absolute values of real and imaginary components: + float out = c_scasum( N, (void *)cx, strideX ); + + // Print the result: + printf( "out: %f\n", out ); +} diff --git a/lib/node_modules/@stdlib/blas/base/scasum/examples/index.js b/lib/node_modules/@stdlib/blas/base/scasum/examples/index.js new file mode 100644 index 00000000000..21df227bc54 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scasum = require( './../lib' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +console.log( cx.toString() ); + +// Compute the sum of the absolute values of real and imaginary components: +var out = scasum( cx.length, cx, 1 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/base/scasum/include.gypi b/lib/node_modules/@stdlib/blas/base/scasum/include.gypi new file mode 100644 index 00000000000..497aeca1532 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/include.gypi @@ -0,0 +1,70 @@ +# @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. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "linear", + "algebra", + "subroutines", + "scasum", + "sum", + "absolute", + "vector", + "typed", + "array", + "ndarray", + "complex", + "complex64", + "float", + "float32", + "single", + "float32array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/scasum/src/Makefile b/lib/node_modules/@stdlib/blas/base/scasum/src/Makefile new file mode 100644 index 00000000000..bcf18aa4665 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/scasum/src/addon.c b/lib/node_modules/@stdlib/blas/base/scasum/src/addon.c new file mode 100644 index 00000000000..f1690c1beeb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/src/addon.c @@ -0,0 +1,45 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/scasum.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_complex64array.h" +#include "stdlib/napi/create_double.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CX, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(c_scasum)( N, CX, strideX ), out ); + return out; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/scasum/src/scasum.c b/lib/node_modules/@stdlib/blas/base/scasum/src/scasum.c new file mode 100644 index 00000000000..acea98236b8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/src/scasum.c @@ -0,0 +1,48 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/scasum.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/math/base/special/absf.h" + +/** +* Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. +* +* @param N number of indexed elements +* @param CX input array +* @param strideX CX stride length +*/ +float API_SUFFIX(c_scasum)( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX ) { + float *x = (float *)CX; + float stemp; + CBLAS_INT sx; + CBLAS_INT ix; + CBLAS_INT i; + + if ( N <= 0 || strideX <= 0 ) { + return 0.0f; + } + stemp = 0.0f; + sx = strideX * 2; + ix = 0; + for( i = 0; i < N; i++ ) { + stemp += stdlib_base_absf( x[ix] ) + stdlib_base_absf( x[ix+1] ); + ix += sx; + } + return stemp; +} diff --git a/lib/node_modules/@stdlib/blas/base/scasum/src/scasum.f b/lib/node_modules/@stdlib/blas/base/scasum/src/scasum.f new file mode 100644 index 00000000000..db9e192422c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/src/scasum.f @@ -0,0 +1,83 @@ +!> +! @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. +!< + +!> Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. +! +! ## Notes +! +! * Modified version of reference BLAS level1 routine (version 3.8.0). Updated to "free form" Fortran 95. +! +! ## Authors +! +! * Edward Anderson, Lockheed Martin +! * Weslley Pereira, University of Colorado Denver, USA +! +! ## History +! +! * Original version written on August 2016. +! +! ## License +! +! From : +! +! > The reference BLAS is a freely-available software package. It is available from netlib via anonymous ftp and the World Wide Web. Thus, it can be included in commercial software packages (and has been). We only ask that proper credit be given to the authors. +! > +! > Like all software, it is copyrighted. It is not trademarked, but we do ask the following: +! > +! > * If you modify the source for these routines we ask that you change the name of the routine and comment the changes made to the original. +! > +! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support. +! +! @param {integer} N - number of indexed elements +! @param {Array} cx - array +! @param {integer} strideX - `cx` stride length +! @returns {real} result +!< +real function scasum( N, cx, strideX ) + implicit none + ! .. + ! Scalar arguments: + integer :: N, strideX + ! .. + ! Array arguments: + complex :: cx( * ) + ! .. + ! Local scalars: + integer :: i, nix + real :: stemp + ! .. + ! Intrinsic functions: + intrinsic abs, aimag, real + ! .. + scasum = 0.0e0 + stemp = 0.0e0 + ! .. + if ( N <= 0 .or. strideX <= 0 ) return + if( strideX == 1 ) then + do i = 1, N + stemp = stemp + abs( real( cx( i ) ) ) + abs( aimag( cx( i ) ) ) + end do + else + nix = N*strideX + do i = 1, nix, strideX + stemp = stemp + abs( real( cx( i ) ) ) + abs( aimag( cx( i ) ) ) + end do + end if + scasum = stemp + return +end function scasum \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/scasum/src/scasum_cblas.c b/lib/node_modules/@stdlib/blas/base/scasum/src/scasum_cblas.c new file mode 100644 index 00000000000..076520afef4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/src/scasum_cblas.c @@ -0,0 +1,32 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/scasum.h" +#include "stdlib/blas/base/scasum_cblas.h" +#include "stdlib/blas/base/shared.h" + +/** +* Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. +* +* @param N number of indexed elements +* @param CX input array +* @param strideX CX stride length +*/ +float API_SUFFIX(c_scasum)( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX ) { + return API_SUFFIX(cblas_scasum)( N, CX, strideX ); +} diff --git a/lib/node_modules/@stdlib/blas/base/scasum/src/scasum_f.c b/lib/node_modules/@stdlib/blas/base/scasum/src/scasum_f.c new file mode 100644 index 00000000000..23b9d6df35a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/src/scasum_f.c @@ -0,0 +1,35 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/scasum.h" +#include "stdlib/blas/base/scasum_fortran.h" +#include "stdlib/blas/base/shared.h" + +/** +* Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector. +* +* @param N number of indexed elements +* @param CX input array +* @param strideX CX stride length +* @return result +*/ +float API_SUFFIX(c_scasum)( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX ) { + float out; + scasumsub( &N, CX, &strideX, &out ); + return out; +} diff --git a/lib/node_modules/@stdlib/blas/base/scasum/src/scasumsub.f b/lib/node_modules/@stdlib/blas/base/scasum/src/scasumsub.f new file mode 100644 index 00000000000..d7d31791086 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/src/scasumsub.f @@ -0,0 +1,46 @@ +!> +! @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. +!< + +!> Wraps `scasum` as a subroutine. +! +! @param {integer} N - number of indexed elements +! @param {Array} cx - input array +! @param {integer} strideX - `cx` stride length +! @param {real} out - output variable reference +!< +subroutine scasumsub( N, cx, strideX, out ) + implicit none + ! .. + ! External functions: + interface + real function scasum( N, cx, strideX ) + complex :: cx(*) + integer :: strideX, N + end function scasum + end interface + ! .. + ! Scalar arguments: + integer :: strideX, N + real :: out + ! .. + ! Array arguments: + complex :: cx(*) + ! .. + out = scasum( N, cx, strideX ) + return +end subroutine scasumsub \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/scasum/test/test.js b/lib/node_modules/@stdlib/blas/base/scasum/test/test.js new file mode 100644 index 00000000000..70a24dafec2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/test/test.js @@ -0,0 +1,82 @@ +/** +* @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 proxyquire = require( 'proxyquire' ); +var isBrowser = require( '@stdlib/assert/is-browser' ); +var scasum = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': isBrowser +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scasum, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof scasum.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var scasum = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( scasum, mock, 'returns native implementation' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var scasum; + var main; + + main = require( './../lib/scasum.js' ); + + scasum = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( scasum, main, 'returns JavaScript implementation' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/scasum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/scasum/test/test.ndarray.js new file mode 100644 index 00000000000..c03e237af46 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/test/test.ndarray.js @@ -0,0 +1,189 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var scasum = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {number} actual - actual value +* @param {number} expected - expected value +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value' ); + } else { + delta = abs( actual - expected ); + tol = rtol * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scasum, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( scasum.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector', function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2, // 4 + 2.0, + 3.0 + ]); + expected = 1.6; + + actual = scasum( 4, cx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + cx = new Complex64Array([ + 0.1, // 1 + 0.1, // 1 + -0.6, // 2 + 0.1, // 2 + 0.1, // 3 + -0.3, // 3 + 7.0, + 8.0 + ]); + expected = 1.3; + + actual = scasum( 3, cx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + t.end(); +}); + +tape( 'if provided an `N` or a stride parameter less than or equal to `0`, the function returns `0.0`', function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0.0; + + actual = scasum( 0, cx, 1, 0 ); + t.strictEqual( actual, expected, 'returns expected value' ); + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0.0; + + actual = scasum( 2, cx, 0, 0 ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 5.0, + 8.0, + 0.5, // 2 + 0.0, // 2 + 6.0, + 9.0, + 0.0, // 3 + 0.5, // 3 + 8.0, + 3.0, + 0.0, // 4 + 0.2, // 4 + 9.0, + 4.0 + ]); + expected = 1.6; + + actual = scasum( 4, cx, 2, 0 ); + isApprox( t, actual, expected, 2.0 ); + t.end(); +}); + +tape( 'the function supports specifying an offset', function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, // 2 + 6.0, // 2 + 7.0, // 3 + 8.0, // 3 + 9.0, + 10.0 + ]); + expected = 33.0; + + actual = scasum( 3, cx, 1, 1 ); + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/scasum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/scasum/test/test.ndarray.native.js new file mode 100644 index 00000000000..b46180e74dd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/test/test.ndarray.native.js @@ -0,0 +1,198 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var scasum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( scasum instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {number} actual - actual value +* @param {number} expected - expected value +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value' ); + } else { + delta = abs( actual - expected ); + tol = rtol * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); + } +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scasum, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', opts, function test( t ) { + t.strictEqual( scasum.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector', opts, function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2, // 4 + 2.0, + 3.0 + ]); + expected = 1.6; + + actual = scasum( 4, cx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + cx = new Complex64Array([ + 0.1, // 1 + 0.1, // 1 + -0.6, // 2 + 0.1, // 2 + 0.1, // 3 + -0.3, // 3 + 7.0, + 8.0 + ]); + expected = 1.3; + + actual = scasum( 3, cx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + t.end(); +}); + +tape( 'if provided an `N` or a stride parameter less than or equal to `0`, the function returns `0.0`', opts, function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0.0; + + actual = scasum( 0, cx, 1, 0 ); + t.strictEqual( actual, expected, 'returns expected value' ); + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0.0; + + actual = scasum( 2, cx, 0, 0 ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', opts, function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 5.0, + 8.0, + 0.5, // 2 + 0.0, // 2 + 6.0, + 9.0, + 0.0, // 3 + 0.5, // 3 + 8.0, + 3.0, + 0.0, // 4 + 0.2, // 4 + 9.0, + 4.0 + ]); + expected = 1.6; + + actual = scasum( 4, cx, 2, 0 ); + isApprox( t, actual, expected, 2.0 ); + t.end(); +}); + +tape( 'the function supports specifying an offset', opts, function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, // 2 + 6.0, // 2 + 7.0, // 3 + 8.0, // 3 + 9.0, + 10.0 + ]); + expected = 33.0; + + actual = scasum( 3, cx, 1, 1 ); + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/scasum/test/test.scasum.js b/lib/node_modules/@stdlib/blas/base/scasum/test/test.scasum.js new file mode 100644 index 00000000000..e5e7ab6b13c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/test/test.scasum.js @@ -0,0 +1,192 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var scasum = require( './../lib/scasum.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {number} actual - actual value +* @param {number} expected - expected value +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value' ); + } else { + delta = abs( actual - expected ); + tol = rtol * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scasum, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( scasum.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector', function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2, // 4 + 2.0, + 3.0 + ]); + expected = 1.6; + + actual = scasum( 4, cx, 1 ); + isApprox( t, actual, expected, 2.0 ); + + cx = new Complex64Array([ + 0.1, // 1 + 0.1, // 1 + -0.6, // 2 + 0.1, // 2 + 0.1, // 3 + -0.3, // 3 + 7.0, + 8.0 + ]); + expected = 1.3; + + actual = scasum( 3, cx, 1 ); + isApprox( t, actual, expected, 2.0 ); + t.end(); +}); + +tape( 'if provided an `N` or a stride parameter less than or equal to `0`, the function returns `0.0`', function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0.0; + + actual = scasum( 0, cx, 1 ); + t.strictEqual( actual, expected, 'returns expected value' ); + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0.0; + + actual = scasum( 2, cx, 0 ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 5.0, + 8.0, + 0.5, // 2 + 0.0, // 2 + 6.0, + 9.0, + 0.0, // 3 + 0.5, // 3 + 8.0, + 3.0, + 0.0, // 4 + 0.2, // 4 + 9.0, + 4.0 + ]); + expected = 1.6; + + actual = scasum( 4, cx, 2 ); + isApprox( t, actual, expected, 2.0 ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var actual; + var cx0; + var cx1; + + cx0 = new Complex64Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, // 2 + 6.0, // 2 + 7.0, // 3 + 8.0, // 3 + 9.0, + 10.0 + ]); + expected = 33.0; + + cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); + + actual = scasum( 3, cx1, 1 ); + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/scasum/test/test.scasum.native.js b/lib/node_modules/@stdlib/blas/base/scasum/test/test.scasum.native.js new file mode 100644 index 00000000000..78627c4ff89 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/scasum/test/test.scasum.native.js @@ -0,0 +1,201 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var scasum = tryRequire( resolve( __dirname, './../lib/scasum.native.js' ) ); +var opts = { + 'skip': ( scasum instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {number} actual - actual value +* @param {number} expected - expected value +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value' ); + } else { + delta = abs( actual - expected ); + tol = rtol * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); + } +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scasum, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', opts, function test( t ) { + t.strictEqual( scasum.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector', opts, function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2, // 4 + 2.0, + 3.0 + ]); + expected = 1.6; + + actual = scasum( 4, cx, 1 ); + isApprox( t, actual, expected, 2.0 ); + + cx = new Complex64Array([ + 0.1, // 1 + 0.1, // 1 + -0.6, // 2 + 0.1, // 2 + 0.1, // 3 + -0.3, // 3 + 7.0, + 8.0 + ]); + expected = 1.3; + + actual = scasum( 3, cx, 1 ); + isApprox( t, actual, expected, 2.0 ); + t.end(); +}); + +tape( 'if provided an `N` or a stride parameter less than or equal to `0`, the function returns `0.0`', opts, function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0.0; + + actual = scasum( 0, cx, 1 ); + t.strictEqual( actual, expected, 'returns expected value' ); + + cx = new Complex64Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0.0; + + actual = scasum( 2, cx, 0 ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', opts, function test( t ) { + var expected; + var actual; + var cx; + + cx = new Complex64Array([ + 0.3, // 1 + 0.1, // 1 + 5.0, + 8.0, + 0.5, // 2 + 0.0, // 2 + 6.0, + 9.0, + 0.0, // 3 + 0.5, // 3 + 8.0, + 3.0, + 0.0, // 4 + 0.2, // 4 + 9.0, + 4.0 + ]); + expected = 1.6; + + actual = scasum( 4, cx, 2 ); + isApprox( t, actual, expected, 2.0 ); + t.end(); +}); + +tape( 'the function supports view offsets', opts, function test( t ) { + var expected; + var actual; + var cx0; + var cx1; + + cx0 = new Complex64Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, // 2 + 6.0, // 2 + 7.0, // 3 + 8.0, // 3 + 9.0, + 10.0 + ]); + expected = 33.0; + + cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); + + actual = scasum( 3, cx1, 1 ); + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); +});