BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ArrayUtils::CreateDataImpl Class Reference

Classes

struct  baseClass
 
struct  baseClass< std::vector< T, A > >
 
struct  nDim
 Holds the dimensionality of template argument as the enum value. More...
 
struct  nDim< std::vector< T, A > >
 

Private Types

template<class T >
using ReturnType = std::unique_ptr< OutputData< typename CreateDataImpl::baseClass< T >::value > >
 

Static Private Member Functions

template<class T >
static std::unique_ptr< OutputData< T > > createDataImpl (const std::vector< std::vector< T >> &vec)
 
template<class T >
static std::unique_ptr< OutputData< T > > createDataImpl (const std::vector< T > &vec)
 

Friends

template<class T >
ReturnType< T > createData (const T &vec)
 Creates OutputData array from input vector. More...
 

Detailed Description

Definition at line 35 of file ArrayUtils.h.

Member Typedef Documentation

◆ ReturnType

template<class T >
using ArrayUtils::CreateDataImpl::ReturnType = std::unique_ptr<OutputData<typename CreateDataImpl::baseClass<T>::value> >
private

Definition at line 53 of file ArrayUtils.h.

Member Function Documentation

◆ createDataImpl() [1/2]

template<class T >
std::unique_ptr< OutputData< T > > ArrayUtils::CreateDataImpl::createDataImpl ( const std::vector< std::vector< T >> &  vec)
staticprivate

Definition at line 101 of file ArrayUtils.h.

102 {
103  auto result = std::make_unique<OutputData<T>>();
104 
105  auto shape = ArrayUtils::getShape(vec);
106  const size_t nrows = shape.first;
107  const size_t ncols = shape.second;
108 
109  if (nrows == 0 || ncols == 0)
110  throw std::runtime_error(
111  "Error in ArrayUtils::createDataImpl: input argument contains empty dimensions");
112 
113  result->addAxis(FixedBinAxis("axis0", ncols, 0.0, static_cast<double>(ncols)));
114  result->addAxis(FixedBinAxis("axis1", nrows, 0.0, static_cast<double>(nrows)));
115 
116  // filling the data
117  for (size_t row = 0; row < nrows; ++row) {
118  for (size_t col = 0; col < ncols; ++col) {
119  size_t globalbin = nrows - row - 1 + col * nrows;
120  (*result)[globalbin] = vec[row][col];
121  }
122  }
123 
124  return result;
125 }
Axis with fixed bin size.
Definition: FixedBinAxis.h:23
std::pair< size_t, size_t > getShape(const T &data)
Returns shape nrows, ncols of 2D array.
Definition: ArrayUtils.h:127

References ArrayUtils::getShape().

Here is the call graph for this function:

◆ createDataImpl() [2/2]

template<class T >
std::unique_ptr< OutputData< T > > ArrayUtils::CreateDataImpl::createDataImpl ( const std::vector< T > &  vec)
staticprivate

Definition at line 90 of file ArrayUtils.h.

91 {
92  auto result = std::make_unique<OutputData<T>>();
93  const size_t length = vec.size();
94  result->addAxis(FixedBinAxis("axis0", length, 0.0, static_cast<double>(length)));
95  result->setRawDataVector(vec);
96  return result;
97 }

Friends And Related Function Documentation

◆ createData

template<class T >
ReturnType<T> createData ( const T &  vec)
friend

Creates OutputData array from input vector.

Definition at line 65 of file ArrayUtils.h.

66 {
67  constexpr const int size = CreateDataImpl::nDim<T>::value;
68  static_assert(
69  size == 1 || size == 2,
70  "Error in ArrayUtils::createData: invalid dimensionality or type of the input argument");
71  static_assert(std::is_same<CreateDataImpl::ReturnType<T>,
72  decltype(CreateDataImpl::createDataImpl(vec))>::value,
73  "Error in ArrayUtils::createData: invalid return type.");
75 }
static std::unique_ptr< OutputData< T > > createDataImpl(const std::vector< T > &vec)
Definition: ArrayUtils.h:90

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