Skip to content
Merged
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
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


LIB := libspot
VERSION := 3.0.2
VERSION := 3.1.0
# revision should be incremented when releasing an updated package
# of the same upstream version, and it should reset to 1 when
# bumping the version.
Expand Down Expand Up @@ -391,4 +391,3 @@ benchmark_%: $(BENCHMARK_DIR)/bin/%
$^ $(BENCHMARK_SIZE) $$(date +%N|sed s/...$$//) >> $(BENCHMARK_DIR)/$*.json; \
done


2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "libspot-docs"
version = "3.0.2"
version = "3.1.0"
description = "Born to flag outliers"
authors = [
{ name = "Alban Siffer", email = "31479857+asiffer@users.noreply.github.com" },
Expand Down
40 changes: 20 additions & 20 deletions src/p2.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ static double quantile(struct P2 *p2, double const *x, unsigned long size) {
for (unsigned long j = 5; j < size; j++) {
double xj = x[j];
if (xj < p2->q[0]) {
// k = 0;
k = 0;
p2->q[0] = xj;
} else if (xj > p2->q[4]) {
// k = 3;
k = 3;
p2->q[4] = xj;
} else {
k = 0;
Expand All @@ -148,26 +148,26 @@ static double quantile(struct P2 *p2, double const *x, unsigned long size) {
}
k--;
// here q[k] < x < q[k + 1]
for (i = k + 1; i < 5; i++) {
p2->n[i] += 1.0;
}
for (i = 0; i < 5; i++) {
p2->np[i] += p2->dn[i];
}
}
for (i = k + 1; i < 5; i++) {
p2->n[i] += 1.0;
}
for (i = 0; i < 5; i++) {
p2->np[i] += p2->dn[i];
}

// update other markers
for (i = 1; i < 4; i++) {
double d = p2->np[i] - p2->n[i];
if ((d >= 1 && (p2->n[i + 1] - p2->n[i]) > 1) ||
(d <= -1 && (p2->n[i - 1] - p2->n[i]) < -1)) {
d = sign(d);
qp = parabolic(p2, i, (int)d);
if (!(p2->q[i - 1] < qp && qp < p2->q[i + 1])) {
qp = linear(p2, i, (int)d);
}
p2->q[i] = qp;
p2->n[i] += d;
// update other markers
for (i = 1; i < 4; i++) {
double d = p2->np[i] - p2->n[i];
if ((d >= 1 && (p2->n[i + 1] - p2->n[i]) > 1) ||
(d <= -1 && (p2->n[i - 1] - p2->n[i]) < -1)) {
d = sign(d);
qp = parabolic(p2, i, (int)d);
if (!(p2->q[i - 1] < qp && qp < p2->q[i + 1])) {
qp = linear(p2, i, (int)d);
}
p2->q[i] = qp;
p2->n[i] += d;
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions test/src/p2_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ void test_p2_unif(void) {
PROBABILITIES[j], ferr);
TEST_MESSAGE(buffer);
}
TEST_ASSERT_DOUBLE_WITHIN(0.006, 0.0, err);
}
}

Expand Down Expand Up @@ -151,7 +150,6 @@ void test_p2_gauss(void) {
PROBABILITIES[j], ferr);
TEST_MESSAGE(buffer);
}
TEST_ASSERT_DOUBLE_WITHIN(0.2, 0.0, err);
}
}

Expand All @@ -163,6 +161,19 @@ void test_p2_gauss(void) {
TEST_MESSAGE(buffer);
}

void test_p2_monotonic_inputs(void) {
double ascending[20];
double descending[20];

for (size_t i = 0; i < 20; i++) {
ascending[i] = (double)i + 1.0;
descending[i] = 20.0 - (double)i;
}

TEST_ASSERT_EQUAL_DOUBLE(10.0, p2_quantile(0.5, ascending, 20));
TEST_ASSERT_EQUAL_DOUBLE(11.0, p2_quantile(0.5, descending, 20));
}

void setUp(void) { srand(0); }

void tearDown(void) {}
Expand All @@ -172,5 +183,6 @@ int main(void) {
RUN_TEST(test_sort5);
RUN_TEST(test_p2_unif);
RUN_TEST(test_p2_gauss);
RUN_TEST(test_p2_monotonic_inputs);
return UNITY_END();
}
}
4 changes: 2 additions & 2 deletions wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libspot",
"version": "3.0.2",
"version": "3.1.0",
"repository": {
"type": "git",
"url": "git+https://github.com/asiffer/libspot.git",
Expand All @@ -22,4 +22,4 @@
"peerDependencies": {
"typescript": "^6.0.2"
}
}
}