BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ArrayUtils::CreateDataImpl Class Reference
Collaboration diagram for ArrayUtils::CreateDataImpl:

Classes

struct  baseClass
 
struct  baseClass< std::vector< T, A > >
 
struct  nDim
 
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< T > &vec)
 
template<class T >
static std::unique_ptr< OutputData< T > > createDataImpl (const std::vector< std::vector< T >> &vec)
 

Friends

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

Detailed Description

Definition at line 30 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 49 of file ArrayUtils.h.

Member Function Documentation

◆ createDataImpl() [1/2]

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

Definition at line 86 of file ArrayUtils.h.

87 {
88  auto result = std::make_unique<OutputData<T>>();
89  const size_t length = vec.size();
90  result->addAxis(FixedBinAxis("axis0", length, 0.0, static_cast<double>(length)));
91  result->setRawDataVector(vec);
92  return result;
93 }
Axis with fixed bin size.
Definition: FixedBinAxis.h:24

References anonymous_namespace{BoxCompositionBuilder.cpp}::length.

◆ createDataImpl() [2/2]

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

Definition at line 97 of file ArrayUtils.h.

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

References ArrayUtils::getShape().

Here is the call graph for this function:

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 61 of file ArrayUtils.h.

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

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