///|
/// Kernel that applies a general dense unitary matrix.
/// Stores the matrix in row-major order.
pub(all) struct DenseKernel {
  data : Array[@maths.Complex]
  size : Int32
}

///|
pub impl LinearKernel for DenseKernel with fn size(self) -> Int32 {
  self.size
}

///|
/// Multiply the row-order unitary matrix by the local input and write all outputs.
pub impl LinearKernel for DenseKernel with fn apply(self, args) {
  for row in 0.. &UnitaryKernel {
  let data = Array::makei(self.data.length(), fn(i) {
    self.data[i % self.size * self.size + i / self.size].conjugate()
  })
  DenseKernel::{ data, size: self.size, }
}

///|
pub extend DenseKernel with LinearKernel::{size, apply}

///|
pub extend DenseKernel with UnitaryKernel::{adjoint}