Skip to content

Commit 919ecdf

Browse files
committed
feat: add C ndarray interface and refactor implementation
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 4d14525 commit 919ecdf

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

lib/node_modules/@stdlib/stats/base/snanmeanors/include/stdlib/stats/base/snanmeanors.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef STDLIB_STATS_BASE_SNANMEANORS_H
2020
#define STDLIB_STATS_BASE_SNANMEANORS_H
2121

22-
#include <stdint.h>
22+
#include "stdlib/blas/base/shared.h"
2323

2424
/*
2525
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
@@ -31,7 +31,12 @@ extern "C" {
3131
/**
3232
* Computes the arithmetic mean of a single-precision floating-point strided array, ignoring `NaN` values and using ordinary recursive summation.
3333
*/
34-
float stdlib_strided_snanmeanors( const int64_t N, const float *X, const int64_t stride );
34+
float API_SUFFIX(stdlib_strided_snanmeanors)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
35+
36+
/**
37+
* Computes the arithmetic mean of a single-precision floating-point strided array, ignoring `NaN` values and using ordinary recursive summation and alternative indexing semantics.
38+
*/
39+
float API_SUFFIX(stdlib_strided_snanmeanors_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
3540

3641
#ifdef __cplusplus
3742
}

lib/node_modules/@stdlib/stats/base/snanmeanors/src/snanmeanors.c

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,45 @@
1717
*/
1818

1919
#include "stdlib/stats/base/snanmeanors.h"
20-
#include <stdint.h>
20+
#include "stdlib/blas/base/shared.h"
21+
#include "stdlib/strided/base/stride2offset.h"
2122

2223
/**
2324
* Computes the arithmetic mean of a single-precision floating-point strided array, ignoring `NaN` values and using ordinary recursive summation.
2425
*
25-
* @param N number of indexed elements
26-
* @param X input array
27-
* @param stride stride length
28-
* @return output value
26+
* @param N number of indexed elements
27+
* @param X input array
28+
* @param strideX stride length
29+
* @return output value
2930
*/
30-
float stdlib_strided_snanmeanors( const int64_t N, const float *X, const int64_t stride ) {
31-
int64_t ix;
32-
int64_t i;
33-
int64_t n;
31+
float API_SUFFIX(stdlib_strided_snanmeanors)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) {
32+
const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
33+
return API_SUFFIX(stdlib_strided_snanmeanors_ndarray)( N, X, strideX, ox );
34+
}
35+
36+
/**
37+
* Computes the arithmetic mean of a single-precision floating-point strided array, ignoring `NaN` values and using ordinary recursive summation and alternative indexing semantics.
38+
*
39+
* @param N number of indexed elements
40+
* @param X input array
41+
* @param strideX stride length
42+
* @param offsetX starting index
43+
* @return output value
44+
*/
45+
float API_SUFFIX(stdlib_strided_snanmeanors)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
46+
CBLAS_INT ix;
47+
CBLAS_INT i;
48+
CBLAS_INT n;
3449
float sum;
3550
float v;
3651

3752
if ( N <= 0 ) {
3853
return 0.0f / 0.0f; // NaN
3954
}
40-
if ( N == 1 || stride == 0 ) {
41-
return X[ 0 ];
42-
}
43-
if ( stride < 0 ) {
44-
ix = (1-N) * stride;
45-
} else {
46-
ix = 0;
55+
if ( N == 1 || strideX == 0 ) {
56+
return X[ offsetX ];
4757
}
58+
ix = offsetX;
4859
sum = 0.0f;
4960
n = 0;
5061
for ( i = 0; i < N; i++ ) {
@@ -53,7 +64,7 @@ float stdlib_strided_snanmeanors( const int64_t N, const float *X, const int64_t
5364
sum += v;
5465
n += 1;
5566
}
56-
ix += stride;
67+
ix += strideX;
5768
}
5869
if ( n == 0 ) {
5970
return 0.0f / 0.0f; // NaN

0 commit comments

Comments
 (0)