use crate::hom::Morphism;
use crate::homspace::scale_morphism;
use crate::linalg::DenseMat;
pub(super) fn negate(f: &Morphism) -> Morphism {
let field = f.source().field();
scale_morphism(f, field.neg(field.one()))
}
pub(super) fn factor_through_epi(epi: &Morphism, map: &Morphism) -> Morphism {
debug_assert!(epi.source().ptr_eq(map.source()));
let field = epi.source().field();
let nv = epi.source().algebra().quiver().num_vertices();
let maps = (0..nv)
.map(|v| {
let (e, m) = (epi.map_at(v), map.map_at(v));
if m.cols() == 0 {
return DenseMat::zero(e.cols(), 0);
}
e.solve_many(m, &field)
.expect("factor_through_epi: the map kills the kernel of the epimorphism")
})
.collect();
Morphism::new(epi.target(), map.target(), maps)
.expect("a factorization through an epimorphism is A-linear")
}