Skip to content

Commit

Permalink
still working on lifetime brands
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-quinones committed Sep 30, 2024
1 parent 42b7272 commit dc70e34
Show file tree
Hide file tree
Showing 28 changed files with 615 additions and 438 deletions.
51 changes: 25 additions & 26 deletions src/col/colmut.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use crate::{
Idx, IdxInc,
diag::{DiagMut, DiagRef},
iter,
iter::chunks::ChunkPolicy,
Expand Down Expand Up @@ -172,13 +173,13 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {

#[inline(always)]
#[doc(hidden)]
pub unsafe fn overflowing_ptr_at(self, row: R::IdxInc) -> GroupFor<E, *const E::Unit> {
pub unsafe fn overflowing_ptr_at(self, row: IdxInc<R>) -> GroupFor<E, *const E::Unit> {
self.into_const().overflowing_ptr_at(row)
}

#[inline(always)]
#[doc(hidden)]
pub unsafe fn overflowing_ptr_at_mut(self, row: R::IdxInc) -> GroupFor<E, *mut E::Unit> {
pub unsafe fn overflowing_ptr_at_mut(self, row: IdxInc<R>) -> GroupFor<E, *mut E::Unit> {
unsafe {
let cond = row != self.nrows();
let offset = (cond as usize).wrapping_neg() as isize
Expand All @@ -199,7 +200,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row < self.nrows()`.
#[inline(always)]
#[track_caller]
pub unsafe fn ptr_inbounds_at(self, row: R::Idx) -> GroupFor<E, *const E::Unit> {
pub unsafe fn ptr_inbounds_at(self, row: Idx<R>) -> GroupFor<E, *const E::Unit> {
self.into_const().ptr_inbounds_at(row)
}

Expand All @@ -211,7 +212,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row < self.nrows()`.
#[inline(always)]
#[track_caller]
pub unsafe fn ptr_inbounds_at_mut(self, row: R::Idx) -> GroupFor<E, *mut E::Unit> {
pub unsafe fn ptr_inbounds_at_mut(self, row: Idx<R>) -> GroupFor<E, *mut E::Unit> {
debug_assert!(row < self.nrows());
self.ptr_at_mut_unchecked(row.unbound())
}
Expand Down Expand Up @@ -262,7 +263,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row <= self.nrows()`.
#[inline(always)]
#[track_caller]
pub unsafe fn split_at_unchecked(self, row: R::IdxInc) -> (ColRef<'a, E>, ColRef<'a, E>) {
pub unsafe fn split_at_unchecked(self, row: IdxInc<R>) -> (ColRef<'a, E>, ColRef<'a, E>) {
self.into_const().split_at_unchecked(row)
}

Expand All @@ -276,7 +277,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row <= self.nrows()`.
#[inline(always)]
#[track_caller]
pub unsafe fn split_at_mut_unchecked(self, row: R::IdxInc) -> (ColMut<'a, E>, ColMut<'a, E>) {
pub unsafe fn split_at_mut_unchecked(self, row: IdxInc<R>) -> (ColMut<'a, E>, ColMut<'a, E>) {
let (top, bot) = self.into_const().split_at_unchecked(row);
unsafe { (top.const_cast(), bot.const_cast()) }
}
Expand All @@ -291,7 +292,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row <= self.nrows()`.
#[inline(always)]
#[track_caller]
pub fn split_at(self, row: R::IdxInc) -> (ColRef<'a, E>, ColRef<'a, E>) {
pub fn split_at(self, row: IdxInc<R>) -> (ColRef<'a, E>, ColRef<'a, E>) {
self.into_const().split_at(row)
}

Expand All @@ -305,7 +306,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row <= self.nrows()`.
#[inline(always)]
#[track_caller]
pub fn split_at_mut(self, row: R::IdxInc) -> (ColMut<'a, E>, ColMut<'a, E>) {
pub fn split_at_mut(self, row: IdxInc<R>) -> (ColMut<'a, E>, ColMut<'a, E>) {
assert!(row <= self.nrows());
unsafe { self.split_at_mut_unchecked(row) }
}
Expand Down Expand Up @@ -403,7 +404,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row` must be in `[0, self.nrows())`.
#[inline(always)]
#[track_caller]
pub fn at(self, row: R::Idx) -> Ref<'a, E> {
pub fn at(self, row: Idx<R>) -> Ref<'a, E> {
self.into_const().at(row)
}

Expand All @@ -418,7 +419,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row` must be in `[0, self.nrows())`.
#[inline(always)]
#[track_caller]
pub fn at_mut(self, row: R::Idx) -> Mut<'a, E> {
pub fn at_mut(self, row: Idx<R>) -> Mut<'a, E> {
assert!(row < self.nrows());
unsafe {
E::faer_map(
Expand All @@ -440,7 +441,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row` must be in `[0, self.nrows())`.
#[inline(always)]
#[track_caller]
pub unsafe fn at_unchecked(self, row: R::Idx) -> Ref<'a, E> {
pub unsafe fn at_unchecked(self, row: Idx<R>) -> Ref<'a, E> {
self.into_const().at_unchecked(row)
}

Expand All @@ -455,7 +456,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row` must be in `[0, self.nrows())`.
#[inline(always)]
#[track_caller]
pub unsafe fn at_mut_unchecked(self, row: R::Idx) -> Mut<'a, E> {
pub unsafe fn at_mut_unchecked(self, row: Idx<R>) -> Mut<'a, E> {
unsafe {
E::faer_map(
self.ptr_inbounds_at_mut(row),
Expand All @@ -472,7 +473,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row < self.nrows()`.
#[inline(always)]
#[track_caller]
pub unsafe fn read_unchecked(&self, row: R::Idx) -> E {
pub unsafe fn read_unchecked(&self, row: Idx<R>) -> E {
self.rb().read_unchecked(row)
}

Expand All @@ -483,7 +484,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row < self.nrows()`.
#[inline(always)]
#[track_caller]
pub fn read(&self, row: R::Idx) -> E {
pub fn read(&self, row: Idx<R>) -> E {
self.rb().read(row)
}

Expand All @@ -494,7 +495,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row < self.nrows()`.
#[inline(always)]
#[track_caller]
pub unsafe fn write_unchecked(&mut self, row: R::Idx, value: E) {
pub unsafe fn write_unchecked(&mut self, row: Idx<R>, value: E) {
let units = value.faer_into_units();
let zipped = E::faer_zip(units, (*self).rb_mut().ptr_inbounds_at_mut(row));
E::faer_map(
Expand All @@ -511,7 +512,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `row < self.nrows()`.
#[inline(always)]
#[track_caller]
pub fn write(&mut self, row: R::Idx, value: E) {
pub fn write(&mut self, row: Idx<R>, value: E) {
assert!(row < self.nrows());
unsafe { self.write_unchecked(row, value) };
}
Expand Down Expand Up @@ -658,7 +659,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
#[inline(always)]
pub unsafe fn subrows_unchecked<V: Shape>(
self,
row_start: R::IdxInc,
row_start: IdxInc<R>,
nrows: V,
) -> ColRef<'a, E, V> {
self.into_const().subrows_unchecked(row_start, nrows)
Expand All @@ -675,7 +676,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
#[inline(always)]
pub unsafe fn subrows_mut_unchecked<V: Shape>(
self,
row_start: R::IdxInc,
row_start: IdxInc<R>,
nrows: V,
) -> ColMut<'a, E, V> {
self.into_const()
Expand All @@ -692,7 +693,7 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `nrows <= self.nrows() - row_start`.
#[track_caller]
#[inline(always)]
pub fn subrows<V: Shape>(self, row_start: R::IdxInc, nrows: V) -> ColRef<'a, E, V> {
pub fn subrows<V: Shape>(self, row_start: IdxInc<R>, nrows: V) -> ColRef<'a, E, V> {
self.into_const().subrows(row_start, nrows)
}

Expand All @@ -705,26 +706,24 @@ impl<'a, E: Entity, R: Shape> ColMut<'a, E, R> {
/// * `nrows <= self.nrows() - row_start`.
#[track_caller]
#[inline(always)]
pub fn subrows_mut<V: Shape>(self, row_start: R::IdxInc, nrows: V) -> ColMut<'a, E, V> {
pub fn subrows_mut<V: Shape>(self, row_start: IdxInc<R>, nrows: V) -> ColMut<'a, E, V> {
unsafe { self.into_const().subrows(row_start, nrows).const_cast() }
}

/// Given a matrix with a single column, returns an object that interprets
/// the column as a diagonal matrix, whose diagonal elements are values in the column.
#[track_caller]
#[inline(always)]
pub fn column_vector_as_diagonal(self) -> DiagRef<'a, E> {
pub fn column_vector_as_diagonal(self) -> DiagRef<'a, E, R> {
self.into_const().column_vector_as_diagonal()
}

/// Given a matrix with a single column, returns an object that interprets
/// the column as a diagonal matrix, whose diagonal elements are values in the column.
#[track_caller]
#[inline(always)]
pub fn column_vector_as_diagonal_mut(self) -> DiagMut<'a, E> {
DiagMut {
inner: self.as_dyn_mut(),
}
pub fn column_vector_as_diagonal_mut(self) -> DiagMut<'a, E, R> {
DiagMut { inner: self }
}

/// Returns an owning [`Col`] of the data.
Expand Down Expand Up @@ -1120,7 +1119,7 @@ impl<E: Entity, R: Shape> AsColMut<E> for ColMut<'_, E, R> {
}
}

impl<'a, E: Entity> core::fmt::Debug for ColMut<'a, E> {
impl<'a, E: Entity, R: Shape> core::fmt::Debug for ColMut<'a, E, R> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.rb().fmt(f)
}
Expand Down
34 changes: 17 additions & 17 deletions src/col/colref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
diag::DiagRef,
iter::{self, chunks::ChunkPolicy},
row::RowRef,
Unbind,
Idx, IdxInc, Unbind,
};

/// Immutable view over a column vector, similar to an immutable reference to a strided
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {

#[inline(always)]
#[doc(hidden)]
pub unsafe fn overflowing_ptr_at(self, row: R::IdxInc) -> GroupFor<E, *const E::Unit> {
pub unsafe fn overflowing_ptr_at(self, row: IdxInc<R>) -> GroupFor<E, *const E::Unit> {
unsafe {
let cond = row != self.nrows();
let offset = (cond as usize).wrapping_neg() as isize
Expand All @@ -167,7 +167,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
/// * `row < self.nrows()`.
#[inline(always)]
#[track_caller]
pub unsafe fn ptr_inbounds_at(self, row: R::Idx) -> GroupFor<E, *const E::Unit> {
pub unsafe fn ptr_inbounds_at(self, row: Idx<R>) -> GroupFor<E, *const E::Unit> {
debug_assert!(row < self.nrows());
self.ptr_at_unchecked(row.unbound())
}
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
#[track_caller]
pub unsafe fn split_at_unchecked(
self,
row: R::IdxInc,
row: IdxInc<R>,
) -> (ColRef<'a, E, usize>, ColRef<'a, E, usize>) {
debug_assert!(row <= self.nrows());

Expand Down Expand Up @@ -243,7 +243,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
/// * `row <= self.nrows()`.
#[inline(always)]
#[track_caller]
pub fn split_at(self, row: R::IdxInc) -> (ColRef<'a, E, usize>, ColRef<'a, E, usize>) {
pub fn split_at(self, row: IdxInc<R>) -> (ColRef<'a, E, usize>, ColRef<'a, E, usize>) {
assert!(row <= self.nrows());
unsafe { self.split_at_unchecked(row) }
}
Expand Down Expand Up @@ -300,7 +300,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
/// * `row` must be in `[0, self.nrows())`.
#[inline(always)]
#[track_caller]
pub unsafe fn at_unchecked(self, row: R::Idx) -> Ref<'a, E> {
pub unsafe fn at_unchecked(self, row: Idx<R>) -> Ref<'a, E> {
E::faer_map(
self.ptr_inbounds_at(row),
#[inline(always)]
Expand All @@ -319,7 +319,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
/// * `row` must be in `[0, self.nrows())`.
#[inline(always)]
#[track_caller]
pub fn at(self, row: R::Idx) -> Ref<'a, E> {
pub fn at(self, row: Idx<R>) -> Ref<'a, E> {
assert!(row < self.nrows());
unsafe { self.at_unchecked(row) }
}
Expand All @@ -331,7 +331,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
/// * `row < self.nrows()`.
#[inline(always)]
#[track_caller]
pub unsafe fn read_unchecked(&self, row: R::Idx) -> E {
pub unsafe fn read_unchecked(&self, row: Idx<R>) -> E {
E::faer_from_units(E::faer_map(
self.at_unchecked(row),
#[inline(always)]
Expand All @@ -346,7 +346,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
/// * `row < self.nrows()`.
#[inline(always)]
#[track_caller]
pub fn read(&self, row: R::Idx) -> E {
pub fn read(&self, row: Idx<R>) -> E {
E::faer_from_units(E::faer_map(
self.at(row),
#[inline(always)]
Expand Down Expand Up @@ -440,7 +440,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
#[inline(always)]
pub unsafe fn subrows_unchecked<V: Shape>(
self,
row_start: R::IdxInc,
row_start: IdxInc<R>,
nrows: V,
) -> ColRef<'a, E, V> {
debug_assert!(all(row_start <= self.nrows()));
Expand All @@ -462,7 +462,7 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
/// * `nrows <= self.nrows() - row_start`.
#[track_caller]
#[inline(always)]
pub fn subrows<V: Shape>(self, row_start: R::IdxInc, nrows: V) -> ColRef<'a, E, V> {
pub fn subrows<V: Shape>(self, row_start: IdxInc<R>, nrows: V) -> ColRef<'a, E, V> {
assert!(all(row_start <= self.nrows()));
{
let nrows = nrows.unbound();
Expand All @@ -476,10 +476,8 @@ impl<'a, E: Entity, R: Shape> ColRef<'a, E, R> {
/// the column as a diagonal matrix, whose diagonal elements are values in the column.
#[track_caller]
#[inline(always)]
pub fn column_vector_as_diagonal(self) -> DiagRef<'a, E> {
DiagRef {
inner: self.as_dyn(),
}
pub fn column_vector_as_diagonal(self) -> DiagRef<'a, E, R> {
DiagRef { inner: self }
}

/// Returns an owning [`Col`] of the data.
Expand Down Expand Up @@ -760,9 +758,11 @@ impl<E: Entity, R: Shape> AsColRef<E> for ColRef<'_, E, R> {
}
}

impl<'a, E: Entity> core::fmt::Debug for ColRef<'a, E> {
impl<'a, E: Entity, R: Shape> core::fmt::Debug for ColRef<'a, E, R> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.as_2d().fmt(f)
f.debug_list()
.entries(self.iter().map(|x| E::faer_from_units(E::faer_deref(x))))
.finish()
}
}

Expand Down
Loading

0 comments on commit dc70e34

Please sign in to comment.