27 #ifndef RANDOM_UNITARY_H 28 #define RANDOM_UNITARY_H 60 template<
typename DerU,
typename Rng,
typename Log>
63 {
using namespace Eigen; EIGEN_STATIC_ASSERT_LVALUE(DerU); }
65 tomographer_assert(U.rows() == U.cols());
66 const int n = U.rows();
68 logger.longdebug(
"randomUnitary()",
"n = %d", n);
70 typedef typename DerU::Scalar Scalar;
78 A = Tomographer::Tools::denseRandom<MatrixType>(rng, normdist, n, n);
86 for (
int j = 0; j < n; ++j) {
88 VectorType v = VectorType::Zero(n);
92 for (
int k = 0; k < j; ++k) {
93 Scalar p = U.
col(k).adjoint() * v;
97 U.
col(j) = v / v.norm();
106 logger.longdebug(
"randomUnitary()", [&](
std::ostream& str) {
107 str <<
"randomUnitary: got U = \n" << U <<
"\n" 108 <<
"Check: U*U.adjoint() ==\n" << U*U.
adjoint() <<
"\n" 109 <<
"Check: U.adjoint()*U ==\n" << U.
adjoint()*U;
114 template<
typename Der1,
typename Rng>
117 randomUnitary<Der1, Rng>(U, rng, Logger::vacuum_logger);
Base namespace for the Tomographer project.
Basic utilities for dealing with Eigen matrices and other types.
Some C++ utilities, with a tad of C++11 tricks.
const AdjointReturnType adjoint() const
Utilities for logging messages.