Skip to content

Commit

Permalink
3.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
liborty committed Mar 6, 2024
1 parent 31c7dae commit 1084b74
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 372 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "medians"
version = "3.0.7"
version = "3.0.8"
authors = ["Libor Spacek"]
edition = "2021"
description = "Median, Statistical Measures, Mathematics, Statistics"
Expand Down
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Fast algorithm for finding medians of one dimensional data, implemented in 100% safe Rust.

```rust
use medians::{medianu8,Medians,Medianf64,Median};
use medians::{*,algos::*};
```

## Introduction
Expand Down Expand Up @@ -111,6 +111,8 @@ pub trait Median<'a, T> {

## Release Notes

**Version 3.0.8** - Added `implementation.rs` module and reorganized the source.

**Version 3.0.7** - Added `medf_weighted`, applying `&[f64]` weights.

**Version 3.0.6** - Moved `part`, `ref_vec` and `deref_vec` into crate `Indxvec`, to allow their wider use.
Expand All @@ -126,19 +128,3 @@ pub trait Median<'a, T> {
**Version 3.0.1** - Renamed `correlation` to `med_correlation` to avoid name clashes elsewhere.

**Version 3.0.0** - Numerous improvements to speed and generality and renaming.

**Version 2.3.1** - Further speed optimisation of `partf64`.

**Version 2.3.0** - Some minor changes to `algosf64.rs`. Improvements to this manual.

**Version 2.2.6** - Improved `README.md`. No changes to the code.

**Version 2.2.5** - Upped dependency on `indxvec` to version 1.8.

**Version 2.2.3** - Slight further improvement to efficiency of `part`.

**Version 2.2.2** - Corrected some comment and readme typos. No change in functionality.

**Version 2.2.1** - Some code pruning and streamlining. No change in functionality.

**Version 2.2.0** - Major new version with much improved speed and generality and some breaking changes (renaming).
24 changes: 20 additions & 4 deletions src/algos.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::cmp::{Ordering, Ordering::*};
use std::ops::Range;
use indxvec::Mutops;
use crate::{Me,merror};

/// Scan a slice of f64s for NANs
pub fn nans(v: &[f64]) -> bool {
Expand Down Expand Up @@ -111,7 +112,7 @@ pub fn qbalance<T>(s: &[T], centre: &f64, q: impl Fn(&T) -> f64) -> i64 {
}

/// Odd median of `&[u8]`
pub fn oddmedianu8(s: &[u8]) -> f64 {
fn oddmedianu8(s: &[u8]) -> f64 {
let need = s.len() / 2; // median target position
let mut histogram = [0_usize; 256];
let mut cummulator = 0_usize;
Expand All @@ -133,7 +134,7 @@ pub fn oddmedianu8(s: &[u8]) -> f64 {
}

/// Even median of `&[u8]`
pub fn evenmedianu8(s: &[u8]) -> f64 {
fn evenmedianu8(s: &[u8]) -> f64 {
let need = s.len() / 2; // first median target position
let mut histogram = [0_usize; 256];
let mut cummulator = 0_usize;
Expand Down Expand Up @@ -163,9 +164,24 @@ pub fn evenmedianu8(s: &[u8]) -> f64 {
res
}

/// Median of primitive type u8 by fast radix search
pub fn medianu8(s:&[u8]) -> Result<f64, Me> {
let n = s.len();
match n {
0 => return merror("size", "median: zero length data")?,
1 => return Ok(s[0] as f64),
2 => return Ok((s[0] as f64 + s[1] as f64) / 2.0),
_ => (),
};
if (n & 1) == 1 {
Ok(oddmedianu8(s))
} else {
Ok(evenmedianu8(s))
}
}

/// Median of odd sized generic data with Odering comparisons by custom closure
pub fn oddmedian_by<'a, T>(s: &mut [&'a T], c: &mut impl FnMut(&T, &T) -> Ordering) -> &'a T {
pub(super) fn oddmedian_by<'a, T>(s: &mut [&'a T], c: &mut impl FnMut(&T, &T) -> Ordering) -> &'a T {
let mut rng = 0..s.len();
let need = s.len() / 2; // median target position in fully partitioned set
loop {
Expand Down Expand Up @@ -214,7 +230,7 @@ pub fn oddmedian_by<'a, T>(s: &mut [&'a T], c: &mut impl FnMut(&T, &T) -> Orderi
}

/// Median of even sized generic data with Odering comparisons by custom closure
pub fn evenmedian_by<'a, T>(
pub(super) fn evenmedian_by<'a, T>(
s: &mut [&'a T],
c: &mut impl FnMut(&T, &T) -> Ordering,
) -> (&'a T, &'a T) {
Expand Down
40 changes: 0 additions & 40 deletions src/error.rs

This file was deleted.

Loading

0 comments on commit 1084b74

Please sign in to comment.