use crate::hom::Morphism;
use crate::profile::{Site, hit};
use super::element_matrix::ElementMatrix;
use super::maps::{build_vertex_maps, injective_sum};
pub fn nu_of_presentation_map(matrix: &ElementMatrix) -> Morphism {
hit(Site::NuOfPresentation);
let algebra = matrix.algebra();
let field = matrix.field();
let positions = algebra.component_positions();
let source = injective_sum(algebra, matrix.sources());
let target = injective_sum(algebra, matrix.targets());
let maps = build_vertex_maps(
algebra,
matrix.sources(),
matrix.targets(),
|s, w| algebra.paths_between(w, s).len(),
|t, w| algebra.paths_between(w, t).len(),
|w, k, _s, l, t, row_offset, col_offset, mat| {
for (ri, &r) in algebra.paths_between(t, _s).iter().enumerate() {
let c = matrix.entry(k, l)[ri];
if c.is_zero() {
continue;
}
for (pi, &p) in algebra.paths_between(w, t).iter().enumerate() {
for &(q, qc) in &algebra.mul_basis(p, r) {
let row = row_offset + positions[q];
let col = col_offset + pi;
let add = field.mul(c, qc);
mat.set(row, col, field.add(mat.get(row, col), add));
}
}
}
},
);
Morphism::new(&source, &target, maps)
.expect("ν of an element matrix is A-linear between the injective sums")
}