From 899866b0ba259da6e428e3e3cc951d51ff924f32 Mon Sep 17 00:00:00 2001 From: AtharvaPatange <164712914+AtharvaPatange@users.noreply.github.com> Date: Sun, 8 Feb 2026 22:06:18 +0530 Subject: [PATCH 1/8] feat: add C implementation for stats/base/ndarray/smeankbn --- .../stats/base/ndarray/smeankbn/README.md | 148 ++++++++++++++ .../ndarray/smeankbn/benchmark/benchmark.js | 2 +- .../smeankbn/benchmark/benchmark.native.js | 114 +++++++++++ .../ndarray/smeankbn/benchmark/c/Makefile | 138 +++++++++++++ .../smeankbn/benchmark/c/benchmark.length.c | 185 ++++++++++++++++++ .../stats/base/ndarray/smeankbn/binding.gyp | 105 ++++++++++ .../base/ndarray/smeankbn/examples/c/Makefile | 138 +++++++++++++ .../ndarray/smeankbn/examples/c/example.c | 74 +++++++ .../base/ndarray/smeankbn/examples/index.js | 2 +- .../stats/base/ndarray/smeankbn/include.gypi | 53 +++++ .../stdlib/stats/base/ndarray/smeankbn.h | 40 ++++ .../stats/base/ndarray/smeankbn/lib/index.js | 16 +- .../stats/base/ndarray/smeankbn/lib/native.js | 55 ++++++ .../stats/base/ndarray/smeankbn/manifest.json | 110 +++++++++++ .../stats/base/ndarray/smeankbn/package.json | 4 + .../stats/base/ndarray/smeankbn/src/Makefile | 70 +++++++ .../stats/base/ndarray/smeankbn/src/addon.c | 58 ++++++ .../stats/base/ndarray/smeankbn/src/main.c | 33 ++++ .../stats/base/ndarray/smeankbn/test/test.js | 154 +++------------ .../base/ndarray/smeankbn/test/test.main.js | 173 ++++++++++++++++ .../base/ndarray/smeankbn/test/test.native.js | 155 +++++++++++++++ 21 files changed, 1699 insertions(+), 128 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include/stdlib/stats/base/ndarray/smeankbn.h create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/README.md index b84657b388e1..f59ec709ac31 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/README.md @@ -110,6 +110,154 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/ndarray/smeankbn.h" +``` + +#### stdlib_stats_smeankbn( arrays ) + +Computes the [arithmetic mean][arithmetic-mean] of a one-dimensional single-precision floating-point ndarray using an improved Kahan–Babuška algorithm. + +```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 float data[] = { 1.0f, 2.0f, 3.0f, 4.0f }; +int64_t shape[] = { 4 }; +int64_t strides[] = { STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT }; +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Compute the arithmetic mean: +const struct ndarray *arrays[] = { x }; +float v = stdlib_stats_smeankbn( arrays ); +// returns 2.5f + +// Free allocated memory: +stdlib_ndarray_free( x ); +``` + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` list containing a one-dimensional input ndarray. + +```c +float stdlib_stats_smeankbn( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/ndarray/smeankbn.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 float data[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 4 }; + + // Specify the array strides: + int64_t strides[] = { 2*STDLIB_NDARRAY_FLOAT32_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: + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + if ( x == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x }; + + // Compute the arithmetic mean: + float v = stdlib_stats_smeankbn( arrays ); + + // Print the result: + printf( "mean: %f\n", v ); + + // Free allocated memory: + stdlib_ndarray_free( x ); +} +``` + +
+ + + +
+ + + + * * *
diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.js index 7fe421717c4b..0af417069b06 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.js @@ -26,7 +26,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var pkg = require( './../package.json' ).name; -var smeankbn = require( './../lib' ); +var smeankbn = require( './../lib/main.js' ); // VARIABLES // diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js new file mode 100644 index 000000000000..a858938816ed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js @@ -0,0 +1,114 @@ +/** +* @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/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var format = require( '@stdlib/string/format' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var smeankbn = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( smeankbn 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 xbuf; + var x; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = smeankbn( [ x ] ); + if ( isnanf( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( v ) ) { + 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+':len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/Makefile new file mode 100644 index 000000000000..fdee8ba8a8a5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/Makefile @@ -0,0 +1,138 @@ +#/ +# @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 benchmark.length.out +#/ +benchmark.length.out: $(SOURCE_FILES) + $(QUIET) $(CC) \ + $(CFLAGS) \ + $(fPIC) \ + $(INCLUDE) \ + -I ./../../include \ + -o $@ \ + $(SOURCE_FILES) \ + ./benchmark.length.c \ + $(LIBPATH) \ + $(LIBRARIES) + +.PHONY: benchmark.length.out + +#/ +# Runs the benchmark. +# +# @example +# make benchmark +#/ +benchmark: benchmark.length.out + $(QUIET) ./benchmark.length.out + +.PHONY: benchmark + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..6f86e4b375ce --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c @@ -0,0 +1,185 @@ +/** +* @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/stats/base/ndarray/smeankbn.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 "smeankbn" +#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 [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 benchmark( int iterations, int len ) { + enum STDLIB_NDARRAY_INDEX_MODE imode; + const struct ndarray *arrays[ 1 ]; + enum STDLIB_NDARRAY_ORDER order; + int8_t submodes[ 1 ]; + int64_t strides[ 1 ]; + int64_t shape[ 1 ]; + int64_t nsubmodes; + struct ndarray *x; + int64_t offset; + double elapsed; + int64_t ndims; + float *data; + float v; + float t; + int i; + + ndims = 1; + shape[ 0 ] = len; + strides[ 0 ] = STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT; + offset = 0; + order = STDLIB_NDARRAY_ROW_MAJOR; + imode = STDLIB_NDARRAY_INDEX_ERROR; + submodes[ 0 ] = imode; + nsubmodes = 1; + + data = (float *) malloc( len * sizeof( float ) ); + for ( i = 0; i < len; i++ ) { + data[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + // cppcheck-suppress invalidPointerCast + x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + arrays[ 0 ] = x; + + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + v = stdlib_stats_smeankbn( arrays ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + stdlib_ndarray_free( x ); + free( data ); + arrays[ 0 ] = 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 ); +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/binding.gyp b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/binding.gyp new file mode 100644 index 000000000000..e4d4543bf561 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/binding.gyp @@ -0,0 +1,105 @@ +# @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', + ], + }, + ], +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/Makefile new file mode 100644 index 000000000000..2907b378ee50 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/Makefile @@ -0,0 +1,138 @@ +#/ +# @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.out +#/ +example.out: $(SOURCE_FILES) + $(QUIET) $(CC) \ + $(CFLAGS) \ + $(fPIC) \ + $(INCLUDE) \ + -I ./../../include \ + -o $@ \ + $(SOURCE_FILES) \ + ./example.c \ + $(LIBPATH) \ + $(LIBRARIES) + +.PHONY: example.out + +#/ +# Runs the example. +# +# @example +# make example +#/ +example: example.out + $(QUIET) ./example.out + +.PHONY: example + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/example.c new file mode 100644 index 000000000000..a6733dba6935 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/example.c @@ -0,0 +1,74 @@ +/** +* @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/stats/base/ndarray/smeankbn.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 float data[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 4 }; + + // Specify the array strides: + int64_t strides[] = { 2*STDLIB_NDARRAY_FLOAT32_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_FLOAT32, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + if ( x == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x }; + + // Compute the arithmetic mean: + float v = stdlib_stats_smeankbn( arrays ); + + // Print the result: + printf( "mean: %f\n", v ); + + // Free allocated memory: + stdlib_ndarray_free( x ); +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/index.js index 9a265d25c10f..fb95ff2eeaa0 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include.gypi b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/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 an input ndarray +* @returns {number} arithmetic mean +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = smeankbn( [ x ] ); +* // returns 2.5 +*/ +function smeankbn( arrays ) { + var x = arrays[ 0 ]; + return addon( getData( x ), serialize( x ) ); +} + + +// EXPORTS // + +module.exports = smeankbn; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/manifest.json b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/manifest.json new file mode 100644 index 000000000000..0f2cde9eb71e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/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/stats/strided/smeankbn", + "@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/stats/strided/smeankbn", + "@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/stats/strided/smeankbn", + "@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/stats/strided/smeankbn", + "@stdlib/ndarray/ctor" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/package.json index 5f3371f21a4a..40c51330a5e9 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/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/stats/base/ndarray/smeankbn/src/Makefile b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/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/stats/base/ndarray/smeankbn/src/addon.c b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/addon.c new file mode 100644 index 000000000000..c3335ed895a6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/addon.c @@ -0,0 +1,58 @@ +/** +* @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/stats/base/ndarray/smeankbn.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 "stdlib/napi/create_double.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, 2 ); + + // Process provided arguments: + struct ndarray *arrays[ 1 ]; + napi_value err; + napi_status status = stdlib_ndarray_napi_addon_arguments( env, argv, 2, 1, arrays, &err ); + assert( status == napi_ok ); + if ( err != NULL ) { + status = napi_throw( env, err ); + assert( status == napi_ok ); + return NULL; + } + // Perform computation: + STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_stats_smeankbn( arrays ), v ); + + // Free allocated memory: + stdlib_ndarray_free( arrays[ 0 ] ); + arrays[ 0 ] = NULL; + + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/main.c b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/main.c new file mode 100644 index 000000000000..bb67be7c113f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/main.c @@ -0,0 +1,33 @@ +/** +* @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/stats/base/ndarray/smeankbn.h" +#include "stdlib/stats/strided/smeankbn.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/blas/base/shared.h" + +/** +* Computes the arithmetic mean of a one-dimensional single-precision floating-point ndarray using an improved Kahan–Babuška algorithm. +* +* @param arrays list containing an input ndarray +* @return arithmetic mean +*/ +float stdlib_stats_smeankbn( const struct ndarray *arrays[] ) { + const struct ndarray *x = arrays[ 0 ]; + return API_SUFFIX(stdlib_strided_smeankbn_ndarray)( stdlib_ndarray_dimension( x, 0 ), (const float *)stdlib_ndarray_data( x ), stdlib_ndarray_stride_elements( x, 0 ), stdlib_ndarray_offset_elements( x ) ); +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.js index 3586946cf690..6f33180e179a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. @@ -21,28 +21,16 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); -var Float32Array = require( '@stdlib/array/float32' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); var smeankbn = require( './../lib' ); -// FUNCTIONS // +// VARIABLES // -/** -* Returns a one-dimensional ndarray. -* -* @private -* @param {Collection} 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( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); -} +var opts = { + 'skip': IS_BROWSER +}; // TESTS // @@ -53,121 +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( smeankbn.length, 1, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the arithmetic mean of a one-dimensional ndarray', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = smeankbn( [ vector( x, 6, 1, 0 ) ] ); - t.strictEqual( v, 0.5, 'returns expected value' ); - - x = new Float32Array( [ -4.0, -5.0 ] ); - v = smeankbn( [ vector( x, 2, 1, 0 ) ] ); - t.strictEqual( v, -4.5, 'returns expected value' ); - - x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); - v = smeankbn( [ vector( x, 3, 1, 0 ) ] ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); - - x = new Float32Array( [ NaN ] ); - v = smeankbn( [ vector( x, 1, 1, 0 ) ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - x = new Float32Array( [ NaN, NaN ] ); - v = smeankbn( [ vector( x, 2, 1, 0 ) ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an empty ndarray, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [] ); - - v = smeankbn( [ vector( x, 0, 1, 0 ) ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an ndarray containing a single element, the function returns that element', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0 ] ); - - v = smeankbn( [ vector( x, 1, 1, 0 ) ] ); - t.strictEqual( v, 1.0, 'returns expected value' ); +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var smeankbn = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + t.strictEqual( smeankbn, mock, 'returns expected value' ); t.end(); -}); -tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { - var x; - var v; + function tryRequire() { + return mock; + } - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = smeankbn( [ vector( x, 4, 2, 0 ) ] ); - - t.strictEqual( v, 1.25, 'returns expected value' ); - t.end(); + function mock() { + // Mock... + } }); -tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { - var x; - var v; +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var smeankbn; + var main; - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); + main = require( './../lib/main.js' ); - v = smeankbn( [ vector( x, 4, -2, 6 ) ] ); + smeankbn = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); - t.strictEqual( v, 1.25, 'returns expected value' ); + t.strictEqual( smeankbn, main, 'returns expected value' ); t.end(); -}); -tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]); - - v = smeankbn( [ vector( x, 4, 2, 1 ) ] ); - t.strictEqual( v, 1.25, 'returns expected value' ); - - t.end(); + function tryRequire() { + return new Error( 'Cannot find module' ); + } }); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.main.js new file mode 100644 index 000000000000..1346c77670b3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.main.js @@ -0,0 +1,173 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var smeankbn = require( './../lib/main.js' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} 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( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof smeankbn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( smeankbn.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the arithmetic mean of a one-dimensional ndarray', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = smeankbn( [ vector( x, 6, 1, 0 ) ] ); + t.strictEqual( v, 0.5, 'returns expected value' ); + + x = new Float32Array( [ -4.0, -5.0 ] ); + v = smeankbn( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( v, -4.5, 'returns expected value' ); + + x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); + v = smeankbn( [ vector( x, 3, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + v = smeankbn( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + v = smeankbn( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty ndarray, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [] ); + + v = smeankbn( [ vector( x, 0, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an ndarray containing a single element, the function returns that element', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0 ] ); + + v = smeankbn( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = smeankbn( [ vector( x, 4, 2, 0 ) ] ); + + t.strictEqual( v, 1.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = smeankbn( [ vector( x, 4, -2, 6 ) ] ); + + t.strictEqual( v, 1.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = smeankbn( [ vector( x, 4, 2, 1 ) ] ); + t.strictEqual( v, 1.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js new file mode 100644 index 000000000000..c70aebfd405a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js @@ -0,0 +1,155 @@ +/** +* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var smeankbn = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( smeankbn instanceof Error ) +}; + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Float32Array} 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( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof smeankbn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', opts, function test( t ) { + t.strictEqual( smeankbn.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the arithmetic mean of a one-dimensional ndarray', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = smeankbn( [ vector( x, 6, 1, 0 ) ] ); + t.strictEqual( v, 0.5, 'returns expected value' ); + + x = new Float32Array( [ -4.0, -5.0 ] ); + v = smeankbn( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( v, -4.5, 'returns expected value' ); + + x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); + v = smeankbn( [ vector( x, 3, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + v = smeankbn( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + v = smeankbn( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty ndarray, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [] ); + + v = smeankbn( [ vector( x, 0, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an ndarray containing a single element, the function returns that element', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0 ] ); + + v = smeankbn( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the arithmetic mean of a strided ndarray (positive stride)', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + v = smeankbn( [ vector( x, 3, 2, 0 ) ] ); + t.strictEqual( v, 3.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the arithmetic mean of a strided ndarray (negative stride)', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + v = smeankbn( [ vector( x, 3, -2, 4 ) ] ); + t.strictEqual( v, 3.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the arithmetic mean of a strided ndarray (offset)', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + v = smeankbn( [ vector( x, 3, 1, 1 ) ] ); + t.strictEqual( v, 3.0, 'returns expected value' ); + + t.end(); +}); From 6ee861e24c441d6035ab816f23dcffbbec1c3b15 Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> Date: Sun, 8 Feb 2026 22:56:23 +0530 Subject: [PATCH 2/8] Change copyright year from 2026 to 2025 Update copyright year in license comment. Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> --- .../@stdlib/stats/base/ndarray/smeankbn/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/index.js index fb95ff2eeaa0..9a265d25c10f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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. From 16624ec6439a34a7c8d79c355a608921d0b91228 Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> Date: Sun, 8 Feb 2026 22:58:58 +0530 Subject: [PATCH 3/8] change dtype Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> --- .../stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c index 6f86e4b375ce..f876a9317839 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c @@ -114,7 +114,7 @@ static double benchmark( int iterations, int len ) { int64_t ndims; float *data; float v; - float t; + double t; int i; ndims = 1; From 861ca089b1c87b34671ed62b4f2c4f911ad4d68d Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> Date: Sun, 8 Feb 2026 23:01:05 +0530 Subject: [PATCH 4/8] Update benchmark to use isnanf and format Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> --- .../stats/base/ndarray/smeankbn/benchmark/benchmark.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.js index 0af417069b06..1e8c06327ef9 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.js @@ -22,8 +22,9 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var pkg = require( './../package.json' ).name; var smeankbn = require( './../lib/main.js' ); @@ -67,12 +68,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { v = smeankbn( [ x ] ); - if ( isnan( v ) ) { + if ( isnanf( v ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( v ) ) { + if ( isnanf( v ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); @@ -101,7 +102,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':len='+len, f ); + bench( format( '%s:len=%d', pkg, len ), f ); } } From 2147e7ad1d4f0ccbdecd80c0f705d715580c4e7e Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> Date: Mon, 9 Feb 2026 00:33:10 +0530 Subject: [PATCH 5/8] Update benchmark Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> --- .../stats/base/ndarray/smeankbn/benchmark/benchmark.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js index a858938816ed..16b140b8fa88 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js @@ -107,7 +107,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':len='+len, opts, f ); + bench( format( '%s::native:len=%d', pkg, len ), opts, f ); } } From 69e1aefcbb3720e1e8dbe69543cf1a128e48f660 Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> Date: Mon, 9 Feb 2026 00:57:41 +0530 Subject: [PATCH 6/8] Update assertions for NaN and positive zero checks Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> --- .../stats/base/ndarray/smeankbn/test/test.main.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.main.js index 1346c77670b3..6c563f05680b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.main.js @@ -21,8 +21,8 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); var Float32Array = require( '@stdlib/array/float32' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var smeankbn = require( './../lib/main.js' ); @@ -34,7 +34,7 @@ var smeankbn = require( './../lib/main.js' ); * Returns a one-dimensional ndarray. * * @private -* @param {Collection} buffer - underlying data buffer +* @param {Float32Array} buffer - underlying data buffer * @param {NonNegativeInteger} length - number of indexed elements * @param {integer} stride - stride length * @param {NonNegativeInteger} offset - index offset @@ -72,15 +72,15 @@ tape( 'the function calculates the arithmetic mean of a one-dimensional ndarray' x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); v = smeankbn( [ vector( x, 3, 1, 0 ) ] ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); x = new Float32Array( [ NaN ] ); v = smeankbn( [ vector( x, 1, 1, 0 ) ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); x = new Float32Array( [ NaN, NaN ] ); v = smeankbn( [ vector( x, 2, 1, 0 ) ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -92,7 +92,7 @@ tape( 'if provided an empty ndarray, the function returns `NaN`', function test( x = new Float32Array( [] ); v = smeankbn( [ vector( x, 0, 1, 0 ) ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); From 0ddb50f0756f346428fc2c859c18de86d57cab56 Mon Sep 17 00:00:00 2001 From: orthodox-64 Date: Mon, 9 Feb 2026 01:56:01 +0530 Subject: [PATCH 7/8] chore: addressed some changes --- 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 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 --- --- .../base/ndarray/smeankbn/test/test.native.js | 57 ++++++++++++++----- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js index c70aebfd405a..34a6a2402c19 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js @@ -23,7 +23,7 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zero' ); var Float32Array = require( '@stdlib/array/float32' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -81,7 +81,7 @@ tape( 'the function calculates the arithmetic mean of a one-dimensional ndarray' x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); v = smeankbn( [ vector( x, 3, 1, 0 ) ] ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); x = new Float32Array( [ NaN ] ); v = smeankbn( [ vector( x, 1, 1, 0 ) ] ); @@ -118,38 +118,65 @@ tape( 'if provided an ndarray containing a single element, the function returns t.end(); }); -tape( 'the function computes the arithmetic mean of a strided ndarray (positive stride)', opts, function test( t ) { +tape( 'the function supports one-dimensional ndarrays having non-unit strides', opts, function test( t ) { var x; var v; - x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); - v = smeankbn( [ vector( x, 3, 2, 0 ) ] ); - t.strictEqual( v, 3.0, 'returns expected value' ); + v = smeankbn( [ vector( x, 4, 2, 0 ) ] ); + t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); -tape( 'the function computes the arithmetic mean of a strided ndarray (negative stride)', opts, function test( t ) { +tape( 'the function supports one-dimensional ndarrays having negative strides', opts, function test( t ) { var x; var v; - x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); - v = smeankbn( [ vector( x, 3, -2, 4 ) ] ); - t.strictEqual( v, 3.0, 'returns expected value' ); + v = smeankbn( [ vector( x, 4, -2, 6 ) ] ); + t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); -tape( 'the function computes the arithmetic mean of a strided ndarray (offset)', opts, function test( t ) { +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', opts, function test( t ) { var x; var v; - x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - - v = smeankbn( [ vector( x, 3, 1, 1 ) ] ); - t.strictEqual( v, 3.0, 'returns expected value' ); + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = smeankbn( [ vector( x, 4, 2, 1 ) ] ); + t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); From 2900f035378a9aaecf9460245f3c8e4e8379c791 Mon Sep 17 00:00:00 2001 From: AtharvaPatange <164712914+AtharvaPatange@users.noreply.github.com> Date: Mon, 9 Feb 2026 23:17:29 +0530 Subject: [PATCH 8/8] fix: standardize copyright years to 2025 for smeankbn package --- .../stats/base/ndarray/smeankbn/benchmark/benchmark.native.js | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/benchmark/c/Makefile | 2 +- .../stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/binding.gyp | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/examples/c/Makefile | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/examples/c/example.c | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/include.gypi | 2 +- .../smeankbn/include/stdlib/stats/base/ndarray/smeankbn.h | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/lib/native.js | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/src/Makefile | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/src/addon.c | 2 +- lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/main.c | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/test/test.js | 2 +- .../@stdlib/stats/base/ndarray/smeankbn/test/test.native.js | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js index 16b140b8fa88..e1bc14a5ee13 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/Makefile index fdee8ba8a8a5..4e9ea5c5b811 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2026 The Stdlib Authors. +# Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c index f876a9317839..16261528c461 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/benchmark/c/benchmark.length.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/binding.gyp b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/binding.gyp index e4d4543bf561..0b13f6253234 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/binding.gyp @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2026 The Stdlib Authors. +# Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/Makefile index 2907b378ee50..893ed9202548 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2026 The Stdlib Authors. +# Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/example.c index a6733dba6935..b3b6790509ed 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/examples/c/example.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include.gypi b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include.gypi index bee8d41a2caf..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include.gypi @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2026 The Stdlib Authors. +# Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include/stdlib/stats/base/ndarray/smeankbn.h b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include/stdlib/stats/base/ndarray/smeankbn.h index 1f34e6d395d3..a1d43b337fb0 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include/stdlib/stats/base/ndarray/smeankbn.h +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/include/stdlib/stats/base/ndarray/smeankbn.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/lib/native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/lib/native.js index a1992580f306..5f65d965acf7 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/lib/native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/Makefile b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/Makefile index 2caf905cedbe..7733b6180cb4 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/Makefile +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2026 The Stdlib Authors. +# Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/addon.c b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/addon.c index c3335ed895a6..931224d590b3 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/main.c b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/main.c index bb67be7c113f..011abd2e2b33 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.js index 6f33180e179a..365f359602b8 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js index 34a6a2402c19..f2f61ab62e9a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smeankbn/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2026 The Stdlib Authors. +* Copyright (c) 2025 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.