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>
impl<'a, const N: usize> SafView<'a, N>
Sourcepub fn iter_blocks(&self, block_size: usize) -> BlockIter<'a, N> ⓘ
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());
Sourcepub fn iter_sites(&self) -> SiteIter<'a, N> ⓘ
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());
Sourcepub fn new(values: &'a [f32], shape: [usize; N]) -> Result<Self, ShapeError<N>>
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());
Sourcepub fn par_iter_blocks(&self, block_size: usize) -> ParBlockIter<'_, N>
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());
Sourcepub fn par_iter_sites(&self) -> ParSiteIter<'_, N>
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.]);
Sourcepub fn as_slice(&self) -> &[f32]
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.
Trait Implementations§
Source§impl<'a, const N: usize> AsSafView<N> for SafView<'a, N>
impl<'a, const N: usize> AsSafView<N> for SafView<'a, N>
Source§fn as_saf_view(&self) -> <Self as Lifetime<'_>>::Item
fn as_saf_view(&self) -> <Self as Lifetime<'_>>::Item
self
.Source§impl<'a, 'b, const N: usize> IntoBlockIterator<N> for &'b SafView<'a, N>
impl<'a, 'b, const N: usize> IntoBlockIterator<N> for &'b SafView<'a, N>
Source§impl<'a, const N: usize> IntoBlockIterator<N> for SafView<'a, N>
impl<'a, const N: usize> IntoBlockIterator<N> for SafView<'a, N>
Source§impl<'a, 'b, const N: usize> IntoParallelBlockIterator<N> for &'b SafView<'a, N>
impl<'a, 'b, const N: usize> IntoParallelBlockIterator<N> for &'b SafView<'a, N>
Source§impl<'a, const N: usize> IntoParallelBlockIterator<N> for SafView<'a, N>
impl<'a, const N: usize> IntoParallelBlockIterator<N> for SafView<'a, N>
Source§impl<'a, 'b, const N: usize> IntoParallelSiteIterator<N> for &'b SafView<'a, N>
impl<'a, 'b, const N: usize> IntoParallelSiteIterator<N> for &'b SafView<'a, N>
Source§impl<'a, const N: usize> IntoParallelSiteIterator<N> for SafView<'a, N>
impl<'a, const N: usize> IntoParallelSiteIterator<N> for SafView<'a, N>
Source§impl<'a, 'b, const N: usize> IntoSiteIterator<N> for &'b SafView<'a, N>
impl<'a, 'b, const N: usize> IntoSiteIterator<N> for &'b SafView<'a, N>
Source§impl<'a, const N: usize> IntoSiteIterator<N> for SafView<'a, N>
impl<'a, const N: usize> IntoSiteIterator<N> for SafView<'a, N>
impl<'a, const N: usize> Copy for SafView<'a, N>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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