132 data = (r > 0 && c > 0) ?
new nr_complex_t[r * c] : NULL;
147 if (rows > 0 && cols > 0) {
149 memcpy (data, m.data, sizeof (
nr_complex_t) * rows * cols);
170 if (rows > 0 && cols > 0) {
172 memcpy (data, m.data, sizeof (
nr_complex_t) * rows * cols);
183 if (data)
delete[] data;
193 return data[r * cols +
c];
204 data[r * cols +
c] = z;
210 for (
int r = 0; r < rows; r++) {
211 for (
int c = 0;
c < cols;
c++) {
212 fprintf (stderr,
"%+.2e,%+.2e ", (
double)
real (
get (r,
c)),
213 (
double)
imag (
get (r,
c)));
230 for (
int r = 0; r < a.
getRows (); r++)
245 for (i = 0, r = 0; r < a.
getRows (); r++)
246 for (c = 0; c < a.
getCols (); c++, i++)
247 data[i] += a.
get (r, c);
261 for (
int r = 0; r < a.
getRows (); r++)
271 for (i = 0, r = 0; r <
getRows (); r++)
272 for (c = 0; c <
getCols (); c++, i++)
273 res.
set (r, c, -data[i]);
284 for (i = 0, r = 0; r < a.
getRows (); r++)
285 for (c = 0; c < a.
getCols (); c++, i++)
286 data[i] -= a.
get (r, c);
298 for (
int r = 0; r < a.
getRows (); r++)
323 for (
int r = 0; r < a.
getRows (); r++)
348 for (
int r = 0; r < a.
getRows (); r++)
362 for (
int r = 0; r < a.
getRows (); r++)
382 for (r = 0; r < a.
getRows (); r++) {
383 for (c = 0; c < b.
getCols (); c++) {
384 for (i = 0, z = 0; i <
n; i++) z += a.
get (r, i) * b.
get (i, c);
399 for (
int r = 0; r < a.
getRows (); r++)
424 for (
int r = 0; r < a.
getRows (); r++)
492 for (
int r = 0; r < a.
getRows (); r++)
505 for (
int r = 0; r < a.
getRows (); r++)
531 for (
int r = 0; r < a.
getRows (); r++)
542 for (
int r = 0; r < a.
getRows (); r++)
555 for (
int r = 0; r < a.
getRows (); r++)
568 for (
int r = 0; r < a.
getRows (); r++)
581 for (
int r = 0; r < a.
getRows (); r++)
596 for (
int r = 0; r < res.
getRows (); r++)
598 if (r ==
c) res.
set (r,
c, 1);
618 for (
int i = 0;
i < size;
i++) res (
i,
i) = diag (
i);
629 res = a = n < 0 ?
inverse (a) : a;
630 for (
int i = 1;
i <
abs (n);
i++)
651 for (ra = r = 0; r < res.getRows (); r++, ra++) {
653 for (ca = c = 0; c < res.getCols (); c++, ca++) {
655 res.set (r, c, a.
get (ra, ca));
659 return ((u + v) & 1) ? -z : z;
685 for (
int i = 0;
i <
s;
i++) {
710 nr_double_t MaxPivot;
716 if (n == 0)
return 1;
717 if (n == 1)
return a (0, 0);
723 for (res = 1, i = 0; i <
n; i++) {
725 for (MaxPivot = 0, pivot = r = i; r <
n; r++) {
726 if (
abs (b.
get (r, i)) > MaxPivot) {
727 MaxPivot =
abs (b.
get (r, i));
732 assert (MaxPivot != 0);
733 if (i != pivot) { b.
exchangeRows (i, pivot); res = -res; }
735 for (r = i + 1; r <
n; r++) {
736 f = b.
get (r, i) / b.
get (i, i);
737 for (c = i + 1; c <
n; c++) {
738 b.
set (r, c, b.
get (r, c) - f * b.
get (i, c));
744 for (i = 0; i <
n; i++) res *= b.
get (i, i);
773 assert (
abs (d) != 0);
774 for (
int r = 0; r < a.
getRows (); r++)
790 nr_double_t MaxPivot;
800 for (i = 0; i <
n; i++) {
802 for (MaxPivot = 0, pivot = r = i; r <
n; r++) {
803 if (
abs (b (r, i)) > MaxPivot) {
804 MaxPivot =
abs (b (r, i));
809 assert (MaxPivot != 0);
816 for (f = b (i, i), c = 0; c <
n; c++) {
822 for (r = 0; r <
n; r++) {
824 for (f = b (r, i), c = 0; c <
n; c++) {
825 b (r, c) -= f *
b (i, c);
826 e (r, c) -= f *
e (i, c);
888 r =
diagonal ((z0 - zref) / (z0 + zref));
973 return inverse (gref) *
inverse (e - s) * (s * zref + zref) * gref;
1133 return gref * (e - zref * y) *
inverse (e + zref * y) *
inverse (gref);
1179 a.
set (0, 0, (
conj (z1) + z1 * s (0, 0) -
1180 conj (z1) * s (1, 1) - z1 * d) / n);
1182 conj (z1) * z2 * s (1, 1) + z1 * z2 * d) / n);
1183 a.
set (1, 0, (1.0 - s (0, 0) - s (1, 1) + d) / n);
1185 z2 * s (1, 1) - z2 * d) / n);
1216 a (1, 0) * z1 * z2 + a (1, 1) * z1;
1221 s.
set (0, 0, (a (0, 0) * z2 + a (0, 1)
1222 - a (1, 0) *
conj (z1) * z2 - a (1, 1) *
conj (z1)) / n);
1223 s.
set (0, 1, (a (0, 0) * a (1, 1) -
1224 a (0, 1) * a (1, 0)) * d / n);
1225 s.
set (1, 0, d / n);
1226 s.
set (1, 1, (a (1, 1) * z1 - a (0, 0) *
conj (z2) +
1227 a (0, 1) - a (1, 0) * z1 *
conj (z2)) / n);
1267 h.
set (0, 0, ((1.0 + s (0, 0)) * (1.0 + s (1, 1)) - n) * z1 / d);
1268 h.
set (0, 1, +2.0 * s (0, 1) / d);
1269 h.
set (1, 0, -2.0 * s (1, 0) / d);
1270 h.
set (1, 1, ((1.0 - s (0, 0)) * (1.0 - s (1, 1)) - n) / z2 / d);
1300 nr_complex_t d = (1.0 + h (0, 0) / z1) * (1.0 + z2 * h (1, 1)) - n;
1305 s.
set (0, 0, ((h (0, 0) / z1 - 1.0) * (1.0 + z2 * h (1, 1)) - n) / d);
1306 s.
set (0, 1, +2.0 * h (0, 1) / d);
1307 s.
set (1, 0, -2.0 * h (1, 0) / d);
1308 s.
set (1, 1, ((1.0 + h (0, 0) / z1) * (1.0 - z2 * h (1, 1)) + n) / d);
1329 g.
set (0, 0, ((1.0 - s (0, 0)) * (1.0 - s (1, 1)) - n) / z1 / d);
1330 g.
set (0, 1, -2.0 * s (0, 1) / d);
1331 g.
set (1, 0, +2.0 * s (1, 0) / d);
1332 g.
set (1, 1, ((1.0 + s (0, 0)) * (1.0 + s (1, 1)) - n) * z2 / d);
1348 nr_complex_t d = (1.0 + g (0, 0) * z1) * (1.0 + g (1, 1) / z2) - n;
1353 s.
set (0, 0, ((1.0 - g (0, 0) * z1) * (1.0 + g (1, 1) / z2) + n) / d);
1354 s.
set (0, 1, -2.0 * g (0, 1) / d);
1355 s.
set (1, 0, +2.0 * g (1, 0) / d);
1356 s.
set (1, 1, ((g (0, 0) * z1 + 1.0) * (g (1, 1) / z2 - 1.0) - n) / d);
1401 return (e + s) * cy *
adjoint (e + s) / 4;
1427 return (e + y) * cs *
adjoint (e + y);
1454 return (e - s) * cz *
adjoint (e - s) / 4;
1478 return (e + z) * cs *
adjoint (e + z);
1538 assert (r1 >= 0 && r2 >= 0 && r1 < rows && r2 < rows);
1540 memcpy (s, &data[r1 * cols], len);
1541 memcpy (&data[r1 * cols], &data[r2 * cols], len);
1542 memcpy (&data[r2 * cols], s, len);
1555 assert (c1 >= 0 && c2 >= 0 && c1 < cols && c2 < cols);
1557 for (
int r = 0; r < rows * cols; r += cols) {
1559 data[r + c1] = data[r + c2];
1597 d = m (0, 0) * m (1, 1) - m (0, 1) * m (1, 0);
1598 res.
set (0, 0, m (1, 1) / d);
1599 res.
set (0, 1, -m (0, 1) / d);
1600 res.
set (1, 0, -m (1, 0) / d);
1601 res.
set (1, 1, m (0, 0) / d);
1605 res.
set (0, 0, 1.0 / d);
1606 res.
set (0, 1, -m (0, 1) / d);
1607 res.
set (1, 0, m (1, 0) / d);
1608 res.
set (1, 1, m (1, 1) - m (0, 1) * m (1, 0) / d);
1612 res.
set (0, 0, m (0, 0) - m (0, 1) * m (1, 0) / d);
1613 res.
set (0, 1, m (0, 1) / d);
1614 res.
set (1, 0, -m (1, 0) / d);
1615 res.
set (1, 1, 1.0 / d);
1619 res.
set (0, 0, -m (1, 1) / d);
1620 res.
set (0, 1, -1.0 / d);
1621 res.
set (1, 0, m (0, 1) - m (1, 1) * m (0, 0) / d);
1622 res.
set (1, 1, -m (0, 0) / d);
1632 d = m (0, 0) * m (1, 1) - m (0, 1) * m (1, 0);
1633 res.
set (0, 0, m (1, 1) / d);
1634 res.
set (0, 1, -m (0, 1) / d);
1635 res.
set (1, 0, -m (1, 0) / d);
1636 res.
set (1, 1, m (0, 0) / d);
1643 res.
set (0, 0, m (0, 0) - m (0, 1) * m (1, 0) / d);
1644 res.
set (0, 1, m (0, 1) / d);
1645 res.
set (1, 0, -m (1, 0) / d);
1646 res.
set (1, 1, 1.0 / d);
1650 res.
set (0, 0, 1.0 / d);
1651 res.
set (0, 1, -m (0, 1) / d);
1652 res.
set (1, 0, m (1, 0) / d);
1653 res.
set (1, 1, m (1, 1) - m (0, 1) * m (1, 0) / d);
1657 res.
set (0, 0, m (0, 0) / d);
1658 res.
set (0, 1, m (0, 0) * m (1, 1) / d - m (0, 1));
1659 res.
set (1, 0, 1.0 / d);
1660 res.
set (1, 1, m (1, 1) / d);
1671 res.
set (0, 0, 1.0 / d);
1672 res.
set (0, 1, -m (0, 1) / d);
1673 res.
set (1, 0, m (1, 0) / d);
1674 res.
set (1, 1, m (1, 1) - m (0, 1) * m.
get(2, 1) / d);
1678 res.
set (0, 0, m (0, 0) - m (0, 1) * m (1, 0) / d);
1679 res.
set (0, 1, m (0, 1) / d);
1680 res.
set (1, 0, -m (1, 0) / d);
1681 res.
set (1, 1, 1.0 / d);
1687 d = m (0, 0) * m (1, 1) - m (0, 1) * m (1, 0);
1688 res.
set (0, 0, m (1, 1) / d);
1689 res.
set (0, 1, -m (0, 1) / d);
1690 res.
set (1, 0, -m (1, 0) / d);
1691 res.
set (1, 1, m (0, 0) / d);
1695 res.
set (0, 0, m (0, 1) - m (0, 0) * m (1, 1) / d);
1696 res.
set (0, 1, -m (0, 0) / d);
1697 res.
set (1, 0, -m (1, 1) / d);
1698 res.
set (1, 1, -1.0 / d);
1709 res.
set (0, 0, m (0, 0) - m (0, 1) * m (1, 0) / d);
1710 res.
set (0, 1, m (0, 1) / d);
1711 res.
set (1, 0, -m (1, 0) / d);
1712 res.
set (1, 1, 1.0 / d);
1716 res.
set (0, 0, 1.0 / d);
1717 res.
set (0, 1, -m (0, 1) / d);
1718 res.
set (1, 0, m (1, 0) / d);
1719 res.
set (1, 1, m (1, 1) - m (0, 1) * m (1, 0) / d);
1722 d = m (0, 0) * m (1, 1) - m (0, 1) * m (1, 0);
1723 res.
set (0, 0, m (1, 1) / d);
1724 res.
set (0, 1, -m (0, 1) / d);
1725 res.
set (1, 0, -m (1, 0) / d);
1726 res.
set (1, 1, m (0, 0) / d);
1733 res.
set (0, 0, 1.0 / d);
1734 res.
set (0, 1, m (1, 1) / d);
1735 res.
set (1, 0, m (0, 0) / d);
1736 res.
set (1, 1, m (0, 0) * m (1, 1) / d - m (0, 1));
1747 res.
set (0, 0, m (1, 1) / d);
1748 res.
set (0, 1, m (1, 0) - m (0, 0) * m (1, 1) / d);
1749 res.
set (1, 0, -1.0 / d);
1750 res.
set (1, 1, m (0, 0) / d);
1754 res.
set (0, 0, m (0, 0) / d);
1755 res.
set (0, 1, m (0, 0) * m (1, 1) / d - m (0, 1));
1756 res.
set (1, 0, 1.0 / d);
1757 res.
set (1, 1, m (1, 1) / d);
1761 res.
set (0, 0, m (0, 1) / d);
1762 res.
set (0, 1, m (0, 0) - m (0, 1) * m (1, 0) / d);
1763 res.
set (1, 0, -1.0 / d);
1764 res.
set (1, 1, m (1, 0) / d);
1768 res.
set (0, 0, m (1, 0) / d);
1769 res.
set (0, 1, m (1, 0) * m (0, 1) / d - m (1, 1));
1770 res.
set (1, 0, 1.0 / d);
1771 res.
set (1, 1, m (0, 1) / d);
1788 res.
set (0, 0, m (0, 1) - m (0, 0) * m (1, 1) / d);
1789 res.
set (0, 1, m (0, 0) / d);
1790 res.
set (1, 0, -m (1, 1) / d);
1791 res.
set (0, 1, 1.0 / d);
1814 res.
set (0, 0, m (0, 1) / d);
1815 res.
set (0, 1, m (0, 0) - m (0, 1) * m (1, 0) / d);
1816 res.
set (1, 0, 1.0 / d);
1817 res.
set (0, 1, -m (1, 0) / d);
1849 2 /
abs (m (0, 1) * m (1, 0));