https://mooseframework.inl.gov
Public Member Functions | Protected Attributes | Static Private Member Functions | Private Attributes | List of all members
StochasticTools::CartesianProduct< T > Class Template Reference

#include <CartesianProduct.h>

Inheritance diagram for StochasticTools::CartesianProduct< T >:
[legend]

Public Member Functions

 CartesianProduct (const std::vector< std::vector< T >> &items)
 
std::vector< std::vector< T > > computeMatrix () const
 Compute the complete Cartesian product matrix. More...
 
std::vector< T > computeRow (std::size_t row) const
 Compute specified row of Cartesian product matrix. More...
 
computeValue (std::size_t row, std::size_t col) const
 Compute specific value, given row and column, of the Cartesian product matrix. More...
 
std::size_t numRows () const
 Total number of rows in the complete matrix. More...
 
std::size_t numCols () const
 Total number of columns in the complete matrix. More...
 

Protected Attributes

const std::size_t _n_rows
 Number of rows/columns. More...
 
const std::size_t _n_cols
 

Static Private Member Functions

static std::size_t computeRowCount (const std::vector< std::vector< T >> &items)
 Helper to compute the rows in initialization list to allow _n_rows to be const. More...
 

Private Attributes

const std::vector< std::vector< T > > _items
 Data used to create Cartesian product use a copy because a temporary can be supplied, as is the case in the CartesianProductSampler. More...
 
std::deque< unsigned int_denomenators
 Containers for lazy Cartesian product calculation. More...
 
std::deque< unsigned int_moduli
 

Detailed Description

template<class T>
class StochasticTools::CartesianProduct< T >

Definition at line 25 of file CartesianProduct.h.

Constructor & Destructor Documentation

◆ CartesianProduct()

template<typename T>
StochasticTools::CartesianProduct< T >::CartesianProduct ( const std::vector< std::vector< T >> &  items)

Definition at line 64 of file CartesianProduct.h.

65  : _n_rows(computeRowCount(items)), _n_cols(items.size()), _items(items)
66 {
67  dof_id_type d = 1;
68  for (typename std::vector<std::vector<T>>::const_reverse_iterator iter = _items.rbegin();
69  iter != _items.rend();
70  ++iter)
71  {
72  std::size_t n = iter->size();
73  _denomenators.push_front(d);
74  _moduli.push_front(n);
75  d *= n;
76  }
77 }
std::deque< unsigned int > _denomenators
Containers for lazy Cartesian product calculation.
std::deque< unsigned int > _moduli
const std::size_t _n_rows
Number of rows/columns.
const std::vector< std::vector< T > > _items
Data used to create Cartesian product use a copy because a temporary can be supplied, as is the case in the CartesianProductSampler.
static std::size_t computeRowCount(const std::vector< std::vector< T >> &items)
Helper to compute the rows in initialization list to allow _n_rows to be const.
uint8_t dof_id_type

Member Function Documentation

◆ computeMatrix()

template<typename T >
std::vector< std::vector< T > > StochasticTools::CartesianProduct< T >::computeMatrix ( ) const

Compute the complete Cartesian product matrix.

Definition at line 81 of file CartesianProduct.h.

82 {
83  std::vector<std::vector<T>> output(_n_rows, std::vector<T>(_n_cols));
84  for (std::size_t row = 0; row < _n_rows; ++row)
85  for (std::size_t col = 0; col < _n_cols; ++col)
86  output[row][col] = computeValue(row, col);
87  return output;
88 }
T computeValue(std::size_t row, std::size_t col) const
Compute specific value, given row and column, of the Cartesian product matrix.
const std::size_t _n_rows
Number of rows/columns.

◆ computeRow()

template<typename T >
std::vector< T > StochasticTools::CartesianProduct< T >::computeRow ( std::size_t  row) const

Compute specified row of Cartesian product matrix.

Definition at line 92 of file CartesianProduct.h.

Referenced by PolynomialQuadrature::ClenshawCurtisGrid::ClenshawCurtisGrid(), StochasticTools::MultiDimPolynomialGenerator::generateTuple(), and PolynomialQuadrature::SmolyakGrid::SmolyakGrid().

93 {
94  std::vector<T> output(_n_cols);
95  for (std::size_t col = 0; col < _n_cols; ++col)
96  output[col] = computeValue(row, col);
97  return output;
98 }
T computeValue(std::size_t row, std::size_t col) const
Compute specific value, given row and column, of the Cartesian product matrix.

◆ computeRowCount()

template<typename T>
std::size_t StochasticTools::CartesianProduct< T >::computeRowCount ( const std::vector< std::vector< T >> &  items)
staticprivate

Helper to compute the rows in initialization list to allow _n_rows to be const.

Definition at line 111 of file CartesianProduct.h.

112 {
113  std::size_t n_rows = 1;
114  for (const auto & inner : items)
115  n_rows *= inner.size();
116  return n_rows;
117 }

◆ computeValue()

template<typename T >
T StochasticTools::CartesianProduct< T >::computeValue ( std::size_t  row,
std::size_t  col 
) const

Compute specific value, given row and column, of the Cartesian product matrix.

Definition at line 102 of file CartesianProduct.h.

103 {
104  mooseAssert(row < _n_rows, "Row index out of range.");
105  mooseAssert(col < _n_cols, "Column index out of range.");
106  return _items[col][(row / _denomenators[col]) % _moduli[col]];
107 }
std::deque< unsigned int > _denomenators
Containers for lazy Cartesian product calculation.
std::deque< unsigned int > _moduli
const std::size_t _n_rows
Number of rows/columns.
const std::vector< std::vector< T > > _items
Data used to create Cartesian product use a copy because a temporary can be supplied, as is the case in the CartesianProductSampler.

◆ numCols()

template<class T>
std::size_t StochasticTools::CartesianProduct< T >::numCols ( ) const
inline

Total number of columns in the complete matrix.

Definition at line 43 of file CartesianProduct.h.

Referenced by TEST().

43 { return _n_cols; }

◆ numRows()

template<class T>
std::size_t StochasticTools::CartesianProduct< T >::numRows ( ) const
inline

Total number of rows in the complete matrix.

Definition at line 40 of file CartesianProduct.h.

Referenced by PolynomialQuadrature::ClenshawCurtisGrid::ClenshawCurtisGrid(), StochasticTools::MultiDimPolynomialGenerator::generateTuple(), PolynomialQuadrature::SmolyakGrid::SmolyakGrid(), and TEST().

40 { return _n_rows; }
const std::size_t _n_rows
Number of rows/columns.

Member Data Documentation

◆ _denomenators

template<class T>
std::deque<unsigned int> StochasticTools::CartesianProduct< T >::_denomenators
private

Containers for lazy Cartesian product calculation.

Definition at line 56 of file CartesianProduct.h.

◆ _items

template<class T>
const std::vector<std::vector<T> > StochasticTools::CartesianProduct< T >::_items
private

Data used to create Cartesian product use a copy because a temporary can be supplied, as is the case in the CartesianProductSampler.

Definition at line 53 of file CartesianProduct.h.

◆ _moduli

template<class T>
std::deque<unsigned int> StochasticTools::CartesianProduct< T >::_moduli
private

Definition at line 57 of file CartesianProduct.h.

◆ _n_cols

template<class T>
const std::size_t StochasticTools::CartesianProduct< T >::_n_cols
protected

Definition at line 48 of file CartesianProduct.h.

◆ _n_rows

template<class T>
const std::size_t StochasticTools::CartesianProduct< T >::_n_rows
protected

Number of rows/columns.

Definition at line 47 of file CartesianProduct.h.


The documentation for this class was generated from the following file: