Skip to content

Commit

Permalink
Added [typenum]-facing side to [Conv] trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzuchun committed Nov 17, 2024
1 parent 1d19e3d commit be6012d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ pub trait Conv {
/// [`nalgebra`]-faced type (matrix dimension)
type Nalg: Dim;

/// [`typenum`]/[`generic_array`]-faced type (generic array length)
/// [`typenum`]-faced type (unsigned int)
type TNum: Unsigned;

/// [`generic_array`]-faced type (generic array length)
type ArrLen: ArrayLength;

/// Constructor method used in [`nalgebra`] implementations
Expand All @@ -44,14 +47,17 @@ pub trait Conv {

impl<const N: usize> Conv for nalgebra::Const<N>
where
typenum::Const<N>: generic_array::IntoArrayLength,
typenum::Const<N>: generic_array::IntoArrayLength + typenum::ToUInt,
<typenum::Const<N> as typenum::ToUInt>::Output: Unsigned,
{
const SEAL: Seal = Seal(());

const NUM: usize = N;

type Nalg = nalgebra::Const<N>;

type TNum = typenum::U<N>;

type ArrLen = <typenum::Const<N> as generic_array::IntoArrayLength>::ArrayLength;

fn new_nalg() -> Self::Nalg {
Expand All @@ -61,14 +67,17 @@ where

impl<const N: usize> Conv for typenum::Const<N>
where
typenum::Const<N>: generic_array::IntoArrayLength,
typenum::Const<N>: generic_array::IntoArrayLength + typenum::ToUInt,
<typenum::Const<N> as typenum::ToUInt>::Output: Unsigned,
{
const SEAL: Seal = Seal(());

const NUM: usize = N;

type Nalg = nalgebra::Const<N>;

type TNum = typenum::U<N>;

type ArrLen = <typenum::Const<N> as generic_array::IntoArrayLength>::ArrayLength;

fn new_nalg() -> Self::Nalg {
Expand All @@ -83,6 +92,8 @@ impl Conv for typenum::UTerm {

type Nalg = nalgebra::Const<0>;

type TNum = typenum::consts::U0;

type ArrLen = Self;

fn new_nalg() -> Self::Nalg {
Expand All @@ -103,6 +114,8 @@ where

type Nalg = <U::Nalg as nalgebra::dimension::DimMul<nalgebra::U2>>::Output;

type TNum = typenum::operator_aliases::Prod<U::ArrLen, typenum::U2>;

type ArrLen = typenum::operator_aliases::Prod<U::ArrLen, typenum::U2>;

fn new_nalg() -> Self::Nalg {
Expand All @@ -124,6 +137,8 @@ where
type Nalg =
<<typenum::UInt<U, B0> as Conv>::Nalg as nalgebra::dimension::DimAdd<nalgebra::U1>>::Output;

type TNum = typenum::operator_aliases::Sum<<typenum::UInt<U, B0> as Conv>::ArrLen, typenum::U1>;

type ArrLen =
typenum::operator_aliases::Sum<<typenum::UInt<U, B0> as Conv>::ArrLen, typenum::U1>;

Expand Down Expand Up @@ -202,7 +217,7 @@ use nalgebra::{
allocator::Allocator, ArrayStorage, Dim, IsContiguous, Matrix, Owned, RawStorage,
RawStorageMut, Scalar, Storage,
};
use typenum::{B0, B1};
use typenum::{Unsigned, B0, B1};

/// A stack-allocated storage, of [`typenum`]-backed col-major two dimensional array
///
Expand Down

0 comments on commit be6012d

Please sign in to comment.