#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ArrayRequirements(u32);
impl ArrayRequirements {
pub const CONTIGUOUS: Self = Self(1 << 0);
pub const C_LAYOUT: Self = Self(1 << 1);
pub const F_LAYOUT: Self = Self(1 << 2);
pub const OWNDATA: Self = Self(1 << 3);
pub const WRITEABLE: Self = Self(1 << 4);
pub fn empty() -> Self {
Self(0)
}
pub fn is_empty(&self) -> bool {
self.0 == 0
}
pub fn contains(&self, other: Self) -> bool {
(self.0 & other.0) == other.0
}
}
impl std::ops::BitOr for ArrayRequirements {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
Self(self.0 | rhs.0)
}
}
impl std::ops::BitAnd for ArrayRequirements {
type Output = Self;
fn bitand(self, rhs: Self) -> Self {
Self(self.0 & rhs.0)
}
}
pub enum AxisArg {
Single(usize),
Multiple(Vec<usize>),
}
impl From<usize> for AxisArg {
fn from(axis: usize) -> Self {
AxisArg::Single(axis)
}
}
impl From<&[usize]> for AxisArg {
fn from(axes: &[usize]) -> Self {
AxisArg::Multiple(axes.to_vec())
}
}
impl From<Vec<usize>> for AxisArg {
fn from(axes: Vec<usize>) -> Self {
AxisArg::Multiple(axes)
}
}
pub enum SplitArg {
Sections(usize),
Indices(Vec<usize>),
}
impl From<usize> for SplitArg {
fn from(sections: usize) -> Self {
SplitArg::Sections(sections)
}
}
impl From<&[usize]> for SplitArg {
fn from(indices: &[usize]) -> Self {
SplitArg::Indices(indices.to_vec())
}
}
impl From<Vec<usize>> for SplitArg {
fn from(indices: Vec<usize>) -> Self {
SplitArg::Indices(indices)
}
}
pub trait NumericExt {
fn is_multiple_of(&self, divisor: Self) -> bool;
}
impl NumericExt for usize {
#[allow(clippy::manual_is_multiple_of)]
fn is_multiple_of(&self, divisor: Self) -> bool {
if divisor == 0 {
false
} else {
self % divisor == 0
}
}
}