ubiquity_hyperquiver/
lib.rs

1//! ubiquity-hyperquiver: multilinear hyperedges
2
3use ndarray::{Array1, Array2};
4use ubiquity_kernel::UbiqError;
5
6/// k-ary hyperedge modeled as multilinear map via tensor folding (naive)
7pub struct HyperEdge {
8    pub dims: Vec<usize>,   // input dims for each leg
9    pub out_dim: usize,
10    pub weights: Vec<Array2<f32>>, // simple chain of bilinear projections for demo
11}
12
13impl HyperEdge {
14    pub fn apply(&self, inputs: &[Array1<f32>]) -> Result<Array1<f32>, UbiqError> {
15        if inputs.len() != self.dims.len() { return Err(UbiqError::Dim("arity mismatch".into())); }
16        // Fold inputs through chained bilinear maps (placeholder)
17        let mut acc = inputs[0].clone();
18        for (i, w) in self.weights.iter().enumerate() {
19            if i+1 >= inputs.len() { break; }
20            let next = &inputs[i+1];
21            // concatenate [acc | next] and project
22            let mut cat = Array1::<f32>::zeros(acc.len() + next.len());
23            cat.slice_mut(ndarray::s![..acc.len()]).assign(&acc);
24            cat.slice_mut(ndarray::s![acc.len()..]).assign(next);
25            acc = w.dot(&cat);
26        }
27        Ok(acc)
28    }
29}