28 #ifndef RANDOM_UNITARY_H 29 #define RANDOM_UNITARY_H 61 template<
typename DerU,
typename Rng,
typename Log>
64 {
using namespace Eigen; EIGEN_STATIC_ASSERT_LVALUE(DerU); }
67 const int n = U.rows();
69 logger.longdebug(
"randomUnitary()",
"n = %d", n);
71 typedef typename DerU::Scalar Scalar;
79 A = Tomographer::Tools::denseRandom<MatrixType>(rng, normdist, n, n);
87 for (
int j = 0; j < n; ++j) {
89 VectorType v = VectorType::Zero(n);
93 for (
int k = 0; k < j; ++k) {
94 Scalar p = U.
col(k).adjoint() * v;
98 U.
col(j) = v / v.norm();
107 logger.longdebug(
"randomUnitary()", [&](
std::ostream& str) {
108 str <<
"randomUnitary: got U = \n" << U <<
"\n" 109 <<
"Check: U*U.adjoint() ==\n" << U*U.
adjoint() <<
"\n" 110 <<
"Check: U.adjoint()*U ==\n" << U.
adjoint()*U;
115 template<
typename Der1,
typename Rng>
118 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
#define tomographer_assert(...)
Assertion test macro.
Utilities for logging messages.