27 #ifndef RANDOM_UNITARY_H
28 #define RANDOM_UNITARY_H
59 template<
typename DerU,
typename Rng,
typename Log>
62 {
using namespace Eigen; EIGEN_STATIC_ASSERT_LVALUE(DerU); }
64 assert(U.rows() == U.cols());
65 const int n = U.rows();
67 logger.longdebug(
"random_unitary()",
"n = %d", n);
69 typedef typename DerU::Scalar Scalar;
77 A = Tomographer::dense_random<MatrixType>(rng, normdist, n, n);
85 for (
int j = 0; j < n; ++j) {
87 VectorType v = VectorType::Zero(n);
91 for (
int k = 0; k < j; ++k) {
92 Scalar p = U.
col(k).adjoint() * v;
96 U.
col(j) = v / v.norm();
105 logger.longdebug(
"random_unitary()", [&](
std::ostream& str) {
106 str <<
"random_unitary: got U = \n" << U <<
"\n"
107 <<
"Check: U*U.adjoint() ==\n" << U*U.
adjoint() <<
"\n"
108 <<
"Check: U.adjoint()*U ==\n" << U.
adjoint()*U;
113 template<
typename Der1,
typename Rng>
116 random_unitary<Der1, Rng>(U, rng, Logger::vacuum_logger);
Base namespace for the Tomographer project.
void random_unitary(Eigen::MatrixBase< DerU > &U, Rng &rng, Log &logger)
Generate a Haar-distributed random unitary.
const AdjointReturnType adjoint() const
Basic utilities for dealing with Eigen matrices and other types.
Utilities for logging messages.