https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
std::vector< TcomputeRow (std::size_t row) const
 Compute specified row of Cartesian product matrix.
 
T computeValue (std::size_t row, std::size_t col) const
 Compute specific value, given row and column, of the Cartesian product matrix.
 
std::size_t numRows () const
 Total number of rows in the complete matrix.
 
std::size_t numCols () const
 Total number of columns in the complete matrix.
 

Protected Attributes

const std::size_t _n_rows
 Number of rows/columns.
 
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.
 

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.
 
std::deque< unsigned int_denomenators
 Containers for lazy Cartesian product calculation.
 
std::deque< unsigned int_moduli
 

Detailed Description

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

Definition at line 26 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 65 of file CartesianProduct.h.

66 : _n_rows(computeRowCount(items)), _n_cols(items.size()), _items(items)
67{
68 dof_id_type d = 1;
69 for (typename std::vector<std::vector<T>>::const_reverse_iterator iter = _items.rbegin();
70 iter != _items.rend();
71 ++iter)
72 {
73 std::size_t n = iter->size();
74 _denomenators.push_front(d);
75 _moduli.push_front(n);
76 d *= n;
77 }
78}
std::deque< unsigned int > _moduli
const std::size_t _n_rows
Number of rows/columns.
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.
const std::vector< std::vector< T > > _items
Data used to create Cartesian product use a copy because a temporary can be supplied,...
std::deque< unsigned int > _denomenators
Containers for lazy Cartesian product calculation.
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 82 of file CartesianProduct.h.

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

Referenced by TEST().

◆ 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 93 of file CartesianProduct.h.

94{
95 std::vector<T> output(_n_cols);
96 for (std::size_t col = 0; col < _n_cols; ++col)
97 output[col] = computeValue(row, col);
98 return output;
99}

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

◆ 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 112 of file CartesianProduct.h.

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

◆ 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 103 of file CartesianProduct.h.

104{
105 mooseAssert(row < _n_rows, "Row index out of range.");
106 mooseAssert(col < _n_cols, "Column index out of range.");
107 return _items[col][(row / _denomenators[col]) % _moduli[col]];
108}

Referenced by TEST().

◆ numCols()

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

Total number of columns in the complete matrix.

Definition at line 44 of file CartesianProduct.h.

44{ return _n_cols; }

Referenced by TEST(), and TEST().

◆ numRows()

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

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 57 of file CartesianProduct.h.

Referenced by StochasticTools::CartesianProduct< T >::CartesianProduct().

◆ _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 54 of file CartesianProduct.h.

Referenced by StochasticTools::CartesianProduct< T >::CartesianProduct().

◆ _moduli

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

◆ _n_cols

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

Definition at line 49 of file CartesianProduct.h.

Referenced by StochasticTools::CartesianProduct< T >::numCols().

◆ _n_rows

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

Number of rows/columns.

Definition at line 48 of file CartesianProduct.h.

Referenced by StochasticTools::CartesianProduct< T >::numRows().


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