17 #include <pybind11/numpy.h>
24 template <
class TDataType>
27 pybind11::array::c_style
30 template <
class TDataType>
32 const std::size_t NumberOfEntities,
33 const std::vector<std::size_t>& rShape)
35 const std::size_t size = std::accumulate(rShape.begin(),
38 [](std::size_t
left, std::size_t right) {return left * right;});
40 TDataType* array =
new TDataType[size * NumberOfEntities];
41 pybind11::capsule release(array, [](
void*
a) {
42 delete[]
reinterpret_cast<TDataType*
>(
a);
49 std::vector<std::size_t> c_shape(rShape.size() + 1);
50 c_shape[0] = NumberOfEntities;
51 std::copy(rShape.begin(), rShape.end(), c_shape.begin() + 1);
55 std::vector<std::size_t> strides(c_shape.size());
56 std::size_t stride_items = 1;
57 for (
int i = c_shape.size() - 1;
i >= 0; --
i) {
58 strides[
i] =
sizeof(
double) * stride_items;
59 stride_items *= c_shape[
i];
70 template <
class TDataType>
72 TDataType
const* pBegin,
73 TDataType
const* pEnd,
74 const std::vector<std::size_t>& rShape)
76 auto array = AllocateNumpyArray<TDataType>(rShape);
80 array.mutable_data());
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
Definition: add_distributed_sparse_matrices_to_python.cpp:28
pybind11::array_t< TDataType > MakeNumpyArray(TDataType const *pBegin, TDataType const *pEnd, const std::vector< std::size_t > &rShape)
Definition: numpy_utils.h:71
pybind11::array_t< TDataType, pybind11::array::c_style > ContiguousNumpyArray
Definition: numpy_utils.h:28
pybind11::array_t< TDataType > AllocateNumpyArray(const std::size_t NumberOfEntities, const std::vector< std::size_t > &rShape)
Definition: numpy_utils.h:31
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
left
Definition: exact_hinsberg_test.py:140
a
Definition: generate_stokes_twofluid_element.py:77
integer i
Definition: TensorModule.f:17