//! Compatibility constraints between matrix shapes, e.g., for addition or multiplication. use base::dimension::{Dim, DimName, Dynamic}; /// A type used in `where` clauses for enforcing constraints. pub struct ShapeConstraint; /// Constraints `C1` and `R2` to be equivalent. pub trait AreMultipliable: DimEq {} impl AreMultipliable for ShapeConstraint where ShapeConstraint: DimEq {} /// Constraints `D1` and `D2` to be equivalent. pub trait DimEq { /// This is either equal to `D1` or `D2`, always choosing the one (if any) which is a type-level /// constant. type Representative: Dim; } impl DimEq for ShapeConstraint { type Representative = D; } impl DimEq for ShapeConstraint { type Representative = D; } impl DimEq for ShapeConstraint { type Representative = D; } macro_rules! equality_trait_decl( ($($doc: expr, $Trait: ident),* $(,)*) => {$( // XXX: we can't do something like `DimEq for D2` because we would require a blancket impl… #[doc = $doc] pub trait $Trait: DimEq + DimEq { /// This is either equal to `D1` or `D2`, always choosing the one (if any) which is a type-level /// constant. type Representative: Dim; } impl $Trait for ShapeConstraint { type Representative = D; } impl $Trait for ShapeConstraint { type Representative = D; } impl $Trait for ShapeConstraint { type Representative = D; } )*} ); equality_trait_decl!( "Constraints `D1` and `D2` to be equivalent. \ They are both assumed to be the number of \ rows of a matrix.", SameNumberOfRows, "Constraints `D1` and `D2` to be equivalent. \ They are both assumed to be the number of \ columns of a matrix.", SameNumberOfColumns ); /// Constraints D1 and D2 to be equivalent, where they both designate dimensions of algebraic /// entities (e.g. square matrices). pub trait SameDimension: SameNumberOfRows + SameNumberOfColumns { /// This is either equal to `D1` or `D2`, always choosing the one (if any) which is a type-level /// constant. type Representative: Dim; } impl SameDimension for ShapeConstraint { type Representative = D; } impl SameDimension for ShapeConstraint { type Representative = D; } impl SameDimension for ShapeConstraint { type Representative = D; }