use super::*;
use crate::internal_prelude::{DiagMut, DiagRef};
#[derive(Clone)]
pub struct Own<T, Dim: Shape = usize> {
pub(crate) inner: Col<T, Dim>,
}
impl<T: core::fmt::Debug, Dim: Shape> core::fmt::Debug for Own<T, Dim> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.inner.fmt(f)
}
}
impl<T, Dim: Shape> Diag<T, Dim> {
#[inline(always)]
pub fn stride(&self) -> isize {
1
}
#[inline]
pub fn map<U>(&self, f: impl Fn(&T) -> U) -> Diag<U, Dim> {
self.rb().map(f)
}
#[inline]
pub fn for_each(&self, f: impl Fn(&T)) {
self.rb().for_each(f)
}
#[inline]
pub fn map_mut<U>(&mut self, f: impl FnMut(&mut T) -> U) -> Diag<U, Dim> {
self.rb_mut().map_mut(f)
}
#[inline]
pub fn for_each_mut(&mut self, f: impl FnMut(&mut T)) {
self.rb_mut().for_each_mut(f)
}
#[inline(always)]
pub fn column_vector(&self) -> ColRef<'_, T, Dim> {
self.as_ref().column_vector()
}
#[inline(always)]
pub fn column_vector_mut(&mut self) -> ColMut<'_, T, Dim> {
self.as_mut().column_vector_mut()
}
#[inline(always)]
pub fn into_column_vector(self) -> Col<T, Dim> {
self.0.inner
}
#[inline(always)]
pub fn as_ref(&self) -> DiagRef<'_, T, Dim> {
DiagRef {
0: Ref {
inner: self.0.inner.as_ref(),
},
}
}
#[inline(always)]
pub fn as_mut(&mut self) -> DiagMut<'_, T, Dim> {
DiagMut {
0: Mut {
inner: self.0.inner.as_mut(),
},
}
}
#[inline]
#[track_caller]
pub fn as_shape<D: Shape>(&self, len: D) -> DiagRef<'_, T, D> {
DiagRef {
0: Ref {
inner: self.0.inner.as_row_shape(len),
},
}
}
#[inline]
pub fn as_dyn(&self) -> DiagRef<'_, T> {
self.as_ref().as_dyn()
}
#[inline]
pub fn as_dyn_mut(&mut self) -> DiagMut<'_, T> {
self.as_mut().as_dyn_mut()
}
#[inline]
pub fn conjugate(&self) -> DiagRef<'_, T::Conj, Dim>
where
T: Conjugate,
{
DiagRef {
0: Ref {
inner: self.0.inner.conjugate(),
},
}
}
#[inline]
pub fn canonical(&self) -> DiagRef<'_, T::Canonical, Dim>
where
T: Conjugate,
{
DiagRef {
0: Ref {
inner: self.0.inner.canonical(),
},
}
}
#[inline]
#[track_caller]
pub fn as_shape_mut<D: Shape>(&mut self, len: D) -> DiagMut<'_, T, D> {
DiagMut {
0: Mut {
inner: self.0.inner.as_row_shape_mut(len),
},
}
}
#[inline]
pub fn conjugate_mut(&mut self) -> DiagMut<'_, T::Conj, Dim>
where
T: Conjugate,
{
DiagMut {
0: Mut {
inner: self.0.inner.conjugate_mut(),
},
}
}
#[inline]
pub fn canonical_mut(&mut self) -> DiagMut<'_, T::Canonical, Dim>
where
T: Conjugate,
{
DiagMut {
0: Mut {
inner: self.0.inner.canonical_mut(),
},
}
}
#[inline]
pub fn dim(&self) -> Dim {
self.0.inner.nrows()
}
#[inline]
pub fn zeros(dim: Dim) -> Self
where
T: ComplexField,
{
Self {
0: Own {
inner: Col::zeros(dim),
},
}
}
#[inline]
pub fn ones(dim: Dim) -> Self
where
T: ComplexField,
{
Self {
0: Own {
inner: Col::ones(dim),
},
}
}
#[inline]
pub fn full(dim: Dim, value: T) -> Self
where
T: Clone,
{
Self {
0: Own {
inner: Col::full(dim, value),
},
}
}
#[inline]
#[track_caller]
pub fn copy_from<RhsT: Conjugate<Canonical = T>>(
&mut self,
rhs: impl AsDiagRef<T = RhsT, Dim = Dim>,
) where
T: ComplexField,
{
self.0.inner.copy_from(rhs.as_diag_ref().inner)
}
}
impl<'short, T, Dim: Shape> Reborrow<'short> for Own<T, Dim> {
type Target = Ref<'short, T, Dim>;
#[inline]
fn rb(&'short self) -> Self::Target {
Ref {
inner: self.inner.rb(),
}
}
}
impl<'short, T, Dim: Shape> ReborrowMut<'short> for Own<T, Dim> {
type Target = Mut<'short, T, Dim>;
#[inline]
fn rb_mut(&'short mut self) -> Self::Target {
Mut {
inner: self.inner.rb_mut(),
}
}
}