import mir.blas;
import mir.complex;
import mir.ndslice;
import mir.math;
auto data =
[[ 0, 1],
[-1, 0]].fuse.as!double.rcslice;
auto eigenvalues = [Complex!double(0, 1), Complex!double(0, -1)].sliced;
auto eigenvectors =
[[Complex!double(0, -1), Complex!double(1, 0)],
[Complex!double(0, 1), Complex!double(1, 0)]].fuse;
auto res = data.eigen;
assert(res.eigenvalues.equal!approxEqual(eigenvalues));
foreach (i; 0 .. eigenvectors.length)
assert((res.eigenvectors.lightScope[i] / eigenvectors[i]).diff.slice.nrm2.approxEqual(0));
import mir.complex;
import mir.ndslice;
import mir.math;
import mir.blas;
auto data =
[[0, 1, 0],
[0, 0, 1],
[1, 0, 0]].fuse.as!double.rcslice;
auto c = 3.0.sqrt;
auto eigenvalues = [Complex!double(-1, c) / 2, Complex!double(-1, - c) / 2, Complex!double(1, 0)];
auto eigenvectors =
[[Complex!double(-1, +c), Complex!double(-1, -c) , Complex!double(2, 0)],
[Complex!double(-1, -c), Complex!double(-1, +c) , Complex!double(2, 0)],
[Complex!double(1, 0), Complex!double(1, 0), Complex!double(1, 0)]].fuse;
auto res = data.eigen;
assert(res.eigenvalues.equal!approxEqual(eigenvalues));
foreach (i; 0 .. eigenvectors.length)
assert((res.eigenvectors.lightScope[i] / eigenvectors[i]).diff.slice.nrm2.approxEqual(0));
auto cdata = data.lightScope.as!(Complex!double).rcslice;
res = cdata.eigen;
assert(res.eigenvalues.equal!approxEqual(eigenvalues));
foreach (i; 0 .. eigenvectors.length)
assert((res.eigenvectors.lightScope[i] / eigenvectors[i]).diff.slice.nrm2.approxEqual(0));