ndarray-linalg
ndarray-linalg copied to clipboard
Adding an Adjoint trait for operators
I am writing an optimization library for which I would like several of the routine's inputs to be generic LinearOperators. I was happy to find that this trait abstraction was already provided in ndarray-linalg, but some of my inputs additionally require that I can take an adjoint/hermitian transpose.
I've implemented this trait and its function on Array2, Diagonal, as well as my own LinearOperators (Identity, DFT), but as adjoints are a linear algebra concept, and linear operators in other languages often come with this functionality, I thought I'd see if there was any interest in a pull request.
Here is some example code. I could add into_adj()
or adj_mut()
if necessary.
pub trait Adjoint<'a>
{
type Output;
fn adj(&'a self) -> Self::Output;
}
impl<'a, A, S> Adjoint<'a> for ArrayBase<S, Ix2>
where
A: 'a + Float, // just the real case
S: Data<Elem = A>,
{
type Output = ArrayView<'a, A, Ix2>;
fn adj(&'a self) -> Self::Output {
self.t()
}
}
How this issue currently being addressed?
The above code doesn't seem to follow the case of complex numbers, but I think it can be easily extended by applying Scalar::conj()
to each element.
If this trait is not implemented yet, I will send PR, but I'd appreciate it if you could tell me in which mod
I should implement it (including the case of creating a new mod
file).