Skip to content

Commit 21ec175

Browse files
committed
feat: add C ndarray interface and refactor implementation
1 parent 04fda1b commit 21ec175

File tree

4 files changed

+90
-191
lines changed

4 files changed

+90
-191
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef STDLIB_STATS_BASE_DNANMAXABS_H
2020
#define STDLIB_STATS_BASE_DNANMAXABS_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 maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values.
3333
*/
34-
double stdlib_strided_dnanmaxabs( const int64_t N, const double *X, const int64_t stride );
34+
double API_SUFFIX(stdlib_strided_dnanmaxabs)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
35+
36+
/**
37+
* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics .
38+
*/
39+
double API_SUFFIX(stdlib_strided_dnanmaxabs_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
3540

3641
#ifdef __cplusplus
3742
}

lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/addon.cpp

Lines changed: 0 additions & 117 deletions
This file was deleted.

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

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2020 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+
#include "stdlib/stats/base/dnanmaxabs.h"
20+
#include "stdlib/math/base/assert/is_nan.h"
21+
#include "stdlib/blas/base/shared.h"
22+
#include "stdlib/math/base/special/abs.h"
23+
#include "stdlib/strided/base/stride2offset.h"
24+
25+
/**
26+
* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values.
27+
*
28+
* @param N number of indexed elements
29+
* @param X input array
30+
* @param strideX stride length
31+
* @return output value
32+
*/
33+
double API_SUFFIX(stdlib_strided_dnanmaxabs)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) {
34+
const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
35+
return API_SUFFIX(stdlib_strided_dnanmaxabs_ndarray)( N, X, strideX, ox );
36+
}
37+
38+
/**
39+
* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
40+
*
41+
* @param N number of indexed elements
42+
* @param X input array
43+
* @param strideX stride length
44+
* @param offsetX starting index for X
45+
* @return output value
46+
*/
47+
double API_SUFFIX(stdlib_strided_dnanmaxabs_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
48+
double max;
49+
CBLAS_INT ix;
50+
CBLAS_INT i;
51+
double v;
52+
53+
if ( N <= 0 ) {
54+
return 0.0 / 0.0; // NaN
55+
}
56+
if ( N == 1 || strideX == 0 ) {
57+
return stdlib_base_abs( X[ offsetX ] );
58+
}
59+
ix = offsetX;
60+
for ( i = 0; i < N; i++ ) {
61+
v = X[ ix ];
62+
if ( v == v ) {
63+
break;
64+
}
65+
ix += strideX;
66+
}
67+
if ( i == N ) {
68+
return 0.0 / 0.0; // NaN
69+
}
70+
max = stdlib_base_abs( v );
71+
i += 1;
72+
for (; i < N; i++ ) {
73+
ix += strideX;
74+
v = stdlib_base_abs( X[ ix ] );
75+
if ( stdlib_base_is_nan( v ) ) {
76+
continue;
77+
}
78+
if ( v > max ) {
79+
max = v;
80+
}
81+
}
82+
return max;
83+
}

0 commit comments

Comments
 (0)