Skip to content

Commit

Permalink
Merge branch 'steve/bazel' into wolfgang/pic_built_with_cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
wlanghans committed May 6, 2024
2 parents 201fe96 + 950b0f6 commit ae85575
Show file tree
Hide file tree
Showing 7 changed files with 5,785 additions and 34 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ swift_cc_test(
"tests/test_block_utils.cc",
"tests/test_call_trace.cc",
"tests/test_callers.cc",
"tests/test_chi_squared_versus_gsl.cc",
"tests/test_compression.cc",
"tests/test_concatenate.cc",
"tests/test_conditional_gaussian.cc",
Expand Down
8 changes: 4 additions & 4 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
workspace(name = "albatross")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_swiftnav",
sha256 = "8e00b694b6dce9c91d811e2e9e13e148af5f1dd329b85b7c5d2d9d2238aa92dc",
strip_prefix = "rules_swiftnav-1c51c97743c9632169dd7e5a228c6ce915893236",
url = "https://github.com/swift-nav/rules_swiftnav/archive/1c51c97743c9632169dd7e5a228c6ce915893236.tar.gz",
sha256 = "2f91790be7845e2eeb746dd33c59d1ba5d6ee85360a3218d2a4a77ead79f81b9",
strip_prefix = "rules_swiftnav-030c1c5050e7541ce66cd82f523939a525b1551c",
url = "https://github.com/swift-nav/rules_swiftnav/archive/030c1c5050e7541ce66cd82f523939a525b1551c.tar.gz",
)

load("@rules_swiftnav//cc:repositories.bzl", "register_swift_cc_toolchains", "swift_cc_toolchain")
Expand Down
1 change: 1 addition & 0 deletions include/albatross/Stats
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef ALBATROSS_STATS_H
#define ALBATROSS_STATS_H

#include <albatross/src/details/typecast.hpp>
#include <albatross/src/stats/gaussian.hpp>
#include <albatross/src/stats/gauss_legendre.hpp>
#include <albatross/src/stats/incomplete_gamma.hpp>
Expand Down
17 changes: 13 additions & 4 deletions include/albatross/src/stats/chi_squared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ namespace albatross {

namespace details {

inline double chi_squared_cdf_unsafe(double x, std::size_t degrees_of_freedom) {
return incomplete_gamma(0.5 * cast::to_double(degrees_of_freedom), 0.5 * x);
inline double chi_squared_cdf_unsafe(double x, double degrees_of_freedom) {
return incomplete_gamma(0.5 * degrees_of_freedom, 0.5 * x);
}

inline double chi_squared_cdf_safe(double x, std::size_t degrees_of_freedom) {
inline double chi_squared_cdf_safe(double x, double degrees_of_freedom) {

if (std::isnan(x) || x < 0.) {
return NAN;
Expand All @@ -53,7 +53,16 @@ inline double chi_squared_cdf_safe(double x, std::size_t degrees_of_freedom) {

} // namespace details

inline double chi_squared_cdf(double x, std::size_t degrees_of_freedom) {
template <typename IntType,
typename = std::enable_if_t<std::is_integral<IntType>::value>>
inline double chi_squared_cdf(double x, IntType degrees_of_freedom) {
// due to implicit argument conversions we can't directly use cast::to_double
// here.
return details::chi_squared_cdf_safe(x,
static_cast<double>(degrees_of_freedom));
}

inline double chi_squared_cdf(double x, double degrees_of_freedom) {
return details::chi_squared_cdf_safe(x, degrees_of_freedom);
}

Expand Down
31 changes: 5 additions & 26 deletions include/albatross/src/stats/incomplete_gamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,11 @@ inline double incomplete_gamma_quadrature_recursive(double lb, double ub,

inline std::pair<double, double> incomplete_gamma_quadrature_bounds(double a,
double z) {

if (a > 800) {
return std::make_pair(std::max(0., std::min(z, a) - 11 * sqrt(a)),
std::min(z, a + 10 * sqrt(a)));
} else if (a > 300) {
return std::make_pair(std::max(0., std::min(z, a) - 10 * sqrt(a)),
std::min(z, a + 9 * sqrt(a)));
} else if (a > 90) {
return std::make_pair(std::max(0., std::min(z, a) - 9 * sqrt(a)),
std::min(z, a + 8 * sqrt(a)));
} else if (a > 70) {
return std::make_pair(std::max(0., std::min(z, a) - 8 * sqrt(a)),
std::min(z, a + 7 * sqrt(a)));
} else if (a > 50) {
return std::make_pair(std::max(0., std::min(z, a) - 7 * sqrt(a)),
std::min(z, a + 6 * sqrt(a)));
} else if (a > 40) {
return std::make_pair(std::max(0., std::min(z, a) - 6 * sqrt(a)),
std::min(z, a + 5 * sqrt(a)));
} else if (a > 30) {
return std::make_pair(std::max(0., std::min(z, a) - 5 * sqrt(a)),
std::min(z, a + 4 * sqrt(a)));
} else {
return std::make_pair(std::max(0., std::min(z, a) - 4 * sqrt(a)),
std::min(z, a + 4 * sqrt(a)));
}
// NOTE: GCEM uses a large conditional block to select tighter bounds, but in
// practice those bounds were not tight enough, particularly on the upper
// bound, so we've modified this function to be more conservative
return std::make_pair(std::max(0., std::min(z, a) - 12 * sqrt(a)),
std::min(z, a + 13 * sqrt(a + 1)));
}

inline double incomplete_gamma_quadrature(double a, double z) {
Expand Down
Loading

0 comments on commit ae85575

Please sign in to comment.