From 32082fa664e2393b8c98042fb1e7692c16cb3cb6 Mon Sep 17 00:00:00 2001 From: Arjan Date: Thu, 27 Aug 2026 11:07:06 +0530 Subject: [PATCH 1/7] chore: scaffold C implementation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/ndarray/dxmy/binding.gyp | 170 ++++++++++++++++++ .../blas/ext/base/ndarray/dxmy/include.gypi | 53 ++++++ .../stdlib/blas/ext/base/ndarray/dxmy.h | 40 +++++ .../blas/ext/base/ndarray/dxmy/lib/index.js | 16 +- .../blas/ext/base/ndarray/dxmy/lib/native.js | 67 +++++++ .../blas/ext/base/ndarray/dxmy/manifest.json | 110 ++++++++++++ .../blas/ext/base/ndarray/dxmy/package.json | 4 + .../blas/ext/base/ndarray/dxmy/src/Makefile | 70 ++++++++ .../blas/ext/base/ndarray/dxmy/src/addon.c | 63 +++++++ .../blas/ext/base/ndarray/dxmy/src/main.c | 50 ++++++ 10 files changed, 642 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/include/stdlib/blas/ext/base/ndarray/dxmy.h create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/main.c diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/binding.gyp b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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', + + # 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 + }, # 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/ext/base/ndarray/dxmy/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '} arrays - array-like object containing ndarrays +* @returns {ndarray} output ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* +* var x = new Float64Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Vector( [ 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* var out = dxmy( [ x, y ] ); +* // returns [ 2.0, 6.0, 12.0, 20.0, 30.0 ] +*/ +function dxmy( arrays ) { + var x; + var y; + + x = arrays[ 0 ]; + y = arrays[ 1 ]; + addon( getData( x ), serialize( x ), getData( y ), serialize( y ) ); + return y; +} + + +// EXPORTS // + +module.exports = dxmy; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/manifest.json new file mode 100644 index 000000000000..5463f08b2d02 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/manifest.json @@ -0,0 +1,110 @@ +{ + "options": { + "task": "build", + "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", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dxmy", + "@stdlib/ndarray/ctor", + "@stdlib/ndarray/base/napi/addon-arguments", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/create-double" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dxmy", + "@stdlib/ndarray/ctor", + "@stdlib/ndarray/dtypes", + "@stdlib/ndarray/index-modes", + "@stdlib/ndarray/orders", + "@stdlib/ndarray/base/bytes-per-element" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dxmy", + "@stdlib/ndarray/ctor", + "@stdlib/ndarray/dtypes", + "@stdlib/ndarray/index-modes", + "@stdlib/ndarray/orders", + "@stdlib/ndarray/base/bytes-per-element" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dxmy", + "@stdlib/ndarray/ctor" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/package.json index 23db04d61100..905b1d7acce2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/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", diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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/ext/base/ndarray/dxmy/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/addon.c new file mode 100644 index 000000000000..19d5195b6aed --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/addon.c @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/ext/base/ndarray/dxmy.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/base/napi/addon_arguments.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include +#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, 4 ); + // Process provided arguments: + struct ndarray *arrays[ 2 ]; + napi_value err; + napi_status status = stdlib_ndarray_napi_addon_arguments( env, argv, 4, 2, arrays, &err ); + assert( status == napi_ok ); + if ( err != NULL ) { + status = napi_throw( env, err ); + assert( status == napi_ok ); + return NULL; + } + // Create a const-qualified view of the argument pointer list: + const struct ndarray *arr[ 2 ] = { + arrays[ 0 ], + arrays[ 1 ] + }; + // Perform computation: + stdlib_blas_ext_dxmy( arr ); + + // Free allocated memory: + stdlib_ndarray_free( arrays[ 0 ] ); + stdlib_ndarray_free( arrays[ 1 ] ); + arrays[ 0 ] = NULL; + arrays[ 1 ] = NULL; + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/main.c new file mode 100644 index 000000000000..68184cf152a3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/src/main.c @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/ext/base/ndarray/dxmy.h" +#include "stdlib/blas/ext/base/dxmy.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/blas/base/shared.h" + +/** +* Multiplies elements of a one-dimensional double-precision floating-point ndarray by the corresponding elements of a second one-dimensional double-precision floating-point ndarray and assigns the results to the second ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional output ndarray. +* +* @param arrays list containing ndarrays +*/ +void stdlib_blas_ext_dxmy( const struct ndarray *arrays[] ) { + const struct ndarray *x = arrays[ 0 ]; + const struct ndarray *y = arrays[ 1 ]; + + const CBLAS_INT N = stdlib_ndarray_dimension( x, 0 ); + + const CBLAS_INT strideX = stdlib_ndarray_stride_elements( x, 0 ); + const CBLAS_INT offsetX = stdlib_ndarray_offset_elements( x ); + const CBLAS_INT strideY = stdlib_ndarray_stride_elements( y, 0 ); + const CBLAS_INT offsetY = stdlib_ndarray_offset_elements( y ); + + const double *dataX = (const double *)stdlib_ndarray_data( x ); + double *dataY = (double *)stdlib_ndarray_data( y ); + API_SUFFIX(stdlib_strided_dxmy_ndarray)( N, dataX, strideX, offsetX, dataY, strideY, offsetY ); +} From 03265ae44931d89a1c4885d041a9a989beff1578 Mon Sep 17 00:00:00 2001 From: Arjan Date: Thu, 27 Aug 2026 11:08:23 +0530 Subject: [PATCH 2/7] test: add tests for native addon --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/ndarray/dxmy/test/test.js | 213 ++------------- .../ext/base/ndarray/dxmy/test/test.main.js | 234 +++++++++++++++++ .../ext/base/ndarray/dxmy/test/test.native.js | 243 ++++++++++++++++++ 3 files changed, 505 insertions(+), 185 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.js index 9808017488b2..0a74ffb3215b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.js @@ -21,26 +21,16 @@ // MODULES // var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); var dxmy = require( './../lib' ); -// FUNCTIONS // +// VARIABLES // -/** -* Returns a one-dimensional ndarray. -* -* @private -* @param {Float64Array} buffer - underlying data buffer -* @param {NonNegativeInteger} length - number of indexed elements -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - index offset -* @returns {ndarray} one-dimensional ndarray -*/ -function vector( buffer, length, stride, offset ) { - return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' ); -} +var opts = { + 'skip': IS_BROWSER +}; // TESTS // @@ -51,184 +41,37 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 1', function test( t ) { - t.strictEqual( dxmy.length, 1, 'has expected arity' ); - t.end(); -}); - -tape( 'the function multiplies `x` by `y` and assigns the results to `y`', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - - xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); - ybuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -1.0 ] ); - x = vector( xbuf, 5, 1, 0 ); - y = vector( ybuf, 5, 1, 0 ); - expected = new Float64Array([ - -2.0, // -2.0 * 1.0 - 2.0, // 1.0 * 2.0 - -9.0, // 3.0 * (-3.0) - -20.0, // -5.0 * 4.0 - -4.0 // 4.0 * (-1.0) - ]); - - actual = dxmy( [ x, y ] ); - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dxmy = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + t.strictEqual( dxmy, mock, 'returns expected value' ); t.end(); -}); -tape( 'the function supports input ndarrays having non-unit strides', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - - xbuf = new Float64Array([ - -2.0, // 0 - 1.0, - 3.0, // 1 - -5.0, - 4.0, // 2 - 0.0, - -1.0, // 3 - -3.0 - ]); - ybuf = new Float64Array([ - 1.0, // 0 - 2.0, - -3.0, // 1 - 4.0, - -1.0, // 2 - 0.0, - 3.0, // 3 - 2.0 - ]); - x = vector( xbuf, 4, 2, 0 ); - y = vector( ybuf, 4, 2, 0 ); - expected = new Float64Array([ - -2.0, // -2.0 * 1.0 - 2.0, - -9.0, // 3.0 * (-3.0) - 4.0, - -4.0, // 4.0 * (-1.0) - 0.0, - -3.0, // -1.0 * 3.0 - 2.0 - ]); - - actual = dxmy( [ x, y ] ); - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); + function tryRequire() { + return mock; + } - t.end(); + function mock() { + // Mock... + } }); -tape( 'the function supports input ndarrays having negative strides', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - - xbuf = new Float64Array([ - -2.0, // 4 - 1.0, // 3 - 3.0, // 2 - -5.0, // 1 - 4.0 // 0 - ]); - ybuf = new Float64Array([ - 1.0, // 4 - 2.0, // 3 - -3.0, // 2 - 4.0, // 1 - -1.0 // 0 - ]); - x = vector( xbuf, 5, -1, 4 ); - y = vector( ybuf, 5, -1, 4 ); - expected = new Float64Array([ - -2.0, // -2.0 * 1.0 - 2.0, // 1.0 * 2.0 - -9.0, // 3.0 * (-3.0) - -20.0, // -5.0 * 4.0 - -4.0 // 4.0 * (-1.0) - ]); - - actual = dxmy( [ x, y ] ); - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dxmy; + var main; - t.end(); -}); + main = require( './../lib/main.js' ); -tape( 'the function supports input ndarrays having non-zero offsets', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - - xbuf = new Float64Array([ - 1.0, - -2.0, - 3.0, // 0 - -5.0, // 1 - 4.0, // 2 - 0.0 - ]); - ybuf = new Float64Array([ - 1.0, - -2.0, - 0.0, // 0 - 4.0, // 1 - -1.0, // 2 - 0.0 - ]); - x = vector( xbuf, 3, 1, 2 ); - y = vector( ybuf, 3, 1, 2 ); - expected = new Float64Array([ - 1.0, - -2.0, - 0.0, // 3.0 * 0.0 - -20.0, // -5.0 * 4.0 - -4.0, // 4.0 * (-1.0) - 0.0 - ]); - - actual = dxmy( [ x, y ] ); - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); + dxmy = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + t.strictEqual( dxmy, main, 'returns expected value' ); t.end(); -}); - -tape( 'the function returns the output ndarray unchanged when the input ndarrays are empty', function test( t ) { - var expected; - var actual; - var xbuf; - var ybuf; - var x; - var y; - xbuf = new Float64Array( [] ); - ybuf = new Float64Array( [] ); - x = vector( xbuf, 0, 1, 0 ); - y = vector( ybuf, 0, 1, 0 ); - expected = new Float64Array( [] ); - - actual = dxmy( [ x, y ] ); - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); + function tryRequire() { + return new Error( 'Cannot find module' ); + } }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.main.js new file mode 100644 index 000000000000..1c8d080e03b5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.main.js @@ -0,0 +1,234 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var dxmy = require( './../lib/main.js' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Float64Array} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dxmy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( dxmy.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function multiplies `x` by `y` and assigns the results to `y`', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); + ybuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -1.0 ] ); + x = vector( xbuf, 5, 1, 0 ); + y = vector( ybuf, 5, 1, 0 ); + expected = new Float64Array([ + -2.0, // -2.0 * 1.0 + 2.0, // 1.0 * 2.0 + -9.0, // 3.0 * (-3.0) + -20.0, // -5.0 * 4.0 + -4.0 // 4.0 * (-1.0) + ]); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input ndarrays having non-unit strides', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array([ + -2.0, // 0 + 1.0, + 3.0, // 1 + -5.0, + 4.0, // 2 + 0.0, + -1.0, // 3 + -3.0 + ]); + ybuf = new Float64Array([ + 1.0, // 0 + 2.0, + -3.0, // 1 + 4.0, + -1.0, // 2 + 0.0, + 3.0, // 3 + 2.0 + ]); + x = vector( xbuf, 4, 2, 0 ); + y = vector( ybuf, 4, 2, 0 ); + expected = new Float64Array([ + -2.0, // -2.0 * 1.0 + 2.0, + -9.0, // 3.0 * (-3.0) + 4.0, + -4.0, // 4.0 * (-1.0) + 0.0, + -3.0, // -1.0 * 3.0 + 2.0 + ]); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input ndarrays having negative strides', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array([ + -2.0, // 4 + 1.0, // 3 + 3.0, // 2 + -5.0, // 1 + 4.0 // 0 + ]); + ybuf = new Float64Array([ + 1.0, // 4 + 2.0, // 3 + -3.0, // 2 + 4.0, // 1 + -1.0 // 0 + ]); + x = vector( xbuf, 5, -1, 4 ); + y = vector( ybuf, 5, -1, 4 ); + expected = new Float64Array([ + -2.0, // -2.0 * 1.0 + 2.0, // 1.0 * 2.0 + -9.0, // 3.0 * (-3.0) + -20.0, // -5.0 * 4.0 + -4.0 // 4.0 * (-1.0) + ]); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input ndarrays having non-zero offsets', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array([ + 1.0, + -2.0, + 3.0, // 0 + -5.0, // 1 + 4.0, // 2 + 0.0 + ]); + ybuf = new Float64Array([ + 1.0, + -2.0, + 0.0, // 0 + 4.0, // 1 + -1.0, // 2 + 0.0 + ]); + x = vector( xbuf, 3, 1, 2 ); + y = vector( ybuf, 3, 1, 2 ); + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, // 3.0 * 0.0 + -20.0, // -5.0 * 4.0 + -4.0, // 4.0 * (-1.0) + 0.0 + ]); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the output ndarray unchanged when the input ndarrays are empty', function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array( [] ); + ybuf = new Float64Array( [] ); + x = vector( xbuf, 0, 1, 0 ); + y = vector( ybuf, 0, 1, 0 ); + expected = new Float64Array( [] ); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.native.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.native.js new file mode 100644 index 000000000000..e279e8e2c560 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/test/test.native.js @@ -0,0 +1,243 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var dxmy = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( dxmy instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Float64Array} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dxmy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', opts, function test( t ) { + t.strictEqual( dxmy.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function multiplies `x` by `y` and assigns the results to `y`', opts, function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0 ] ); + ybuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -1.0 ] ); + x = vector( xbuf, 5, 1, 0 ); + y = vector( ybuf, 5, 1, 0 ); + expected = new Float64Array([ + -2.0, // -2.0 * 1.0 + 2.0, // 1.0 * 2.0 + -9.0, // 3.0 * (-3.0) + -20.0, // -5.0 * 4.0 + -4.0 // 4.0 * (-1.0) + ]); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input ndarrays having non-unit strides', opts, function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array([ + -2.0, // 0 + 1.0, + 3.0, // 1 + -5.0, + 4.0, // 2 + 0.0, + -1.0, // 3 + -3.0 + ]); + ybuf = new Float64Array([ + 1.0, // 0 + 2.0, + -3.0, // 1 + 4.0, + -1.0, // 2 + 0.0, + 3.0, // 3 + 2.0 + ]); + x = vector( xbuf, 4, 2, 0 ); + y = vector( ybuf, 4, 2, 0 ); + expected = new Float64Array([ + -2.0, // -2.0 * 1.0 + 2.0, + -9.0, // 3.0 * (-3.0) + 4.0, + -4.0, // 4.0 * (-1.0) + 0.0, + -3.0, // -1.0 * 3.0 + 2.0 + ]); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input ndarrays having negative strides', opts, function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array([ + -2.0, // 4 + 1.0, // 3 + 3.0, // 2 + -5.0, // 1 + 4.0 // 0 + ]); + ybuf = new Float64Array([ + 1.0, // 4 + 2.0, // 3 + -3.0, // 2 + 4.0, // 1 + -1.0 // 0 + ]); + x = vector( xbuf, 5, -1, 4 ); + y = vector( ybuf, 5, -1, 4 ); + expected = new Float64Array([ + -2.0, // -2.0 * 1.0 + 2.0, // 1.0 * 2.0 + -9.0, // 3.0 * (-3.0) + -20.0, // -5.0 * 4.0 + -4.0 // 4.0 * (-1.0) + ]); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input ndarrays having non-zero offsets', opts, function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array([ + 1.0, + -2.0, + 3.0, // 0 + -5.0, // 1 + 4.0, // 2 + 0.0 + ]); + ybuf = new Float64Array([ + 1.0, + -2.0, + 0.0, // 0 + 4.0, // 1 + -1.0, // 2 + 0.0 + ]); + x = vector( xbuf, 3, 1, 2 ); + y = vector( ybuf, 3, 1, 2 ); + expected = new Float64Array([ + 1.0, + -2.0, + 0.0, // 3.0 * 0.0 + -20.0, // -5.0 * 4.0 + -4.0, // 4.0 * (-1.0) + 0.0 + ]); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the output ndarray unchanged when the input ndarrays are empty', opts, function test( t ) { + var expected; + var actual; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Float64Array( [] ); + ybuf = new Float64Array( [] ); + x = vector( xbuf, 0, 1, 0 ); + y = vector( ybuf, 0, 1, 0 ); + expected = new Float64Array( [] ); + + actual = dxmy( [ x, y ] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); From 9858de4b7647df21a1777ce9c192074b84bd9d03 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 28 Aug 2026 10:36:44 +0530 Subject: [PATCH 3/7] bench: add benchmark for native addon --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/ndarray/dxmy/benchmark/benchmark.js | 2 +- .../dxmy/benchmark/benchmark.native.js | 108 ++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/benchmark.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/benchmark.js index a8d2f826b5f6..562602c69a06 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/benchmark.js @@ -25,7 +25,7 @@ var uniform = require( '@stdlib/random/uniform' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; -var dxmy = require( './../lib' ); +var dxmy = require( './../lib/main.js' ); // VARIABLES // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/benchmark.native.js new file mode 100644 index 000000000000..652b2b8908ce --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/benchmark.native.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dxmy = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( dxmy instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( [ len ], -100.0, 100.0, options ); + var y = uniform( [ len ], -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dxmy( [ x, y ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + 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( format( '%s:len=%d', pkg, len ), opts, f ); + } +} + +main(); From a46c6a706b4610441fdb190e417ac14296005b20 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 28 Aug 2026 10:44:12 +0530 Subject: [PATCH 4/7] bench: benchmark C api --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/ndarray/dxmy/benchmark/c/Makefile | 146 +++++++++++++ .../dxmy/benchmark/c/benchmark.length.c | 193 ++++++++++++++++++ 2 files changed, 339 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/c/benchmark.length.c diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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/ext/base/ndarray/dxmy/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..ac7c8154687e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/benchmark/c/benchmark.length.c @@ -0,0 +1,193 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/ext/base/ndarray/dxmy.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include +#include +#include +#include +#include +#include + +#define NAME "dxmy" +#define ITERATIONS 1000000 +#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 [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark( int iterations, int len ) { + enum STDLIB_NDARRAY_INDEX_MODE imode; + const struct ndarray *arrays[ 2 ]; + enum STDLIB_NDARRAY_ORDER order; + int8_t submodes[ 1 ]; + int64_t strides[ 1 ]; + int64_t shape[ 1 ]; + int64_t nsubmodes; + struct ndarray *x; + struct ndarray *y; + int64_t offset; + double elapsed; + int64_t ndims; + double *dataX; + double *dataY; + double t; + int i; + + ndims = 1; + shape[ 0 ] = len; + strides[ 0 ] = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT; + offset = 0; + order = STDLIB_NDARRAY_ROW_MAJOR; + imode = STDLIB_NDARRAY_INDEX_ERROR; + submodes[ 0 ] = imode; + nsubmodes = 1; + + dataX = (double *) malloc( len * sizeof( double ) ); + dataY = (double *) malloc( len * sizeof( double ) ); + for ( i = 0; i < len; i++ ) { + dataX[ i ] = random_uniform( -100.0, 100.0 ); + dataY[ i ] = random_uniform( -100.0, 100.0 ); + } + + // cppcheck-suppress invalidPointerCast + x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + // cppcheck-suppress invalidPointerCast + y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataY, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + arrays[ 0 ] = x; + arrays[ 1 ] = y; + + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_blas_ext_dxmy( arrays ); + if ( dataY[0] != dataY[0] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + stdlib_ndarray_free( x ); + stdlib_ndarray_free( y ); + free( dataX ); + free( dataY ); + arrays[ 0 ] = NULL; + arrays[ 1 ] = NULL; + + 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 ); +} From e6f1278e0142862c4d7a07dee9dd23b92c819ffa Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 28 Aug 2026 10:51:53 +0530 Subject: [PATCH 5/7] chore: examples for C api --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: passed - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../ext/base/ndarray/dxmy/examples/c/Makefile | 146 ++++++++++++++++++ .../base/ndarray/dxmy/examples/c/example.c | 80 ++++++++++ 2 files changed, 226 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/examples/c/example.c diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/examples/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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/ext/base/ndarray/dxmy/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/examples/c/example.c new file mode 100644 index 000000000000..db1814e4a97f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/examples/c/example.c @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/ext/base/ndarray/dxmy.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include +#include +#include + +int main( void ) { + // Create a data buffer: + const double dataX[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + double dataY[] = { 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 8 }; + + // Specify the array strides: + int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + + // Specify the byte offset: + const int64_t offset = 0; + + // Specify the array order: + const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; + + // Specify the index mode: + const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; + + // Specify the subscript index modes: + int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + const int64_t nsubmodes = 1; + + // Create an ndarray: + // cppcheck-suppress invalidPointerCast + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + // cppcheck-suppress invalidPointerCast + struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataY, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + if ( x == NULL || y == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, y }; + + // Perform computation: + stdlib_blas_ext_dxmy( arrays ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "y[ %i ] = %lf\n", i, dataY[ i ] ); + } + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( y ); +} From c046f5c305d43e62691014afb3915ad948507197 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 28 Aug 2026 11:06:07 +0530 Subject: [PATCH 6/7] docs: document C api in README --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/ndarray/dxmy/README.md | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/README.md index 43b9e92d5cb3..6f3f8c8ad07d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dxmy/README.md @@ -112,6 +112,168 @@ console.log( ndarray2array( y ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/dxdy.h" +``` + +#### stdlib_blas_ext_dxdy( arrays ) + +Multiply elements of a one-dimensional double-precision floating-point ndarray by the corresponding elements of a second one-dimensional double-precision floating-point ndarray and assign the results to the second ndarray. + +```c +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include + +// Create an ndarray: + +const double dataX[] = { 6.0, 12.0, 20.0, 30.0, 42.0 }; +const double dataY[] = { 2.0, 3.0, 4.0, 5.0, 6.0 }; +int64_t shape[] = { 5 }; +int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + +// cppcheck-suppress invalidPointerCast +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); +// cppcheck-suppress invalidPointerCast +struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataY, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Perform computation:Add a comment on line R171Add diff commentMarkdown input: edit mode selected.WritePreviewAdd a suggestionHeadingBold(control b) control⌃ bBItalic(control i) control⌃ iIQuote(control shift right angle bracket) control⌃ shift⇧ right angle bracket>Code(control e) control⌃ eELink(control k) control⌃ kKUnordered list(control 8) control⌃ 88Numbered list(control shift ampersand) control⌃ shift⇧ ampersand&Task list(control shift l) control⌃ shift⇧ lLMentionReferenceMore itemsSaved repliesAdd FilesPaste, drop, or click to add filesCancelCommentStart a review +const struct ndarray *arrays[] = { x, y }; +stdlib_blas_ext_dxmy( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( x ); +stdlib_ndarray_free( y ); +``` + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` list containing the following ndarrays: + + - a one-dimensional input ndarray. + - a one-dimensional output ndarray. + +```c +void stdlib_blas_ext_dxmy( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/dxmy.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include +#include +#include + +int main( void ) { + // Create a data buffer: + const double dataX[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + double dataY[] = { 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 8 }; + + // Specify the array strides: + int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + + // Specify the byte offset: + const int64_t offset = 0; + + // Specify the array order: + const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; + + // Specify the index mode: + const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; + + // Specify the subscript index modes: + int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + const int64_t nsubmodes = 1; + + // Create an ndarray: + // cppcheck-suppress invalidPointerCast + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + // cppcheck-suppress invalidPointerCast + struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataY, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + if ( x == NULL || y == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, y }; + + // Perform computation: + stdlib_blas_ext_dxmy( arrays ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "y[ %i ] = %lf\n", i, dataY[ i ] ); + } + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( y ); +} +``` + +
+ + + +
+ + +