Struct SafView

Source
pub struct SafView<'a, const N: usize> { /* private fields */ }
Expand description

A view of a joint SAF likelihood matrix for N populations.

This may or may not be the entire matrix, but it always represents a contiguous block of sites.

Implementations§

Source§

impl<'a, const N: usize> SafView<'a, N>

Source

pub fn iter_blocks(&self, block_size: usize) -> BlockIter<'a, N>

Returns an iterator over blocks of sites in the SAF.

If the number of sites in the SAF is not evenly divided by block_size, the last block will be smaller than the others.

§Examples
use winsfs_core::saf1d;
let saf = saf1d![
    [0.0,  0.1,  0.2],
    [0.3,  0.4,  0.5],
    [0.6,  0.7,  0.8],
    [0.9,  0.10, 0.11],
    [0.12, 0.13, 0.14],
];
let mut iter = saf.view().iter_blocks(2);
assert_eq!(
    iter.next().unwrap(),
    saf1d![[0.0, 0.1, 0.2], [0.3, 0.4, 0.5]].view()
);
assert_eq!(
    iter.next().unwrap(),
    saf1d![[0.6, 0.7, 0.8], [0.9, 0.10, 0.11]].view()
);
assert_eq!(iter.next().unwrap(), saf1d![[0.12, 0.13, 0.14]].view());
assert!(iter.next().is_none());
Source

pub fn iter_sites(&self) -> SiteIter<'a, N>

Returns an iterator over the sites in the SAF.

§Examples
use winsfs_core::saf1d;
let saf = saf1d![
    [0.0,  0.1,  0.2],
    [0.3,  0.4,  0.5],
    [0.6,  0.7,  0.8],
];
let mut iter = saf.view().iter_sites();
assert_eq!(iter.next().unwrap().as_slice(), [0.0,  0.1,  0.2]);
assert_eq!(iter.next().unwrap().as_slice(), [0.3,  0.4,  0.5]);
assert_eq!(iter.next().unwrap().as_slice(), [0.6,  0.7,  0.8]);
assert!(iter.next().is_none());
Source

pub fn new(values: &'a [f32], shape: [usize; N]) -> Result<Self, ShapeError<N>>

Returns a new SAF view.

The number of provided values must be a multiple of the sum of shapes. See the Saf documentation for details on the storage order.

To create an owned SAF matrix, see Saf::new for the equivalent method.

§Examples
use winsfs_core::{saf::SafView, saf2d};
let slice = &[0.0, 0.1, 0.2, 1.0, 1.1, 0.3, 0.4, 0.5, 1.2, 1.3];
let shape = [3, 2];
assert_eq!(
    SafView::new(slice, shape).unwrap(),
    saf2d![
        [0.0,  0.1,  0.2 ; 1.0, 1.1],
        [0.3,  0.4,  0.5 ; 1.2, 1.3],
    ].view(),
);

A ShapeError is thrown if the shape does not fit the number of values:

use winsfs_core::saf::SafView;
let slice = &[0.0, 0.1, 0.2, 1.0, 1.1, 0.3, 0.4, 0.5, 1.2, 1.3];
let wrong_shape = [4, 2];
assert!(SafView::new(slice, wrong_shape).is_err());
Source

pub fn par_iter_blocks(&self, block_size: usize) -> ParBlockIter<'_, N>

Returns a parallel iterator over the blocks in the SAF.

This is the parallel version of SafView::iter_blocks. If the number of sites in the SAF is not evenly divided by block_size, the last block will be smaller than the others.

§Examples
use winsfs_core::{saf::SafView, saf1d};
use rayon::iter::ParallelIterator;
let saf = saf1d![
    [0.0,  0.1,  0.2],
    [0.3,  0.4,  0.5],
    [0.6,  0.7,  0.8],
    [0.9,  0.10, 0.11],
    [0.12, 0.13, 0.14],
];
let view = saf.view();
let blocks: Vec<SafView<1>> = view.par_iter_blocks(2).collect();
assert_eq!(blocks.len(), 3);
assert_eq!(
    blocks[0],
    saf1d![[0.0, 0.1, 0.2], [0.3,  0.4,  0.5]].view()
);
assert_eq!(
    blocks[1],
    saf1d![[0.6, 0.7, 0.8], [0.9,  0.10,  0.11]].view()
);
assert_eq!(blocks[2], saf1d![[0.12, 0.13, 0.14]].view());
Source

pub fn par_iter_sites(&self) -> ParSiteIter<'_, N>

Returns a parallel iterator over the sites in the SAF.

This is the parallel version of SafView::iter_sites.

§Examples
use winsfs_core::saf1d;
use rayon::iter::ParallelIterator;
let saf = saf1d![
    [1.,  1.,  1.],
    [1.,  1.,  1.],
    [1.,  1.,  1.],
];
saf.view().par_iter_sites().all(|site| site.as_slice() == &[1., 1., 1.]);
Source

pub fn as_slice(&self) -> &[f32]

Returns the values of the SAF as a flat slice.

See the Saf documentation for details on the storage order.

Source

pub fn iter(&self) -> Iter<'_, f32>

Returns an iterator over all values in the SAF.

See the Saf documentation for details on the storage order.

Source

pub fn get_site(&self, index: usize) -> SiteView<'_, N>

Returns a single site in the SAF.

Source

pub fn sites(&self) -> usize

Returns the number of sites in the SAF.

Source

pub fn shape(&self) -> [usize; N]

Returns the shape of the SAF.

Trait Implementations§

Source§

impl<'a, const N: usize> AsSafView<N> for SafView<'a, N>

Source§

fn as_saf_view(&self) -> <Self as Lifetime<'_>>::Item

Returns a SAF view of self.
Source§

impl<'a, const N: usize> Clone for SafView<'a, N>

Source§

fn clone(&self) -> SafView<'a, N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, const N: usize> Debug for SafView<'a, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, 'b, const N: usize> IntoBlockIterator<N> for &'b SafView<'a, N>

Source§

type Item = SafView<'a, N>

The type of each individual block.
Source§

type Iter = BlockIter<'a, N>

The type of iterator.
Source§

fn into_block_iter(self, block_size: usize) -> Self::Iter

Convert this type into an iterator over SAF blocks containing block_size sites per block.
Source§

impl<'a, const N: usize> IntoBlockIterator<N> for SafView<'a, N>

Source§

type Item = SafView<'a, N>

The type of each individual block.
Source§

type Iter = BlockIter<'a, N>

The type of iterator.
Source§

fn into_block_iter(self, block_size: usize) -> Self::Iter

Convert this type into an iterator over SAF blocks containing block_size sites per block.
Source§

impl<'a, 'b, const N: usize> IntoParallelBlockIterator<N> for &'b SafView<'a, N>

Source§

type Item = SafView<'a, N>

The type of each individual block.
Source§

type Iter = ParBlockIter<'a, N>

The type of iterator.
Source§

fn into_par_block_iter(self, block_size: usize) -> Self::Iter

Convert this type into a parallel iterator over SAF blocks containing block_size sites per block.
Source§

impl<'a, const N: usize> IntoParallelBlockIterator<N> for SafView<'a, N>

Source§

type Item = SafView<'a, N>

The type of each individual block.
Source§

type Iter = ParBlockIter<'a, N>

The type of iterator.
Source§

fn into_par_block_iter(self, block_size: usize) -> Self::Iter

Convert this type into a parallel iterator over SAF blocks containing block_size sites per block.
Source§

impl<'a, 'b, const N: usize> IntoParallelSiteIterator<N> for &'b SafView<'a, N>

Source§

type Item = SiteView<'a, N>

The type of each individual site.
Source§

type Iter = ParSiteIter<'a, N>

The type of iterator.
Source§

fn into_par_site_iter(self) -> Self::Iter

Convert this type into a parallel SAF site iterator.
Source§

impl<'a, const N: usize> IntoParallelSiteIterator<N> for SafView<'a, N>

Source§

type Item = SiteView<'a, N>

The type of each individual site.
Source§

type Iter = ParSiteIter<'a, N>

The type of iterator.
Source§

fn into_par_site_iter(self) -> Self::Iter

Convert this type into a parallel SAF site iterator.
Source§

impl<'a, 'b, const N: usize> IntoSiteIterator<N> for &'b SafView<'a, N>

Source§

type Item = SiteView<'a, N>

The type of each individual site.
Source§

type Iter = SiteIter<'a, N>

The type of iterator.
Source§

fn into_site_iter(self) -> Self::Iter

Convert this type into a SAF site iterator.
Source§

impl<'a, const N: usize> IntoSiteIterator<N> for SafView<'a, N>

Source§

type Item = SiteView<'a, N>

The type of each individual site.
Source§

type Iter = SiteIter<'a, N>

The type of iterator.
Source§

fn into_site_iter(self) -> Self::Iter

Convert this type into a SAF site iterator.
Source§

impl<'a, 'b, const N: usize> Lifetime<'a> for SafView<'b, N>

Source§

type Item = SafView<'a, N>

The inner item, the lifetime of which should be tied to Self.
Source§

impl<'a, const N: usize> PartialEq for SafView<'a, N>

Source§

fn eq(&self, other: &SafView<'a, N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, const N: usize> Copy for SafView<'a, N>

Source§

impl<'a, const N: usize> StructuralPartialEq for SafView<'a, N>

Auto Trait Implementations§

§

impl<'a, const N: usize> Freeze for SafView<'a, N>

§

impl<'a, const N: usize> RefUnwindSafe for SafView<'a, N>

§

impl<'a, const N: usize> Send for SafView<'a, N>

§

impl<'a, const N: usize> Sync for SafView<'a, N>

§

impl<'a, const N: usize> Unpin for SafView<'a, N>

§

impl<'a, const N: usize> UnwindSafe for SafView<'a, N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V