Skip to content

Commit 9fd10fb

Browse files
committed
Auto-generated commit
1 parent c884129 commit 9fd10fb

23 files changed

Lines changed: 1884 additions & 161 deletions

CHANGELOG.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,52 @@
22

33
> Package changelog.
44
5+
<section class="release" id="unreleased">
6+
7+
## Unreleased (2026-03-07)
8+
9+
<section class="features">
10+
11+
### Features
12+
13+
- [`7564e0f`](https://github.com/stdlib-js/stdlib/commit/7564e0f86e6a9a4c28affc29b1ef524f1cb43314) - add C implementation for `stats/base/ndarray/smidrange` [(#10057)](https://github.com/stdlib-js/stdlib/pull/10057)
14+
15+
</section>
16+
17+
<!-- /.features -->
18+
19+
<section class="commits">
20+
21+
### Commits
22+
23+
<details>
24+
25+
- [`7564e0f`](https://github.com/stdlib-js/stdlib/commit/7564e0f86e6a9a4c28affc29b1ef524f1cb43314) - **feat:** add C implementation for `stats/base/ndarray/smidrange` [(#10057)](https://github.com/stdlib-js/stdlib/pull/10057) _(by Samarth Kolarkar, Philipp Burckhardt, Sachin Pangal)_
26+
27+
</details>
28+
29+
</section>
30+
31+
<!-- /.commits -->
32+
33+
<section class="contributors">
34+
35+
### Contributors
36+
37+
A total of 3 people contributed to this release. Thank you to the following contributors:
38+
39+
- Philipp Burckhardt
40+
- Sachin Pangal
41+
- Samarth Kolarkar
42+
43+
</section>
44+
45+
<!-- /.contributors -->
46+
47+
</section>
48+
49+
<!-- /.release -->
50+
551
<section class="release" id="v0.1.1">
652

753
## 0.1.1 (2026-02-08)

README.md

Lines changed: 149 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,153 @@ console.log( v );
130130

131131
<!-- /.examples -->
132132

133+
<!-- C interface documentation. -->
134+
135+
* * *
136+
137+
<section class="c">
138+
139+
## C APIs
140+
141+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
142+
143+
<section class="intro">
144+
145+
</section>
146+
147+
<!-- /.intro -->
148+
149+
<!-- C usage documentation. -->
150+
151+
<section class="usage">
152+
153+
### Usage
154+
155+
```c
156+
#include "stdlib/stats/base/ndarray/smidrange.h"
157+
```
158+
159+
#### stdlib_stats_smidrange( arrays )
160+
161+
Computes the [mid-range][mid-range] of a one-dimensional single-precision floating-point ndarray.
162+
163+
```c
164+
#include "stdlib/ndarray/ctor.h"
165+
#include "stdlib/ndarray/dtypes.h"
166+
#include "stdlib/ndarray/index_modes.h"
167+
#include "stdlib/ndarray/orders.h"
168+
#include "stdlib/ndarray/base/bytes_per_element.h"
169+
#include <stdint.h>
170+
171+
// Create an ndarray:
172+
const float data[] = { 1.0f, 2.0f, 3.0f, 4.0f };
173+
int64_t shape[] = { 4 };
174+
int64_t strides[] = { STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT };
175+
int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
176+
177+
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 );
178+
179+
// Compute the mid-range:
180+
const struct ndarray *arrays[] = { x };
181+
float v = stdlib_stats_smidrange( arrays );
182+
// returns 2.5f
183+
184+
// Free allocated memory:
185+
stdlib_ndarray_free( x );
186+
```
187+
188+
The function accepts the following arguments:
189+
190+
- **arrays**: `[in] struct ndarray**` list containing a one-dimensional input ndarray.
191+
192+
```c
193+
float stdlib_stats_smidrange( const struct ndarray *arrays[] );
194+
```
195+
196+
</section>
197+
198+
<!-- /.usage -->
199+
200+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
201+
202+
<section class="notes">
203+
204+
</section>
205+
206+
<!-- /.notes -->
207+
208+
<!-- C API usage examples. -->
209+
210+
<section class="examples">
211+
212+
### Examples
213+
214+
```c
215+
#include "stdlib/stats/base/ndarray/smidrange.h"
216+
#include "stdlib/ndarray/ctor.h"
217+
#include "stdlib/ndarray/dtypes.h"
218+
#include "stdlib/ndarray/index_modes.h"
219+
#include "stdlib/ndarray/orders.h"
220+
#include "stdlib/ndarray/base/bytes_per_element.h"
221+
#include <stdint.h>
222+
#include <stdlib.h>
223+
#include <stdio.h>
224+
225+
int main( void ) {
226+
// Create a data buffer:
227+
const float data[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f };
228+
229+
// Specify the number of array dimensions:
230+
const int64_t ndims = 1;
231+
232+
// Specify the array shape:
233+
int64_t shape[] = { 4 };
234+
235+
// Specify the array strides:
236+
int64_t strides[] = { 2*STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT };
237+
238+
// Specify the byte offset:
239+
const int64_t offset = 0;
240+
241+
// Specify the array order:
242+
const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
243+
244+
// Specify the index mode:
245+
const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
246+
247+
// Specify the subscript index modes:
248+
int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
249+
const int64_t nsubmodes = 1;
250+
251+
// Create an ndarray:
252+
struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
253+
if ( x == NULL ) {
254+
fprintf( stderr, "Error allocating memory.\n" );
255+
exit( 1 );
256+
}
257+
258+
// Define a list of ndarrays:
259+
const struct ndarray *arrays[] = { x };
260+
261+
// Compute the mid-range:
262+
float v = stdlib_stats_smidrange( arrays );
263+
264+
// Print the result:
265+
printf( "mid-range: %f\n", v );
266+
267+
// Free allocated memory:
268+
stdlib_ndarray_free( x );
269+
}
270+
```
271+
272+
</section>
273+
274+
<!-- /.examples -->
275+
276+
</section>
277+
278+
<!-- /.c -->
279+
133280
<section class="references">
134281
135282
</section>
@@ -183,8 +330,8 @@ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
183330
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-ndarray-smidrange.svg
184331
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-ndarray-smidrange
185332
186-
[test-image]: https://github.com/stdlib-js/stats-base-ndarray-smidrange/actions/workflows/test.yml/badge.svg?branch=v0.1.1
187-
[test-url]: https://github.com/stdlib-js/stats-base-ndarray-smidrange/actions/workflows/test.yml?query=branch:v0.1.1
333+
[test-image]: https://github.com/stdlib-js/stats-base-ndarray-smidrange/actions/workflows/test.yml/badge.svg?branch=main
334+
[test-url]: https://github.com/stdlib-js/stats-base-ndarray-smidrange/actions/workflows/test.yml?query=branch:main
188335
189336
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-ndarray-smidrange/main.svg
190337
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-ndarray-smidrange?branch=main

benchmark/benchmark.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ var uniform = require( '@stdlib/random-array-uniform' );
2525
var isnanf = require( '@stdlib/math-base-assert-is-nanf' );
2626
var pow = require( '@stdlib/math-base-special-pow' );
2727
var ndarray = require( '@stdlib/ndarray-base-ctor' );
28+
var format = require( '@stdlib/string-format' );
2829
var pkg = require( './../package.json' ).name;
29-
var smidrange = require( './../lib' );
30+
var smidrange = require( './../lib/main.js' );
3031

3132

3233
// VARIABLES //
@@ -101,7 +102,7 @@ function main() {
101102
for ( i = min; i <= max; i++ ) {
102103
len = pow( 10, i );
103104
f = createBenchmark( len );
104-
bench( pkg+':len='+len, f );
105+
bench( format( '%s:len=%d', pkg, len ), f );
105106
}
106107
}
107108

benchmark/benchmark.native.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench-harness' );
25+
var uniform = require( '@stdlib/random-array-uniform' );
26+
var isnanf = require( '@stdlib/math-base-assert-is-nanf' );
27+
var pow = require( '@stdlib/math-base-special-pow' );
28+
var ndarray = require( '@stdlib/ndarray-base-ctor' );
29+
var format = require( '@stdlib/string-format' );
30+
var tryRequire = require( '@stdlib/utils-try-require' );
31+
var pkg = require( './../package.json' ).name;
32+
33+
34+
// VARIABLES //
35+
36+
var smidrange = tryRequire( resolve( __dirname, './../lib/native.js' ) );
37+
var opts = {
38+
'skip': ( smidrange instanceof Error )
39+
};
40+
var options = {
41+
'dtype': 'float32'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {PositiveInteger} len - array length
52+
* @returns {Function} benchmark function
53+
*/
54+
function createBenchmark( len ) {
55+
var xbuf;
56+
var x;
57+
58+
xbuf = uniform( len, -10.0, 10.0, options );
59+
x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' );
60+
61+
return benchmark;
62+
63+
/**
64+
* Benchmark function.
65+
*
66+
* @private
67+
* @param {Benchmark} b - benchmark instance
68+
*/
69+
function benchmark( b ) {
70+
var v;
71+
var i;
72+
73+
b.tic();
74+
for ( i = 0; i < b.iterations; i++ ) {
75+
v = smidrange( [ x ] );
76+
if ( isnanf( v ) ) {
77+
b.fail( 'should not return NaN' );
78+
}
79+
}
80+
b.toc();
81+
if ( isnanf( v ) ) {
82+
b.fail( 'should not return NaN' );
83+
}
84+
b.pass( 'benchmark finished' );
85+
b.end();
86+
}
87+
}
88+
89+
90+
// MAIN //
91+
92+
/**
93+
* Main execution sequence.
94+
*
95+
* @private
96+
*/
97+
function main() {
98+
var len;
99+
var min;
100+
var max;
101+
var f;
102+
var i;
103+
104+
min = 1; // 10^min
105+
max = 6; // 10^max
106+
107+
for ( i = min; i <= max; i++ ) {
108+
len = pow( 10, i );
109+
f = createBenchmark( len );
110+
bench( format( '%s::native:len=%d', pkg, len ), opts, f );
111+
}
112+
}
113+
114+
main();

0 commit comments

Comments
 (0)