Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: Add float and double versions of BN_NAN #373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions bottleneck/include/bottleneck.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ static inline float __bn_nanf(void) {
return __bint.__f;
}

#define BN_INFINITYF __bn_inff()
#define BN_NANF __bn_nanf()
#define BN_INFINITY ((npy_double)BN_INFINITYF)
#define BN_NAN ((npy_double)BN_NANF)
#define BN_INFINITYF __bn_inff()
#define BN_NANF __bn_nanf()
#define BN_INFINITY ((npy_double)BN_INFINITYF)
#define BN_NAN ((npy_double)BN_NANF)
#define BN_NAN_float32 BN_NANF
#define BN_NAN_float64 BN_NAN

/* WIRTH ----------------------------------------------------------------- */

Expand Down
42 changes: 21 additions & 21 deletions bottleneck/src/move_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ MOVE(move_sum, DTYPE0) {
asum += ai;
count += 1;
}
YI(DTYPE0) = BN_NAN;
YI(DTYPE0) = BN_NAN_DTYPE0;
}
WHILE1 {
const npy_DTYPE0 ai = AI(DTYPE0);
if (!bn_isnan(ai)) {
asum += ai;
count += 1;
}
YI(DTYPE0) = count >= min_count ? asum : BN_NAN;
YI(DTYPE0) = count >= min_count ? asum : BN_NAN_DTYPE0;
}
WHILE2 {
const npy_DTYPE0 ai = AI(DTYPE0);
Expand All @@ -109,7 +109,7 @@ MOVE(move_sum, DTYPE0) {
count--;
}
}
YI(DTYPE0) = count >= min_count ? asum : BN_NAN;
YI(DTYPE0) = count >= min_count ? asum : BN_NAN_DTYPE0;
}
NEXT2
}
Expand All @@ -127,7 +127,7 @@ MOVE(move_sum, DTYPE0) {
asum = 0;
WHILE0 {
asum += AI(DTYPE0);
YI(DTYPE1) = BN_NAN;
YI(DTYPE1) = BN_NAN_DTYPE1;
}
WHILE1 {
asum += AI(DTYPE0);
Expand Down Expand Up @@ -162,15 +162,15 @@ MOVE(move_mean, DTYPE0) {
asum += ai;
count += 1;
}
YI(DTYPE0) = BN_NAN;
YI(DTYPE0) = BN_NAN_DTYPE0;
}
WHILE1 {
const npy_DTYPE0 ai = AI(DTYPE0);
if (!bn_isnan(ai)) {
asum += ai;
count += 1;
}
YI(DTYPE0) = count >= min_count ? asum / count : BN_NAN;
YI(DTYPE0) = count >= min_count ? asum / count : BN_NAN_DTYPE0;
}
count_inv = 1.0 / count;
WHILE2 {
Expand All @@ -191,7 +191,7 @@ MOVE(move_mean, DTYPE0) {
count_inv = 1.0 / count;
}
}
YI(DTYPE0) = count >= min_count ? asum * count_inv : BN_NAN;
YI(DTYPE0) = count >= min_count ? asum * count_inv : BN_NAN_DTYPE0;
}
NEXT2
}
Expand All @@ -209,7 +209,7 @@ MOVE(move_mean, DTYPE0) {
asum = 0;
WHILE0 {
asum += AI(DTYPE0);
YI(DTYPE1) = BN_NAN;
YI(DTYPE1) = BN_NAN_DTYPE1;
}
WHILE1 {
asum += AI(DTYPE0);
Expand Down Expand Up @@ -249,7 +249,7 @@ MOVE(NAME, DTYPE0) {
amean += delta / count;
assqdm += delta * (ai - amean);
}
YI(DTYPE0) = BN_NAN;
YI(DTYPE0) = BN_NAN_DTYPE0;
}
WHILE1 {
const npy_DTYPE0 ai = AI(DTYPE0);
Expand All @@ -265,7 +265,7 @@ MOVE(NAME, DTYPE0) {
}
yi = FUNC(assqdm / (count - ddof));
} else {
yi = BN_NAN;
yi = BN_NAN_DTYPE0;
}
YI(DTYPE0) = yi;
}
Expand Down Expand Up @@ -310,7 +310,7 @@ MOVE(NAME, DTYPE0) {
}
yi = FUNC(assqdm * ddof_inv);
} else {
yi = BN_NAN;
yi = BN_NAN_DTYPE0;
}
YI(DTYPE0) = yi;
}
Expand All @@ -335,7 +335,7 @@ MOVE(NAME, DTYPE0) {
const npy_DTYPE1 delta = ai - amean;
amean += delta / (INDEX + 1);
assqdm += delta * (ai - amean);
YI(DTYPE1) = BN_NAN;
YI(DTYPE1) = BN_NAN_DTYPE1;
}
WHILE1 {
const npy_DTYPE1 ai = AI(DTYPE0);
Expand Down Expand Up @@ -457,16 +457,16 @@ MOVE(NAME, DTYPE0) {
extreme_pair->death = window;
WHILE0 {
MACRO_FLOAT(DTYPE0,
BN_NAN, )
BN_NAN_DTYPE0, )
}
WHILE1 {
MACRO_FLOAT(DTYPE0,
count >= min_count ? VALUE : BN_NAN, )
count >= min_count ? VALUE : BN_NAN_DTYPE0, )
}
WHILE2 {
MACRO_FLOAT(
DTYPE0,
count >= min_count ? VALUE : BN_NAN,
count >= min_count ? VALUE : BN_NAN_DTYPE0,
const npy_DTYPE0 aold = AOLD(DTYPE0);
if (!bn_isnan(aold)) count--;
if (extreme_pair->death == INDEX) {
Expand Down Expand Up @@ -501,7 +501,7 @@ MOVE(NAME, DTYPE0) {
WHILE0 {
MACRO_INT(DTYPE0,
DTYPE1,
BN_NAN, )
BN_NAN_DTYPE1, )
}
WHILE1 {
MACRO_INT(DTYPE0,
Expand Down Expand Up @@ -625,7 +625,7 @@ MOVE_MAIN(move_median, 0)
} \
} \
if (n < min_count) { \
r = BN_NAN; \
r = BN_NAN_##dtype1; \
} else if (n == 1) { \
r = 0.0; \
} else { \
Expand All @@ -634,7 +634,7 @@ MOVE_MAIN(move_median, 0)
r = 2.0 * (r - 0.5); \
} \
} else { \
r = BN_NAN; \
r = BN_NAN_##dtype1; \
}

/* dtype = [['float64', 'float64'], ['float32', 'float32']] */
Expand All @@ -643,7 +643,7 @@ MOVE(move_rank, DTYPE0) {
BN_BEGIN_ALLOW_THREADS
WHILE {
WHILE0 {
YI(DTYPE1) = BN_NAN;
YI(DTYPE1) = BN_NAN_DTYPE1;
}
WHILE1 {
MOVE_RANK(DTYPE0, DTYPE1, 0)
Expand All @@ -668,7 +668,7 @@ MOVE(move_rank, DTYPE0) {
BN_BEGIN_ALLOW_THREADS
WHILE {
WHILE0 {
YI(DTYPE1) = BN_NAN;
YI(DTYPE1) = BN_NAN_DTYPE1;
}
WHILE1 {
const npy_DTYPE0 ai = AI(DTYPE0);
Expand All @@ -683,7 +683,7 @@ MOVE(move_rank, DTYPE0) {
}
}
if (INDEX < min_count - 1) {
r = BN_NAN;
r = BN_NAN_DTYPE1;
} else if (INDEX == 0) {
r = 0.0;
} else {
Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/nonreduce_axis_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ NRA(push, DTYPE0) {
BN_BEGIN_ALLOW_THREADS
WHILE {
index = 0;
ai_last = BN_NAN;
ai_last = BN_NAN_DTYPE0;
FOR {
ai = AI(DTYPE0);
if (!bn_isnan(ai)) {
Expand Down
Loading