//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Base/Py/ArrayWrapper.cpp
//! @brief     Implements ArrayWrapper classes.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "ArrayWrapper.h"

#ifdef BORNAGAIN_PYTHON

Arrayf64Wrapper::Arrayf64Wrapper(const std::size_t rank, const int* dims,
                                 const std::vector<double>* array_ptr, const bool copy_data)
{
    // NOTE: std::vector may have zero size.

    // check validity
    if (!array_ptr || rank < 1 || !dims)
        return;

    for (std::size_t i_d = 0; i_d < rank; ++i_d)
        if (dims[i_d] < 1)
            return;

    // initialize the array descriptor
    m_dims.resize(rank);
    for (std::size_t i_d = 0; i_d < rank; ++i_d)
        m_dims[i_d] = dims[i_d];

    if (copy_data) {
        // clone the data
        m_array = *array_ptr;
        m_array_ptr = nullptr;
    } else {
        m_array_ptr = array_ptr;
    }
}

#endif // BORNAGAIN_PYTHON
