use crate::hom::Morphism;
use crate::module::Module;
use crate::profile::{Site, hit};
use super::common::{is_direct_sum, trace_dims};
#[derive(Clone, Debug)]
pub struct FacWitness {
pub(super) module: Module,
pub(super) summands: Vec<Module>,
pub(super) summand: Module,
pub(super) maps: Vec<Morphism>,
}
impl FacWitness {
accessor_methods! {
pub module() -> &Module = |this| &this.module;
pub summands() -> &[Module] = |this| &this.summands;
pub summand() -> &Module = |this| &this.summand;
pub maps() -> &[Morphism] = |this| &this.maps;
pub image_dims() -> Vec<usize> = |this| trace_dims(&this.maps, &this.summand);
}
pub fn verify(&self) -> bool {
hit(Site::FacWitnessVerify);
is_direct_sum(&self.module, &self.summands)
&& self
.maps
.iter()
.all(|f| f.source().ptr_eq(&self.module) && f.target().ptr_eq(&self.summand))
&& trace_dims(&self.maps, &self.summand) == self.summand.dim_vector()
}
}