ndarray_cg/d2/mat/
access_mirror.rs

1use crate::*;
2
3impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
4where
5  E : MatEl,
6  // < Self as Collection >::Scalar : Copy,
7  Self : RawSlice,
8{
9
10  /// Returns a reference to the underlying data as a flat array.
11  #[ inline( always ) ]
12  pub fn raw_slice( &self ) -> &[ < Self as Collection >::Scalar ]
13  {
14    < Self as RawSlice >::raw_slice( self )
15  }
16
17}
18
19impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
20where
21  E : MatEl,
22  // < Self as Collection >::Scalar : Copy,
23  Self : RawSliceMut,
24{
25  /// Returns a mutable reference to the underlying data as a flat array.
26  ///
27  /// # Returns
28  /// - A mutable slice of the scalar data.
29  #[ inline( always ) ]
30  pub fn as_raw_slice_mut( &mut self ) -> &mut [ < Self as Collection >::Scalar ]
31  {
32    < Self as RawSliceMut >::raw_slice_mut( self )
33  }
34
35  /// Sets the underlying data from a slice of scalars.
36  ///
37  /// # Arguments
38  /// - `scalars`: A slice of scalars to set the data.
39  #[ inline( always ) ]
40  pub fn set_raw_slice( &mut self, scalars : &[ < Self as Collection >::Scalar ] )
41  {
42    < Self as RawSliceMut >::raw_set_slice( self, scalars )
43  }
44
45  /// Sets the underlying data from an array of scalars.
46  ///
47  /// # Arguments
48  /// - `scalars`: An array of scalars to set the data.
49  #[ inline( always ) ]
50  pub fn set_raw< const N : usize >( self, scalars : [ < Self as Collection >::Scalar ; N ] ) -> Self
51  {
52    < Self as RawSliceMut >::raw_set( self, scalars )
53  }
54
55  /// Sets the underlying data from an array of scalars, assuming the input to be in row major order.
56  /// The resulting data will conform to the type of matrix used - row major or column major.
57  ///
58  /// # Arguments
59  /// - `scalars`: An array of scalars to set the data.
60  #[ inline( always ) ]
61  pub fn set_data< const N : usize >( self, scalars : [ < Self as Collection >::Scalar ; N ] ) -> Self
62  {
63    < Self as RawSliceMut >::set( self, scalars )
64  }
65
66  /// Sets the underlying data from an array of scalars, assuming the input to be in row major order.
67  /// The resulting data will conform to the type of matrix used - row major or column major.
68  ///
69  /// # Arguments
70  /// - `scalars`: An array of scalars to set the data.
71  #[ inline( always ) ]
72  pub fn set_row_major( self, scalars : &[ < Self as Collection >::Scalar ] ) -> Self
73  {
74    < Self as RawSliceMut >::with_row_major( self, scalars )
75  }
76
77  /// Sets the underlying data from an array of scalars, assuming the input to be in column major order.
78  /// The resulting data will conform to the type of matrix used - row major or column major.
79  ///
80  /// /// # Arguments
81  /// - `scalars`: An array of scalars to set the data.
82  #[ inline( always ) ]
83  pub fn set_column_major( self, scalars : &[ < Self as Collection >::Scalar ] ) -> Self
84  {
85    < Self as RawSliceMut >::with_column_major( self, scalars )
86  }
87}
88
89// impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
90// where
91//   E : nd::NdFloat + Copy,
92//   Self : Zero,
93// {
94//
95//   #[ inline( always ) ]
96//   pub fn zero() -> Self
97//   {
98//     < Self as Zero >::zero()
99//   }
100//
101//   #[ inline( always ) ]
102//   pub fn is_zero( &self ) -> bool
103//   {
104//     < Self as Zero >::is_zero( self )
105//   }
106//
107//   #[ inline( always ) ]
108//   pub fn set_zero( &mut self )
109//   {
110//     < Self as Zero >::set_zero( self )
111//   }
112//
113// }
114
115impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
116where
117  E : MatEl,
118  E : nd::NdFloat,
119  Self : IndexingRef,
120{
121  /// Iterate over scalars of a single 1D lane.
122  ///
123  /// # Parameters
124  /// - `varying_dim`: The dimension that varies (0 for rows, 1 for columns).
125  /// - `lane`: The index of the lane (row or column) to iterate over.
126  ///
127  /// # Returns
128  /// - An iterator over references to the scalars in the specified lane.
129  #[ inline( always ) ]
130  pub fn lane_iter( &self, varying_dim : usize, lane : usize )
131  -> impl Iterator< Item = &< Self as Collection >::Scalar >
132  {
133    < Self as IndexingRef >::lane_iter( self, varying_dim, lane )
134  }
135
136  /// Iterate over scalars of a single 1D lane with indices.
137  ///
138  /// # Parameters
139  /// - `varying_dim`: The dimension that varies (0 for rows, 1 for columns).
140  /// - `lane`: The index of the lane (row or column) to iterate over.
141  ///
142  /// # Returns
143  /// - An iterator over tuples of indices and references to the scalars in the specified lane.
144  #[ inline( always ) ]
145  pub fn lane_indexed_iter( &self, varying_dim : usize, lane : usize )
146  -> impl Iterator< Item = ( < Self as Indexable >::Index, &< Self as Collection >::Scalar ) >
147  {
148    < Self as IndexingRef >::lane_indexed_iter( self, varying_dim, lane )
149  }
150
151  /// Iterate over all scalars. Order of iteration is not specified.
152  ///
153  /// # Returns
154  /// - An iterator over references to all scalars in the matrix.
155  #[ inline( always ) ]
156  pub fn iter_unstable( &self )
157  -> impl Iterator< Item = &< Self as Collection >::Scalar >
158  {
159    < Self as IndexingRef >::iter_unstable( self )
160  }
161
162  /// Iterate over all scalars with indices. Order of iteration is not specified.
163  ///
164  /// # Returns
165  /// - An iterator over tuples of indices and references to all scalars in the matrix.
166  #[ inline( always ) ]
167  pub fn iter_indexed_unstable( &self )
168  -> impl Iterator< Item = ( < Self as Indexable >::Index, &< Self as Collection >::Scalar ) >
169  {
170    < Self as IndexingRef >::iter_indexed_unstable( self )
171  }
172
173  /// Iterate over all scalars in least significant dimension order.
174  ///
175  /// # Returns
176  /// - An iterator over references to all scalars in the matrix.
177  #[ inline( always ) ]
178  pub fn iter_lsfirst( &self )
179  -> impl Iterator< Item = &< Self as Collection >::Scalar >
180  {
181    < Self as IndexingRef >::iter_lsfirst( self )
182  }
183
184  /// Iterate over all scalars with indices in least significant dimension order.
185  ///
186  /// # Returns
187  /// - An iterator over tuples of indices and references to all scalars in the matrix.
188  #[ inline( always ) ]
189  pub fn iter_indexed_lsfirst( &self )
190  -> impl Iterator< Item = ( < Self as Indexable >::Index, &< Self as Collection >::Scalar ) >
191  {
192    < Self as IndexingRef >::iter_indexed_lsfirst( self )
193  }
194
195  /// Iterate over all scalars in most significant dimension order.
196  ///
197  /// # Returns
198  /// - An iterator over references to all scalars in the matrix.
199  #[ inline( always ) ]
200  pub fn iter_msfirst( &self )
201  -> impl Iterator< Item = &< Self as Collection >::Scalar >
202  {
203    < Self as IndexingRef >::iter_msfirst( self )
204  }
205
206  /// Iterate over all scalars with indices in most significant dimension order.
207  ///
208  /// # Returns
209  /// - An iterator over tuples of indices and references to all scalars in the matrix.
210  #[ inline( always ) ]
211  pub fn iter_indexed_msfirst( &self )
212  -> impl Iterator< Item = ( < Self as Indexable >::Index, &< Self as Collection >::Scalar ) >
213  {
214    < Self as IndexingRef >::iter_indexed_msfirst( self )
215  }
216}
217
218impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
219where
220  E : MatEl,
221  E : nd::NdFloat,
222  Self : IndexingMut,
223{
224  /// Iterate over scalars of a single 1D lane with mutable access.
225  ///
226  /// # Parameters
227  /// - `varying_dim`: The dimension that varies (0 for rows, 1 for columns).
228  /// - `lane`: The index of the lane (row or column) to iterate over.
229  ///
230  /// # Returns
231  /// - An iterator over mutable references to the scalars in the specified lane.
232  #[ inline( always ) ]
233  pub fn lane_iter_mut( &mut self, varying_dim : usize, lane : usize ) -> impl Iterator< Item = &mut < Self as Collection>::Scalar >
234  {
235    < Self as IndexingMut>::lane_iter_mut( self, varying_dim, lane )
236  }
237
238  /// Iterate over scalars of a single 1D lane with indices and mutable access.
239  ///
240  /// # Parameters
241  /// - `varying_dim`: The dimension that varies (0 for rows, 1 for columns).
242  /// - `lane`: The index of the lane (row or column) to iterate over.
243  ///
244  /// # Returns
245  /// - An iterator over tuples of indices and mutable references to the scalars in the specified lane.
246  #[ inline( always ) ]
247  pub fn lane_iter_indexed_mut( &mut self, varying_dim : usize, lane : usize ) -> impl Iterator< Item = ( < Self as Indexable>::Index, &mut < Self as Collection>::Scalar ) >
248  {
249    < Self as IndexingMut>::lane_iter_indexed_mut( self, varying_dim, lane )
250  }
251
252  /// Iterate over all scalars with mutable access. Order of iteration is not specified.
253  ///
254  /// # Returns
255  /// - An iterator over mutable references to all scalars in the matrix.
256  #[ inline( always ) ]
257  pub fn iter_unstable_mut( &mut self ) -> impl Iterator< Item = &mut < Self as Collection>::Scalar >
258  {
259    < Self as IndexingMut>::iter_unstable_mut( self )
260  }
261
262  /// Iterate over all scalars with indices and mutable access. Order of iteration is not specified.
263  ///
264  /// # Returns
265  /// - An iterator over tuples of indices and mutable references to all scalars in the matrix.
266  #[ inline( always ) ]
267  pub fn iter_indexed_unstable_mut( &mut self ) -> impl Iterator< Item = ( < Self as Indexable>::Index, &mut < Self as Collection>::Scalar ) >
268  {
269    < Self as IndexingMut>::iter_indexed_unstable_mut( self )
270  }
271
272  /// Iterate over all scalars in least significant dimension order with mutable access.
273  ///
274  /// # Returns
275  /// - An iterator over mutable references to all scalars in the matrix.
276  #[ inline( always ) ]
277  pub fn iter_lsfirst_mut( &mut self ) -> impl Iterator< Item = &mut < Self as Collection>::Scalar >
278  {
279    < Self as IndexingMut >::iter_lsfirst_mut( self )
280  }
281
282  /// Iterate over all scalars with indices in least significant dimension order with mutable access.
283  ///
284  /// # Returns
285  /// - An iterator over tuples of indices and mutable references to all scalars in the matrix.
286  #[ inline( always ) ]
287  pub fn iter_indexed_lsfirst_mut( &mut self ) -> impl Iterator< Item = ( < Self as Indexable>::Index, &mut < Self as Collection>::Scalar ) >
288  {
289    < Self as IndexingMut >::iter_indexed_lsfirst_mut( self )
290  }
291
292  /// Iterate over all scalars in most significant dimension order with mutable access.
293  ///
294  /// # Returns
295  /// - An iterator over mutable references to all scalars in the matrix.
296  #[ inline( always ) ]
297  pub fn iter_msfirst_mut( &mut self ) -> impl Iterator< Item = &mut < Self as Collection>::Scalar >
298  {
299    < Self as IndexingMut >::iter_msfirst_mut( self )
300  }
301
302  /// Iterate over all scalars with indices in most significant dimension order with mutable access.
303  ///
304  /// # Returns
305  /// - An iterator over tuples of indices and mutable references to all scalars in the matrix.
306  #[ inline( always ) ]
307  pub fn iter_indexed_msfirst_mut( &mut self ) -> impl Iterator< Item = ( < Self as Indexable>::Index, &mut < Self as Collection>::Scalar ) >
308  {
309    < Self as IndexingMut >::iter_indexed_msfirst_mut( self )
310  }
311}
312
313impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
314where
315  E : MatEl,
316  E : nd::NdFloat,
317  Self : ScalarRef,
318{
319  /// Get a reference to a scalar at a specified index.
320  ///
321  /// # Parameters
322  /// - `index`: The index of the scalar to access.
323  ///
324  /// # Returns
325  /// - A mutable reference to the scalar at the specified index.
326  #[ inline( always ) ]
327  pub fn scalar_ref( &self, index : < Self as Indexable >::Index ) -> &< Self as Collection >::Scalar
328  {
329    < Self as ScalarRef >::scalar_ref( self, index )
330  }
331}
332
333impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
334where
335  E : MatEl,
336  E : nd::NdFloat,
337  Self : ScalarMut,
338{
339  /// Get a mutable reference to a scalar at a specified index.
340  ///
341  /// # Parameters
342  /// - `index`: The index of the scalar to access.
343  ///
344  /// # Returns
345  /// - A mutable reference to the scalar at the specified index.
346  #[ inline( always ) ]
347  pub fn scalar_mut( &mut self, index : < Self as Indexable >::Index ) -> &mut < Self as Collection >::Scalar
348  {
349    < Self as ScalarMut >::scalar_mut( self, index )
350  }
351}
352
353impl< E, const ROWS : usize, const COLS : usize, Descriptor : mat::Descriptor > Mat< ROWS, COLS, E, Descriptor >
354where
355  E : MatEl,
356  Self : ConstLayout,
357{
358  /// Get offset for a specified scalar from beginning of underlying buffer.
359  #[ inline( always ) ]
360  pub fn scalar_offset( index : < Self as Indexable >::Index ) -> usize
361  {
362    < Self as ConstLayout >::scalar_offset( index )
363  }
364}