Struct rv::data::Partition[][src]

pub struct Partition { /* fields omitted */ }

Implementations

impl Partition[src]

pub fn new() -> Partition[src]

Empty partition

pub fn new_unchecked(z: Vec<usize>, counts: Vec<usize>) -> Self[src]

pub fn z(&self) -> &Vec<usize>[src]

pub fn z_mut(&mut self) -> &mut Vec<usize>[src]

pub fn counts(&self) -> &Vec<usize>[src]

pub fn counts_mut(&mut self) -> &mut Vec<usize>[src]

pub fn from_z(z: Vec<usize>) -> Result<Self, PartitionError>[src]

Create a Partition with a given assignment, z

Examples

let z1 = vec![0, 1, 2, 3, 1, 2];
let part = Partition::from_z(z1).unwrap();

assert_eq!(*part.z(), vec![0, 1, 2, 3, 1, 2]);
assert_eq!(*part.counts(), vec![1, 2, 2, 1]);

// Invalid z because k=4 is empty. All partitions must be occupied.
let z2 = vec![0, 1, 2, 3, 1, 5];
assert!(Partition::from_z(z2).is_err());

pub fn remove(&mut self, ix: usize) -> Result<(), PartitionError>[src]

Remove the item at index ix

Example

let mut part = Partition::from_z(vec![0, 1, 0, 2]).unwrap();
part.remove(1).expect("Could not remove");

assert_eq!(*part.z(), vec![0, 0, 1]);
assert_eq!(*part.counts(), vec![2, 1]);

pub fn append(&mut self, zi: usize) -> Result<(), PartitionError>[src]

Append a new item assigned to partition zi

Example

let mut part = Partition::from_z(vec![0, 1, 0, 2]).unwrap();
part.append(3).expect("Could not append");

assert_eq!(*part.z(), vec![0, 1, 0, 2, 3]);
assert_eq!(*part.counts(), vec![2, 1, 1, 1]);

pub fn k(&self) -> usize[src]

Returns the number of partitions, k.

Example

let part = Partition::from_z(vec![0, 1, 0, 2]).unwrap();

assert_eq!(part.k(), 3);
assert_eq!(*part.counts(), vec![2, 1, 1]);

pub fn len(&self) -> usize[src]

Returns the number items

pub fn is_empty(&self) -> bool[src]

pub fn weights(&self) -> Vec<f64>[src]

Return the partition weights (normalized counts)

Example

let part = Partition::from_z(vec![0, 1, 0, 2]).unwrap();
let weights = part.weights();

assert_eq!(weights, vec![0.5, 0.25, 0.25]);

Trait Implementations

impl Clone for Partition[src]

impl Debug for Partition[src]

impl Default for Partition[src]

impl Display for Partition[src]

impl Eq for Partition[src]

impl PartialEq<Partition> for Partition[src]

impl Rv<Partition> for Crp[src]

impl StructuralEq for Partition[src]

impl StructuralPartialEq for Partition[src]

impl Support<Partition> for Crp[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,