Skip to content

feat: add C implementation for blas/ext/base/ndarray/scircshift - #16502

Open
utkarshpatwa393-sys wants to merge 2 commits into
stdlib-js:developfrom
utkarshpatwa393-sys:feat/c-impl-blas-ext-base-ndarray-scircshift
Open

utkarshpatwa393-sys wants to merge 2 commits into
stdlib-js:developfrom
utkarshpatwa393-sys:feat/c-impl-blas-ext-base-ndarray-scircshift

Conversation

@utkarshpatwa393-sys

Copy link
Copy Markdown

Description

This PR adds the native C implementation for @stdlib/blas/ext/base/ndarray/scircshift (circularly shift the elements of a one-dimensional single-precision floating-point ndarray by a specified number of positions).

Part of #14819.

Changes

  • Added src/main.c, src/addon.c, src/Makefile
  • Added header include/stdlib/blas/ext/base/ndarray/scircshift.h
  • Added manifest.json, binding.gyp, include.gypi
  • Added Node-API native bridge in lib/native.js and updated lib/index.js
  • Added unit tests in test/test.main.js and test/test.native.js
  • Added C example in examples/c/example.c and examples/c/Makefile
  • Added C and native benchmarks in benchmark/c/ (with srand seeding and TAP format) and benchmark/benchmark.native.js
  • Updated README.md with C APIs documentation and usage examples
  • Updated package.json with browser, gypfile, and directory mappings

Checklist

Signed-off-by: Utkarsh patwa <utkarshpatwa393@gmail.com>
@utkarshpatwa393-sys
utkarshpatwa393-sys requested a review from a team November 4, 2026 17:56
@stdlib-bot stdlib-bot added BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Review A pull request which needs code review. labels Nov 4, 2026
…lementation

Signed-off-by: Utkarsh patwa <utkarshpatwa393@gmail.com>
var k;

x = uniform( [ len ], 0.0, 100.0, options );
k = scalar2ndarray( 3, options );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
k = scalar2ndarray( 3, {
'dtype': 'int32'
});

Comment on lines +23 to +30
var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/uniform' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

benchmark.native.js should be the same as benchmark.js, plus the native wiring.

Suggested change
var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/uniform' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
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;
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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - ndarray length

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {PositiveInteger} len - ndarray length
* @param {PositiveInteger} len - array length

Comment on lines +54 to +57
var x = uniform( [ len ], -100.0, 100.0, options );
var k = scalar2ndarray( 2, {
'dtype': 'int64'
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var x = uniform( [ len ], -100.0, 100.0, options );
var k = scalar2ndarray( 2, {
'dtype': 'int64'
});
var x;
var k;
x = uniform( [ len ], 0.0, 100.0, options );
k = scalar2ndarray( 3, {
'dtype': 'int32'
});

Comment on lines +39 to +49
int64_t k;

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 );

float *dataX = (float *)stdlib_ndarray_data( x );

stdlib_ndarray_get_int64( arrays[ 1 ], NULL, &k );

API_SUFFIX(stdlib_strided_scircshift_ndarray)( N, (CBLAS_INT)k, dataX, strideX, offsetX );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read k as int32 (same as ztril), so no cast is needed, and read the scalar first as in the other packages.

Suggested change
int64_t k;
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 );
float *dataX = (float *)stdlib_ndarray_data( x );
stdlib_ndarray_get_int64( arrays[ 1 ], NULL, &k );
API_SUFFIX(stdlib_strided_scircshift_ndarray)( N, (CBLAS_INT)k, dataX, strideX, offsetX );
int32_t k;
stdlib_ndarray_get_int32( arrays[ 1 ], NULL, &k );
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 );
float *dataX = (float *)stdlib_ndarray_data( x );
API_SUFFIX(stdlib_strided_scircshift_ndarray)( N, k, dataX, strideX, offsetX );

@ujjwalv01 ujjwalv01 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@utkarshpatwa393-sys! Same as #16501 (dcircshift): k should be int32 throughout the package rather than converted to int64 in native.js; Please apply the same changes suggested there , here as well. Left suggestions for the files that differ here.

@ujjwalv01 ujjwalv01 added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Nov 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Changes Pull request which needs changes before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants