Skip to content

Commit 2cb348e

Browse files
committed
Auto-generated commit
1 parent 0e62e37 commit 2cb348e

18 files changed

Lines changed: 1250 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
<section class="release" id="unreleased">
66

7-
## Unreleased (2026-08-22)
7+
## Unreleased (2026-08-23)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`d9249d2`](https://github.com/stdlib-js/stdlib/commit/d9249d20cfec52a4742a02008c4c84d8b92d612a) - add `ndarray/base/clip-upper-index` [(#14556)](https://github.com/stdlib-js/stdlib/pull/14556)
1314
- [`cb7c674`](https://github.com/stdlib-js/stdlib/commit/cb7c674be0615fb38e4ddcdec80c52581b224e25) - update `ndarray/base` TypeScript declarations [(#14464)](https://github.com/stdlib-js/stdlib/pull/14464)
1415
- [`5500b7c`](https://github.com/stdlib-js/stdlib/commit/5500b7c8f280c02568ed9bfac2f01ae22324b82f) - add `clipIndex` to namespace
1516
- [`d681a2e`](https://github.com/stdlib-js/stdlib/commit/d681a2e7667990b06abb08a1aaf2ab205be20846) - add `ndarray/base/clip-index` [(#14432)](https://github.com/stdlib-js/stdlib/pull/14432)
@@ -90,6 +91,7 @@ A total of 2 issues were closed in this release:
9091

9192
<details>
9293

94+
- [`d9249d2`](https://github.com/stdlib-js/stdlib/commit/d9249d20cfec52a4742a02008c4c84d8b92d612a) - **feat:** add `ndarray/base/clip-upper-index` [(#14556)](https://github.com/stdlib-js/stdlib/pull/14556) _(by Muhammad Haris)_
9395
- [`fdbc822`](https://github.com/stdlib-js/stdlib/commit/fdbc82241f30438af95d53f451c1c4cd4523859f) - **chore:** remove unnecessary `format` calls [(#14520)](https://github.com/stdlib-js/stdlib/pull/14520) _(by Philipp Burckhardt)_
9496
- [`668ccdd`](https://github.com/stdlib-js/stdlib/commit/668ccdd7e8a924d21f431ca83782bb8f6af724f2) - **fix:** add missing arguments to `format` calls [(#14517)](https://github.com/stdlib-js/stdlib/pull/14517) _(by Philipp Burckhardt)_
9597
- [`cb7c674`](https://github.com/stdlib-js/stdlib/commit/cb7c674be0615fb38e4ddcdec80c52581b224e25) - **feat:** update `ndarray/base` TypeScript declarations [(#14464)](https://github.com/stdlib-js/stdlib/pull/14464) _(by stdlib-bot)_

base/clip-upper-index/README.md

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# clipUpperIndex
22+
23+
> Clip an index to the interval `[-1,max]`.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var clipUpperIndex = require( '@stdlib/ndarray/base/clip-upper-index' );
41+
```
42+
43+
#### clipUpperIndex( idx, max )
44+
45+
Clips an index to the interval `[-1,max]`.
46+
47+
```javascript
48+
var idx = clipUpperIndex( 2, 10 );
49+
// returns 2
50+
51+
idx = clipUpperIndex( -5, 10 );
52+
// returns 5
53+
```
54+
55+
If provided an out-of-bounds index, the function clips the index to the nearest interval bound.
56+
57+
```javascript
58+
var idx = clipUpperIndex( 15, 10 );
59+
// returns 10
60+
61+
idx = clipUpperIndex( -15, 10 );
62+
// returns -1
63+
```
64+
65+
</section>
66+
67+
<!-- /.usage -->
68+
69+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
70+
71+
<section class="notes">
72+
73+
## Notes
74+
75+
- Negative indices are normalized according to `max + idx`.
76+
77+
</section>
78+
79+
<!-- /.notes -->
80+
81+
<!-- Package usage examples. -->
82+
83+
<section class="examples">
84+
85+
## Examples
86+
87+
<!-- eslint no-undef: "error" -->
88+
89+
```javascript
90+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
91+
var logEachMap = require( '@stdlib/console/log-each-map' );
92+
var clipUpperIndex = require( '@stdlib/ndarray/base/clip-upper-index' );
93+
94+
var idx = discreteUniform( 100, -20, 20, {
95+
'dtype': 'generic'
96+
});
97+
98+
logEachMap( '%d => [-1,%d] => %d', idx, 10, clipUpperIndex );
99+
```
100+
101+
</section>
102+
103+
<!-- /.examples -->
104+
105+
<!-- C interface documentation. -->
106+
107+
* * *
108+
109+
<section class="c">
110+
111+
## C APIs
112+
113+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
114+
115+
<section class="intro">
116+
117+
</section>
118+
119+
<!-- /.intro -->
120+
121+
<!-- C usage documentation. -->
122+
123+
<section class="usage">
124+
125+
### Usage
126+
127+
```c
128+
#include "stdlib/ndarray/base/clip_upper_index.h"
129+
```
130+
131+
#### stdlib_ndarray_clip_upper_index( idx, max )
132+
133+
Clips an index to the interval `[-1,max]`.
134+
135+
```c
136+
#include <stdint.h>
137+
138+
int64_t idx = stdlib_ndarray_clip_upper_index( -2, 8 );
139+
// returns 6
140+
```
141+
142+
The function accepts the following arguments:
143+
144+
- **idx**: `[in] int64_t` index.
145+
- **max**: `[in] int64_t` maximum index.
146+
147+
```c
148+
int64_t stdlib_ndarray_clip_upper_index( const int64_t idx, const int64_t max );
149+
```
150+
151+
</section>
152+
153+
<!-- /.usage -->
154+
155+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
156+
157+
<section class="notes">
158+
159+
</section>
160+
161+
<!-- /.notes -->
162+
163+
<!-- C API usage examples. -->
164+
165+
<section class="examples">
166+
167+
### Examples
168+
169+
```c
170+
#include "stdlib/ndarray/base/clip_upper_index.h"
171+
#include <stdio.h>
172+
#include <inttypes.h>
173+
174+
int main( void ) {
175+
const int64_t idx[] = { -15, 8, 11, 4 };
176+
177+
int64_t out;
178+
int i;
179+
for ( i = 0; i < 4; i++ ) {
180+
out = stdlib_ndarray_clip_upper_index( idx[ i ], 10 );
181+
printf( "clip_upper_index(%" PRId64 ", 10) => %" PRId64 "\n", idx[ i ], out );
182+
}
183+
}
184+
```
185+
186+
</section>
187+
188+
<!-- /.examples -->
189+
190+
</section>
191+
192+
<!-- /.c -->
193+
194+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
195+
196+
<section class="references">
197+
198+
</section>
199+
200+
<!-- /.references -->
201+
202+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
203+
204+
<section class="related">
205+
206+
</section>
207+
208+
<!-- /.related -->
209+
210+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
211+
212+
<section class="links">
213+
214+
</section>
215+
216+
<!-- /.links -->
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 bench = require( '@stdlib/bench' );
24+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
25+
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
26+
var pkg = require( './../package.json' ).name;
27+
var clipUpperIndex = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var values;
34+
var out;
35+
var i;
36+
37+
values = discreteUniform( 100, -20, 20, {
38+
'dtype': 'generic'
39+
});
40+
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
out = clipUpperIndex( values[ i%values.length ], 10 );
44+
if ( out !== out ) {
45+
b.fail( 'should not return NaN' );
46+
}
47+
}
48+
b.toc();
49+
if ( !isInteger( out ) ) {
50+
b.fail( 'should return an integer' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
});

0 commit comments

Comments
 (0)