Commit 849ad30a authored by Jan-Oliver Kaiser's avatar Jan-Oliver Kaiser

Add inline annotations.

parent 2cc206c8
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
//// STIRLING APPROXIMATIONS //// STIRLING APPROXIMATIONS
pub mod stirling_approximation{ pub mod stirling_approximation{
use std::f64; use std::f64;
#[inline]
pub fn fac_stirling(n: f64) -> f64{ pub fn fac_stirling(n: f64) -> f64{
let result: f64 = (2.0*f64::consts::PI*n).sqrt(); let result: f64 = (2.0*f64::consts::PI*n).sqrt();
let frac: f64 = (n/f64::consts::E).powf(n); let frac: f64 = (n/f64::consts::E).powf(n);
...@@ -15,6 +16,7 @@ pub mod stirling_approximation{ ...@@ -15,6 +16,7 @@ pub mod stirling_approximation{
} }
#[inline]
pub fn log_binomial_coefficient_stirling(n: usize, k: usize) -> f64{ pub fn log_binomial_coefficient_stirling(n: usize, k: usize) -> f64{
let res: f64; let res: f64;
if n == k{ if n == k{
...@@ -33,6 +35,7 @@ pub mod stirling_approximation{ ...@@ -33,6 +35,7 @@ pub mod stirling_approximation{
} }
#[inline]
pub fn gammaln_stirling(z: f64) -> f64{ pub fn gammaln_stirling(z: f64) -> f64{
let result: f64 = z*z.ln() - z + 0.5*(2.0*f64::consts::PI/z).ln(); let result: f64 = z*z.ln() - z + 0.5*(2.0*f64::consts::PI/z).ln();
result / f64::consts::LN_2 result / f64::consts::LN_2
...@@ -42,6 +45,8 @@ pub mod stirling_approximation{ ...@@ -42,6 +45,8 @@ pub mod stirling_approximation{
//// DATA-TO-MODEL FOR DISTRIBUTIONS //// DATA-TO-MODEL FOR DISTRIBUTIONS
pub mod d2m_codes{ pub mod d2m_codes{
use basic_codes::stirling_approximation; use basic_codes::stirling_approximation;
#[inline]
pub fn d2m_nonzero_distribution_cost(counts: usize, bins: usize) -> f64{ pub fn d2m_nonzero_distribution_cost(counts: usize, bins: usize) -> f64{
//println!("approximating d2m NONZERO distribution cost: {} counts in {} bins", counts, bins); //println!("approximating d2m NONZERO distribution cost: {} counts in {} bins", counts, bins);
if counts < bins{ if counts < bins{
...@@ -54,6 +59,7 @@ pub mod d2m_codes{ ...@@ -54,6 +59,7 @@ pub mod d2m_codes{
stirling_approximation::log_binomial_coefficient_stirling(counts - 1, bins - 1) stirling_approximation::log_binomial_coefficient_stirling(counts - 1, bins - 1)
} }
#[inline]
pub fn d2m_distribution_cost(counts: usize, bins: usize) -> f64{ pub fn d2m_distribution_cost(counts: usize, bins: usize) -> f64{
//println!("approximating d2m distribution cost: {} counts in {} bins", counts, bins); //println!("approximating d2m distribution cost: {} counts in {} bins", counts, bins);
if bins == 1 if bins == 1
...@@ -101,6 +107,7 @@ pub mod uic{ ...@@ -101,6 +107,7 @@ pub mod uic{
res + UIC_NORMALIZATION_CONSTANT res + UIC_NORMALIZATION_CONSTANT
} }
#[inline]
pub fn uic_memoized(n: usize) -> f64 { pub fn uic_memoized(n: usize) -> f64 {
if n < MAX_UIC_MEMOIZATION if n < MAX_UIC_MEMOIZATION
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment