From be6012d6589e4605fd477de893c43f18b6c2b6d6 Mon Sep 17 00:00:00 2001 From: Dzuchun Date: Sun, 17 Nov 2024 06:15:48 +0200 Subject: [PATCH] Added [`typenum`]-facing side to [`Conv`] trait --- src/lib.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4d3b454..20b0fe0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 @@ -44,7 +47,8 @@ pub trait Conv { impl Conv for nalgebra::Const where - typenum::Const: generic_array::IntoArrayLength, + typenum::Const: generic_array::IntoArrayLength + typenum::ToUInt, + as typenum::ToUInt>::Output: Unsigned, { const SEAL: Seal = Seal(()); @@ -52,6 +56,8 @@ where type Nalg = nalgebra::Const; + type TNum = typenum::U; + type ArrLen = as generic_array::IntoArrayLength>::ArrayLength; fn new_nalg() -> Self::Nalg { @@ -61,7 +67,8 @@ where impl Conv for typenum::Const where - typenum::Const: generic_array::IntoArrayLength, + typenum::Const: generic_array::IntoArrayLength + typenum::ToUInt, + as typenum::ToUInt>::Output: Unsigned, { const SEAL: Seal = Seal(()); @@ -69,6 +76,8 @@ where type Nalg = nalgebra::Const; + type TNum = typenum::U; + type ArrLen = as generic_array::IntoArrayLength>::ArrayLength; fn new_nalg() -> Self::Nalg { @@ -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 { @@ -103,6 +114,8 @@ where type Nalg = >::Output; + type TNum = typenum::operator_aliases::Prod; + type ArrLen = typenum::operator_aliases::Prod; fn new_nalg() -> Self::Nalg { @@ -124,6 +137,8 @@ where type Nalg = < as Conv>::Nalg as nalgebra::dimension::DimAdd>::Output; + type TNum = typenum::operator_aliases::Sum< as Conv>::ArrLen, typenum::U1>; + type ArrLen = typenum::operator_aliases::Sum< as Conv>::ArrLen, typenum::U1>; @@ -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 ///