diff --git a/Cargo.toml b/Cargo.toml index 1f77a0c2..6511837f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "faer" -version = "0.20.0" +version = "0.20.1" edition = "2021" authors = ["sarah <>"] description = "Linear algebra routines" @@ -19,7 +19,7 @@ reborrow = "0.5.5" dyn-stack = { version = "0.11.0", default-features = false } equator = "0.4.1" -faer-entity = { version ="0.20.0", default-features = false, path = "./faer-entity" } +faer-entity = { version ="0.20.1", default-features = false, path = "./faer-entity" } gemm = { version = "0.18.0", default-features = false } nano-gemm = { version = "0.1.2", default-features = false } diff --git a/faer-entity/Cargo.toml b/faer-entity/Cargo.toml index 2e7bc9b2..a7bd203b 100644 --- a/faer-entity/Cargo.toml +++ b/faer-entity/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "faer-entity" -version = "0.20.0" +version = "0.20.1" edition = "2021" authors = ["sarah <>"] description = "Basic linear algebra routines" diff --git a/faer-entity/src/lib.rs b/faer-entity/src/lib.rs index a55c0854..e1d23d87 100644 --- a/faer-entity/src/lib.rs +++ b/faer-entity/src/lib.rs @@ -1897,6 +1897,95 @@ unsafe impl Entity for f64 { } } +macro_rules! impl_for_int { + ($($int: ty),* $(,)?) => {$( + unsafe impl Entity for $int { + type Unit = Self; + type Index = usize; + type SimdUnit = Self; + type SimdMask = bool; + type SimdIndex = Self; + type Group = IdentityGroup; + type Iter = I; + + type PrefixUnit<'a, S: Simd> = &'a [Self]; + type SuffixUnit<'a, S: Simd> = &'a [Self]; + type PrefixMutUnit<'a, S: Simd> = &'a mut [Self]; + type SuffixMutUnit<'a, S: Simd> = &'a mut [Self]; + + const N_COMPONENTS: usize = 1; + const UNIT: GroupFor = (); + + #[inline(always)] + fn faer_first(group: GroupFor) -> T { + group + } + + #[inline(always)] + fn faer_from_units(group: GroupFor>) -> Self { + group + } + + #[inline(always)] + fn faer_into_units(self) -> GroupFor> { + self + } + + #[inline(always)] + fn faer_as_ref(group: &GroupFor) -> GroupFor { + group + } + + #[inline(always)] + fn faer_as_mut(group: &mut GroupFor) -> GroupFor { + group + } + + #[inline(always)] + fn faer_as_ptr(group: *mut GroupFor) -> GroupFor { + group + } + + #[inline(always)] + fn faer_map_impl( + group: GroupFor, + f: &mut impl FnMut(T) -> U, + ) -> GroupFor { + (*f)(group) + } + #[inline(always)] + fn faer_map_with_context( + ctx: Ctx, + group: GroupFor, + f: &mut impl FnMut(Ctx, T) -> (Ctx, U), + ) -> (Ctx, GroupFor) { + (*f)(ctx, group) + } + + #[inline(always)] + fn faer_zip( + first: GroupFor, + second: GroupFor, + ) -> GroupFor { + (first, second) + } + #[inline(always)] + fn faer_unzip( + zipped: GroupFor, + ) -> (GroupFor, GroupFor) { + zipped + } + + #[inline(always)] + fn faer_into_iter(iter: GroupFor) -> Self::Iter { + iter.into_iter() + } + } + )*}; +} + +impl_for_int!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); + unsafe impl Entity for Complex { const IS_NUM_COMPLEX: bool = true; const IS_REAL: bool = false; diff --git a/src/mat/matmut.rs b/src/mat/matmut.rs index 4e64cf6f..bd917f04 100644 --- a/src/mat/matmut.rs +++ b/src/mat/matmut.rs @@ -1463,12 +1463,14 @@ impl<'a, E: Entity, R: Shape, C: Shape> MatMut<'a, E, R, C> { #[track_caller] #[inline(always)] + #[doc(hidden)] pub fn subcols_range(self, cols: Range>) -> MatRef<'a, E, R, usize> { self.into_const().subcols_range(cols) } #[track_caller] #[inline(always)] + #[doc(hidden)] pub fn subcols_range_mut(self, cols: Range>) -> MatMut<'a, E, R, usize> { unsafe { self.into_const().subcols_range(cols).const_cast() } } diff --git a/src/mat/matown.rs b/src/mat/matown.rs index 8f429dee..701ed628 100644 --- a/src/mat/matown.rs +++ b/src/mat/matown.rs @@ -111,7 +111,7 @@ impl Mat { #[inline] pub fn full(nrows: R, ncols: C, constant: E) -> Self where - E: ComplexField, + E: Copy, { Self::from_fn(nrows, ncols, |_, _| constant) } diff --git a/src/mat/matref.rs b/src/mat/matref.rs index a6ffab74..07081d36 100644 --- a/src/mat/matref.rs +++ b/src/mat/matref.rs @@ -821,6 +821,7 @@ impl<'a, E: Entity, R: Shape, C: Shape> MatRef<'a, E, R, C> { #[track_caller] #[inline(always)] + #[doc(hidden)] pub fn subcols_range(self, cols: Range>) -> MatRef<'a, E, R, usize> { assert!(all(cols.start <= self.ncols(), cols.end <= self.ncols())); let ncols = cols.end.unbound().saturating_sub(cols.start.unbound()); diff --git a/src/mat/mod.rs b/src/mat/mod.rs index d5686001..aa0b2c94 100644 --- a/src/mat/mod.rs +++ b/src/mat/mod.rs @@ -254,4 +254,10 @@ mod tests { a.resize_with(50, 2, |_, _| 0.0); a.resize_with(60, 1, |_, _| 0.0); } + + #[test] + fn test_int() { + let mut m = Mat::full(3, 4, 0u32); + m[(0, 0)] = 3; + } }