Skip to content

Commit

Permalink
add basic integer support
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-quinones committed Dec 21, 2024
1 parent c379c3b commit 30cdd7b
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "faer"
version = "0.20.0"
version = "0.20.1"
edition = "2021"
authors = ["sarah <>"]
description = "Linear algebra routines"
Expand All @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion faer-entity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
89 changes: 89 additions & 0 deletions faer-entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: Simd> = Self;
type SimdMask<S: Simd> = bool;
type SimdIndex<S: Simd> = Self;
type Group = IdentityGroup;
type Iter<I: Iterator> = 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<Self, ()> = ();

#[inline(always)]
fn faer_first<T>(group: GroupFor<Self, T>) -> T {
group
}

#[inline(always)]
fn faer_from_units(group: GroupFor<Self, UnitFor<Self>>) -> Self {
group
}

#[inline(always)]
fn faer_into_units(self) -> GroupFor<Self, UnitFor<Self>> {
self
}

#[inline(always)]
fn faer_as_ref<T>(group: &GroupFor<Self, T>) -> GroupFor<Self, &T> {
group
}

#[inline(always)]
fn faer_as_mut<T>(group: &mut GroupFor<Self, T>) -> GroupFor<Self, &mut T> {
group
}

#[inline(always)]
fn faer_as_ptr<T>(group: *mut GroupFor<Self, T>) -> GroupFor<Self, *mut T> {
group
}

#[inline(always)]
fn faer_map_impl<T, U>(
group: GroupFor<Self, T>,
f: &mut impl FnMut(T) -> U,
) -> GroupFor<Self, U> {
(*f)(group)
}
#[inline(always)]
fn faer_map_with_context<Ctx, T, U>(
ctx: Ctx,
group: GroupFor<Self, T>,
f: &mut impl FnMut(Ctx, T) -> (Ctx, U),
) -> (Ctx, GroupFor<Self, U>) {
(*f)(ctx, group)
}

#[inline(always)]
fn faer_zip<T, U>(
first: GroupFor<Self, T>,
second: GroupFor<Self, U>,
) -> GroupFor<Self, (T, U)> {
(first, second)
}
#[inline(always)]
fn faer_unzip<T, U>(
zipped: GroupFor<Self, (T, U)>,
) -> (GroupFor<Self, T>, GroupFor<Self, U>) {
zipped
}

#[inline(always)]
fn faer_into_iter<I: IntoIterator>(iter: GroupFor<Self, I>) -> Self::Iter<I::IntoIter> {
iter.into_iter()
}
}
)*};
}

impl_for_int!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);

unsafe impl<E: Entity> Entity for Complex<E> {
const IS_NUM_COMPLEX: bool = true;
const IS_REAL: bool = false;
Expand Down
2 changes: 2 additions & 0 deletions src/mat/matmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IdxInc<C>>) -> 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<IdxInc<C>>) -> MatMut<'a, E, R, usize> {
unsafe { self.into_const().subcols_range(cols).const_cast() }
}
Expand Down
2 changes: 1 addition & 1 deletion src/mat/matown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<E: Entity, R: Shape, C: Shape> Mat<E, R, C> {
#[inline]
pub fn full(nrows: R, ncols: C, constant: E) -> Self
where
E: ComplexField,
E: Copy,
{
Self::from_fn(nrows, ncols, |_, _| constant)
}
Expand Down
1 change: 1 addition & 0 deletions src/mat/matref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IdxInc<C>>) -> 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());
Expand Down
6 changes: 6 additions & 0 deletions src/mat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 30cdd7b

Please sign in to comment.