BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ArrayUtils.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Device/Data/ArrayUtils.h
6 //! @brief Defines various functions to interact from numpy on Python side
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_DEVICE_DATA_ARRAYUTILS_H
21 #define BORNAGAIN_DEVICE_DATA_ARRAYUTILS_H
22 
23 #include "Device/Data/Datafield.h"
24 #include <memory>
25 #include <vector>
26 
27 //! Array utility functions getShape
28 
29 namespace DataUtils::Array {
30 
31 //! Returns shape nrows, ncols of 2D array.
32 std::pair<size_t, size_t> getShape(const std::vector<std::vector<double>>& data);
33 
34 std::unique_ptr<Datafield> createPField1D(const std::vector<double>& vec);
35 
36 std::unique_ptr<Datafield> createPField2D(const std::vector<std::vector<double>>& vec);
37 
38 //! Creates 1D vector from Datafield.
39 std::vector<double> createVector1D(const Datafield& data);
40 
41 //! Creates 2D vector from Datafield.
42 std::vector<std::vector<double>> createVector2D(const Datafield& data);
43 
44 } // namespace DataUtils::Array
45 
46 #endif // BORNAGAIN_DEVICE_DATA_ARRAYUTILS_H
47 #endif // USER_API
Defines and implements templated class Datafield.
Stores radiation power per bin.
Definition: Datafield.h:30
Array utility functions getShape.
Definition: ArrayUtils.h:29
std::pair< size_t, size_t > getShape(const std::vector< std::vector< double >> &data)
Returns shape nrows, ncols of 2D array.
Definition: ArrayUtils.cpp:20
std::vector< double > createVector1D(const Datafield &data)
Creates 1D vector from Datafield.
Definition: ArrayUtils.cpp:64
std::vector< std::vector< double > > createVector2D(const Datafield &data)
Creates 2D vector from Datafield.
Definition: ArrayUtils.cpp:73
std::unique_ptr< Datafield > createPField1D(const std::vector< double > &vec)
Definition: ArrayUtils.cpp:32
std::unique_ptr< Datafield > createPField2D(const std::vector< std::vector< double >> &vec)
Definition: ArrayUtils.cpp:40