From fe751f052b0473092dcb422f0293b46e5c40866a Mon Sep 17 00:00:00 2001
From: AtharvaPatange <164712914+AtharvaPatange@users.noreply.github.com>
Date: Tue, 20 Oct 2026 23:52:55 +0530
Subject: [PATCH 1/4] feat: add C implementation for
blas/ext/base/ndarray/dtriu
---
.../blas/ext/base/ndarray/dtriu/README.md | 176 ++++++++++++-
.../base/ndarray/dtriu/benchmark/benchmark.js | 4 +-
.../dtriu/benchmark/benchmark.native.js | 115 ++++++++
.../base/ndarray/dtriu/benchmark/c/Makefile | 146 +++++++++++
.../dtriu/benchmark/c/benchmark.length.c | 214 +++++++++++++++
.../blas/ext/base/ndarray/dtriu/binding.gyp | 170 ++++++++++++
.../blas/ext/base/ndarray/dtriu/docs/repl.txt | 2 +-
.../base/ndarray/dtriu/docs/types/index.d.ts | 6 +-
.../ext/base/ndarray/dtriu/docs/types/test.ts | 4 +-
.../base/ndarray/dtriu/examples/c/Makefile | 146 +++++++++++
.../base/ndarray/dtriu/examples/c/example.c | 84 ++++++
.../ext/base/ndarray/dtriu/examples/index.js | 2 +-
.../blas/ext/base/ndarray/dtriu/include.gypi | 53 ++++
.../stdlib/blas/ext/base/ndarray/dtriu.h | 40 +++
.../blas/ext/base/ndarray/dtriu/lib/index.js | 18 +-
.../blas/ext/base/ndarray/dtriu/lib/main.js | 2 +-
.../blas/ext/base/ndarray/dtriu/lib/native.js | 73 ++++++
.../blas/ext/base/ndarray/dtriu/manifest.json | 109 ++++++++
.../blas/ext/base/ndarray/dtriu/package.json | 4 +
.../blas/ext/base/ndarray/dtriu/src/Makefile | 70 +++++
.../blas/ext/base/ndarray/dtriu/src/addon.c | 67 +++++
.../blas/ext/base/ndarray/dtriu/src/main.c | 58 +++++
.../blas/ext/base/ndarray/dtriu/test/test.js | 212 ++-------------
.../ext/base/ndarray/dtriu/test/test.main.js | 237 +++++++++++++++++
.../base/ndarray/dtriu/test/test.native.js | 246 ++++++++++++++++++
25 files changed, 2058 insertions(+), 200 deletions(-)
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/benchmark/benchmark.native.js
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/benchmark/c/Makefile
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/benchmark/c/benchmark.length.c
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/binding.gyp
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/examples/c/Makefile
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/examples/c/example.c
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/include.gypi
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/include/stdlib/blas/ext/base/ndarray/dtriu.h
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/lib/native.js
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/manifest.json
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/src/Makefile
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/src/addon.c
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/src/main.c
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/test/test.main.js
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/test/test.native.js
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/README.md
index f73d510c904f..f6b3398fb727 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/README.md
+++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dtriu/README.md
@@ -48,7 +48,7 @@ var A = new Float64Matrix( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
var B = new Float64Matrix( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] );
var k = scalar2ndarray( 0, {
- 'dtype': 'generic'
+ 'dtype': 'int32'
});
var out = dtriu( [ A, B, k ] );
@@ -103,7 +103,7 @@ var B = discreteUniform( [ 5, 5 ], -50, 50, opts );
console.log( ndarray2array( B ) );
var k = scalar2ndarray( 0, {
- 'dtype': 'generic'
+ 'dtype': 'int32'
});
var out = dtriu( [ A, B, k ] );
@@ -114,6 +114,178 @@ console.log( ndarray2array( out ) );
+
+
+* * *
+
+
+
+## C APIs
+
+
+
+
+
+
+
+
+
+
+
+### Usage
+
+```c
+#include "stdlib/blas/ext/base/ndarray/dtriu.h"
+```
+
+#### stdlib_blas_ext_dtriu( arrays )
+
+Copies the upper triangular part of a double-precision floating-point matrix `A` to another matrix `B`.
+
+```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 ndarrays:
+const double dataA[] = { 1.0, 2.0, 3.0, 4.0 };
+double dataB[] = { 0.0, 0.0, 0.0, 0.0 };
+int32_t k_data[] = { 0 };
+int64_t shape[] = { 2, 2 };
+int64_t strides[] = { (int64_t)2*STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
+int64_t k_strides[] = { 0 };
+int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR, STDLIB_NDARRAY_INDEX_ERROR };
+
+struct ndarray *A = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataA, 2, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 2, submodes );
+struct ndarray *B = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataB, 2, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 2, submodes );
+struct ndarray *k = stdlib_ndarray_allocate( STDLIB_NDARRAY_INT32, (uint8_t *)k_data, 0, shape, k_strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes );
+
+// Perform computation:
+const struct ndarray *arrays[] = { A, B, k };
+stdlib_blas_ext_dtriu( arrays );
+
+// Free allocated memory:
+stdlib_ndarray_free( A );
+stdlib_ndarray_free( B );
+stdlib_ndarray_free( k );
+```
+
+The function accepts the following arguments:
+
+- **arrays**: `[in] struct ndarray**` list containing the following ndarrays:
+
+ - `[in] struct ndarray*` a two-dimensional input ndarray.
+ - `[inout] struct ndarray*` a two-dimensional output ndarray.
+ - `[in] struct ndarray*` a zero-dimensional ndarray specifying the diagonal below which to ignore. A value equal to zero refers to the main diagonal, greater than zero refers to a diagonal above the main diagonal, and less than zero refers to a diagonal below the main diagonal.
+
+```c
+void stdlib_blas_ext_dtriu( const struct ndarray *arrays[] );
+```
+
+
+
+
+
+
+
+
+
+### Notes
+
+- Elements outside of the copied region are left unchanged.
+
+
+
+
+
+
+
+
+
+### Examples
+
+```c
+#include "stdlib/blas/ext/base/ndarray/dtriu.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 data buffers:
+ const double dataA[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
+ double dataB[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
+ int32_t k_data[] = { 0 };
+
+ // Specify the number of array dimensions:
+ const int64_t ndims = 2;
+
+ // Specify the array shape:
+ int64_t shape[] = { 3, 3 };
+
+ // Specify the array strides:
+ int64_t strides[] = { (int64_t)3*STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
+ int64_t k_strides[] = { 0 };
+
+ // 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, STDLIB_NDARRAY_INDEX_ERROR };
+ const int64_t nsubmodes = 2;
+
+ // Create ndarrays:
+ struct ndarray *A = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataA, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
+ struct ndarray *B = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataB, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
+ struct ndarray *k = stdlib_ndarray_allocate( STDLIB_NDARRAY_INT32, (uint8_t *)k_data, 0, NULL, k_strides, offset, order, imode, 1, submodes );
+ if ( A == NULL || B == NULL || k == NULL ) {
+ fprintf( stderr, "Error allocating memory.\n" );
+ exit( 1 );
+ }
+
+ // Define a list of ndarrays:
+ const struct ndarray *arrays[] = { A, B, k };
+
+ // Perform computation:
+ stdlib_blas_ext_dtriu( arrays );
+
+ // Print the result:
+ for ( int i = 0; i < 3; i++ ) {
+ for ( int j = 0; j < 3; j++ ) {
+ printf( "B[ %i,%i ] = %lf\n", i, j, dataB[ (i*3)+j ] );
+ }
+ }
+
+ // Free allocated memory:
+ stdlib_ndarray_free( A );
+ stdlib_ndarray_free( B );
+ stdlib_ndarray_free( k );
+}
+```
+
+
+
+
+
+
+
+
+