use scirs2_core::ndarray::Array2;
use crate::error::KernelError;
type Result<T> = std::result::Result<T, KernelError>;
pub trait MultiOutputKernel: Send + Sync {
fn n_outputs(&self) -> usize;
fn compute_block(&self, x: &[f64], y: &[f64]) -> Result<Array2<f64>>;
fn block_gram_matrix(&self, inputs: &[Vec<f64>]) -> Result<Array2<f64>> {
let n = inputs.len();
let p = self.n_outputs();
let np = n * p;
let mut gram = Array2::<f64>::zeros((np, np));
for i in 0..n {
for j in i..n {
let block = self.compute_block(&inputs[i], &inputs[j])?;
for ri in 0..p {
for ci in 0..p {
gram[[i * p + ri, j * p + ci]] = block[[ri, ci]];
gram[[j * p + ci, i * p + ri]] = block[[ci, ri]];
}
}
}
}
Ok(gram)
}
fn name(&self) -> &str;
}