Skip to content

Commit 24755a8

Browse files
authored
feat: add blas/ext/base/scuevery
PR-URL: stdlib-js#12842 Reviewed-by: Athan Reines <kgryte@gmail.com> Closes: stdlib-js/metr-issue-tracker#696
1 parent 053c8cd commit 24755a8

33 files changed

Lines changed: 3628 additions & 0 deletions
Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
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+
# scuevery
22+
23+
> Cumulatively test whether every element in a single-precision floating-point strided array is truthy.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var scuevery = require( '@stdlib/blas/ext/base/scuevery' );
37+
```
38+
39+
#### scuevery( N, x, strideX, out, strideOut )
40+
41+
Cumulatively tests whether every element in a single-precision floating-point strided array is truthy.
42+
43+
```javascript
44+
var Float32Array = require( '@stdlib/array/float32' );
45+
var BooleanArray = require( '@stdlib/array/bool' );
46+
47+
var x = new Float32Array( [ 1.0, 1.0, 0.0, 0.0 ] );
48+
var out = new BooleanArray( 4 );
49+
50+
scuevery( x.length, x, 1, out, 1 );
51+
// out => <BooleanArray>[ true, true, false, false ]
52+
```
53+
54+
The function has the following parameters:
55+
56+
- **N**: number of indexed elements.
57+
- **x**: input [`Float32Array`][@stdlib/array/float32].
58+
- **strideX**: stride length for `x`.
59+
- **out**: output [`BooleanArray`][@stdlib/array/bool].
60+
- **strideOut**: stride length for `out`.
61+
62+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to cumulatively test every other element:
63+
64+
```javascript
65+
var Float32Array = require( '@stdlib/array/float32' );
66+
var BooleanArray = require( '@stdlib/array/bool' );
67+
68+
var x = new Float32Array( [ 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
69+
var out = new BooleanArray( 4 );
70+
71+
scuevery( 4, x, 2, out, 1 );
72+
// out => <BooleanArray>[ true, true, false, false ]
73+
```
74+
75+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
76+
77+
<!-- eslint-disable stdlib/capitalized-comments -->
78+
79+
```javascript
80+
var Float32Array = require( '@stdlib/array/float32' );
81+
var BooleanArray = require( '@stdlib/array/bool' );
82+
83+
// Initial arrays...
84+
var x0 = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] );
85+
var o0 = new BooleanArray( x0.length );
86+
87+
// Create offset views...
88+
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
89+
var o1 = new BooleanArray( o0.buffer, o0.BYTES_PER_ELEMENT*3 ); // start at 4th element
90+
91+
scuevery( 3, x1, 2, o1, 1 );
92+
// o0 => <BooleanArray>[ false, false, false, true, false, false ]
93+
```
94+
95+
#### scuevery.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut )
96+
97+
Cumulatively tests whether every element in a single-precision floating-point strided array is truthy using alternative indexing semantics.
98+
99+
```javascript
100+
var Float32Array = require( '@stdlib/array/float32' );
101+
var BooleanArray = require( '@stdlib/array/bool' );
102+
103+
var x = new Float32Array( [ 1.0, 1.0, 0.0, 0.0 ] );
104+
var out = new BooleanArray( 4 );
105+
106+
scuevery.ndarray( x.length, x, 1, 0, out, 1, 0 );
107+
// out => <BooleanArray>[ true, true, false, false ]
108+
```
109+
110+
The function has the following additional parameters:
111+
112+
- **offsetX**: starting index for `x`.
113+
- **offsetOut**: starting index for `out`.
114+
115+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to cumulatively test every other element starting from the third element:
116+
117+
```javascript
118+
var Float32Array = require( '@stdlib/array/float32' );
119+
var BooleanArray = require( '@stdlib/array/bool' );
120+
121+
var x = new Float32Array( [ 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
122+
var out = new BooleanArray( 3 );
123+
124+
scuevery.ndarray( 3, x, 2, 2, out, 1, 0 );
125+
// out => <BooleanArray>[ true, false, false ]
126+
```
127+
128+
</section>
129+
130+
<!-- /.usage -->
131+
132+
<section class="notes">
133+
134+
## Notes
135+
136+
- If `N <= 0`, both functions return `out` unchanged.
137+
138+
</section>
139+
140+
<!-- /.notes -->
141+
142+
<section class="examples">
143+
144+
## Examples
145+
146+
<!-- eslint no-undef: "error" -->
147+
148+
```javascript
149+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
150+
var scuevery = require( '@stdlib/blas/ext/base/scuevery' );
151+
var logEach = require( '@stdlib/console/log-each' );
152+
var BooleanArray = require( '@stdlib/array/bool' );
153+
154+
var x = bernoulli( 10, 0.5, {
155+
'dtype': 'float32'
156+
});
157+
console.log( x );
158+
159+
var out = new BooleanArray( x.length );
160+
scuevery( x.length, x, 1, out, 1 );
161+
logEach( '%s', out );
162+
```
163+
164+
</section>
165+
166+
<!-- /.examples -->
167+
168+
<!-- C interface documentation. -->
169+
170+
* * *
171+
172+
<section class="c">
173+
174+
## C APIs
175+
176+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
177+
178+
<section class="intro">
179+
180+
</section>
181+
182+
<!-- /.intro -->
183+
184+
<!-- C usage documentation. -->
185+
186+
<section class="usage">
187+
188+
### Usage
189+
190+
```c
191+
#include "stdlib/blas/ext/base/scuevery.h"
192+
```
193+
194+
#### stdlib_strided_scuevery( N, \*X, strideX, \*Out, strideOut )
195+
196+
Cumulatively tests whether every element in a single-precision floating-point strided array is truthy.
197+
198+
```c
199+
#include <stdbool.h>
200+
201+
const float x[] = { 1.0f, 1.0f, 0.0f, 0.0f };
202+
bool out[] = { false, false, false, false };
203+
204+
stdlib_strided_scuevery( 4, x, 1, out, 1 );
205+
```
206+
207+
The function accepts the following arguments:
208+
209+
- **N**: `[in] CBLAS_INT` number of indexed elements.
210+
- **X**: `[in] float*` input array.
211+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
212+
- **Out**: `[out] bool*` output array.
213+
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
214+
215+
```c
216+
void stdlib_strided_scuevery( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, bool *Out, const CBLAS_INT strideOut );
217+
```
218+
219+
<!-- lint disable maximum-heading-length -->
220+
221+
#### stdlib_strided_scuevery_ndarray( N, \*X, strideX, offsetX, \*Out, strideOut, offsetOut )
222+
223+
<!-- lint enable maximum-heading-length -->
224+
225+
Cumulatively tests whether every element in a single-precision floating-point strided array is truthy using alternative indexing semantics.
226+
227+
```c
228+
#include <stdbool.h>
229+
230+
const float x[] = { 1.0f, 1.0f, 0.0f, 0.0f };
231+
bool out[] = { false, false, false, false };
232+
233+
stdlib_strided_scuevery_ndarray( 4, x, 1, 0, out, 1, 0 );
234+
```
235+
236+
The function accepts the following arguments:
237+
238+
- **N**: `[in] CBLAS_INT` number of indexed elements.
239+
- **X**: `[in] float*` input array.
240+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
241+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
242+
- **Out**: `[out] bool*` output array.
243+
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
244+
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.
245+
246+
```c
247+
void stdlib_strided_scuevery_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, bool *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut );
248+
```
249+
250+
</section>
251+
252+
<!-- /.usage -->
253+
254+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
255+
256+
<section class="notes">
257+
258+
</section>
259+
260+
<!-- /.notes -->
261+
262+
<!-- C API usage examples. -->
263+
264+
<section class="examples">
265+
266+
### Examples
267+
268+
```c
269+
#include "stdlib/blas/ext/base/scuevery.h"
270+
#include <stdio.h>
271+
#include <stdbool.h>
272+
273+
int main( void ) {
274+
// Create strided arrays:
275+
const float x[] = { 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f };
276+
bool out[] = { false, false, false, false, false, false, false, false };
277+
278+
// Specify the number of indexed elements:
279+
const int N = 8;
280+
281+
// Specify strides:
282+
const int strideX = 1;
283+
const int strideOut = 1;
284+
285+
// Cumulatively test whether every element is truthy:
286+
stdlib_strided_scuevery( N, x, strideX, out, strideOut );
287+
288+
// Print the results:
289+
for ( int i = 0; i < 8; i++ ) {
290+
printf( "Out[ %i ] = %s\n", i, out[ i ] ? "true" : "false" );
291+
}
292+
}
293+
```
294+
295+
</section>
296+
297+
<!-- /.examples -->
298+
299+
</section>
300+
301+
<!-- /.c -->
302+
303+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
304+
305+
<section class="related">
306+
307+
</section>
308+
309+
<!-- /.related -->
310+
311+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
312+
313+
<section class="links">
314+
315+
[@stdlib/array/float32]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float32
316+
317+
[@stdlib/array/bool]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/bool
318+
319+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
320+
321+
<!-- <related-links> -->
322+
323+
<!-- </related-links> -->
324+
325+
</section>
326+
327+
<!-- /.links -->

0 commit comments

Comments
 (0)