use ndarray::*;
use crate::error::*;
use crate::layout::*;
use crate::types::*;
pub use crate::lapack::NormType;
pub trait OperationNorm {
type Output: Scalar;
fn opnorm(&self, t: NormType) -> Result<Self::Output>;
fn opnorm_one(&self) -> Result<Self::Output> {
self.opnorm(NormType::One)
}
fn opnorm_inf(&self) -> Result<Self::Output> {
self.opnorm(NormType::Infinity)
}
fn opnorm_fro(&self) -> Result<Self::Output> {
self.opnorm(NormType::Frobenius)
}
}
impl<A, S> OperationNorm for ArrayBase<S, Ix2>
where
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type Output = A::Real;
fn opnorm(&self, t: NormType) -> Result<Self::Output> {
let l = self.layout()?;
let a = self.as_allocated()?;
Ok(unsafe { A::opnorm(t, l, a) })
}
}