Skip to content

Commit

Permalink
fix QR decomp for complex-valued matrix (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Kazuki Komatsu <komatsu.kazuki.op@tut.jp>
  • Loading branch information
k3kaimu and Kazuki Komatsu committed Feb 24, 2022
1 parent d8e98a0 commit 113478c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion source/kaleidic/lubeck2.d
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,12 @@ struct QRResult(T)
auto aScope = aSliced.lightScope.canonical;
auto tauSliced = tau.as!T.rcslice;
auto tauScope = tauSliced.lightScope;
orgqr!T(aScope, tauScope, work);

static if(is(T == double) || is(T == float))
orgqr!T(aScope, tauScope, work);
else
ungqr!T(aScope, tauScope, work);

Q = aScope.transposed.as!T.rcslice;
}
}
Expand Down Expand Up @@ -752,6 +757,31 @@ unittest
assert(equal!approxEqual(mtimes(res.Q, res.R), data));
}

pure nothrow
unittest
{
import mir.ndslice;
import mir.math;

auto data = mininitRcslice!(Complex!double)(3, 3);
data[] = [[12, -51, 4],
[ 6, 167, -68],
[-4, 24, -41]];

auto res = qr(data);
auto q = mininitRcslice!(Complex!double)(3, 3);
q[] = [[-6.0/7.0, 69.0/175.0, 58.0/175.0],
[-3.0/7.0, -158.0/175.0, -6.0/175.0],
[ 2.0/7.0, -6.0/35.0 , 33.0/35.0 ]];
auto aE = function (Complex!double x, Complex!double y) => approxEqual(x, y, 0.00005, 0.00005);
auto r = mininitRcslice!(Complex!double)(3, 3);
r[] = [[-14, -21, 14],
[ 0, -175, 70],
[ 0, 0, -35]];
assert(equal!approxEqual(mtimes(res.Q, res.R), data));
}


@safe pure @nogc
EigenResult!(realType!T) eigen(T, SliceKind kind)(
auto ref Slice!(const(T)*,2, kind) a,
Expand Down

0 comments on commit 113478c

Please sign in to comment.