From a2ac4c9f38e9e8e75b093ef678f0812bcc4ee497 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Fri, 28 Aug 2026 05:18:01 +0530 Subject: [PATCH 1/8] feat(stats/base/ndarray/smskrange): add C implementation and native addon bindings Signed-off-by: Aryan Sharma --- .../stats/base/ndarray/smskrange/README.md | 134 ++++++++- .../ndarray/smskrange/benchmark/benchmark.c | 200 +++++++++++++ .../ndarray/smskrange/benchmark/benchmark.js | 2 +- .../smskrange/benchmark/benchmark.native.js | 118 ++++++++ .../stats/base/ndarray/smskrange/binding.gyp | 29 ++ .../ndarray/smskrange/docs/types/index.d.ts | 4 +- .../stdlib/stats/base/ndarray/smskrange.h | 40 +++ .../stats/base/ndarray/smskrange/lib/index.js | 38 ++- .../stats/base/ndarray/smskrange/lib/main.js | 4 +- .../base/ndarray/smskrange/lib/native.js | 62 ++++ .../stats/base/ndarray/smskrange/package.json | 34 ++- .../stats/base/ndarray/smskrange/src/Makefile | 39 +++ .../stats/base/ndarray/smskrange/src/addon.c | 63 ++++ .../stats/base/ndarray/smskrange/src/main.c | 84 ++++++ .../stats/base/ndarray/smskrange/test/test.js | 210 ++----------- .../base/ndarray/smskrange/test/test.main.js | 255 ++++++++++++++++ .../ndarray/smskrange/test/test.native.js | 276 ++++++++++++++++++ 17 files changed, 1402 insertions(+), 190 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/benchmark/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/include/stdlib/stats/base/ndarray/smskrange.h create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md index e2dfa95fe321..50b1d0bcab83 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +Copyright (c) 2025, 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. @@ -40,7 +40,7 @@ var smskrange = require( '@stdlib/stats/base/ndarray/smskrange' ); #### smskrange( arrays ) -Computes the [range][range] of a one-dimensional single-precision floating-point ndarray according to a mask. +Compute the [range][range] of a one-dimensional single-precision floating-point ndarray according to a mask. ```javascript var Float32Vector = require( '@stdlib/ndarray/vector/float32' ); @@ -105,6 +105,136 @@ console.log( v ); +
+ +## C APIs + +
+ +### Usage + +```c +#include "stdlib/stats/base/ndarray/smskrange.h" +``` + +#### stdlib_stats_smskrange( arrays ) + +Compute the range of a one-dimensional single-precision floating-point ndarray according to a mask. + +```c +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/index_modes.h" +#include + +// ... + +// Create ndarray and mask... +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, ndims, shape, xstrides, offset, order, imode, nsubmodes, submodes ); +struct ndarray *mask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, (uint8_t *)mdata, ndims, shape, mstrides, offset, order, imode, nsubmodes, submodes ); + +const struct ndarray *arrays[] = { x, mask }; + +float v = stdlib_stats_smskrange( arrays ); + +// ... + +// Free memory: +stdlib_ndarray_free( x ); +stdlib_ndarray_free( mask ); +``` + +The function accepts the following arguments: + +- **arrays**: `[2](const struct ndarray *)` array containing ndarrays (a one-dimensional input ndarray and a one-dimensional mask ndarray). + +```c +float stdlib_stats_smskrange( const struct ndarray *arrays[] ); +``` + +
+ + + +
+ +
+ + + +
+ +### Examples + +```c +#include "stdlib/stats/base/ndarray/smskrange.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/index_modes.h" +#include +#include + +int main( void ) { + float x[] = { 1.0f, -2.0f, 4.0f, 2.0f }; + uint8_t mask[] = { 0, 0, 1, 0 }; + + int64_t ndims = 1; + int64_t shape[] = { 4 }; + int64_t strides[] = { 4 }; + int64_t mstrides[] = { 1 }; + int64_t offset = 0; + enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; + enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; + int8_t submodes[] = { imode }; + int64_t nsubmodes = 1; + + struct ndarray *X = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)x, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + if ( X == NULL ) { + printf( "Error allocating memory.\n" ); + return 1; + } + + struct ndarray *Mask = stdlib_ndarray_allocate( STDLIB_NDARRAY_UINT8, (uint8_t *)mask, ndims, shape, mstrides, offset, order, imode, nsubmodes, submodes ); + if ( Mask == NULL ) { + printf( "Error allocating memory.\n" ); + stdlib_ndarray_free( X ); + return 1; + } + + const struct ndarray *arrays[] = { X, Mask }; + + float v = stdlib_stats_smskrange( arrays ); + printf( "Range: %f\n", v ); + + stdlib_ndarray_free( X ); + stdlib_ndarray_free( Mask ); + + return 0; +} +``` + +
+ + + + + + + + + + + +
+ + +