1use super::*;
2use crate::internal_prelude::{DiagMut, DiagRef};
3
4#[derive(Clone)]
6pub struct Own<T, Dim: Shape = usize> {
7 pub(crate) inner: Col<T, Dim>,
8}
9
10impl<T: core::fmt::Debug, Dim: Shape> core::fmt::Debug for Own<T, Dim> {
11 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
12 self.inner.fmt(f)
13 }
14}
15
16impl<T, Dim: Shape> Diag<T, Dim> {
17 #[inline(always)]
19 pub fn column_vector(&self) -> ColRef<'_, T, Dim> {
20 self.as_ref().column_vector()
21 }
22
23 #[inline(always)]
25 pub fn column_vector_mut(&mut self) -> ColMut<'_, T, Dim> {
26 self.as_mut().column_vector_mut()
27 }
28
29 #[inline(always)]
31 pub fn into_column_vector(self) -> Col<T, Dim> {
32 self.0.inner
33 }
34
35 #[inline(always)]
37 pub fn as_ref(&self) -> DiagRef<'_, T, Dim> {
38 DiagRef {
39 0: Ref {
40 inner: self.0.inner.as_ref(),
41 },
42 }
43 }
44
45 #[inline(always)]
47 pub fn as_mut(&mut self) -> DiagMut<'_, T, Dim> {
48 DiagMut {
49 0: Mut {
50 inner: self.0.inner.as_mut(),
51 },
52 }
53 }
54
55 #[inline]
56 #[track_caller]
57 pub fn as_shape<D: Shape>(&self, len: D) -> DiagRef<'_, T, D> {
59 DiagRef {
60 0: Ref {
61 inner: self.0.inner.as_row_shape(len),
62 },
63 }
64 }
65
66 #[inline]
67 pub fn as_dyn(&self) -> DiagRef<'_, T> {
69 self.as_ref().as_dyn()
70 }
71
72 #[inline]
73 pub fn as_dyn_mut(&mut self) -> DiagMut<'_, T> {
75 self.as_mut().as_dyn_mut()
76 }
77
78 #[inline]
79 pub fn conjugate(&self) -> DiagRef<'_, T::Conj, Dim>
81 where
82 T: Conjugate,
83 {
84 DiagRef {
85 0: Ref {
86 inner: self.0.inner.conjugate(),
87 },
88 }
89 }
90
91 #[inline]
92 pub fn canonical(&self) -> DiagRef<'_, T::Canonical, Dim>
94 where
95 T: Conjugate,
96 {
97 DiagRef {
98 0: Ref {
99 inner: self.0.inner.canonical(),
100 },
101 }
102 }
103
104 #[inline]
105 #[track_caller]
106 pub fn as_shape_mut<D: Shape>(&mut self, len: D) -> DiagMut<'_, T, D> {
108 DiagMut {
109 0: Mut {
110 inner: self.0.inner.as_row_shape_mut(len),
111 },
112 }
113 }
114
115 #[inline]
116 pub fn conjugate_mut(&mut self) -> DiagMut<'_, T::Conj, Dim>
118 where
119 T: Conjugate,
120 {
121 DiagMut {
122 0: Mut {
123 inner: self.0.inner.conjugate_mut(),
124 },
125 }
126 }
127
128 #[inline]
129 pub fn canonical_mut(&mut self) -> DiagMut<'_, T::Canonical, Dim>
131 where
132 T: Conjugate,
133 {
134 DiagMut {
135 0: Mut {
136 inner: self.0.inner.canonical_mut(),
137 },
138 }
139 }
140
141 #[inline]
143 pub fn dim(&self) -> Dim {
144 self.0.inner.nrows()
145 }
146
147 #[inline]
149 pub fn zeros(dim: Dim) -> Self
150 where
151 T: ComplexField,
152 {
153 Self {
154 0: Own { inner: Col::zeros(dim) },
155 }
156 }
157
158 #[inline]
160 pub fn ones(dim: Dim) -> Self
161 where
162 T: ComplexField,
163 {
164 Self {
165 0: Own { inner: Col::ones(dim) },
166 }
167 }
168
169 #[inline]
171 pub fn full(dim: Dim, value: T) -> Self
172 where
173 T: Clone,
174 {
175 Self {
176 0: Own {
177 inner: Col::full(dim, value),
178 },
179 }
180 }
181
182 #[inline]
184 #[track_caller]
185 pub fn copy_from<RhsT: Conjugate<Canonical = T>>(&mut self, rhs: impl AsDiagRef<T = RhsT, Dim = Dim>)
186 where
187 T: ComplexField,
188 {
189 self.0.inner.copy_from(rhs.as_diag_ref().inner)
190 }
191}
192
193impl<'short, T, Dim: Shape> Reborrow<'short> for Own<T, Dim> {
194 type Target = Ref<'short, T, Dim>;
195
196 #[inline]
197 fn rb(&'short self) -> Self::Target {
198 Ref { inner: self.inner.rb() }
199 }
200}
201impl<'short, T, Dim: Shape> ReborrowMut<'short> for Own<T, Dim> {
202 type Target = Mut<'short, T, Dim>;
203
204 #[inline]
205 fn rb_mut(&'short mut self) -> Self::Target {
206 Mut { inner: self.inner.rb_mut() }
207 }
208}