From 13178162395644a832cd84a213b7e74019f67446 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Wed, 11 Dec 2024 13:51:13 +0530 Subject: [PATCH 1/5] feat: add C ndarray implementation for caxpy --- .../base/caxpy/benchmark/benchmark.native.js | 120 ++++ .../benchmark/benchmark.ndarray.native.js | 120 ++++ .../blas/base/caxpy/benchmark/c/Makefile | 146 ++++ .../base/caxpy/benchmark/c/benchmark.length.c | 200 ++++++ .../@stdlib/blas/base/caxpy/binding.gyp | 265 ++++++++ .../blas/base/caxpy/examples/c/Makefile | 146 ++++ .../blas/base/caxpy/examples/c/example.c | 53 ++ .../@stdlib/blas/base/caxpy/include.gypi | 70 ++ .../caxpy/include/stdlib/blas/base/caxpy.h | 49 ++ .../include/stdlib/blas/base/caxpy_cblas.h | 44 ++ .../blas/base/caxpy/lib/caxpy.native.js | 71 ++ .../blas/base/caxpy/lib/ndarray.native.js | 73 ++ .../@stdlib/blas/base/caxpy/manifest.json | 495 ++++++++++++++ .../@stdlib/blas/base/caxpy/src/Makefile | 70 ++ .../@stdlib/blas/base/caxpy/src/addon.c | 68 ++ .../@stdlib/blas/base/caxpy/src/caxpy.c | 38 ++ .../@stdlib/blas/base/caxpy/src/caxpy_cblas.c | 57 ++ .../blas/base/caxpy/src/caxpy_ndarray.c | 64 ++ .../blas/base/caxpy/test/test.caxpy.native.js | 547 +++++++++++++++ .../base/caxpy/test/test.ndarray.native.js | 632 ++++++++++++++++++ 20 files changed, 3328 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/include/stdlib/blas/base/caxpy.h create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/include/stdlib/blas/base/caxpy_cblas.h create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/lib/caxpy.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_ndarray.c create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.native.js new file mode 100644 index 000000000000..44219212b378 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.native.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 Complex64 = require( '@stdlib/complex/float32/ctor' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var caxpy = tryRequire( resolve( __dirname, './../lib/caxpy.native.js' ) ); +var opts = { + 'skip': ( caxpy instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); + cy = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); + + viewY = reinterpret( cy, 0 ); + + ca = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + caxpy( cx.length, ca, cx, 1, cy, 1 ); + if ( isnanf( viewY[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( viewY[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::native:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..9f33a17db875 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 Complex64 = require( '@stdlib/complex/float32/ctor' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var caxpy = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( caxpy instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); + cy = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); + + viewY = reinterpret( cy, 0 ); + + ca = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + caxpy( cx.length, ca, cx, 1, 0, cy, 1, 0 ); + if ( isnanf( viewY[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( viewY[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::native:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/c/Makefile new file mode 100644 index 000000000000..9f97140e7cb0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/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/caxpy/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..df48d278e0e4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/benchmark/c/benchmark.length.c @@ -0,0 +1,200 @@ +/** +* @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/caxpy.h" +#include "stdlib/complex/float32/ctor.h" +#include +#include +#include +#include +#include + +#define NAME "caxpy" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static 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 +*/ +static 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 +*/ +static 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 +*/ +static 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 +*/ +static 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 +*/ +static double benchmark1( int iterations, int len ) { + stdlib_complex64_t ca; + float cx[ len*2 ]; + float cy[ len*2 ]; + double elapsed; + double t; + int i; + + ca = stdlib_complex64( 1.0f, 0.0f ); + for ( i = 0; i < len*2; i += 2 ) { + cx[ i ] = ( rand_float()*2.0f ) - 1.0f; + cx[ i+1 ] = ( rand_float()*2.0f ) - 1.0f; + cy[ i ] = ( rand_float()*2.0f ) - 1.0f; + cy[ i+1 ] = ( rand_float()*2.0f ) - 1.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_caxpy( len, ca, (void *)cx, 1, (void *)cy, 1 ); + if ( cy[ 0 ] != cy[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( cy[ 0 ] != cy[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + stdlib_complex64_t ca; + float cx[ len*2 ]; + float cy[ len*2 ]; + double elapsed; + double t; + int i; + + ca = stdlib_complex64( 1.0f, 0.0f ); + for ( i = 0; i < len*2; i += 2 ) { + cx[ i ] = ( rand_float()*2.0f ) - 1.0f; + cx[ i+1 ] = ( rand_float()*2.0f ) - 1.0f; + cy[ i ] = ( rand_float()*2.0f ) - 1.0f; + cy[ i+1 ] = ( rand_float()*2.0f ) - 1.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_caxpy_ndarray( len, ca, (void *)cx, 1, 0, (void *)cy, 1, 0 ); + if ( cy[ 0 ] != cy[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( cy[ 0 ] != cy[ 0 ] ) { + 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 = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( 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/caxpy/binding.gyp b/lib/node_modules/@stdlib/blas/base/caxpy/binding.gyp new file mode 100644 index 000000000000..02a2799da097 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/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/caxpy/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/caxpy/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/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/caxpy/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/caxpy/examples/c/example.c new file mode 100644 index 000000000000..2fc282ec34d7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/examples/c/example.c @@ -0,0 +1,53 @@ +/** +* @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/caxpy.h" +#include "stdlib/complex/float32/ctor.h" +#include + +int main( void ) { + // Create strided arrays of interleaved real and imaginary components... + float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + float cy[] = { -1.0f, -2.0f, -3.0f, -4.0f, -5.0f, -6.0f, -7.0f, -8.0f }; + + // Create a complex scalar: + const stdlib_complex64_t ca = stdlib_complex64( 2.0f, 2.0f ); + + // Specify the number of elements: + const int N = 4; + + // Specify strides... + const int strideX = 1; + const int strideY = 1; + + // Scale the elements of the array: + c_caxpy( N, ca, (void *)cx, strideX, (void *)cy, strideY ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "cy[ %i ] = %f + %fj\n", i, cy[ i*2 ], cy[ (i*2)+1 ] ); + } + + // Scale the elements of the array: + c_caxpy_ndarray( N, ca, (void *)cx, -strideX, 3, (void *)cy, -strideY, 3 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "cy[ %i ] = %f + %fj\n", i, cy[ i*2 ], cy[ (i*2)+1 ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/include.gypi b/lib/node_modules/@stdlib/blas/base/caxpy/include.gypi new file mode 100644 index 000000000000..497aeca15320 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/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)', + ' +* +* var re = realf( z ); +* // returns -1.0 +* +* var im = imagf( z ); +* // returns 7.0 +*/ +function caxpy( N, ca, cx, strideX, cy, strideY ) { + var viewCX = reinterpret( cx, 0 ); + var viewCY = reinterpret( cy, 0 ); + addon( N, ca, viewCX, strideX, viewCY, strideY ); + return cy; +} + + +// EXPORTS // + +module.exports = caxpy; diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.native.js new file mode 100644 index 000000000000..e26e0e9f29fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.native.js @@ -0,0 +1,73 @@ +/** +* @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 reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64} ca - scalar constant +* @param {Complex64Array} cx - first input array +* @param {integer} strideX - `cx` stride length +* @param {integer} offsetX - starting index for `cx` +* @param {Complex64Array} cy - second input array +* @param {integer} strideY - `cy` stride length +* @param {integer} offsetY - starting index for `cy` +* @returns {Complex64Array} second input array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/float32/real' ); +* var imagf = require( '@stdlib/complex/float32/imag' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* caxpy( 3, ca, cx, 1, 0, cy, 1, 0 ); +* +* var z = cy.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -1.0 +* +* var im = imagf( z ); +* // returns 7.0 +*/ +function caxpy( N, ca, cx, strideX, offsetX, cy, strideY, offsetY ) { + var viewCX = reinterpret( cx, 0 ); + var viewCY = reinterpret( cy, 0 ); + addon.ndarray( N, ca, viewCX, strideX, offsetX, viewCY, strideY, offsetY ); + return cy; +} + + +// EXPORTS // + +module.exports = caxpy; diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/manifest.json b/lib/node_modules/@stdlib/blas/base/caxpy/manifest.json new file mode 100644 index 000000000000..b49aaf1f1f53 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/manifest.json @@ -0,0 +1,495 @@ +{ + "options": { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/caxpy_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/caxpy_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/caxpy_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/caxpy_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/caxpy_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/caxpy_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/caxpy_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/caxpy_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/caxpy_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul" + ] + }, + { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/caxpy.c", + "./src/caxpy_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/scabs1", + "@stdlib/strided/base/stride2offset", + "@stdlib/complex/float32/base/add", + "@stdlib/complex/float32/base/mul", + "@stdlib/complex/float32/ctor" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/Makefile b/lib/node_modules/@stdlib/blas/base/caxpy/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/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/caxpy/src/addon.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/addon.c new file mode 100644 index 000000000000..8fd4b68c169a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/addon.c @@ -0,0 +1,68 @@ +/** +* @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/caxpy.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_complex64.h" +#include "stdlib/napi/argv_strided_complex64array.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @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, 6 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_COMPLEX64( env, ca, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CX, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CY, N, strideY, argv, 4 ); + API_SUFFIX(c_caxpy)( N, ca, (void *)CX, strideX, (void *)CY, strideY ); + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 8 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 7 ); + STDLIB_NAPI_ARGV_COMPLEX64( env, ca, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CX, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CY, N, strideY, argv, 5 ); + API_SUFFIX(c_caxpy_ndarray)( N, ca, (void *)CX, strideX, offsetX, (void *)CY, strideY, offsetY ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c new file mode 100644 index 000000000000..f76affe3259f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy.c @@ -0,0 +1,38 @@ +/** +* @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/caxpy.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +* @param CY output array +* @param strideY CY stride length +*/ +void API_SUFFIX(c_caxpy)( const CBLAS_INT N, const stdlib_complex64_t ca, const void *CX, const CBLAS_INT strideX, void *CY, const CBLAS_INT strideY ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_caxpy_ndarray)( N, ca, CX, strideX, ox, CY, strideY, oy ); +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c new file mode 100644 index 000000000000..e7633f6d2e53 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_cblas.c @@ -0,0 +1,57 @@ +/** +* @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/caxpy.h" +#include "stdlib/blas/base/caxpy_cblas.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +* @param CY output array +* @param strideY CY stride length +*/ +void API_SUFFIX(c_caxpy)( const CBLAS_INT N, const stdlib_complex64_t ca, const void *CX, const CBLAS_INT strideX, void *CY, const CBLAS_INT strideY ) { + API_SUFFIX(cblas_caxpy)( N, ca, CX, strideX, CY, strideY ); +} + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector using alternative indexing semantics. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +* @param offsetX starting index for CX +* @param CY output array +* @param strideY CY stride length +* @param offsetY starting index for CY +*/ +void API_SUFFIX(c_caxpy_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca, const void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX, void *CY, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + stdlib_complex64_t *cx = (stdlib_complex64_t *)CX; + stdlib_complex64_t *cy = (stdlib_complex64_t *)CY; + + cx += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + cy += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + API_SUFFIX(cblas_caxpy)( N, ca, (void *)cx, sx, (void *)cy, sy ); +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_ndarray.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_ndarray.c new file mode 100644 index 000000000000..2d0c33747063 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_ndarray.c @@ -0,0 +1,64 @@ +/** +* @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/caxpy.h" +#include "stdlib/blas/base/scabs1.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/base/add.h" +#include "stdlib/complex/float32/base/mul.h" +#include + +/** +*Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector using alternative indexing semantics. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +* @param offsetX starting index for CX +* @param CY output array +* @param strideY CY stride length +* @param offsetY starting index for CY +*/ +void API_SUFFIX(c_caxpy_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca, const void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX, void *CY, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + stdlib_complex64_t x; + stdlib_complex64_t y; + int64_t is1; + int64_t is2; + int64_t i; + + if ( N <= 0 ) { + return; + } + if( c_scabs1( ca ) == 0.0f ) { + return; + } + stdlib_complex64_t *ip1 = (stdlib_complex64_t *)CX; + stdlib_complex64_t *ip2 = (stdlib_complex64_t *)CY; + is1 = (int64_t)strideX; + is2 = (int64_t)strideY; + ip1 += offsetX; + ip2 += offsetY; + for ( i = 0; i < N; i++, ip1 += is1, ip2 += is2 ) { + x = *ip1; + y = *ip2; + *ip2 = stdlib_base_complex64_add( stdlib_base_complex64_mul( ca, x ), y ); + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.native.js b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.native.js new file mode 100644 index 000000000000..2ff1902df663 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.native.js @@ -0,0 +1,547 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var caxpy = tryRequire( resolve( __dirname, './../lib/caxpy.native.js' ) ); +var opts = { + 'skip': ( caxpy instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof caxpy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', opts, function test( t ) { + t.strictEqual( caxpy.length, 6, 'arity of 6' ); + t.end(); +}); + +tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy`', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, // 4 + -0.8, // 4 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 1, cy, 1 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -1.55, // 2 + 0.5, // 2 + 0.03, // 3 + -0.89, // 3 + -0.38, // 4 + -0.96, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cx` stride', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, + -0.7, + -0.1, // 2 + -0.9, // 2 + 0.2, + -0.8, + -0.9, // 3 + -0.4, // 3 + 0.1, + 0.4, + -0.6, // 4 + 0.6 // 4 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 2, cy, 1 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -1.57, // 2 + 0.21, // 2 + 0.06, // 3 + -0.13, // 3 + 0.28, // 4 + 0.16, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cy` stride', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, // 4 + -0.8, // 4 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, + 0.5, + 0.7, // 2 + -0.6, // 2 + 0.1, + -0.5, + -0.1, // 3 + -0.2, // 3 + -0.5, + -0.3, + 0.8, // 4 + -0.7 // 4 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 1, cy, 2 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -0.9, + 0.5, + 0.05, // 2 + -0.6, // 2 + 0.1, + -0.5, + -0.77, // 3 + -0.49, // 3 + -0.5, + -0.3, + 0.32, // 4 + -1.16 // 4 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function returns a reference to the output array', opts, function test( t ) { + var out; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + cy = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + out = caxpy( cx.length, ca, cx, 1, cy, 1 ); + + t.strictEqual( out, cy, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the second input array unchanged', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + caxpy( -1, ca, cx, 1, cy, 1 ); + t.deepEqual( viewY, expected, 'returns expected value' ); + + caxpy( 0, ca, cx, 1, cy, 1 ); + t.deepEqual( viewY, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative `cx` strides', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 4 + -0.8, // 4 + -0.4, + -0.7, + -0.1, // 3 + -0.9, // 3 + 0.2, + -0.8, + -0.9, // 2 + -0.4, // 2 + 0.1, + 0.4, + -0.6, // 1 + 0.6 // 1 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, -2, cy, 1 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.78, // 1 + 0.06, // 1 + -1.54, // 2 + 0.97, // 2 + 0.03, // 3 + -0.89, // 3 + -0.18, // 4 + -1.31, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports negative `cy` strides', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, + -0.7, + -0.1, // 2 + -0.9, // 2 + 0.2, + -0.8, + -0.9, // 3 + -0.4, // 3 + 0.1, + 0.4, + -0.6, // 4 + 0.6 // 4 + ] ); + cy = new Complex64Array( [ + 0.6, // 4 + -0.6, // 4 + -0.9, + 0.5, + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, // 2 + -0.2, // 2 + -0.5, + -0.3, + 0.8, // 1 + -0.7 // 1 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 2, cy, -2 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.78, // 4 + 0.06, // 4 + -0.9, + 0.5, + 0.06, // 3 + -0.13, // 3 + 0.1, + -0.5, + -0.77, // 2 + -0.49, // 2 + -0.5, + -0.3, + 0.52, // 1 + -1.51 // 1 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 4 + -0.8, // 4 + -0.4, // 3 + -0.7, // 3 + -0.1, // 2 + -0.9, // 2 + 0.2, // 1 + -0.8, // 1 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 4 + -0.6, // 4 + -0.9, + 0.5, + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, // 2 + -0.2, // 2 + -0.5, + -0.3, + 0.8, // 1 + -0.7 // 1 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, -1, cy, -2 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 4 + -1.41, // 4 + -0.9, + 0.5, + 0.05, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.77, // 2 + -0.49, // 2 + -0.5, + -0.3, + 0.32, // 1 + -1.16 // 1 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports view offsets', opts, function test( t ) { + var expected; + var viewY; + var cx0; + var cy0; + var cx1; + var cy1; + var ca; + + // Initial arrays... + cx0 = new Complex64Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, + 6.0 + ]); + cy0 = new Complex64Array([ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, // 1 + 1.0 // 1 + ]); + + // Define a scalar constant: + ca = new Complex64( 2.0, 2.0 ); + + // Create offset views... + cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // begin at the 2nd element + cy1 = new Complex64Array( cy0.buffer, cy0.BYTES_PER_ELEMENT*2 ); // begin at the 3rd element + + caxpy( 1, ca, cx1, 1, cy1, 1 ); + + viewY = new Float32Array( cy0.buffer ); + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, -1.0, 15.0 ] ); + + t.deepEqual( viewY, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.native.js new file mode 100644 index 000000000000..9b2832ee4b2d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/caxpy/test/test.ndarray.native.js @@ -0,0 +1,632 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var caxpy = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( caxpy instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof caxpy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', opts, function test( t ) { + t.strictEqual( caxpy.length, 8, 'arity of 8' ); + t.end(); +}); + +tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy`', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, // 4 + -0.8, // 4 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 1, 0, cy, 1, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -1.55, // 2 + 0.5, // 2 + 0.03, // 3 + -0.89, // 3 + -0.38, // 4 + -0.96, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cx` stride', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, + -0.7, + -0.1, // 2 + -0.9, // 2 + 0.2, + -0.8, + -0.9, // 3 + -0.4, // 3 + 0.1, + 0.4, + -0.6, // 4 + 0.6 // 4 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 2, 0, cy, 1, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -1.57, // 2 + 0.21, // 2 + 0.06, // 3 + -0.13, // 3 + 0.28, // 4 + 0.16, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cx` offset', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, + -0.8, + -0.4, // 1 + -0.7, // 1 + -0.1, + -0.9, + 0.2, // 2 + -0.8, // 2 + -0.9, + -0.4, + 0.1, // 3 + 0.4, // 3 + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 3, ca, cx, 2, 1, cy, 1, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + -0.05, // 1 + -0.6, // 1 + -1.38, // 2 + 0.04, // 2 + 1.02, // 3 + -0.51, // 3 + 0.1, + -0.5, + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cy` stride', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, // 4 + -0.8, // 4 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, + 0.5, + 0.7, // 2 + -0.6, // 2 + 0.1, + -0.5, + -0.1, // 3 + -0.2, // 3 + -0.5, + -0.3, + 0.8, // 4 + -0.7 // 4 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 1, 0, cy, 2, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 1 + -1.41, // 1 + -0.9, + 0.5, + 0.05, // 2 + -0.6, // 2 + 0.1, + -0.5, + -0.77, // 3 + -0.49, // 3 + -0.5, + -0.3, + 0.32, // 4 + -1.16 // 4 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a `cy` offset', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, // 2 + -0.7, // 2 + -0.1, // 3 + -0.9, // 3 + 0.2, + -0.8, + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, + -0.6, + -0.9, // 1 + 0.5, // 1 + 0.7, + -0.6, + 0.1, // 2 + -0.5, // 2 + -0.1, + -0.2, + -0.5, // 3 + -0.3, // 3 + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 3, ca, cx, 1, 0, cy, 2, 1 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.6, + -0.6, + -1.18, // 1 + -0.31, // 1 + 0.7, + -0.6, + -0.55, // 2 + -0.5, // 2 + -0.1, + -0.2, + -1.17, // 3 + -0.59, // 3 + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function returns a reference to the output array', opts, function test( t ) { + var out; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + cy = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + out = caxpy( cx.length, ca, cx, 1, 0, cy, 1, 0 ); + + t.strictEqual( out, cy, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the second input array unchanged', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + + caxpy( -1, ca, cx, 1, 0, cy, 1, 0 ); + t.deepEqual( viewY, expected, 'returns expected value' ); + + caxpy( 0, ca, cx, 1, 0, cy, 1, 0 ); + t.deepEqual( viewY, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `cx` stride', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 4 + -0.8, // 4 + -0.4, + -0.7, + -0.1, // 3 + -0.9, // 3 + 0.2, + -0.8, + -0.9, // 2 + -0.4, // 2 + 0.1, + 0.4, + -0.6, // 1 + 0.6 // 1 + ] ); + cy = new Complex64Array( [ + 0.6, // 1 + -0.6, // 1 + -0.9, // 2 + 0.5, // 2 + 0.7, // 3 + -0.6, // 3 + 0.1, // 4 + -0.5, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, -2, 6, cy, 1, 0 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.78, // 1 + 0.06, // 1 + -1.54, // 2 + 0.97, // 2 + 0.03, // 3 + -0.89, // 3 + -0.18, // 4 + -1.31, // 4 + -0.1, + -0.2, + -0.5, + -0.3, + 0.8, + -0.7 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports a negative `cy` stride', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 1 + -0.8, // 1 + -0.4, + -0.7, + -0.1, // 2 + -0.9, // 2 + 0.2, + -0.8, + -0.9, // 3 + -0.4, // 3 + 0.1, + 0.4, + -0.6, // 4 + 0.6 // 4 + ] ); + cy = new Complex64Array( [ + 0.6, // 4 + -0.6, // 4 + -0.9, + 0.5, + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, // 2 + -0.2, // 2 + -0.5, + -0.3, + 0.8, // 1 + -0.7 // 1 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, 2, 0, cy, -2, 6 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.78, // 4 + 0.06, // 4 + -0.9, + 0.5, + 0.06, // 3 + -0.13, // 3 + 0.1, + -0.5, + -0.77, // 2 + -0.49, // 2 + -0.5, + -0.3, + 0.52, // 1 + -1.51 // 1 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var expected; + var viewY; + var ca; + var cx; + var cy; + + cx = new Complex64Array( [ + 0.7, // 4 + -0.8, // 4 + -0.4, // 3 + -0.7, // 3 + -0.1, // 2 + -0.9, // 2 + 0.2, // 1 + -0.8, // 1 + -0.9, + -0.4, + 0.1, + 0.4, + -0.6, + 0.6 + ] ); + cy = new Complex64Array( [ + 0.6, // 4 + -0.6, // 4 + -0.9, + 0.5, + 0.7, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.1, // 2 + -0.2, // 2 + -0.5, + -0.3, + 0.8, // 1 + -0.7 // 1 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + caxpy( 4, ca, cx, -1, 3, cy, -2, 6 ); + + viewY = new Float32Array( cy.buffer ); + expected = new Float32Array( [ + 0.32, // 4 + -1.41, // 4 + -0.9, + 0.5, + 0.05, // 3 + -0.6, // 3 + 0.1, + -0.5, + -0.77, // 2 + -0.49, // 2 + -0.5, + -0.3, + 0.32, // 1 + -1.16 // 1 + ] ); + isApprox( t, viewY, expected, 10.0 ); + t.end(); +}); From e045d27de94db3bfe6223bc4d3c5824fcde83f79 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Wed, 11 Dec 2024 19:01:45 +0530 Subject: [PATCH 2/5] chore: update package.json --- lib/node_modules/@stdlib/blas/base/caxpy/package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/package.json b/lib/node_modules/@stdlib/blas/base/caxpy/package.json index 4bad808433a8..5f333ee71a1d 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/package.json +++ b/lib/node_modules/@stdlib/blas/base/caxpy/package.json @@ -14,11 +14,15 @@ } ], "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", + "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", From 613ccaed51d063c24284f627936f81282ee3f24b Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 11 Dec 2024 18:50:59 -0800 Subject: [PATCH 3/5] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_ndarray.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_ndarray.c b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_ndarray.c index 2d0c33747063..0d52ca340a57 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_ndarray.c +++ b/lib/node_modules/@stdlib/blas/base/caxpy/src/caxpy_ndarray.c @@ -25,7 +25,7 @@ #include /** -*Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector using alternative indexing semantics. +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant and adds the result to a single-precision complex floating-point vector using alternative indexing semantics. * * @param N number of indexed elements * @param ca scalar constant @@ -46,7 +46,7 @@ void API_SUFFIX(c_caxpy_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca if ( N <= 0 ) { return; } - if( c_scabs1( ca ) == 0.0f ) { + if ( c_scabs1( ca ) == 0.0f ) { return; } stdlib_complex64_t *ip1 = (stdlib_complex64_t *)CX; From 9aaa148de9c6da48d8c3c372e55f9c81c35c9749 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 12 Dec 2024 11:56:20 +0530 Subject: [PATCH 4/5] docs: update README for C implementation --- .../@stdlib/blas/base/caxpy/README.md | 146 ++++++++++++++++++ .../@stdlib/blas/base/daxpy/README.md | 2 +- 2 files changed, 147 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/caxpy/README.md b/lib/node_modules/@stdlib/blas/base/caxpy/README.md index 08ac120e4b16..80e49ff2b8a2 100644 --- a/lib/node_modules/@stdlib/blas/base/caxpy/README.md +++ b/lib/node_modules/@stdlib/blas/base/caxpy/README.md @@ -229,6 +229,152 @@ logEach( '(%s)*(%s) + (%s) = %s', ca, cx, cyc, cy ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/caxpy.h" +``` + +#### c_caxpy( N, ca, \*CX, strideX, \*CY, strideY ) + +Scales values from `cx` by `ca` and adds the result to `cy`. + +```c +#include "stdlib/complex/float32/ctor.h" + +float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; +float cy[] = { -1.0f, -2.0f, -3.0f, -4.0f, -5.0f, -6.0f, -7.0f, -8.0f }; +const stdlib_complex64_t ca = stdlib_complex64( 2.0f, 2.0f ); + +c_caxpy( 4, ca, (void *)cx, 1, (void *)cy, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **ca**: `[in] stdlib_complex64_t` scalar constant. +- **CX**: `[in] void*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `CX`. +- **CY**: `[inout] void*` output array. +- **strideY**: `[in] CBLAS_INT` index increment for `CY`. + +```c +void c_caxpy( const CBLAS_INT N, const stdlib_complex64_t ca, const void *CX, const CBLAS_INT strideX, void *CY, const CBLAS_INT strideY ); +``` + +#### c_caxpy_ndarray( N, ca, \*CX, strideX, offsetX, \*CY, strideY, offsetY ) + +Scales values from `cx` by `ca` and adds the result to `cy` using alternative indexing semantics. + +```c +#include "stdlib/complex/float32/ctor.h" + +float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; +float cy[] = { -1.0f, -2.0f, -3.0f, -4.0f, -5.0f, -6.0f, -7.0f, -8.0f } +const stdlib_complex64_t ca = stdlib_complex64( 2.0f, 2.0f ); + +c_caxpy( 4, ca, (void *)cx, 1, 0, (void *)cy, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **ca**: `[in] stdlib_complex64_t` scalar constant. +- **CX**: `[in] void*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `CX`. +- **offsetX**: `[in] CBLAS_INT` starting index for `CX`. +- **CY**: `[inout] void*` output array. +- **strideY**: `[in] CBLAS_INT` index increment for `CY`. +- **offsetY**: `[in] CBLAS_INT` starting index for `CY`. + +```c +void c_caxpy_ndarray( const CBLAS_INT N, const stdlib_complex64_t ca, const void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX, void *CY, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/caxpy.h" +#include "stdlib/complex/float32/ctor.h" +#include + +int main( void ) { + // Create strided arrays of interleaved real and imaginary components... + float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + float cy[] = { -1.0f, -2.0f, -3.0f, -4.0f, -5.0f, -6.0f, -7.0f, -8.0f }; + + // Create a complex scalar: + const stdlib_complex64_t ca = stdlib_complex64( 2.0f, 2.0f ); + + // Specify the number of elements: + const int N = 4; + + // Specify strides... + const int strideX = 1; + const int strideY = 1; + + // Scale values from `cx` by `ca` and adds the result to `cy`: + c_caxpy( N, ca, (void *)cx, strideX, (void *)cy, strideY ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "cy[ %i ] = %f + %fj\n", i, cy[ i*2 ], cy[ (i*2)+1 ] ); + } + + // Scales values from `cx` by `ca` and adds the result to `cy` using alternative indexing semantics: + c_caxpy_ndarray( N, ca, (void *)cx, -strideX, 3, (void *)cy, -strideY, 3 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "cy[ %i ] = %f + %fj\n", i, cy[ i*2 ], cy[ (i*2)+1 ] ); + } +} +``` + +
+ + + +
+ + +