41 #include <Eigen/Dense>
42 #include <Eigen/StdVector>
60 template<
typename Scalar>
75 template<
typename Scalar>
81 template<
typename RealScalar>
84 typedef RealScalar type;
135 template<
typename EigenType>
150 namespace tomo_internal {
152 template<
typename Rng,
typename RndDist,
typename Scalar>
153 struct random_generator
155 typedef Scalar result_type;
160 random_generator(Rng & rng_, RndDist & rnddist_)
161 : rng(rng_), rnddist(rnddist_)
165 template<
typename Index>
166 inline const result_type operator() (Index, Index = 0)
const {
171 template<
typename Rng,
typename RndDist,
typename RealScalar>
172 struct random_generator<Rng, RndDist,
std::complex<RealScalar> >
179 random_generator(Rng & rng_, RndDist & rnddist_)
180 : rng(rng_), rnddist(rnddist_)
184 template<
typename Index>
185 inline const result_type operator() (Index, Index = 0)
const {
186 return result_type(rnddist(rng), rnddist(rng));
196 template<
typename Rng,
typename RndDist,
typename Scalar>
197 struct functor_traits<
Tomographer::tomo_internal::random_generator<Rng, RndDist, Scalar> >
198 {
enum { Cost = 50 * NumTraits<Scalar>::MulCost, PacketAccess =
false, IsRepeatable =
false }; };
214 template<
typename Der,
typename Rng,
typename RndDist,
typename... IndexTypes>
215 inline auto dense_random(Rng & rng, RndDist &rnddist, IndexTypes... sizes)
217 tomo_internal::random_generator<Rng, RndDist, typename Eigen::internal::traits<Der>::Scalar>,
221 typedef typename Der::Scalar Scalar;
224 sizes..., tomo_internal::random_generator<Rng, RndDist, Scalar>(rng, rnddist)
234 namespace tomo_internal {
236 template<
typename Scalar,
typename IndexType>
237 struct can_basis_vec_generator
239 typedef Scalar result_type;
244 can_basis_vec_generator(IndexType k_, IndexType j_ = 0)
249 inline const result_type operator() (IndexType a, IndexType b = 0)
const {
250 return (a == k) && (b == j) ? result_type(1) : result_type(0);
258 template<
typename Scalar,
typename IndexType>
259 struct functor_traits<
Tomographer::tomo_internal::can_basis_vec_generator<Scalar, IndexType> >
260 {
enum { Cost = 2 * NumTraits<Scalar>::MulCost, PacketAccess =
false, IsRepeatable =
true }; };
270 template<
typename Der,
typename IndexType>
273 tomo_internal::can_basis_vec_generator<typename Eigen::internal::traits<Der>::Scalar, IndexType>,
277 typedef typename Der::Scalar Scalar;
280 size, tomo_internal::can_basis_vec_generator<Scalar, IndexType>(k)
288 template<
typename Der,
typename IndexType>
289 inline auto can_basis_vec(IndexType k, IndexType j, IndexType rows, IndexType cols)
291 tomo_internal::can_basis_vec_generator<typename Eigen::internal::traits<Der>::Scalar, IndexType>,
295 typedef typename Der::Scalar Scalar;
298 rows, cols, tomo_internal::can_basis_vec_generator<Scalar, IndexType>(k, j)
309 namespace tomo_internal {
311 template<
typename Scalar>
312 struct powers_of_two_generator
316 powers_of_two_generator() { }
318 template<
typename IndexType>
319 inline const result_type operator() (IndexType a)
const {
323 template<
typename IndexType>
324 inline const result_type operator() (IndexType a, IndexType b)
const {
325 eigen_assert(b == 0 &&
"powers_of_two_generator may only be used with 1-D objects!"); (void)b;
335 template<
typename Scalar>
336 struct functor_traits<
Tomographer::tomo_internal::powers_of_two_generator<Scalar> >
337 {
enum { Cost = 8 * NumTraits<Scalar>::MulCost, PacketAccess =
false, IsRepeatable =
true }; };
356 template<
typename Der,
typename... IndexTypes>
359 tomo_internal::powers_of_two_generator<typename Eigen::internal::traits<Der>::Scalar>,
363 typedef typename Der::Scalar Scalar;
366 sizes..., tomo_internal::powers_of_two_generator<Scalar>()
391 template<
int RowFactorCTime,
int ColFactorCTime,
typename Derived,
392 typename std::enable_if<(RowFactorCTime == Eigen::Dynamic || ColFactorCTime == Eigen::Dynamic),
393 bool>::type dummy =
true>
397 eigen_assert(RowFactorCTime == Eigen::Dynamic || row_factor == RowFactorCTime);
398 eigen_assert(ColFactorCTime == Eigen::Dynamic || col_factor == ColFactorCTime);
399 return x.
replicate(row_factor, col_factor);
405 template<
int RowFactorCTime,
int ColFactorCTime,
typename Derived,
406 typename std::enable_if<(RowFactorCTime != Eigen::Dynamic && ColFactorCTime != Eigen::Dynamic),
407 bool>::type dummy2 =
true>
411 eigen_assert(row_factor == RowFactorCTime); (void)row_factor;
412 eigen_assert(col_factor == ColFactorCTime); (void)col_factor;
413 return x.template replicate<RowFactorCTime, ColFactorCTime>();
static const CwiseNullaryOp< CustomNullaryOp, Derived > NullaryExpr(Index rows, Index cols, const CustomNullaryOp &func)
Base namespace for the Tomographer project.
auto powers_of_two(IndexTypes...sizes) -> const Eigen::CwiseNullaryOp< tomo_internal::powers_of_two_generator< typename Eigen::internal::traits< Der >::Scalar >, Der >
Expression for a 1-D expression of powers of two.
auto can_basis_vec(IndexType k, IndexType size) -> const Eigen::CwiseNullaryOp< tomo_internal::can_basis_vec_generator< typename Eigen::internal::traits< Der >::Scalar, IndexType >, Der >
Expression for the k-th canonical basis vector of given dimension.
auto replicated(const Eigen::DenseBase< Derived > &x, int row_factor, int col_factor) -> const Eigen::Replicate< Derived, Eigen::Dynamic, Eigen::Dynamic >
Replicate a Eigen Dense object; same call for compile-time & run-time dimensions. ...
auto dense_random(Rng &rng, RndDist &rnddist, IndexTypes...sizes) -> const Eigen::CwiseNullaryOp< tomo_internal::random_generator< Rng, RndDist, typename Eigen::internal::traits< Der >::Scalar >, Der >
a matrix populated with random entries using C++'s random framework
const Replicate< Derived, RowFactor, ColFactor > replicate() const