Skip to content

Commit 54a6b9c

Browse files
committed
feat: add blas/ext/base/znancount
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 3b3e2b8 commit 54a6b9c

33 files changed

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

0 commit comments

Comments
 (0)